/** A simple Brain implementation. bestMove() iterates through all the possible x values and rotations to play a particular piece (there are only around 10-30 ways to play a piece). For each play, it uses the rateBoard() message to rate how good the resulting board is and it just remembers the play with the lowest score. Undo() is used to back-out each play before trying the next. To experiment with writing your own brain -- just subclass off LameBrain and override rateBoard(). */ public class LameBrain implements Brain { /** Given a piece and a board, returns a move object that represents the best play for that piece, or returns null if no play is possible. See the Brain interface for details. */ public Brain.Move bestMove(Board board, Piece piece, int limitHeight, Brain.Move move) { // Allocate a move object if necessary if (move==null) move = new Brain.Move(); double bestScore = 1e20; int bestX = 0; int bestY = 0; Piece bestPiece = null; Piece current = piece; // loop through all the rotations while (true) { final int yBound = limitHeight - current.getHeight()+1; final int xBound = board.getWidth() - current.getWidth()+1; // For current rotation, try all the possible columns for (int x = 0; x=0) { if (!board.getGrid(x,y)) { holes++; } y--; } } double avgHeight = ((double)sumHeight)/width; // Add up the counts to make an overall score // The weights, 8, 40, etc., are just made up numbers that appear to work return (8*maxHeight + 40*avgHeight + 1.25*holes); } }