added checkers for tests
This commit is contained in:
parent
2adfb6ba1f
commit
193696f4dc
7 changed files with 22 additions and 5 deletions
BIN
assignment/chess
BIN
assignment/chess
Binary file not shown.
|
|
@ -21,10 +21,11 @@ int abs(int value) {
|
|||
}
|
||||
|
||||
struct ChessPiece get_piece(ChessBoard chess_board, File file, Rank rank) {
|
||||
struct ChessPiece piece;
|
||||
piece.color = chess_board[file - 'a'][rank - 1].piece.color;
|
||||
piece.type = chess_board[file - 'a'][rank - 1].piece.type;
|
||||
return piece;
|
||||
if (file < 'a' || file > 'h' || rank < 1 || rank > 8) {
|
||||
struct ChessPiece empty = {NO_COLOR, NoPiece};
|
||||
return empty;
|
||||
}
|
||||
return chess_board[file - 'a'][rank - 1].piece;
|
||||
}
|
||||
|
||||
struct ChessSquare* get_square(ChessBoard chess_board, File file, Rank rank) {
|
||||
|
|
@ -35,6 +36,10 @@ struct ChessSquare* get_square(ChessBoard chess_board, File file, Rank rank) {
|
|||
}
|
||||
|
||||
bool squares_share_pawns_move(Color color, MoveType move, File filePiece1, Rank rankPiece1, File filePiece2, Rank rankPiece2) {
|
||||
if ((color == White && rankPiece1 < 2) || (color == Black && rankPiece1 > 7)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int rank_diff = rankPiece2 - rankPiece1;
|
||||
int file_diff = filePiece2 - filePiece1;
|
||||
|
||||
|
|
@ -110,14 +115,26 @@ bool is_square_occupied(ChessBoard chess_board, File file, Rank rank) {
|
|||
}
|
||||
|
||||
bool squares_share_file(File file1, Rank rank1, File file2, Rank rank2) {
|
||||
if (file1 < 'a' || file1 > 'h' || file2 < 'a' || file2 > 'h' ||
|
||||
rank1 < 1 || rank1 > 8 || rank2 < 1 || rank2 > 8) {
|
||||
return false;
|
||||
}
|
||||
return file1 == file2;
|
||||
}
|
||||
|
||||
bool squares_share_rank(File file1, Rank rank1, File file2, Rank rank2) {
|
||||
if (file1 < 'a' || file1 > 'h' || file2 < 'a' || file2 > 'h' ||
|
||||
rank1 < 1 || rank1 > 8 || rank2 < 1 || rank2 > 8) {
|
||||
return false;
|
||||
}
|
||||
return rank1 == rank2;
|
||||
}
|
||||
|
||||
bool squares_share_diagonal(File file1, Rank rank1, File file2, Rank rank2) {
|
||||
if (file1 < 'a' || file1 > 'h' || file2 < 'a' || file2 > 'h' ||
|
||||
rank1 < 1 || rank1 > 8 || rank2 < 1 || rank2 > 8) {
|
||||
return false;
|
||||
}
|
||||
return abs(file1 - file2) == abs(rank1 - rank2);
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +171,7 @@ bool is_piece(struct ChessPiece piece, Color color, PieceType type) {
|
|||
}
|
||||
|
||||
bool add_piece(ChessBoard chess_board, File file, Rank rank, struct ChessPiece piece) {
|
||||
if (is_square_occupied(chess_board, file, rank)) {
|
||||
if (file < 'a' || file > 'h' || rank < 1 || rank > 8 || is_square_occupied(chess_board, file, rank)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue