Mert Us Matthew Hannay Logan Starr
Dependencies: mbed 4DGL-uLCD-SE
Diff: main.cpp
- Revision:
- 15:cae96e8b62a3
- Parent:
- 14:f390d08e5f92
- Parent:
- 13:3c6da0590428
diff -r f390d08e5f92 -r cae96e8b62a3 main.cpp --- a/main.cpp Sun Dec 04 09:32:07 2022 +0000 +++ b/main.cpp Sun Dec 04 19:48:33 2022 +0000 @@ -3,9 +3,8 @@ #include <vector> uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin; - +Serial Blue(p13, p14); DigitalOut myLed(LED1); -Serial Blue(p13, p14); enum Piece {e, wK, bK, wQ, bQ, wR, bR, wB, bB, wN, bN, w, b}; std::vector<Piece> whitePieces; @@ -42,7 +41,8 @@ //automatic read on RHS operator int (); //index to any switch array style - bool operator[](int index) { + bool operator[](int index) + { return _pins[index]; }; private: @@ -85,62 +85,68 @@ } const float KING_POSITION_VALUES[] = {2.0, 3.0, 1.0, 0.0, 0.0, 1.0, 3.0, 2,0, - 2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, - -1.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -1.0, - -2.0, -3.0, -3.0, -4.0, -4.0, -3.0, -3.0, -2,0, - -3.0, -4.0, -4.0, -5.0, -5.0, -4.0, -4.0, -3.0, - -3.0, -4.0, -4.0, -5.0, -5.0, -4.0, -4.0, -3.0, - -3.0, -4.0, -4.0, -5.0, -5.0, -4.0, -4.0, -3.0, - -3.0, -4.0, -4.0, -5.0, -5.0, -4.0, -4.0, -3.0}; - + 2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, + -1.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -1.0, + -2.0, -3.0, -3.0, -4.0, -4.0, -3.0, -3.0, -2,0, + -3.0, -4.0, -4.0, -5.0, -5.0, -4.0, -4.0, -3.0, + -3.0, -4.0, -4.0, -5.0, -5.0, -4.0, -4.0, -3.0, + -3.0, -4.0, -4.0, -5.0, -5.0, -4.0, -4.0, -3.0, + -3.0, -4.0, -4.0, -5.0, -5.0, -4.0, -4.0, -3.0 + }; + const float QUEEN_POSITION_VALUES[] = {-2.0, -1.0, -1.0, -0.5, -0.5, -1.0, -1.0, -2.0, - -1.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, -1.0, - -1.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, -1.0, - 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.0, -0.5, - -0.5, 0.0, 0.5, 0.5, 0.5, 0.5, 0.0, -0.5, - -1.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.0, -1.0, - -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, - -2.0, -1.0, -1.0, -0.5, -0.5, -1.0, -1.0, -2.0}; + -1.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, -1.0, + -1.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, -1.0, + 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.0, -0.5, + -0.5, 0.0, 0.5, 0.5, 0.5, 0.5, 0.0, -0.5, + -1.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.0, -1.0, + -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, + -2.0, -1.0, -1.0, -0.5, -0.5, -1.0, -1.0, -2.0 + }; const float ROOK_POSITION_VALUES[] = {0.0, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, - -0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.5, - -0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.5, - -0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.5, - -0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.5, - -0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.5, - 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + -0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.5, + -0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.5, + -0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.5, + -0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.5, + -0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.5, + 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 + }; const float BISHOP_POSITION_VALUES[] = {-2.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -2.0, - -1.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, -1.0, - -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, - -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, -1.0, - -1.0, 0.5, 0.5, 1.0, 1.0, 0.5, 0.5, -1.0, - -1.0, 0.0, 0.5, 1.0, 1.0, 0.5, 0.0, -1.0, - -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, - -2.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -2.0}; + -1.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, -1.0, + -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, + -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, -1.0, + -1.0, 0.5, 0.5, 1.0, 1.0, 0.5, 0.5, -1.0, + -1.0, 0.0, 0.5, 1.0, 1.0, 0.5, 0.0, -1.0, + -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, + -2.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -2.0 + }; const float KNIGHT_POSITION_VALUES[] = {-5.0, -4.0, -3.0, -3.0, -3.0, -3.0, -4.0, -5.0, - -4.0, -2.0, 0.0, 0.5, 0.5, 0.0, -2.0, -4.0, - -3.0, 0.5, 1.0, 1.5, 1.5, 1.0, 0.5, -3.0, - -3.0, 0.0, 1.5, 2.0, 2.0, 1.5, 0.0, -3.0, - -3.0, 0.5, 1.5, 2.0, 2.0, 1.5, 0.5, -3.0, - -3.0, 0.0, 1.0, 1.5, 1.5, 1.0, 0.0, -3.0, - -4.0, -2.0, 0.0, 0.0, 0.0, 0.0, -2.0, -4.0, - -5.0, -4.0, -3.0, -3.0, -3.0, -3.0, -4.0, -5.0}; + -4.0, -2.0, 0.0, 0.5, 0.5, 0.0, -2.0, -4.0, + -3.0, 0.5, 1.0, 1.5, 1.5, 1.0, 0.5, -3.0, + -3.0, 0.0, 1.5, 2.0, 2.0, 1.5, 0.0, -3.0, + -3.0, 0.5, 1.5, 2.0, 2.0, 1.5, 0.5, -3.0, + -3.0, 0.0, 1.0, 1.5, 1.5, 1.0, 0.0, -3.0, + -4.0, -2.0, 0.0, 0.0, 0.0, 0.0, -2.0, -4.0, + -5.0, -4.0, -3.0, -3.0, -3.0, -3.0, -4.0, -5.0 + }; const float PAWN_POSITION_VALUES[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.5, 1.0, 1.0, -2.0, -2.0, 1.0, 1.0, 0.5, - 0.5, -0.5, -1.0, 0.0, 0.0, -1.0, -0.5, 0.5, - 0.0, 0.0, 0.0, 2.0, 2.0, 0.0, 0.0, 0.0, - 0.5, 0.5, 1.0, 2.5, 2.5, 1.0, 0.5, 0.5, - 1.0, 1.0, 2.0, 3.0, 3.0, 2.0, 1.0, 1.0, - 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + 0.5, 1.0, 1.0, -2.0, -2.0, 1.0, 1.0, 0.5, + 0.5, -0.5, -1.0, 0.0, 0.0, -1.0, -0.5, 0.5, + 0.0, 0.0, 0.0, 2.0, 2.0, 0.0, 0.0, 0.0, + 0.5, 0.5, 1.0, 2.5, 2.5, 1.0, 0.5, 0.5, + 1.0, 1.0, 2.0, 3.0, 3.0, 2.0, 1.0, 1.0, + 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 + }; class BoardState { private: Piece array[64]; - // These values are for white pieces, need to be inverted + // These values are for white pieces, need to be inverted // when making calculations for black pieces. static const float PAWN_VALUE = 10.0; static const float KNIGHT_VALUE = 30.0; @@ -150,7 +156,7 @@ static const float KING_VALUE = 900.0; public: BoardState() {} - + // calculates the advantage difference for the board state float calculateBoardState() { @@ -198,7 +204,7 @@ break; default: break; - } + } } return sum; } @@ -212,7 +218,14 @@ // puts a piece at a given location void placePiece(Piece piece, int row, int column) { - array[column + 8 * row] = piece; + // pawn promotion handling + if (piece == w && row == 7) { + array[column + 8 * row] = wQ; + } else if (piece == b && row == 0) { + array[column + 8 * row] = bQ; + } else { + array[column + 8 * row] = piece; + } } /* removes a piece from the set position of the board @@ -787,140 +800,145 @@ static const int HOVER_COLOR = 0x0000ff; static const int SELECTED_COLOR = 0xff8800; static const int MOVE_COLOR = 0xff00ff; - - // gets the pixel coordinates of the top left of the square - static pixelCoord getTopLeftOfSquare(boardPos pos) - { - return getTopLeftOfSquare(pos.row, pos.column); - } - static pixelCoord getTopLeftOfSquare(int row, int column) - { - pixelCoord topLeft; - topLeft.x = 16 * column; - topLeft.y = 112 - 16 * row; - return topLeft; + + // gets the pixel coordinates of the top left of the square + static pixelCoord getTopLeftOfSquare(boardPos pos) + { + return getTopLeftOfSquare(pos.row, pos.column); + } + static pixelCoord getTopLeftOfSquare(int row, int column) + { + pixelCoord topLeft; + topLeft.x = 16 * column; + topLeft.y = 112 - 16 * row; + return topLeft; + } + + // piece sprites (12 x 12) + static void drawPawn(int row, int column, bool white, bool light) + { + int X = white ? 0xffffff : 0x000000; + int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR; + int sprite[144] = {_, _, _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, X, X, _, _, _, _, _, + _, _, _, _, X, X, X, X, _, _, _, _, + _, _, _, _, X, X, X, X, _, _, _, _, + _, _, _, _, _, X, X, _, _, _, _, _, + _, _, _, _, _, X, X, _, _, _, _, _, + _, _, _, _, X, X, X, X, _, _, _, _, + _, _, X, X, X, X, X, X, X, X, _, _, + _, _, X, X, X, X, X, X, X, X, _, _ + }; + pixelCoord tl = getTopLeftOfSquare(row, column); + uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite); + } + + static void drawRook(int row, int column, bool white, bool light) + { + int X = white ? 0xffffff : 0x000000; + int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR; + int sprite[144] = {X, X, _, X, X, _, _, X, X, _, X, X, + X, X, _, X, X, _, _, X, X, _, X, X, + X, X, X, X, X, X, X, X, X, X, X, X, + X, X, X, X, X, X, X, X, X, X, X, X, + _, X, X, X, _, X, X, _, X, X, X, _, + _, X, X, X, _, X, X, _, X, X, X, _, + _, _, X, X, _, X, X, _, X, X, _, _, + _, _, X, X, _, X, X, _, X, X, _, _, + _, _, X, X, _, X, X, _, X, X, _, _, + _, X, X, X, X, X, X, X, X, X, X, _, + X, X, X, X, X, X, X, X, X, X, X, X, + X, X, X, X, X, X, X, X, X, X, X, X + }; + pixelCoord tl = getTopLeftOfSquare(row, column); + uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite); } - // piece sprites (12 x 12) - static void drawPawn(int row, int column, bool white, bool light) - { - int X = white ? 0xffffff : 0x000000; - int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR; - int sprite[144] = {_, _, _, _, _, _, _, _, _, _, _, _, - _, _, _, _, _, _, _, _, _, _, _, _, - _, _, _, _, _, _, _, _, _, _, _, _, - _, _, _, _, _, _, _, _, _, _, _, _, - _, _, _, _, _, X, X, _, _, _, _, _, - _, _, _, _, X, X, X, X, _, _, _, _, - _, _, _, _, X, X, X, X, _, _, _, _, - _, _, _, _, _, X, X, _, _, _, _, _, - _, _, _, _, _, X, X, _, _, _, _, _, - _, _, _, _, X, X, X, X, _, _, _, _, - _, _, X, X, X, X, X, X, X, X, _, _, - _, _, X, X, X, X, X, X, X, X, _, _ - }; - pixelCoord tl = getTopLeftOfSquare(row, column); - uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite); - } - static void drawRook(int row, int column, bool white, bool light) - { - int X = white ? 0xffffff : 0x000000; - int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR; - int sprite[144] = {X, X, _, X, X, _, _, X, X, _, X, X, - X, X, _, X, X, _, _, X, X, _, X, X, - X, X, X, X, X, X, X, X, X, X, X, X, - X, X, X, X, X, X, X, X, X, X, X, X, - _, X, X, X, _, X, X, _, X, X, X, _, - _, X, X, X, _, X, X, _, X, X, X, _, - _, _, X, X, _, X, X, _, X, X, _, _, - _, _, X, X, _, X, X, _, X, X, _, _, - _, _, X, X, _, X, X, _, X, X, _, _, - _, X, X, X, X, X, X, X, X, X, X, _, - X, X, X, X, X, X, X, X, X, X, X, X, - X, X, X, X, X, X, X, X, X, X, X, X - }; - pixelCoord tl = getTopLeftOfSquare(row, column); - uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite); - } - static void drawKnight(int row, int column, bool white, bool light) - { - int X = white ? 0xffffff : 0x000000; - int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR; - int sprite[144] = {_, _, _, _, _, _, _, _, _, _, _, _, - _, _, _, _, _, X, X, _, X, X, _, _, - _, _, _, _, _, X, X, _, X, X, _, _, - _, _, _, X, X, X, X, X, X, _, _, _, - _, _, X, X, X, X, X, _, X, _, _, _, - _, _, X, X, X, X, X, X, X, _, _, _, - _, _, _, _, _, X, X, X, X, _, _, _, - _, _, _, _, X, X, X, X, X, _, _, _, - _, _, _, X, X, X, X, X, X, X, _, _, - _, _, X, X, X, X, X, X, X, X, _, _, - _, X, X, X, X, X, X, X, X, X, X, _, - _, X, X, X, X, X, X, X, X, X, X, _ - }; - pixelCoord tl = getTopLeftOfSquare(row, column); - uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite); - } - static void drawBishop(int row, int column, bool white, bool light) - { - int X = white ? 0xffffff : 0x000000; - int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR; - int sprite[144] = {_, _, _, _, _, X, X, _, _, _, _, _, - _, _, _, _, X, X, X, _, _, _, _, _, - _, _, _, X, X, X, _, _, X, _, _, _, - _, _, _, X, X, _, _, X, X, _, _, _, - _, _, _, X, X, X, X, X, X, _, _, _, - _, _, _, _, X, X, X, X, _, _, _, _, - _, _, _, _, _, X, X, _, _, _, _, _, - _, _, _, _, X, X, X, X, _, _, _, _, - _, _, _, X, X, X, X, X, X, _, _, _, - _, _, _, X, X, X, X, X, X, _, _, _, - _, _, X, X, X, X, X, X, X, X, _, _, - _, _, X, X, X, X, X, X, X, X, _, _ - }; - pixelCoord tl = getTopLeftOfSquare(row, column); - uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite); - } - static void drawQueen(int row, int column, bool white, bool light) - { - int X = white ? 0xffffff : 0x000000; - int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR; - int sprite[144] = {_, _, _, _, _, X, X, _, _, _, _, _, - _, _, X, _, _, X, X, _, _, X, _, _, - X, _, X, X, _, X, X, _, X, X, _, X, - X, _, X, X, _, X, X, _, X, X, _, X, - X, _, X, X, _, X, X, _, X, X, _, X, - X, X, X, X, X, X, X, X, X, X, X, X, - X, X, X, X, X, X, X, X, X, X, X, X, - X, X, _, X, X, X, X, X, X, _, X, X, - X, X, X, X, _, X, X, _, X, X, X, X, - _, X, X, X, X, X, X, X, X, X, X, _, - _, _, X, X, X, X, X, X, X, X, _, _, - _, X, X, X, X, X, X, X, X, X, X, _ - }; - pixelCoord tl = getTopLeftOfSquare(row, column); - uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite); - } - static void drawKing(int row, int column, bool white, bool light) - { - int X = white ? 0xffffff : 0x000000; - int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR; - int sprite[144] = {_, _, _, _, _, X, X, _, _, _, _, _, - _, _, _, _, _, X, X, _, _, _, _, _, - _, _, _, X, X, X, X, X, X, _, _, _, - _, _, _, X, X, X, X, X, X, _, _, _, - X, X, _, _, _, X, X, _, _, _, X, X, - X, X, X, X, _, X, X, _, X, X, X, X, - X, _, X, X, X, X, X, X, X, X, _, X, - X, X, X, X, X, X, X, X, X, X, X, X, - X, X, X, _, X, X, X, X, _, X, X, X, - _, X, X, X, X, X, X, X, X, X, X, _, - _, _, X, X, X, _, _, X, X, X, _, _, - _, X, X, X, X, X, X, X, X, X, X, _ - }; - pixelCoord tl = getTopLeftOfSquare(row, column); - uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite); + static void drawKnight(int row, int column, bool white, bool light) + { + int X = white ? 0xffffff : 0x000000; + int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR; + int sprite[144] = {_, _, _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, X, X, _, X, X, _, _, + _, _, _, _, _, X, X, _, X, X, _, _, + _, _, _, X, X, X, X, X, X, _, _, _, + _, _, X, X, X, X, X, _, X, _, _, _, + _, _, X, X, X, X, X, X, X, _, _, _, + _, _, _, _, _, X, X, X, X, _, _, _, + _, _, _, _, X, X, X, X, X, _, _, _, + _, _, _, X, X, X, X, X, X, X, _, _, + _, _, X, X, X, X, X, X, X, X, _, _, + _, X, X, X, X, X, X, X, X, X, X, _, + _, X, X, X, X, X, X, X, X, X, X, _ + }; + pixelCoord tl = getTopLeftOfSquare(row, column); + uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite); + } + + static void drawBishop(int row, int column, bool white, bool light) + { + int X = white ? 0xffffff : 0x000000; + int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR; + int sprite[144] = {_, _, _, _, _, X, X, _, _, _, _, _, + _, _, _, _, X, X, X, _, _, _, _, _, + _, _, _, X, X, X, _, _, X, _, _, _, + _, _, _, X, X, _, _, X, X, _, _, _, + _, _, _, X, X, X, X, X, X, _, _, _, + _, _, _, _, X, X, X, X, _, _, _, _, + _, _, _, _, _, X, X, _, _, _, _, _, + _, _, _, _, X, X, X, X, _, _, _, _, + _, _, _, X, X, X, X, X, X, _, _, _, + _, _, _, X, X, X, X, X, X, _, _, _, + _, _, X, X, X, X, X, X, X, X, _, _, + _, _, X, X, X, X, X, X, X, X, _, _ + }; + pixelCoord tl = getTopLeftOfSquare(row, column); + uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite); + } + + static void drawQueen(int row, int column, bool white, bool light) + { + int X = white ? 0xffffff : 0x000000; + int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR; + int sprite[144] = {_, _, _, _, _, X, X, _, _, _, _, _, + _, _, X, _, _, X, X, _, _, X, _, _, + X, _, X, X, _, X, X, _, X, X, _, X, + X, _, X, X, _, X, X, _, X, X, _, X, + X, _, X, X, _, X, X, _, X, X, _, X, + X, X, X, X, X, X, X, X, X, X, X, X, + X, X, X, X, X, X, X, X, X, X, X, X, + X, X, _, X, X, X, X, X, X, _, X, X, + X, X, X, X, _, X, X, _, X, X, X, X, + _, X, X, X, X, X, X, X, X, X, X, _, + _, _, X, X, X, X, X, X, X, X, _, _, + _, X, X, X, X, X, X, X, X, X, X, _ + }; + pixelCoord tl = getTopLeftOfSquare(row, column); + uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite); + } + + static void drawKing(int row, int column, bool white, bool light) + { + int X = white ? 0xffffff : 0x000000; + int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR; + int sprite[144] = {_, _, _, _, _, X, X, _, _, _, _, _, + _, _, _, _, _, X, X, _, _, _, _, _, + _, _, _, X, X, X, X, X, X, _, _, _, + _, _, _, X, X, X, X, X, X, _, _, _, + X, X, _, _, _, X, X, _, _, _, X, X, + X, X, X, X, _, X, X, _, X, X, X, X, + X, _, X, X, X, X, X, X, X, X, _, X, + X, X, X, X, X, X, X, X, X, X, X, X, + X, X, X, _, X, X, X, X, _, X, X, X, + _, X, X, X, X, X, X, X, X, X, X, _, + _, _, X, X, X, _, _, X, X, X, _, _, + _, X, X, X, X, X, X, X, X, X, X, _ + }; + pixelCoord tl = getTopLeftOfSquare(row, column); + uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite); } public: @@ -996,31 +1014,38 @@ { boardState.placePiece(piece, row, column); pixelCoord tl = getTopLeftOfSquare(row, column); - switch(piece) { - case wK: - case bK: - drawKing(row, column, piece==wK, (row+column)%2); - break; - case wQ: - case bQ: - drawQueen(row, column, piece==wQ, (row+column)%2); - break; - case wB: - case bB: - drawBishop(row, column, piece==wB, (row+column)%2); - break; - case wN: - case bN: - drawKnight(row, column, piece==wN, (row+column)%2); - break; - case wR: - case bR: - drawRook(row, column, piece==wR, (row+column)%2); - break; - case w: - case b: - drawPawn(row, column, piece==w, (row+column)%2); - break; + switch(piece) { + case wK: + case bK: + drawKing(row, column, piece==wK, (row+column)%2); + break; + case wQ: + case bQ: + drawQueen(row, column, piece==wQ, (row+column)%2); + break; + case wB: + case bB: + drawBishop(row, column, piece==wB, (row+column)%2); + break; + case wN: + case bN: + drawKnight(row, column, piece==wN, (row+column)%2); + break; + case wR: + case bR: + drawRook(row, column, piece==wR, (row+column)%2); + break; + case w: + case b: + if (piece == w && row == 7) { + drawQueen(row, column, true, (row+column)%2); + } else if (piece == b && row == 0) { + drawQueen(row, column, false, (row+column)%2); + } else { + drawPawn(row, column, piece==w, (row+column)%2); + } + break; + } } @@ -1204,8 +1229,7 @@ state = state == whiteSelecting ? whitePickedUp : blackPickedUp; } } else { - selectedPos = (boardPos) - { + selectedPos = (boardPos) { 10, 10 }; } @@ -1239,8 +1263,7 @@ gameBoard.unselectSquare(selectedPos); gameBoard.hoverSquare(cursorPos); possibleMoves.clear(); - selectedPos = (boardPos) - { + selectedPos = (boardPos) { 10, 10 }; break; @@ -1309,7 +1332,7 @@ } } } - + if (bestMoveValueDepth1 < bestMoveValueDepth0) { bestMoveSourceDepth0 = currSourceDepth0; bestMoveDestDepth0 = *it; @@ -1337,7 +1360,7 @@ volatile int bhit = 0; enum statetype {start = 0, got_exclm, got_B, got_num, got_hit}; statetype bluetooth_state = start; - + void parse_message() { switch (bluetooth_state) { @@ -1371,7 +1394,6 @@ int main() { - //gameBoard = GameBoard(); whitePieces.push_back(wK); whitePieces.push_back(wQ); whitePieces.push_back(wB); @@ -1384,8 +1406,10 @@ blackPieces.push_back(bN); blackPieces.push_back(bR); blackPieces.push_back(b); + moveCursor(0, 0); Blue.attach(&parse_message,Serial::RxIrq); + while (1) { if (state == blackAI) { joyStickPressed();