Answer the question
In order to leave comments, you need to log in
Optimizing the polyomino inference algorithm?
I have a two dimensional array
{0, 0, 0, 0, 0},
{0, 0, 1, 0, 0},
{0, 0, 2, 0, 0}, // 2 is rotation center, center of 5x5 array
{0, 0, 1, 0, 0},
{0, 0, 1, 0, 0}
// он же
00000
00010
00210
00100
00000
if (2 == piece) {
setChar(pX, pY, pieceSymbol);
}
// piece parts, drawing calculated from rotation point which is always at array[2][2](3-d from all sides) position in array[5][5]
if (1 == piece) {
// [0][0]
if (0 == x, 0 == y) {
setChar(pX - 2, pY - 2, pieceSymbol);
}
else if (0 == x, 1 == y) {
setChar(pX - 2, pY + 1, pieceSymbol);
}
else if (0 == x, 2 == y) {
setChar(pX - 2, pY, pieceSymbol);
}
else if (0 == x, 3 == y) {
setChar(pX - 2, pY + 1, pieceSymbol);
}
else if (0 == x, 4 == y) {
setChar(pX - 2, pY + 2, pieceSymbol);
}
// [1][0]
else if (1 == x, 0 == y) {
setChar(pX - 1, pY - 2, pieceSymbol);
}
else if (1 == x, 1 == y) {
setChar(pX - 1, pY - 1, pieceSymbol);
}
else if (1 == x, 2 == y) {
setChar(pX - 1, pY, pieceSymbol);
}
else if (1 == x, 3 == y) {
setChar(pX - 1, pY + 1, pieceSymbol);
}
else if (1 == x, 4 == y) {
setChar(pX - 1, pY + 2, pieceSymbol);
}
// [2][0]
else if (2 == x, 0 == y) {
setChar(pX, pY - 2, pieceSymbol);
}
else if (2 == x, 1 == y) {
setChar(pX, pY - 1, pieceSymbol);
}
else if (2 == x, 2 == y) {
setChar(pX, pY, pieceSymbol);
}
else if (2 == x, 3 == y) {
setChar(pX, pY + 1, pieceSymbol);
}
else if (2 == x, 4 == y) {
setChar(pX, pY + 2, pieceSymbol);
}
// [3][0]
else if (3 == x, 0 == y) {
setChar(pX+ 1, pY - 2, pieceSymbol);
}
else if (3 == x, 1 == y) {
setChar(pX+ 1, pY - 1, pieceSymbol);
}
else if (3 == x, 2 == y) {
setChar(pX+ 1, pY, pieceSymbol);
}
else if (3 == x, 3 == y) {
setChar(pX+ 1, pY + 1, pieceSymbol);
}
else if (3 == x, 4 == y) {
setChar(pX+ 1, pY + 2, pieceSymbol);
}
....
Answer the question
In order to leave comments, you need to log in
The meaning of all these conditions is only to translate from coordinates centered at (0, 0) to coordinates centered at (2, 2)?
It won't replace all if's?setChar(pX - 2 + x, pY - 2 + y, pieceSymbol);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question