Mert Us Matthew Hannay Logan Starr

Dependencies:   mbed 4DGL-uLCD-SE

Committer:
mhannay3
Date:
Fri Nov 11 22:48:30 2022 +0000
Revision:
5:b553c51b3b85
Parent:
4:5798e4062350
Child:
6:1c4dd5e24b8d
fixed compile issues and implemented graphics

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mhannay3 5:b553c51b3b85 1 #include "mbed.h"
mhannay3 5:b553c51b3b85 2 #include "uLCD_4DGL.h"
mhannay3 1:cd78922f70fa 3
mhannay3 5:b553c51b3b85 4 uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin;
mhannay3 5:b553c51b3b85 5
mhannay3 5:b553c51b3b85 6 enum Piece {e, wK, bK, wQ, bQ, wR, bR, wB, bB, wN, bN, w, b};
mhannay3 1:cd78922f70fa 7
mhannay3 1:cd78922f70fa 8 struct coord {
mhannay3 1:cd78922f70fa 9 uint8_t x;
mhannay3 1:cd78922f70fa 10 uint8_t y;
mhannay3 5:b553c51b3b85 11 };
mhannay3 1:cd78922f70fa 12
mhannay3 5:b553c51b3b85 13 class BoardState
mhannay3 5:b553c51b3b85 14 {
mhannay3 5:b553c51b3b85 15 private:
mhannay3 5:b553c51b3b85 16 Piece array[64];
mhannay3 5:b553c51b3b85 17 public:
mhannay3 4:5798e4062350 18 // calculates the advantage difference for the board state
mhannay3 5:b553c51b3b85 19 float calculateBoardState()
mhannay3 5:b553c51b3b85 20 {
mhannay3 4:5798e4062350 21 return 0.0;
mhannay3 4:5798e4062350 22 }
mhannay3 5:b553c51b3b85 23
mhannay3 4:5798e4062350 24 // returns the piece at a given location
mhannay3 5:b553c51b3b85 25 Piece getPiece(int row, int column)
mhannay3 5:b553c51b3b85 26 {
mhannay3 5:b553c51b3b85 27 return array[column + 8 * row];
mhannay3 4:5798e4062350 28 }
mhannay3 4:5798e4062350 29
mhannay3 5:b553c51b3b85 30 // puts a piece at a given location
mhannay3 5:b553c51b3b85 31 void placePiece(Piece piece, int row, int column)
mhannay3 5:b553c51b3b85 32 {
mhannay3 5:b553c51b3b85 33 array[column + 8 * row] = piece;
mhannay3 4:5798e4062350 34 }
mhannay3 4:5798e4062350 35
mhannay3 4:5798e4062350 36 /* removes a piece from the set position of the board
mhannay3 4:5798e4062350 37 returns the bit representation of the piece
mhannay3 4:5798e4062350 38 */
mhannay3 5:b553c51b3b85 39 Piece removePiece(int row, int column)
mhannay3 5:b553c51b3b85 40 {
mhannay3 5:b553c51b3b85 41 Piece removedPiece = array[column + 8 * row];
mhannay3 5:b553c51b3b85 42 array[column + 8 * row] = e;
mhannay3 4:5798e4062350 43 return removedPiece;
mhannay3 1:cd78922f70fa 44 }
mhannay3 1:cd78922f70fa 45
mhannay3 1:cd78922f70fa 46 /* moves a piece from one position to another
mhannay3 1:cd78922f70fa 47 returns the captured piece
mhannay3 1:cd78922f70fa 48 */
mhannay3 5:b553c51b3b85 49 Piece movePiece(int startRow, int startColumn, int endRow, int endColumn)
mhannay3 5:b553c51b3b85 50 {
mhannay3 5:b553c51b3b85 51 Piece movingPiece = removePiece(startRow, startColumn);
mhannay3 5:b553c51b3b85 52 Piece capturedPiece = removePiece(endRow, endColumn);
mhannay3 5:b553c51b3b85 53 placePiece(movingPiece, endRow, endColumn);
mhannay3 1:cd78922f70fa 54 return capturedPiece;
mhannay3 1:cd78922f70fa 55 }
mhannay3 5:b553c51b3b85 56 };
mhannay3 1:cd78922f70fa 57
mhannay3 5:b553c51b3b85 58 class GameBoard
mhannay3 5:b553c51b3b85 59 {
mhannay3 5:b553c51b3b85 60 private:
mhannay3 5:b553c51b3b85 61 BoardState boardState;
mhannay3 5:b553c51b3b85 62 static const int BOARD_DARK_COLOR = 0x769656;
mhannay3 5:b553c51b3b85 63 static const int BOARD_LIGHT_COLOR = 0xbaca44;
mhannay3 5:b553c51b3b85 64 static const int HOVER_COLOR = 0x0000ff;
mhannay3 5:b553c51b3b85 65 static const int SELECTED_COLOR = 0xff8800;
mhannay3 5:b553c51b3b85 66
mhannay3 5:b553c51b3b85 67 // piece sprites (12 x 12)
mhannay3 5:b553c51b3b85 68 static void spritePawn(bool white, bool light, int* spriteArray)
mhannay3 5:b553c51b3b85 69 {
mhannay3 5:b553c51b3b85 70 int X = white ? 0xffffff : 0x000000;
mhannay3 5:b553c51b3b85 71 int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR;
mhannay3 5:b553c51b3b85 72 int sprite[144] = {_, _, _, _, _, _, _, _, _, _, _, _,
mhannay3 5:b553c51b3b85 73 _, _, _, _, _, _, _, _, _, _, _, _,
mhannay3 5:b553c51b3b85 74 _, _, _, _, _, _, _, _, _, _, _, _,
mhannay3 5:b553c51b3b85 75 _, _, _, _, _, _, _, _, _, _, _, _,
mhannay3 5:b553c51b3b85 76 _, _, _, _, _, X, X, _, _, _, _, _,
mhannay3 5:b553c51b3b85 77 _, _, _, _, X, X, X, X, _, _, _, _,
mhannay3 5:b553c51b3b85 78 _, _, _, _, X, X, X, X, _, _, _, _,
mhannay3 5:b553c51b3b85 79 _, _, _, _, _, X, X, _, _, _, _, _,
mhannay3 5:b553c51b3b85 80 _, _, _, _, _, X, X, _, _, _, _, _,
mhannay3 5:b553c51b3b85 81 _, _, _, _, X, X, X, X, _, _, _, _,
mhannay3 5:b553c51b3b85 82 _, _, X, X, X, X, X, X, X, X, _, _,
mhannay3 5:b553c51b3b85 83 _, _, X, X, X, X, X, X, X, X, _, _
mhannay3 5:b553c51b3b85 84 };
mhannay3 5:b553c51b3b85 85 memcpy(sprite, spriteArray, sizeof(sprite));
mhannay3 5:b553c51b3b85 86 }
mhannay3 5:b553c51b3b85 87
mhannay3 5:b553c51b3b85 88 static void spriteRook(bool white, bool light, int* spriteArray)
mhannay3 5:b553c51b3b85 89 {
mhannay3 5:b553c51b3b85 90 int X = white ? 0xffffff : 0x000000;
mhannay3 5:b553c51b3b85 91 int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR;
mhannay3 5:b553c51b3b85 92 int sprite[144] = {X, X, _, X, X, _, _, X, X, _, X, X,
mhannay3 5:b553c51b3b85 93 X, X, _, X, X, _, _, X, X, _, X, X,
mhannay3 5:b553c51b3b85 94 X, X, X, X, X, X, X, X, X, X, X, X,
mhannay3 5:b553c51b3b85 95 X, X, X, X, X, X, X, X, X, X, X, X,
mhannay3 5:b553c51b3b85 96 _, X, X, X, _, X, X, _, X, X, X, _,
mhannay3 5:b553c51b3b85 97 _, X, X, X, _, X, X, _, X, X, X, _,
mhannay3 5:b553c51b3b85 98 _, _, X, X, _, X, X, _, X, X, _, _,
mhannay3 5:b553c51b3b85 99 _, _, X, X, _, X, X, _, X, X, _, _,
mhannay3 5:b553c51b3b85 100 _, _, X, X, _, X, X, _, X, X, _, _,
mhannay3 5:b553c51b3b85 101 _, X, X, X, X, X, X, X, X, X, X, _,
mhannay3 5:b553c51b3b85 102 X, X, X, X, X, X, X, X, X, X, X, X,
mhannay3 5:b553c51b3b85 103 X, X, X, X, X, X, X, X, X, X, X, X
mhannay3 5:b553c51b3b85 104 };
mhannay3 5:b553c51b3b85 105 memcpy(sprite, spriteArray, sizeof(sprite));
mhannay3 5:b553c51b3b85 106 }
mhannay3 5:b553c51b3b85 107
mhannay3 5:b553c51b3b85 108 static void spriteKnight(bool white, bool light, int* spriteArray)
mhannay3 5:b553c51b3b85 109 {
mhannay3 5:b553c51b3b85 110 int X = white ? 0xffffff : 0x000000;
mhannay3 5:b553c51b3b85 111 int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR;
mhannay3 5:b553c51b3b85 112 int sprite[144] = {_, _, _, _, _, _, _, _, _, _, _, _,
mhannay3 5:b553c51b3b85 113 _, _, _, _, _, X, X, _, X, X, _, _,
mhannay3 5:b553c51b3b85 114 _, _, _, _, _, X, X, _, X, X, _, _,
mhannay3 5:b553c51b3b85 115 _, _, _, X, X, X, X, X, X, _, _, _,
mhannay3 5:b553c51b3b85 116 _, _, X, X, X, X, X, _, X, _, _, _,
mhannay3 5:b553c51b3b85 117 _, _, X, X, X, X, X, X, X, _, _, _,
mhannay3 5:b553c51b3b85 118 _, _, _, _, _, X, X, X, X, _, _, _,
mhannay3 5:b553c51b3b85 119 _, _, _, _, X, X, X, X, X, _, _, _,
mhannay3 5:b553c51b3b85 120 _, _, _, X, X, X, X, X, X, X, _, _,
mhannay3 5:b553c51b3b85 121 _, _, X, X, X, X, X, X, X, X, _, _,
mhannay3 5:b553c51b3b85 122 _, X, X, X, X, X, X, X, X, X, X, _,
mhannay3 5:b553c51b3b85 123 _, X, X, X, X, X, X, X, X, X, X, _
mhannay3 5:b553c51b3b85 124 };
mhannay3 5:b553c51b3b85 125 memcpy(sprite, spriteArray, sizeof(sprite));
mhannay3 5:b553c51b3b85 126 }
mhannay3 5:b553c51b3b85 127
mhannay3 5:b553c51b3b85 128 static void spriteBishop(bool white, bool light, int* spriteArray)
mhannay3 5:b553c51b3b85 129 {
mhannay3 5:b553c51b3b85 130 int X = white ? 0xffffff : 0x000000;
mhannay3 5:b553c51b3b85 131 int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR;
mhannay3 5:b553c51b3b85 132 int sprite[144] = {_, _, _, _, _, X, X, _, _, _, _, _,
mhannay3 5:b553c51b3b85 133 _, _, _, _, X, X, X, _, _, _, _, _,
mhannay3 5:b553c51b3b85 134 _, _, _, X, X, X, _, _, X, _, _, _,
mhannay3 5:b553c51b3b85 135 _, _, _, X, X, _, _, X, X, _, _, _,
mhannay3 5:b553c51b3b85 136 _, _, _, X, X, X, X, X, X, _, _, _,
mhannay3 5:b553c51b3b85 137 _, _, _, _, X, X, X, X, _, _, _, _,
mhannay3 5:b553c51b3b85 138 _, _, _, _, _, X, X, _, _, _, _, _,
mhannay3 5:b553c51b3b85 139 _, _, _, _, X, X, X, X, _, _, _, _,
mhannay3 5:b553c51b3b85 140 _, _, _, X, X, X, X, X, X, _, _, _,
mhannay3 5:b553c51b3b85 141 _, _, _, X, X, X, X, X, X, _, _, _,
mhannay3 5:b553c51b3b85 142 _, _, X, X, X, X, X, X, X, X, _, _,
mhannay3 5:b553c51b3b85 143 _, _, X, X, X, X, X, X, X, X, _, _
mhannay3 5:b553c51b3b85 144 };
mhannay3 5:b553c51b3b85 145 memcpy(sprite, spriteArray, sizeof(sprite));
mhannay3 5:b553c51b3b85 146 }
mhannay3 5:b553c51b3b85 147
mhannay3 5:b553c51b3b85 148 static void spriteQueen(bool white, bool light, int* spriteArray)
mhannay3 5:b553c51b3b85 149 {
mhannay3 5:b553c51b3b85 150 int X = white ? 0xffffff : 0x000000;
mhannay3 5:b553c51b3b85 151 int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR;
mhannay3 5:b553c51b3b85 152 int sprite[144] = {_, _, _, _, _, X, X, _, _, _, _, _,
mhannay3 5:b553c51b3b85 153 _, _, X, _, _, X, X, _, _, X, _, _,
mhannay3 5:b553c51b3b85 154 X, _, X, X, _, X, X, _, X, X, _, X,
mhannay3 5:b553c51b3b85 155 X, _, X, X, _, X, X, _, X, X, _, X,
mhannay3 5:b553c51b3b85 156 X, _, X, X, _, X, X, _, X, X, _, X,
mhannay3 5:b553c51b3b85 157 X, X, X, X, X, X, X, X, X, X, X, X,
mhannay3 5:b553c51b3b85 158 X, X, X, X, X, X, X, X, X, X, X, X,
mhannay3 5:b553c51b3b85 159 X, X, _, X, X, X, X, X, X, _, X, X,
mhannay3 5:b553c51b3b85 160 X, X, X, X, _, X, X, _, X, X, X, X,
mhannay3 5:b553c51b3b85 161 _, X, X, X, X, X, X, X, X, X, X, _,
mhannay3 5:b553c51b3b85 162 _, _, X, X, X, X, X, X, X, X, _, _,
mhannay3 5:b553c51b3b85 163 _, X, X, X, X, X, X, X, X, X, X, _
mhannay3 5:b553c51b3b85 164 };
mhannay3 5:b553c51b3b85 165 memcpy(sprite, spriteArray, sizeof(sprite));
mhannay3 5:b553c51b3b85 166 }
mhannay3 5:b553c51b3b85 167
mhannay3 5:b553c51b3b85 168 static void spriteKing(bool white, bool light, int* spriteArray)
mhannay3 5:b553c51b3b85 169 {
mhannay3 5:b553c51b3b85 170 int X = white ? 0xffffff : 0x000000;
mhannay3 5:b553c51b3b85 171 int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR;
mhannay3 5:b553c51b3b85 172 int sprite[144] = {_, _, _, _, _, X, X, _, _, _, _, _,
mhannay3 5:b553c51b3b85 173 _, _, _, _, _, X, X, _, _, _, _, _,
mhannay3 5:b553c51b3b85 174 _, _, _, X, X, X, X, X, X, _, _, _,
mhannay3 5:b553c51b3b85 175 _, _, _, X, X, X, X, X, X, _, _, _,
mhannay3 5:b553c51b3b85 176 X, X, _, _, _, X, X, _, _, _, X, X,
mhannay3 5:b553c51b3b85 177 X, X, X, X, _, X, X, _, X, X, X, X,
mhannay3 5:b553c51b3b85 178 X, _, X, X, X, X, X, X, X, X, _, X,
mhannay3 5:b553c51b3b85 179 X, X, X, X, X, X, X, X, X, X, X, X,
mhannay3 5:b553c51b3b85 180 X, X, X, _, X, X, X, X, _, X, X, X,
mhannay3 5:b553c51b3b85 181 _, X, X, X, X, X, X, X, X, X, X, _,
mhannay3 5:b553c51b3b85 182 _, _, X, X, X, _, _, X, X, X, _, _,
mhannay3 5:b553c51b3b85 183 _, X, X, X, X, X, X, X, X, X, X, _
mhannay3 5:b553c51b3b85 184 };
mhannay3 5:b553c51b3b85 185 memcpy(sprite, spriteArray, sizeof(sprite));
mhannay3 5:b553c51b3b85 186 }
mhannay3 5:b553c51b3b85 187
mhannay3 5:b553c51b3b85 188 public:
mhannay3 5:b553c51b3b85 189 BoardState getBoardState()
mhannay3 5:b553c51b3b85 190 {
mhannay3 5:b553c51b3b85 191 return boardState;
mhannay3 5:b553c51b3b85 192 }
mhannay3 5:b553c51b3b85 193
mhannay3 5:b553c51b3b85 194 void setBoardState(BoardState newBoardState)
mhannay3 5:b553c51b3b85 195 {
mhannay3 5:b553c51b3b85 196 boardState = newBoardState;
mhannay3 5:b553c51b3b85 197 }
mhannay3 5:b553c51b3b85 198
mhannay3 5:b553c51b3b85 199 // initializes the starting board state
mhannay3 5:b553c51b3b85 200 GameBoard()
mhannay3 5:b553c51b3b85 201 {
mhannay3 5:b553c51b3b85 202 // draw board
mhannay3 5:b553c51b3b85 203 for (int row = 0; row < 8; row++) {
mhannay3 5:b553c51b3b85 204 for (int column = 0; column < 8; column++) {
mhannay3 5:b553c51b3b85 205 uint64_t color;
mhannay3 5:b553c51b3b85 206 if ((row + column) % 2 == 0) {
mhannay3 5:b553c51b3b85 207 color = BOARD_DARK_COLOR;
mhannay3 5:b553c51b3b85 208 } else {
mhannay3 5:b553c51b3b85 209 color = BOARD_LIGHT_COLOR;
mhannay3 5:b553c51b3b85 210 }
mhannay3 5:b553c51b3b85 211 coord tl = getTopLeftOfSquare(row, column);
mhannay3 5:b553c51b3b85 212 uLCD.filled_rectangle(tl.x, tl.y, tl.x + 15, tl.y + 15, color);
mhannay3 5:b553c51b3b85 213 }
mhannay3 5:b553c51b3b85 214 }
mhannay3 5:b553c51b3b85 215 // draw pieces
mhannay3 5:b553c51b3b85 216 placePieceAndDraw(wR, 0, 0);
mhannay3 5:b553c51b3b85 217 placePieceAndDraw(wN, 0, 1);
mhannay3 5:b553c51b3b85 218 placePieceAndDraw(wB, 0, 2);
mhannay3 5:b553c51b3b85 219 placePieceAndDraw(wQ, 0, 3);
mhannay3 5:b553c51b3b85 220 placePieceAndDraw(wK, 0, 4);
mhannay3 5:b553c51b3b85 221 placePieceAndDraw(wB, 0, 5);
mhannay3 5:b553c51b3b85 222 placePieceAndDraw(wN, 0, 6);
mhannay3 5:b553c51b3b85 223 placePieceAndDraw(wR, 0, 7);
mhannay3 5:b553c51b3b85 224 placePieceAndDraw(bR, 7, 0);
mhannay3 5:b553c51b3b85 225 placePieceAndDraw(bN, 7, 1);
mhannay3 5:b553c51b3b85 226 placePieceAndDraw(bB, 7, 2);
mhannay3 5:b553c51b3b85 227 placePieceAndDraw(bQ, 7, 3);
mhannay3 5:b553c51b3b85 228 placePieceAndDraw(bK, 7, 4);
mhannay3 5:b553c51b3b85 229 placePieceAndDraw(bB, 7, 5);
mhannay3 5:b553c51b3b85 230 placePieceAndDraw(bN, 7, 6);
mhannay3 5:b553c51b3b85 231 placePieceAndDraw(bR, 7, 7);
mhannay3 5:b553c51b3b85 232 for (int i = 0; i < 8; i++) {
mhannay3 5:b553c51b3b85 233 placePieceAndDraw(w, 1, i);
mhannay3 5:b553c51b3b85 234 placePieceAndDraw(b, 6, i);
mhannay3 5:b553c51b3b85 235 }
mhannay3 5:b553c51b3b85 236 }
mhannay3 5:b553c51b3b85 237
mhannay3 5:b553c51b3b85 238 // gets the pixel coordinates of the top left of the square
mhannay3 5:b553c51b3b85 239 coord getTopLeftOfSquare(int row, int column)
mhannay3 5:b553c51b3b85 240 {
mhannay3 5:b553c51b3b85 241 coord topLeft;
mhannay3 5:b553c51b3b85 242 topLeft.x = 16 * column;
mhannay3 5:b553c51b3b85 243 topLeft.y = 112 - 16 * row;
mhannay3 5:b553c51b3b85 244 return topLeft;
mhannay3 5:b553c51b3b85 245 }
mhannay3 5:b553c51b3b85 246
mhannay3 5:b553c51b3b85 247 // PIECE MOVEMENT AND GRAPHICS FUNCTIONS
mhannay3 5:b553c51b3b85 248
mhannay3 5:b553c51b3b85 249 // returns the piece at a given location
mhannay3 5:b553c51b3b85 250 Piece getPiece(int row, int column)
mhannay3 5:b553c51b3b85 251 {
mhannay3 5:b553c51b3b85 252 return boardState.getPiece(row, column);
mhannay3 5:b553c51b3b85 253 }
mhannay3 5:b553c51b3b85 254
mhannay3 5:b553c51b3b85 255 /* puts the bit representation of a piece at the set position of the board
mhannay3 5:b553c51b3b85 256 assumes that the position of the board is emptied beforehand
mhannay3 5:b553c51b3b85 257 */
mhannay3 5:b553c51b3b85 258 void placePieceAndDraw(Piece piece, int row, int column)
mhannay3 5:b553c51b3b85 259 {
mhannay3 5:b553c51b3b85 260 boardState.placePiece(piece, row, column);
mhannay3 5:b553c51b3b85 261 coord tl = getTopLeftOfSquare(row, column);
mhannay3 5:b553c51b3b85 262 int sprite[144];
mhannay3 5:b553c51b3b85 263 switch(piece) {
mhannay3 5:b553c51b3b85 264 case wK:
mhannay3 5:b553c51b3b85 265 case bK:
mhannay3 5:b553c51b3b85 266 spriteKing(piece==wK, (row+column)%2, sprite);
mhannay3 5:b553c51b3b85 267 break;
mhannay3 5:b553c51b3b85 268 case wQ:
mhannay3 5:b553c51b3b85 269 case bQ:
mhannay3 5:b553c51b3b85 270 spriteQueen(piece==wQ, (row+column)%2, sprite);
mhannay3 5:b553c51b3b85 271 break;
mhannay3 5:b553c51b3b85 272 case wB:
mhannay3 5:b553c51b3b85 273 case bB:
mhannay3 5:b553c51b3b85 274 spriteBishop(piece==wB, (row+column)%2, sprite);
mhannay3 5:b553c51b3b85 275 break;
mhannay3 5:b553c51b3b85 276 case wN:
mhannay3 5:b553c51b3b85 277 case bN:
mhannay3 5:b553c51b3b85 278 spriteKing(piece==wN, (row+column)%2, sprite);
mhannay3 5:b553c51b3b85 279 break;
mhannay3 5:b553c51b3b85 280 case wR:
mhannay3 5:b553c51b3b85 281 case bR:
mhannay3 5:b553c51b3b85 282 spriteKing(piece==wR, (row+column)%2, sprite);
mhannay3 5:b553c51b3b85 283 break;
mhannay3 5:b553c51b3b85 284 case w:
mhannay3 5:b553c51b3b85 285 case b:
mhannay3 5:b553c51b3b85 286 spriteKing(piece==w, (row+column)%2, sprite);
mhannay3 5:b553c51b3b85 287 break;
mhannay3 5:b553c51b3b85 288 }
mhannay3 5:b553c51b3b85 289 uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite);
mhannay3 5:b553c51b3b85 290 }
mhannay3 5:b553c51b3b85 291
mhannay3 5:b553c51b3b85 292 /* removes a piece from the set position of the board
mhannay3 5:b553c51b3b85 293 returns the bit representation of the piece
mhannay3 5:b553c51b3b85 294 */
mhannay3 5:b553c51b3b85 295 Piece removePieceAndDraw(int row, int column)
mhannay3 5:b553c51b3b85 296 {
mhannay3 5:b553c51b3b85 297 Piece removedPiece = boardState.removePiece(row, column);
mhannay3 1:cd78922f70fa 298 coord tl = getTopLeftOfSquare(row, column);
mhannay3 1:cd78922f70fa 299 uint64_t color;
mhannay3 1:cd78922f70fa 300 if ((row + column) % 2 == 0) {
mhannay3 1:cd78922f70fa 301 color = BOARD_DARK_COLOR;
mhannay3 1:cd78922f70fa 302 } else {
mhannay3 1:cd78922f70fa 303 color = BOARD_LIGHT_COLOR;
mhannay3 1:cd78922f70fa 304 }
mhannay3 5:b553c51b3b85 305 uLCD.filled_rectangle(tl.x+2, tl.y+2, tl.x + 13, tl.y + 13, color);
mhannay3 5:b553c51b3b85 306 return removedPiece;
mhannay3 5:b553c51b3b85 307 }
mhannay3 5:b553c51b3b85 308
mhannay3 5:b553c51b3b85 309 /* moves a piece from one position to another
mhannay3 5:b553c51b3b85 310 returns the captured piece
mhannay3 5:b553c51b3b85 311 */
mhannay3 5:b553c51b3b85 312 Piece movePieceAndDraw(int startRow, int startColumn, int endRow, int endColumn)
mhannay3 5:b553c51b3b85 313 {
mhannay3 5:b553c51b3b85 314 Piece movingPiece = removePieceAndDraw(startRow, startColumn);
mhannay3 5:b553c51b3b85 315 Piece capturedPiece = boardState.removePiece(endRow, endColumn);
mhannay3 5:b553c51b3b85 316 placePieceAndDraw(movingPiece, endRow, endColumn);
mhannay3 5:b553c51b3b85 317 return capturedPiece;
mhannay3 1:cd78922f70fa 318 }
mhannay3 1:cd78922f70fa 319
mhannay3 5:b553c51b3b85 320 // SQUARE BORDER GRAPHICS FUNCTIONS
mhannay3 5:b553c51b3b85 321
mhannay3 5:b553c51b3b85 322 // removes selection border around square
mhannay3 5:b553c51b3b85 323 void unselectSquare(int row, int column)
mhannay3 5:b553c51b3b85 324 {
mhannay3 1:cd78922f70fa 325 coord tl = getTopLeftOfSquare(row, column);
mhannay3 5:b553c51b3b85 326 uint64_t color;
mhannay3 5:b553c51b3b85 327 if ((row + column) % 2 == 0) {
mhannay3 5:b553c51b3b85 328 color = BOARD_DARK_COLOR;
mhannay3 5:b553c51b3b85 329 } else {
mhannay3 5:b553c51b3b85 330 color = BOARD_LIGHT_COLOR;
mhannay3 5:b553c51b3b85 331 }
mhannay3 5:b553c51b3b85 332 uLCD.rectangle(tl.x, tl.y, tl.x + 15, tl.y + 15, color);
mhannay3 5:b553c51b3b85 333 }
mhannay3 5:b553c51b3b85 334
mhannay3 5:b553c51b3b85 335 void hoverSquare(int row, int column)
mhannay3 5:b553c51b3b85 336 {
mhannay3 5:b553c51b3b85 337 coord tl = getTopLeftOfSquare(row, column);
mhannay3 5:b553c51b3b85 338 uLCD.rectangle(tl.x, tl.y, tl.x + 15, tl.y + 15, HOVER_COLOR);
mhannay3 1:cd78922f70fa 339 }
mhannay3 1:cd78922f70fa 340
mhannay3 1:cd78922f70fa 341 // draws selection border around square
mhannay3 5:b553c51b3b85 342 void selectSquare(int row, int column)
mhannay3 5:b553c51b3b85 343 {
mhannay3 1:cd78922f70fa 344 coord tl = getTopLeftOfSquare(row, column);
mhannay3 5:b553c51b3b85 345 uLCD.rectangle(tl.x, tl.y, tl.x + 15, tl.y + 15, SELECTED_COLOR);
mhannay3 1:cd78922f70fa 346 }
mhannay3 5:b553c51b3b85 347 };
mus3 0:d16cc59110a3 348
mhannay3 5:b553c51b3b85 349 int main()
mhannay3 5:b553c51b3b85 350 {
mhannay3 1:cd78922f70fa 351 return 0;
mhannay3 1:cd78922f70fa 352 }