Adding rscons as the building system and beginning to re-factor code

This commit is contained in:
Daniel Weber 2023-01-01 22:20:32 -05:00
parent a23ce67434
commit 9afc19cba0
10 changed files with 1495 additions and 1472 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
build/
.rscons*
.vscode/

12
Rsconscript.rb Normal file
View File

@ -0,0 +1,12 @@
task "configure" do
check_cxx_compiler "g++"
check_lib "SDL2"
check_lib "SDL2main"
end
task "build" do
env do |env|
env.Program("Chess", glob("src/*.cpp"))
end
end

46
rscons Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
#include "chess_board.h" #include "chess_board.h"
#include <SDL.h> #include <SDL2/SDL.h>
#include <SDL_video.h> #include <SDL2/SDL_video.h>
#include "stdio.h" #include "stdio.h"
#include <stack> #include <stack>
#include <string.h> #include <string.h>
@ -27,10 +27,10 @@
#define POTENTIAL_TAKE 2u #define POTENTIAL_TAKE 2u
#define SUGGESTED_MOVE 3u #define SUGGESTED_MOVE 3u
#define ERROR_MOVE 4u #define ERROR_MOVE 4u
#define PEICE_ORIGIN 5u #define PIECE_ORIGIN 5u
#define PEICE_NEEDS_TO_BE_HERE 6u #define PIECE_NEEDS_TO_BE_HERE 6u
#define POTENTIAL_CASTLE 7u #define POTENTIAL_CASTLE 7u
#define PEICE_NEEDS_TO_BE_REMOVED 8u #define PIECE_NEEDS_TO_BE_REMOVED 8u
#define GAME_STATE_IDLE 0u #define GAME_STATE_IDLE 0u
#define GAME_STATE_P1_TURN_BEGINING 1u #define GAME_STATE_P1_TURN_BEGINING 1u
@ -63,25 +63,14 @@ SDL_Texture * bitmapTextures[12] = {NULL};
static uint8_t Game_State = GAME_STATE_P1_TURN_BEGINING; static uint8_t Game_State = GAME_STATE_P1_TURN_BEGINING;
static uint8_t Last_Game_State = GAME_STATE_P1_TURN_BEGINING; static uint8_t Last_Game_State = GAME_STATE_P1_TURN_BEGINING;
static bool White_Turn = true; static bool White_Turn = true;
static uint8_t Selected_Peice = SQUARE_EMPTY; static uint8_t Selected_Piece = SQUARE_EMPTY;
static uint8_t Error_Count = 0u; static uint8_t Error_Count = 0u;
static uint8_t Taken_Peice = SQUARE_EMPTY; static uint8_t Taken_Piece = SQUARE_EMPTY;
static bool Check[2u] = {false, false}; static bool Check[2u] = {false, false};
static uint8_t King_Locations[2u][2u] = {{7,4}, {0,4}}; static uint8_t King_Locations[2u][2u] = {{7,4}, {0,4}};
static bool Castling_Allowed[2u][2u] = {{true, true}, {true, true}}; static bool Castling_Allowed[2u][2u] = {{true, true}, {true, true}};
static bool High_Alert = false; static bool High_Alert = false;
/**
* @brief Function for figuring out if the current column is one of the jail columns.
* @note Columns 8-12 are in the jail
* @param j: The column under question.
* @retval True if its a jail column, else false.
*/
static inline bool square_in_jail(uint8_t j)
{
return (j > 8u);
}
/** /**
* @brief Function for clearing all of the lights on the board. Except for error moves. * @brief Function for clearing all of the lights on the board. Except for error moves.
* @retval None * @retval None
@ -102,9 +91,9 @@ static void clear_lights(void)
} }
/** /**
* @brief Function for determining if the peice is on the white team or on the black team. * @brief Function for determining if the piece is on the white team or on the black team.
* @note Peices should be enumerated even if white and odd if black. * @note Pieces should be enumerated even if white and odd if black.
* @param piece: The peice under question. * @param piece: The piece under question.
* @retval Return true if on the white team, else false. * @retval Return true if on the white team, else false.
*/ */
static bool white_team(uint8_t piece) static bool white_team(uint8_t piece)
@ -113,9 +102,9 @@ static bool white_team(uint8_t piece)
} }
/** /**
* @brief Function for determining if two peices are on the same team or not. * @brief Function for determining if two pieces are on the same team or not.
* @param piece_one: Peice one ofcoarse. * @param piece_one: Piece one ofcoarse.
* @param piece_two: Peice two obviously. * @param piece_two: Piece two obviously.
* @retval True if on opposite teams, else false. * @retval True if on opposite teams, else false.
*/ */
static bool opposite_teams(uint8_t piece_one, uint8_t piece_two) static bool opposite_teams(uint8_t piece_one, uint8_t piece_two)
@ -131,15 +120,15 @@ static bool opposite_teams(uint8_t piece_one, uint8_t piece_two)
*/ */
bool square_is_safe(uint8_t row, uint8_t column) bool square_is_safe(uint8_t row, uint8_t column)
{ {
int8_t direction = White_Turn ? -1 : 1; int8_t temp = row + (White_Turn ? -1 : 1);
/* first check if pawns can take us */ /* first check if pawns can take us */
if ((row >= 1u) && ((White_Turn ? PAWN_BLACK : PAWN_WHITE) == Board_State[row + direction][column - 1u])) if ((White_Turn ? PAWN_BLACK : PAWN_WHITE) == Board_State[temp][column - 1u])
{ {
//can be eaten by a pawn, not safe. //can be eaten by a pawn, not safe.
return false; return false;
} }
if ((row <= 6u) && ((White_Turn ? PAWN_BLACK : PAWN_WHITE) == Board_State[row + direction][column + 1u])) if ((White_Turn ? PAWN_BLACK : PAWN_WHITE) == Board_State[temp][column + 1u])
{ {
//can be eaten by a pawn, not safe. //can be eaten by a pawn, not safe.
return false; return false;
@ -316,27 +305,15 @@ bool square_is_safe(uint8_t row, uint8_t column)
return true; return true;
} }
bool Check_If_Take_Caused_Check(uint8_t row, uint8_t column)
{
bool ret_val;
uint8_t store_eaten_peice = Board_State[row][column];
Board_State[row][column] = Selected_Peice;
//If its the white's turn we want to see if the white king is still safe.
uint8_t white_black_idx = White_Turn ? 0u : 1u;
ret_val = !square_is_safe(King_Locations[white_black_idx][0u], King_Locations[white_black_idx][1u]);
Board_State[row][column] = store_eaten_peice;
return ret_val;
}
bool Check_If_Move_Caused_Check(uint8_t row, uint8_t column) bool Check_If_Move_Caused_Check(uint8_t row, uint8_t column)
{ {
bool ret_val; bool ret_val;
Board_State[row][column] = Selected_Peice; uint8_t store_current_piece = Board_State[row][column];
Board_State[row][column] = Selected_Piece;
//If its the white's turn we want to see if the white king is still safe. //If its the white's turn we want to see if the white king is still safe.
uint8_t white_black_idx = White_Turn ? 0u : 1u; uint8_t white_black_idx = White_Turn ? 0u : 1u;
ret_val = !square_is_safe(King_Locations[white_black_idx][0u], King_Locations[white_black_idx][1u]); ret_val = !square_is_safe(King_Locations[white_black_idx][0u], King_Locations[white_black_idx][1u]);
Board_State[row][column] = SQUARE_EMPTY; Board_State[row][column] = store_current_piece;
return ret_val; return ret_val;
} }
@ -359,6 +336,14 @@ void Check_If_Could_Cause_Check(uint8_t row, uint8_t column)
Board_State[row][column] = temp_storage; Board_State[row][column] = temp_storage;
} }
static void Set_Light(uint8_t row, uint8_t column, uint8_t state)
{
if ((!High_Alert) || (!Check_If_Move_Caused_Check(row, column)))
{
Board_Lights[row][column] = state;
}
}
/** /**
* @brief Function for marking potential moves for pawns. * @brief Function for marking potential moves for pawns.
* @param row: row to move to * @param row: row to move to
@ -369,10 +354,7 @@ static void pawn_move(uint8_t row, uint8_t column)
{ {
if (Board_State[row][column] == SQUARE_EMPTY) if (Board_State[row][column] == SQUARE_EMPTY)
{ {
if ((!High_Alert) || (!Check_If_Move_Caused_Check(row, column))) Set_Light(row, column, POTENTIAL_MOVE);
{
Board_Lights[row][column] = POTENTIAL_MOVE;
}
} }
} }
@ -383,7 +365,7 @@ static void pawn_move(uint8_t row, uint8_t column)
* @param direction_c: Column direction * @param direction_c: Column direction
* @param row: current row location * @param row: current row location
* @param column: current column location * @param column: current column location
* @param piece_one: the peice that is casting the ray. * @param piece_one: the piece that is casting the ray.
* @retval None * @retval None
*/ */
static void cast_a_ray(int8_t direction_r, int8_t direction_c, uint8_t column, uint8_t row, uint8_t piece_one) static void cast_a_ray(int8_t direction_r, int8_t direction_c, uint8_t column, uint8_t row, uint8_t piece_one)
@ -401,18 +383,12 @@ static void cast_a_ray(int8_t direction_r, int8_t direction_c, uint8_t column, u
} }
else if (Board_State[x][y] == SQUARE_EMPTY) else if (Board_State[x][y] == SQUARE_EMPTY)
{ {
if ((!High_Alert) || (!Check_If_Move_Caused_Check(x, y))) Set_Light(x, y, POTENTIAL_MOVE);
{
Board_Lights[x][y] = POTENTIAL_MOVE;
}
} }
else if (opposite_teams(piece_one, Board_State[x][y])) else if (opposite_teams(piece_one, Board_State[x][y]))
{ {
if ((!High_Alert) || (!Check_If_Take_Caused_Check(x, y))) Set_Light(x, y, POTENTIAL_TAKE);
{ /* once we take a piece we can no longer take anymore */
Board_Lights[x][y] = POTENTIAL_TAKE;
}
/* once we take a peice we can no longer take anymore */
loop = false; loop = false;
} }
else else
@ -423,27 +399,24 @@ static void cast_a_ray(int8_t direction_r, int8_t direction_c, uint8_t column, u
} }
/** /**
* @brief Marking a peice for taking. * @brief Marking a piece for taking.
* @param row: Row ofcoarse * @param row: Row ofcoarse
* @param column: Column obviously * @param column: Column obviously
* @retval None * @retval None
*/ */
static void pawn_take(uint8_t row, uint8_t column) static void pawn_take(uint8_t row, uint8_t column, uint8_t piece)
{ {
if (Board_State[row][column] < SQUARE_EMPTY) if ((Board_State[row][column] < SQUARE_EMPTY) && opposite_teams(piece, Board_State[row][column]))
{ {
if ((!High_Alert) || (!Check_If_Take_Caused_Check(row, column))) Set_Light(row, column, POTENTIAL_TAKE);
{
Board_Lights[row][column] = POTENTIAL_TAKE;
}
} }
} }
/** /**
* @brief Function for marking the potential moves. * @brief Function for marking the potential moves.
* @param piece: Peice that we are marking the potential moves for. * @param piece: Piece that we are marking the potential moves for.
* @param row: Current row location of the peice. * @param row: Current row location of the piece.
* @param column: Current column location of the peice. * @param column: Current column location of the piece.
* @retval None * @retval None
*/ */
static void Mark_Potential_Moves(uint8_t piece, uint8_t column, uint8_t row) static void Mark_Potential_Moves(uint8_t piece, uint8_t column, uint8_t row)
@ -454,24 +427,18 @@ static void Mark_Potential_Moves(uint8_t piece, uint8_t column, uint8_t row)
case PAWN_BLACK: case PAWN_BLACK:
{ {
int8_t direction = White_Turn ? -1 : 1; int8_t direction = White_Turn ? -1 : 1;
uint8_t temp_row = row + direction;
if (row == (White_Turn ? 6u : 1u)) if (row == (White_Turn ? 6u : 1u))
{ {
if(Board_State[row + direction][column] == SQUARE_EMPTY) if(Board_State[temp_row][column] == SQUARE_EMPTY)
{ {
pawn_move(row + (direction * 2u), column); pawn_move(row + (direction * 2u), column);
} }
} }
pawn_move(row + direction, column); pawn_move(temp_row, column);
pawn_take(temp_row, column - 1u, piece);
if ((row >= 1u) && opposite_teams(piece, Board_State[row + direction][column - 1u])) pawn_take(temp_row, column + 1u, piece);
{
pawn_take(row + direction, column - 1u);
}
if ((row <= 6u) && opposite_teams(piece, Board_State[row + direction][column + 1u]))
{
pawn_take(row + direction, column + 1u);
}
break; break;
} }
@ -552,17 +519,11 @@ static void Mark_Potential_Moves(uint8_t piece, uint8_t column, uint8_t row)
{ {
if (Board_State[x][y] == SQUARE_EMPTY) if (Board_State[x][y] == SQUARE_EMPTY)
{ {
if ((!High_Alert) || (!Check_If_Move_Caused_Check(x, y))) Set_Light(x, y, POTENTIAL_MOVE);
{
Board_Lights[x][y] = POTENTIAL_MOVE;
}
} }
else if (opposite_teams(piece, Board_State[x][y])) else if (opposite_teams(piece, Board_State[x][y]))
{ {
if ((!High_Alert) || (!Check_If_Take_Caused_Check(x, y))) Set_Light(x, y, POTENTIAL_TAKE);
{
Board_Lights[x][y] = POTENTIAL_TAKE;
}
} }
} }
} }
@ -674,12 +635,12 @@ static void Mark_Potential_Moves(uint8_t piece, uint8_t column, uint8_t row)
} }
/** /**
* @brief Function for marking the taken peices potention moves to jail. * @brief Function for marking the taken pieces potention moves to jail.
*/ */
void Mark_Taken_Peice_Spots_In_Jail(void) void Mark_Taken_Piece_Spots_In_Jail(void)
{ {
uint8_t add = (white_team(Taken_Peice) ? 8u : 10u); uint8_t add = (white_team(Taken_Piece) ? 8u : 10u);
switch (Taken_Peice) switch (Taken_Piece)
{ {
/* Pawns just send them to jail, we dont care where */ /* Pawns just send them to jail, we dont care where */
case PAWN_WHITE: case PAWN_WHITE:
@ -689,10 +650,10 @@ void Mark_Taken_Peice_Spots_In_Jail(void)
{ {
for (uint8_t i = 0; i < 4u; i++) for (uint8_t i = 0; i < 4u; i++)
{ {
if(Board_State[add + j][i] != Taken_Peice) if(Board_State[add + j][i] != Taken_Piece)
{ {
Board_State[add + j][i] = Taken_Peice; Board_State[add + j][i] = Taken_Piece;
Taken_Peice = SQUARE_EMPTY; Taken_Piece = SQUARE_EMPTY;
return; return;
} }
} }
@ -708,14 +669,14 @@ void Mark_Taken_Peice_Spots_In_Jail(void)
case QUEEN_WHITE: case QUEEN_WHITE:
case QUEEN_BLACK: case QUEEN_BLACK:
{ {
uint8_t jail_row = (Taken_Peice / 2u) + 2u; uint8_t jail_row = (Taken_Piece / 2u) + 2u;
if (Board_State[add][jail_row] != Taken_Peice) if (Board_State[add][jail_row] != Taken_Piece)
{ {
Board_Lights[add][jail_row] = PEICE_NEEDS_TO_BE_HERE; Board_Lights[add][jail_row] = PIECE_NEEDS_TO_BE_HERE;
} }
if (Board_State[add + 1u][jail_row] != Taken_Peice) if (Board_State[add + 1u][jail_row] != Taken_Piece)
{ {
Board_Lights[add + 1u][jail_row] = PEICE_NEEDS_TO_BE_HERE; Board_Lights[add + 1u][jail_row] = PIECE_NEEDS_TO_BE_HERE;
} }
break; break;
} }
@ -741,16 +702,16 @@ void Switch_Turns(void)
} }
/** /**
* @brief Function for checking the selected peice to see if we are moving the king. * @brief Function for checking the selected piece to see if we are moving the king.
* If we are then we also want to update the new location of the corresponding king. * If we are then we also want to update the new location of the corresponding king.
* @param row: Current row location of the peice. * @param row: Current row location of the piece.
* @param column: Current column location of the peice. * @param column: Current column location of the piece.
* @retval None * @retval None
*/ */
void Check_If_Moving_King(uint8_t row, uint8_t column) void Check_If_Moving_King(uint8_t row, uint8_t column)
{ {
uint8_t white_black_idx = White_Turn ? 0u : 1u; uint8_t white_black_idx = White_Turn ? 0u : 1u;
if((Selected_Peice == KING_WHITE) || (Selected_Peice == KING_BLACK)) if((Selected_Piece == KING_WHITE) || (Selected_Piece == KING_BLACK))
{ {
King_Locations[white_black_idx][0u] = row; King_Locations[white_black_idx][0u] = row;
King_Locations[white_black_idx][1u] = column; King_Locations[white_black_idx][1u] = column;
@ -758,8 +719,8 @@ void Check_If_Moving_King(uint8_t row, uint8_t column)
Castling_Allowed[white_black_idx][1u] = false; Castling_Allowed[white_black_idx][1u] = false;
} }
// Disable the castling of the corresponding side if the rook is being moved. // Disable the castling of the corresponding side if the rook is being moved.
else if (((Selected_Peice == ROOK_WHITE) && (row == 7u)) else if (((Selected_Piece == ROOK_WHITE) && (row == 7u))
|| ((Selected_Peice == ROOK_BLACK) && (row == 0u))) || ((Selected_Piece == ROOK_BLACK) && (row == 0u)))
{ {
if (column == 0u) if (column == 0u)
{ {
@ -784,37 +745,37 @@ void Board_Square_Was_Toggled(uint8_t j, uint8_t i)
{ {
case GAME_STATE_ERROR_DETECTED: case GAME_STATE_ERROR_DETECTED:
{ {
if (Board_Lights[j][i] == PEICE_ORIGIN) if (Board_Lights[j][i] == PIECE_ORIGIN)
{ {
Board_State[j][i] = Selected_Peice; Board_State[j][i] = Selected_Piece;
Selected_Peice = SQUARE_EMPTY; Selected_Piece = SQUARE_EMPTY;
clear_lights(); clear_lights();
Last_Game_State--; Last_Game_State--;
} }
else if (Board_Lights[j][i] == PEICE_NEEDS_TO_BE_HERE) else if (Board_Lights[j][i] == PIECE_NEEDS_TO_BE_HERE)
{ {
if (j < 8u) if (j < 8u)
{ {
Board_State[j][i] = Selected_Peice; Board_State[j][i] = Selected_Piece;
Selected_Peice = SQUARE_EMPTY; Selected_Piece = SQUARE_EMPTY;
Board_Lights[j][i] = LIGHT_OFF; Board_Lights[j][i] = LIGHT_OFF;
} }
else else
{ {
Board_State[j][i] = Taken_Peice; Board_State[j][i] = Taken_Piece;
uint8_t board_column = (j / 2u) * 2u; uint8_t board_column = (j / 2u) * 2u;
if(Board_Lights[board_column][i] == PEICE_NEEDS_TO_BE_HERE) if(Board_Lights[board_column][i] == PIECE_NEEDS_TO_BE_HERE)
{ {
Board_Lights[board_column][i] = LIGHT_OFF; Board_Lights[board_column][i] = LIGHT_OFF;
} }
if(Board_Lights[board_column + 1u][i] == PEICE_NEEDS_TO_BE_HERE) if(Board_Lights[board_column + 1u][i] == PIECE_NEEDS_TO_BE_HERE)
{ {
Board_Lights[board_column + 1u][i] = LIGHT_OFF; Board_Lights[board_column + 1u][i] = LIGHT_OFF;
} }
Taken_Peice = SQUARE_EMPTY; Taken_Piece = SQUARE_EMPTY;
} }
if ((Selected_Peice == SQUARE_EMPTY) && (Taken_Peice == SQUARE_EMPTY)) if ((Selected_Piece == SQUARE_EMPTY) && (Taken_Piece == SQUARE_EMPTY))
{ {
Last_Game_State = (White_Turn ? GAME_STATE_P2_TURN_BEGINING : GAME_STATE_P1_TURN_BEGINING); Last_Game_State = (White_Turn ? GAME_STATE_P2_TURN_BEGINING : GAME_STATE_P1_TURN_BEGINING);
White_Turn = !White_Turn; White_Turn = !White_Turn;
@ -843,17 +804,17 @@ void Board_Square_Was_Toggled(uint8_t j, uint8_t i)
case GAME_STATE_P2_TURN_BEGINING: case GAME_STATE_P2_TURN_BEGINING:
case GAME_STATE_P1_TURN_BEGINING: case GAME_STATE_P1_TURN_BEGINING:
{ {
/* We are waiting till the player who's turn it is picks up a peice that is on their team */ /* We are waiting till the player who's turn it is picks up a piece that is on their team */
if ((j < 8u) && (Board_State[j][i] != SQUARE_EMPTY) && (white_team(Board_State[j][i]) == White_Turn)) if ((j < 8u) && (Board_State[j][i] != SQUARE_EMPTY) && (white_team(Board_State[j][i]) == White_Turn))
{ {
if((Board_State[j][i] != KING_BLACK) && (Board_State[j][i] != KING_WHITE)) if((Board_State[j][i] != KING_BLACK) && (Board_State[j][i] != KING_WHITE))
{ {
Check_If_Could_Cause_Check(j, i); Check_If_Could_Cause_Check(j, i);
} }
Selected_Peice = Board_State[j][i]; Selected_Piece = Board_State[j][i];
Board_State[j][i] = SQUARE_EMPTY; Board_State[j][i] = SQUARE_EMPTY;
Mark_Potential_Moves(Selected_Peice, i, j); Mark_Potential_Moves(Selected_Piece, i, j);
Board_Lights[j][i] = PEICE_ORIGIN; Board_Lights[j][i] = PIECE_ORIGIN;
Game_State++; Game_State++;
} }
else else
@ -869,46 +830,46 @@ void Board_Square_Was_Toggled(uint8_t j, uint8_t i)
case GAME_STATE_P2_TURN_IN_PROGRESS: case GAME_STATE_P2_TURN_IN_PROGRESS:
case GAME_STATE_P1_TURN_IN_PROGRESS: case GAME_STATE_P1_TURN_IN_PROGRESS:
{ {
/* We are waiting till the player who's turn it is picks up a peice that is on their team */ /* We are waiting till the player who's turn it is picks up a piece that is on their team */
if (Board_Lights[j][i] == POTENTIAL_MOVE) if (Board_Lights[j][i] == POTENTIAL_MOVE)
{ {
Check_If_Moving_King(j, i); Check_If_Moving_King(j, i);
Board_State[j][i] = Selected_Peice; Board_State[j][i] = Selected_Piece;
Selected_Peice = SQUARE_EMPTY; Selected_Piece = SQUARE_EMPTY;
clear_lights(); clear_lights();
Switch_Turns(); Switch_Turns();
} }
else if (Board_Lights[j][i] == POTENTIAL_TAKE) else if (Board_Lights[j][i] == POTENTIAL_TAKE)
{ {
Taken_Peice = Board_State[j][i]; Taken_Piece = Board_State[j][i];
Board_State[j][i] = SQUARE_EMPTY; Board_State[j][i] = SQUARE_EMPTY;
Game_State = (White_Turn ? GAME_STATE_P1_TURN_TAKING : GAME_STATE_P2_TURN_TAKING); Game_State = (White_Turn ? GAME_STATE_P1_TURN_TAKING : GAME_STATE_P2_TURN_TAKING);
Mark_Taken_Peice_Spots_In_Jail(); Mark_Taken_Piece_Spots_In_Jail();
clear_lights(); clear_lights();
Board_Lights[j][i] = PEICE_NEEDS_TO_BE_HERE; Board_Lights[j][i] = PIECE_NEEDS_TO_BE_HERE;
} }
else if (Board_Lights[j][i] == PEICE_ORIGIN) else if (Board_Lights[j][i] == PIECE_ORIGIN)
{ {
Board_State[j][i] = Selected_Peice; Board_State[j][i] = Selected_Piece;
Selected_Peice = SQUARE_EMPTY; Selected_Piece = SQUARE_EMPTY;
clear_lights(); clear_lights();
Game_State--; Game_State--;
} }
else if (Board_Lights[j][i] == POTENTIAL_CASTLE) else if (Board_Lights[j][i] == POTENTIAL_CASTLE)
{ {
Check_If_Moving_King(j, i); Check_If_Moving_King(j, i);
Board_State[j][i] = Selected_Peice; Board_State[j][i] = Selected_Piece;
Selected_Peice = SQUARE_EMPTY; Selected_Piece = SQUARE_EMPTY;
clear_lights(); clear_lights();
if(i == 2u) if(i == 2u)
{ {
Board_Lights[j][3u] = PEICE_NEEDS_TO_BE_HERE; Board_Lights[j][3u] = PIECE_NEEDS_TO_BE_HERE;
Board_Lights[j][0u] = PEICE_NEEDS_TO_BE_REMOVED; Board_Lights[j][0u] = PIECE_NEEDS_TO_BE_REMOVED;
} }
else if(i == 6u) else if(i == 6u)
{ {
Board_Lights[j][5u] = PEICE_NEEDS_TO_BE_HERE; Board_Lights[j][5u] = PIECE_NEEDS_TO_BE_HERE;
Board_Lights[j][7u] = PEICE_NEEDS_TO_BE_REMOVED; Board_Lights[j][7u] = PIECE_NEEDS_TO_BE_REMOVED;
} }
else else
{ {
@ -916,9 +877,9 @@ void Board_Square_Was_Toggled(uint8_t j, uint8_t i)
} }
} }
else if (Board_Lights[j][i] == PEICE_NEEDS_TO_BE_REMOVED) else if (Board_Lights[j][i] == PIECE_NEEDS_TO_BE_REMOVED)
{ {
Selected_Peice = Board_State[j][i]; Selected_Piece = Board_State[j][i];
Board_State[j][i] = SQUARE_EMPTY; Board_State[j][i] = SQUARE_EMPTY;
Board_Lights[j][i] = LIGHT_OFF; Board_Lights[j][i] = LIGHT_OFF;
Game_State = (White_Turn ? GAME_STATE_P1_TURN_TAKING : GAME_STATE_P2_TURN_TAKING); Game_State = (White_Turn ? GAME_STATE_P1_TURN_TAKING : GAME_STATE_P2_TURN_TAKING);
@ -935,20 +896,20 @@ void Board_Square_Was_Toggled(uint8_t j, uint8_t i)
case GAME_STATE_P2_TURN_TAKING: case GAME_STATE_P2_TURN_TAKING:
case GAME_STATE_P1_TURN_TAKING: case GAME_STATE_P1_TURN_TAKING:
{ {
if (Board_Lights[j][i] == PEICE_NEEDS_TO_BE_HERE) if (Board_Lights[j][i] == PIECE_NEEDS_TO_BE_HERE)
{ {
if(j < 8u) if(j < 8u)
{ {
Board_State[j][i] = Selected_Peice; Board_State[j][i] = Selected_Piece;
Selected_Peice = SQUARE_EMPTY; Selected_Piece = SQUARE_EMPTY;
Board_Lights[j][i] = LIGHT_OFF; Board_Lights[j][i] = LIGHT_OFF;
} }
else else
{ {
Board_State[j][i] = Taken_Peice; Board_State[j][i] = Taken_Piece;
Board_Lights[(j / 2u) * 2u][i] = LIGHT_OFF; Board_Lights[(j / 2u) * 2u][i] = LIGHT_OFF;
Board_Lights[(j / 2u) * 2u + 1u][i] = LIGHT_OFF; Board_Lights[(j / 2u) * 2u + 1u][i] = LIGHT_OFF;
Taken_Peice = SQUARE_EMPTY; Taken_Piece = SQUARE_EMPTY;
} }
} }
@ -960,7 +921,7 @@ void Board_Square_Was_Toggled(uint8_t j, uint8_t i)
Error_Count++; Error_Count++;
} }
if ((Selected_Peice == SQUARE_EMPTY) && (Taken_Peice == SQUARE_EMPTY)) if ((Selected_Piece == SQUARE_EMPTY) && (Taken_Piece == SQUARE_EMPTY))
{ {
Switch_Turns(); Switch_Turns();
} }
@ -1141,7 +1102,7 @@ void chess_board_init(SDL_Renderer *p_renderer)
for (uint8_t i = 0; i < 12; i++) for (uint8_t i = 0; i < 12; i++)
{ {
//location of all the sprites plus the size of file names //location of all the sprites plus the size of file names
char file[25] = "sprites\\"; char file[25] = "sprites/";
memcpy(&file[8], File_Names[i], 16); memcpy(&file[8], File_Names[i], 16);
bitmapSurface = SDL_LoadBMP(file); bitmapSurface = SDL_LoadBMP(file);
bitmapTextures[i] = SDL_CreateTextureFromSurface(p_renderer, bitmapSurface); bitmapTextures[i] = SDL_CreateTextureFromSurface(p_renderer, bitmapSurface);
@ -1182,13 +1143,13 @@ void draw_board(SDL_Renderer *p_renderer)
SDL_RenderFillRect(p_renderer, &Rectangle); SDL_RenderFillRect(p_renderer, &Rectangle);
SDL_SetRenderDrawColor(p_renderer, 0x85, 0x5E, 0x42, 0x00); SDL_SetRenderDrawColor(p_renderer, 0x85, 0x5E, 0x42, 0x00);
} }
else if ((Board_Lights[j][i] == POTENTIAL_TAKE) || (Board_Lights[j][i] == PEICE_NEEDS_TO_BE_HERE) || (Board_Lights[j][i] == PEICE_NEEDS_TO_BE_REMOVED)) else if ((Board_Lights[j][i] == POTENTIAL_TAKE) || (Board_Lights[j][i] == PIECE_NEEDS_TO_BE_HERE) || (Board_Lights[j][i] == PIECE_NEEDS_TO_BE_REMOVED))
{ {
SDL_SetRenderDrawColor(p_renderer, 0xFF, 0x00, 0x00, 0x00); SDL_SetRenderDrawColor(p_renderer, 0xFF, 0x00, 0x00, 0x00);
SDL_RenderFillRect(p_renderer, &Rectangle); SDL_RenderFillRect(p_renderer, &Rectangle);
SDL_SetRenderDrawColor(p_renderer, 0x85, 0x5E, 0x42, 0x00); SDL_SetRenderDrawColor(p_renderer, 0x85, 0x5E, 0x42, 0x00);
} }
else if (Board_Lights[j][i] == PEICE_ORIGIN) else if (Board_Lights[j][i] == PIECE_ORIGIN)
{ {
SDL_SetRenderDrawColor(p_renderer, 0xFF, 0x00, 0xFF, 0x00); SDL_SetRenderDrawColor(p_renderer, 0xFF, 0x00, 0xFF, 0x00);
SDL_RenderFillRect(p_renderer, &Rectangle); SDL_RenderFillRect(p_renderer, &Rectangle);
@ -1230,7 +1191,7 @@ void draw_board(SDL_Renderer *p_renderer)
Rectangle.y = starting_y; Rectangle.y = starting_y;
for (size_t i = 0; i < 8; i++) for (size_t i = 0; i < 8; i++)
{ {
if (Board_Lights[j][i] == PEICE_NEEDS_TO_BE_HERE) if (Board_Lights[j][i] == PIECE_NEEDS_TO_BE_HERE)
{ {
SDL_SetRenderDrawColor(p_renderer, 0xFF, 0x00, 0x00, 0x00); SDL_SetRenderDrawColor(p_renderer, 0xFF, 0x00, 0x00, 0x00);
SDL_RenderFillRect(p_renderer, &Rectangle); SDL_RenderFillRect(p_renderer, &Rectangle);

View File

@ -1,5 +1,5 @@
#include <SDL.h> #include <SDL2/SDL.h>
#include <SDL_video.h> #include <SDL2/SDL_video.h>
void click(SDL_Renderer *p_renderer, int x, int y); void click(SDL_Renderer *p_renderer, int x, int y);
void chess_board_resize(SDL_Renderer *p_renderer, int w, int h); void chess_board_resize(SDL_Renderer *p_renderer, int w, int h);

View File

@ -3,8 +3,8 @@
#include <iostream> #include <iostream>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <SDL.h> #include <SDL2/SDL.h>
#include <SDL_video.h> #include <SDL2/SDL_video.h>
#include <time.h> #include <time.h>
#include "chess_board.h" #include "chess_board.h"

View File

@ -1,5 +1,6 @@
#define SDL_MAIN_HANDLED #define SDL_MAIN_HANDLED
#include <SDL.h> #include <SDL2/SDL.h>
#include <SDL_video.h> #include <SDL2/SDL_video.h>
int begin_game(SDL_Renderer *renderer, SDL_Window *win); int begin_game(SDL_Renderer *renderer, SDL_Window *win);

View File

@ -4,8 +4,8 @@
#include <iostream> #include <iostream>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <SDL.h> #include <SDL2/SDL.h>
#include <SDL_video.h> #include <SDL2/SDL_video.h>
#include "game.h" #include "game.h"
int main( int argc, const char* argv[] ) int main( int argc, const char* argv[] )