* @param s - scheme
* @return the color of blocks which can be add in the fixed fields or -1 if
* the blocks can't be inserted.
*/
private static int goodPosition(int mix, int x, int y, Scheme s) {
Board board = s.start; int color=-1;
switch (mix) {
case COMBINATION_2H: {
if (board.getType(x, y) == Board.CONCRETE) color = board.getColor(x, y);
if (board.getType(x+1, y) == Board.CONCRETE)
if (color==-1 || board.getColor(x+1, y)==color) color = board.getColor(x+1, y);
else return -1;
if (color==-1) color = rand.nextInt(Board.NUM_COLORS);
boolean canMove = false;
boolean block1 = canInsertBlock(x,y,color, true, board, new int[]{0,0,0,0});
if (block1) insertBlock(x, y, color, board);
boolean block2 = canInsertBlock(x+1,y,color, true, board, new int[]{0,0,0,1});
if (block2) insertBlock(x+1, y, color, board);
if (block1 && block2)
canMove = MixGenerator.canMoveBlock(x, y, true, s) ||
MixGenerator.canMoveBlock(x+1, y, true, s);
if (block2) deleteBlock(x+1,y, board);
if (block1) deleteBlock(x,y, board);
if (canMove) return color;
else return -1;
}
case COMBINATION_2V: {
if (board.getType(x, y) == Board.CONCRETE) color = board.getColor(x, y);
if (board.getType(x, y-1) == Board.CONCRETE)
if (color==-1 || board.getColor(x, y-1)==color) color = board.getColor(x, y-1);
else return -1;
if (color==-1) color = rand.nextInt(Board.NUM_COLORS);
boolean canMove = false;
boolean block1 = canInsertBlock(x,y,color, false, board, new int[]{0,0,0,0});
if (block1) insertBlock(x, y, color, board);
boolean block2 = canInsertBlock(x,y-1,color, false, board, new int[]{0,0,1,0});
if (block2) insertBlock(x, y-1, color, board);
if (block1 && block2)
canMove = MixGenerator.canMoveBlock(x, y-1, true, s);
if (block2) deleteBlock(x,y-1, board);
if (block1) deleteBlock(x,y, board);
if (canMove) return color;
else return -1;
}
case COMBINATION_3LV: {
if (board.getType(x, y) == Board.CONCRETE) color = board.getColor(x, y);
if (board.getType(x, y-1) == Board.CONCRETE)
if (color==-1 || board.getColor(x, y-1)==color) color = board.getColor(x, y-1);
else return -1;
if (board.getType(x-1, y-1) == Board.CONCRETE)
if (color==-1 || board.getColor(x-1, y-1)==color) color = board.getColor(x-1, y-1);
else return -1;
if (color==-1) color = rand.nextInt(Board.NUM_COLORS);
boolean canMove = false;
boolean block1 = canInsertBlock(x,y,color, false, board, new int[]{0,0,0,0});
if (block1) insertBlock(x, y, color, board);
boolean block2 = canInsertBlock(x,y-1,color, false, board, new int[]{0,0,1,0});
if (block2) insertBlock(x, y-1, color, board);
boolean block3 = canInsertBlock(x-1,y-1,color, true, board, new int[]{0,1,0,0});
if (block3) insertBlock(x-1, y-1, color, board);
if (block1 && block2 && block3)
canMove = MixGenerator.canMoveBlock(x, y-1, true, s);
if (block3) deleteBlock(x-1,y-1, board);
if (block2) deleteBlock(x,y-1, board);
if (block1) deleteBlock(x,y, board);
if (canMove) return color;
return -1;
}
case COMBINATION_3RV: {
if (board.getType(x, y) == Board.CONCRETE) color = board.getColor(x, y);
if (board.getType(x, y-1) == Board.CONCRETE)
if (color==-1 || board.getColor(x, y-1)==color) color = board.getColor(x, y-1);
else return -1;
if (board.getType(x+1, y-1) == Board.CONCRETE)
if (color==-1 || board.getColor(x+1, y-1)==color) color = board.getColor(x+1, y-1);
else return -1;
if (color==-1) color = rand.nextInt(Board.NUM_COLORS);
boolean canMove = false;
boolean block1 = canInsertBlock(x,y,color, false, board, new int[]{0,0,0,0});
if (block1) insertBlock(x, y, color, board);
boolean block2 = canInsertBlock(x,y-1,color, false, board, new int[]{0,0,1,0});
if (block2) insertBlock(x, y-1, color, board);
boolean block3 = canInsertBlock(x+1,y-1,color, true, board, new int[]{0,0,0,1});
if (block3) insertBlock(x+1, y-1, color, board);
if (block1 && block2 && block3)
canMove = MixGenerator.canMoveBlock(x, y-1, true, s);
if (block3) deleteBlock(x+1,y-1, board);
if (block2) deleteBlock(x,y-1, board);
if (block1) deleteBlock(x,y, board);
if (canMove) return color;
else return -1;
}
case COMBINATION_3H: {
if (board.getType(x, y) == Board.CONCRETE) color = board.getColor(x, y);
if (board.getType(x+1, y) == Board.CONCRETE)
if (color==-1 || board.getColor(x+1, y)==color) color = board.getColor(x+1, y);
else return -1;
if (board.getType(x+2, y) == Board.CONCRETE)
if (color==-1 || board.getColor(x+2, y)==color) color = board.getColor(x+2, y);
else return -1;
if (color==-1) color = rand.nextInt(Board.NUM_COLORS);
boolean canMove = false;