diff --git a/src/chess_board.cpp b/src/chess_board.cpp index 119f3c3..ddb077c 100644 --- a/src/chess_board.cpp +++ b/src/chess_board.cpp @@ -4,9 +4,9 @@ -static uint8_t Board_State[12][8] = {{0}}; -static uint8_t Saved_Binary_Board[12] = {0}; -static uint8_t Board_Lights[12][8] = {{0}}; +static uint8_t Board_State[8][8] = {{0}}; +static uint8_t Saved_Binary_Board[8] = {0}; +static uint8_t Board_Lights[8][8] = {{0}}; static uint8_t Game_State = GAME_STATE_P1_TURN_BEGINING; static uint8_t Last_Game_State = GAME_STATE_P1_TURN_BEGINING; static bool White_Turn = true; @@ -599,59 +599,6 @@ static bool Mark_Potential_Moves(uint8_t piece, uint8_t column, uint8_t row) return ret_val; } -/** - * @brief Function for marking the taken pieces potention moves to jail. - */ -static void Mark_Taken_Piece_Spots_In_Jail(void) -{ - uint8_t add = (white_team(Taken_Piece) ? 8u : 10u); - switch (Taken_Piece) - { - /* Pawns just send them to jail, we dont care where */ - case PAWN_WHITE: - case PAWN_BLACK: - { - for (uint8_t j = 0; j < 2u; j++) - { - for (uint8_t i = 0; i < 4u; i++) - { - if(Board_State[add + j][i] != Taken_Piece) - { - Board_State[add + j][i] = Taken_Piece; - Taken_Piece = SQUARE_EMPTY; - return; - } - } - } - break; - } - case ROOK_WHITE: - case ROOK_BLACK: - case KNIGHT_WHITE: - case KNIGHT_BLACK: - case BISHOP_WHITE: - case BISHOP_BLACK: - case QUEEN_WHITE: - case QUEEN_BLACK: - { - uint8_t jail_row = (Taken_Piece / 2u) + 2u; - if (Board_State[add][jail_row] != Taken_Piece) - { - Board_Lights[add][jail_row] = PIECE_NEEDS_TO_BE_HERE; - } - if (Board_State[add + 1u][jail_row] != Taken_Piece) - { - Board_Lights[add + 1u][jail_row] = PIECE_NEEDS_TO_BE_HERE; - } - break; - } - default: - { - break; - } - } -} - bool Check_If_Player_Can_Move(bool white) { for (uint8_t row = 0; row < 8u; row++) @@ -908,7 +855,6 @@ static void Board_Square_Was_Toggled(uint8_t j, uint8_t i) // Taken_Piece = Board_State[j][i]; Board_State[j][i] = SQUARE_EMPTY; Game_State = (White_Turn ? GAME_STATE_P1_TURN_TAKING : GAME_STATE_P2_TURN_TAKING); - // Mark_Taken_Piece_Spots_In_Jail(); clear_lights(); Board_Lights[j][i] = PIECE_NEEDS_TO_BE_HERE; } @@ -963,21 +909,11 @@ static void Board_Square_Was_Toggled(uint8_t j, uint8_t i) { if (Board_Lights[j][i] == PIECE_NEEDS_TO_BE_HERE) { - if(j < 8u) - { - Check_If_Converting_Pawn(j, i); - Board_State[j][i] = Selected_Piece; - Selected_Piece = SQUARE_EMPTY; - Board_Lights[j][i] = LIGHT_OFF; - } - else - { - Board_State[j][i] = Taken_Piece; - Board_Lights[(j / 2u) * 2u][i] = LIGHT_OFF; - Board_Lights[(j / 2u) * 2u + 1u][i] = LIGHT_OFF; - Taken_Piece = SQUARE_EMPTY; - } - + Check_If_Moving_King(j, i); + Check_If_Converting_Pawn(j, i); + Board_State[j][i] = Selected_Piece; + Selected_Piece = SQUARE_EMPTY; + Board_Lights[j][i] = LIGHT_OFF; } else { @@ -1004,7 +940,7 @@ static void Board_Square_Was_Toggled(uint8_t j, uint8_t i) } } -void Board_get_lights_and_state(uint8_t board_lights[12][8], uint8_t board_state[12][8]) +void Board_get_lights_and_state(uint8_t board_lights[8][8], uint8_t board_state[8][8]) { memcpy(&board_lights[0][0], &Board_Lights[0][0], sizeof(Board_Lights)); memcpy(&board_state[0][0], &Board_State[0][0], sizeof(Board_State)); @@ -1017,9 +953,9 @@ void Board_get_lights_and_state(uint8_t board_lights[12][8], uint8_t board_state * so I'm designing it this way because of the hardware that I'm using. * @retval None */ -void Board_Changed(uint8_t current_binary_board[12]) +void Board_Changed(uint8_t current_binary_board[8]) { - for (uint8_t j = 0u; j < 12u; j++) + for (uint8_t j = 0u; j < 8u; j++) { uint8_t difference = (current_binary_board[j] ^ Saved_Binary_Board[j]); if (difference != 0u) @@ -1045,7 +981,7 @@ void Board_Changed(uint8_t current_binary_board[12]) */ void chess_board_init(void) { - for (uint8_t i = 0u; i < 12u; i++) + for (uint8_t i = 0u; i < 8u; i++) { for (uint8_t j = 0u; j < 8u; j++) { diff --git a/src/user_interface_abstraction.cpp b/src/user_interface_abstraction.cpp index 18156de..592d1ab 100644 --- a/src/user_interface_abstraction.cpp +++ b/src/user_interface_abstraction.cpp @@ -20,10 +20,10 @@ static int Board_Width; SDL_Surface *bitmapSurface = NULL; SDL_Texture * bitmapTextures[12] = {NULL}; -static uint8_t Current_Binary_Board[12] = {0}; +static uint8_t Current_Binary_Board[8] = {0}; -static void ui_draw_end_game(SDL_Renderer *p_renderer, uint8_t board_state[12][8], uint8_t game_state) +static void ui_draw_end_game(SDL_Renderer *p_renderer, uint8_t board_state[8][8], uint8_t game_state) { SDL_SetRenderTarget(p_renderer, Board_Texture); SDL_SetRenderDrawColor(p_renderer, 0x7f, 0x7f, 0x7f, 0); @@ -176,7 +176,7 @@ static void ui_draw_board(SDL_Renderer *p_renderer, uint8_t board_lights[12][8], SDL_SetRenderDrawColor(p_renderer, 0x6F, 0x6f, 0x6f, 0x00); /* Now we draw the jail */ - for (size_t j = 8; j < 12; j++) + for (size_t j = 8; j < 8; j++) { Rectangle.y = starting_y; for (size_t i = 0; i < 8; i++) @@ -226,8 +226,8 @@ static void ui_draw_board(SDL_Renderer *p_renderer, uint8_t board_lights[12][8], void ui_redraw_board(SDL_Renderer *p_renderer) { - uint8_t board_lights[12][8]; - uint8_t board_state[12][8]; + uint8_t board_lights[8][8]; + uint8_t board_state[8][8]; uint8_t game_state; Board_get_game_state(&game_state); Board_get_lights_and_state(board_lights, board_state);