Adding rscons as the building system and beginning to re-factor code
This commit is contained in:
parent
a23ce67434
commit
9afc19cba0
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
build/
|
||||
.rscons*
|
||||
.vscode/
|
12
Rsconscript.rb
Normal file
12
Rsconscript.rb
Normal 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
|
@ -1,6 +1,6 @@
|
||||
#include "chess_board.h"
|
||||
#include <SDL.h>
|
||||
#include <SDL_video.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
#include "stdio.h"
|
||||
#include <stack>
|
||||
#include <string.h>
|
||||
@ -27,10 +27,10 @@
|
||||
#define POTENTIAL_TAKE 2u
|
||||
#define SUGGESTED_MOVE 3u
|
||||
#define ERROR_MOVE 4u
|
||||
#define PEICE_ORIGIN 5u
|
||||
#define PEICE_NEEDS_TO_BE_HERE 6u
|
||||
#define PIECE_ORIGIN 5u
|
||||
#define PIECE_NEEDS_TO_BE_HERE 6u
|
||||
#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_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 Last_Game_State = GAME_STATE_P1_TURN_BEGINING;
|
||||
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 Taken_Peice = SQUARE_EMPTY;
|
||||
static uint8_t Taken_Piece = SQUARE_EMPTY;
|
||||
static bool Check[2u] = {false, false};
|
||||
static uint8_t King_Locations[2u][2u] = {{7,4}, {0,4}};
|
||||
static bool Castling_Allowed[2u][2u] = {{true, true}, {true, true}};
|
||||
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.
|
||||
* @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.
|
||||
* @note Peices should be enumerated even if white and odd if black.
|
||||
* @param piece: The peice under question.
|
||||
* @brief Function for determining if the piece is on the white team or on the black team.
|
||||
* @note Pieces should be enumerated even if white and odd if black.
|
||||
* @param piece: The piece under question.
|
||||
* @retval Return true if on the white team, else false.
|
||||
*/
|
||||
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.
|
||||
* @param piece_one: Peice one ofcoarse.
|
||||
* @param piece_two: Peice two obviously.
|
||||
* @brief Function for determining if two pieces are on the same team or not.
|
||||
* @param piece_one: Piece one ofcoarse.
|
||||
* @param piece_two: Piece two obviously.
|
||||
* @retval True if on opposite teams, else false.
|
||||
*/
|
||||
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)
|
||||
{
|
||||
int8_t direction = White_Turn ? -1 : 1;
|
||||
int8_t temp = row + (White_Turn ? -1 : 1);
|
||||
|
||||
/* 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.
|
||||
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.
|
||||
return false;
|
||||
@ -316,27 +305,15 @@ bool square_is_safe(uint8_t row, uint8_t column)
|
||||
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 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.
|
||||
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] = SQUARE_EMPTY;
|
||||
|
||||
Board_State[row][column] = store_current_piece;
|
||||
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;
|
||||
}
|
||||
|
||||
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.
|
||||
* @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 ((!High_Alert) || (!Check_If_Move_Caused_Check(row, column)))
|
||||
{
|
||||
Board_Lights[row][column] = POTENTIAL_MOVE;
|
||||
}
|
||||
Set_Light(row, column, POTENTIAL_MOVE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -383,7 +365,7 @@ static void pawn_move(uint8_t row, uint8_t column)
|
||||
* @param direction_c: Column direction
|
||||
* @param row: current row 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
|
||||
*/
|
||||
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)
|
||||
{
|
||||
if ((!High_Alert) || (!Check_If_Move_Caused_Check(x, y)))
|
||||
{
|
||||
Board_Lights[x][y] = POTENTIAL_MOVE;
|
||||
}
|
||||
Set_Light(x, y, POTENTIAL_MOVE);
|
||||
}
|
||||
else if (opposite_teams(piece_one, Board_State[x][y]))
|
||||
{
|
||||
if ((!High_Alert) || (!Check_If_Take_Caused_Check(x, y)))
|
||||
{
|
||||
Board_Lights[x][y] = POTENTIAL_TAKE;
|
||||
}
|
||||
/* once we take a peice we can no longer take anymore */
|
||||
Set_Light(x, y, POTENTIAL_TAKE);
|
||||
/* once we take a piece we can no longer take anymore */
|
||||
loop = false;
|
||||
}
|
||||
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 column: Column obviously
|
||||
* @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)))
|
||||
{
|
||||
Board_Lights[row][column] = POTENTIAL_TAKE;
|
||||
}
|
||||
Set_Light(row, column, POTENTIAL_TAKE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for marking the potential moves.
|
||||
* @param piece: Peice that we are marking the potential moves for.
|
||||
* @param row: Current row location of the peice.
|
||||
* @param column: Current column location of the peice.
|
||||
* @param piece: Piece that we are marking the potential moves for.
|
||||
* @param row: Current row location of the piece.
|
||||
* @param column: Current column location of the piece.
|
||||
* @retval None
|
||||
*/
|
||||
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:
|
||||
{
|
||||
int8_t direction = White_Turn ? -1 : 1;
|
||||
uint8_t temp_row = row + direction;
|
||||
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, column);
|
||||
|
||||
if ((row >= 1u) && opposite_teams(piece, Board_State[row + direction][column - 1u]))
|
||||
{
|
||||
pawn_take(row + direction, column - 1u);
|
||||
}
|
||||
if ((row <= 6u) && opposite_teams(piece, Board_State[row + direction][column + 1u]))
|
||||
{
|
||||
pawn_take(row + direction, column + 1u);
|
||||
}
|
||||
pawn_move(temp_row, column);
|
||||
pawn_take(temp_row, column - 1u, piece);
|
||||
pawn_take(temp_row, column + 1u, piece);
|
||||
|
||||
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 ((!High_Alert) || (!Check_If_Move_Caused_Check(x, y)))
|
||||
{
|
||||
Board_Lights[x][y] = POTENTIAL_MOVE;
|
||||
}
|
||||
Set_Light(x, y, POTENTIAL_MOVE);
|
||||
}
|
||||
else if (opposite_teams(piece, Board_State[x][y]))
|
||||
{
|
||||
if ((!High_Alert) || (!Check_If_Take_Caused_Check(x, y)))
|
||||
{
|
||||
Board_Lights[x][y] = POTENTIAL_TAKE;
|
||||
}
|
||||
Set_Light(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);
|
||||
switch (Taken_Peice)
|
||||
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:
|
||||
@ -689,10 +650,10 @@ void Mark_Taken_Peice_Spots_In_Jail(void)
|
||||
{
|
||||
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;
|
||||
Taken_Peice = SQUARE_EMPTY;
|
||||
Board_State[add + j][i] = Taken_Piece;
|
||||
Taken_Piece = SQUARE_EMPTY;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -708,14 +669,14 @@ void Mark_Taken_Peice_Spots_In_Jail(void)
|
||||
case QUEEN_WHITE:
|
||||
case QUEEN_BLACK:
|
||||
{
|
||||
uint8_t jail_row = (Taken_Peice / 2u) + 2u;
|
||||
if (Board_State[add][jail_row] != Taken_Peice)
|
||||
uint8_t jail_row = (Taken_Piece / 2u) + 2u;
|
||||
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;
|
||||
}
|
||||
@ -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.
|
||||
* @param row: Current row location of the peice.
|
||||
* @param column: Current column location of the peice.
|
||||
* @param row: Current row location of the piece.
|
||||
* @param column: Current column location of the piece.
|
||||
* @retval None
|
||||
*/
|
||||
void Check_If_Moving_King(uint8_t row, uint8_t column)
|
||||
{
|
||||
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][1u] = column;
|
||||
@ -758,8 +719,8 @@ void Check_If_Moving_King(uint8_t row, uint8_t column)
|
||||
Castling_Allowed[white_black_idx][1u] = false;
|
||||
}
|
||||
// Disable the castling of the corresponding side if the rook is being moved.
|
||||
else if (((Selected_Peice == ROOK_WHITE) && (row == 7u))
|
||||
|| ((Selected_Peice == ROOK_BLACK) && (row == 0u)))
|
||||
else if (((Selected_Piece == ROOK_WHITE) && (row == 7u))
|
||||
|| ((Selected_Piece == ROOK_BLACK) && (row == 0u)))
|
||||
{
|
||||
if (column == 0u)
|
||||
{
|
||||
@ -784,37 +745,37 @@ void Board_Square_Was_Toggled(uint8_t j, uint8_t i)
|
||||
{
|
||||
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;
|
||||
Selected_Peice = SQUARE_EMPTY;
|
||||
Board_State[j][i] = Selected_Piece;
|
||||
Selected_Piece = SQUARE_EMPTY;
|
||||
clear_lights();
|
||||
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)
|
||||
{
|
||||
Board_State[j][i] = Selected_Peice;
|
||||
Selected_Peice = SQUARE_EMPTY;
|
||||
Board_State[j][i] = Selected_Piece;
|
||||
Selected_Piece = SQUARE_EMPTY;
|
||||
Board_Lights[j][i] = LIGHT_OFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
Board_State[j][i] = Taken_Peice;
|
||||
Board_State[j][i] = Taken_Piece;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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);
|
||||
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_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((Board_State[j][i] != KING_BLACK) && (Board_State[j][i] != KING_WHITE))
|
||||
{
|
||||
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;
|
||||
Mark_Potential_Moves(Selected_Peice, i, j);
|
||||
Board_Lights[j][i] = PEICE_ORIGIN;
|
||||
Mark_Potential_Moves(Selected_Piece, i, j);
|
||||
Board_Lights[j][i] = PIECE_ORIGIN;
|
||||
Game_State++;
|
||||
}
|
||||
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_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)
|
||||
{
|
||||
Check_If_Moving_King(j, i);
|
||||
Board_State[j][i] = Selected_Peice;
|
||||
Selected_Peice = SQUARE_EMPTY;
|
||||
Board_State[j][i] = Selected_Piece;
|
||||
Selected_Piece = SQUARE_EMPTY;
|
||||
clear_lights();
|
||||
Switch_Turns();
|
||||
}
|
||||
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;
|
||||
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();
|
||||
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;
|
||||
Selected_Peice = SQUARE_EMPTY;
|
||||
Board_State[j][i] = Selected_Piece;
|
||||
Selected_Piece = SQUARE_EMPTY;
|
||||
clear_lights();
|
||||
Game_State--;
|
||||
}
|
||||
else if (Board_Lights[j][i] == POTENTIAL_CASTLE)
|
||||
{
|
||||
Check_If_Moving_King(j, i);
|
||||
Board_State[j][i] = Selected_Peice;
|
||||
Selected_Peice = SQUARE_EMPTY;
|
||||
Board_State[j][i] = Selected_Piece;
|
||||
Selected_Piece = SQUARE_EMPTY;
|
||||
clear_lights();
|
||||
if(i == 2u)
|
||||
{
|
||||
Board_Lights[j][3u] = PEICE_NEEDS_TO_BE_HERE;
|
||||
Board_Lights[j][0u] = PEICE_NEEDS_TO_BE_REMOVED;
|
||||
Board_Lights[j][3u] = PIECE_NEEDS_TO_BE_HERE;
|
||||
Board_Lights[j][0u] = PIECE_NEEDS_TO_BE_REMOVED;
|
||||
}
|
||||
else if(i == 6u)
|
||||
{
|
||||
Board_Lights[j][5u] = PEICE_NEEDS_TO_BE_HERE;
|
||||
Board_Lights[j][7u] = PEICE_NEEDS_TO_BE_REMOVED;
|
||||
Board_Lights[j][5u] = PIECE_NEEDS_TO_BE_HERE;
|
||||
Board_Lights[j][7u] = PIECE_NEEDS_TO_BE_REMOVED;
|
||||
}
|
||||
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_Lights[j][i] = LIGHT_OFF;
|
||||
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_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)
|
||||
{
|
||||
Board_State[j][i] = Selected_Peice;
|
||||
Selected_Peice = SQUARE_EMPTY;
|
||||
Board_State[j][i] = Selected_Piece;
|
||||
Selected_Piece = SQUARE_EMPTY;
|
||||
Board_Lights[j][i] = LIGHT_OFF;
|
||||
}
|
||||
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 + 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++;
|
||||
}
|
||||
|
||||
if ((Selected_Peice == SQUARE_EMPTY) && (Taken_Peice == SQUARE_EMPTY))
|
||||
if ((Selected_Piece == SQUARE_EMPTY) && (Taken_Piece == SQUARE_EMPTY))
|
||||
{
|
||||
Switch_Turns();
|
||||
}
|
||||
@ -1141,7 +1102,7 @@ void chess_board_init(SDL_Renderer *p_renderer)
|
||||
for (uint8_t i = 0; i < 12; i++)
|
||||
{
|
||||
//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);
|
||||
bitmapSurface = SDL_LoadBMP(file);
|
||||
bitmapTextures[i] = SDL_CreateTextureFromSurface(p_renderer, bitmapSurface);
|
||||
@ -1182,13 +1143,13 @@ void draw_board(SDL_Renderer *p_renderer)
|
||||
SDL_RenderFillRect(p_renderer, &Rectangle);
|
||||
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_RenderFillRect(p_renderer, &Rectangle);
|
||||
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_RenderFillRect(p_renderer, &Rectangle);
|
||||
@ -1230,7 +1191,7 @@ void draw_board(SDL_Renderer *p_renderer)
|
||||
Rectangle.y = starting_y;
|
||||
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_RenderFillRect(p_renderer, &Rectangle);
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <SDL.h>
|
||||
#include <SDL_video.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
|
||||
void click(SDL_Renderer *p_renderer, int x, int y);
|
||||
void chess_board_resize(SDL_Renderer *p_renderer, int w, int h);
|
||||
|
@ -3,8 +3,8 @@
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <SDL.h>
|
||||
#include <SDL_video.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
#include <time.h>
|
||||
#include "chess_board.h"
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include <SDL.h>
|
||||
#include <SDL_video.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
|
||||
|
||||
int begin_game(SDL_Renderer *renderer, SDL_Window *win);
|
||||
|
@ -4,8 +4,8 @@
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <SDL.h>
|
||||
#include <SDL_video.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
#include "game.h"
|
||||
|
||||
int main( int argc, const char* argv[] )
|
||||
|
Loading…
Reference in New Issue
Block a user