Skip to content

Commit 9c24656

Browse files
committed
fixing queen
1 parent 9196c58 commit 9c24656

File tree

6 files changed

+23
-17
lines changed

6 files changed

+23
-17
lines changed

main.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"C Structs",
3232
"C Pointers",
3333
"C DateTimes",
34-
"Bash"
34+
"C Files",
35+
"Bash",
3536
]
3637
}
3738
*/
@@ -101,17 +102,17 @@ int main(void) {
101102
p1.row = row1;
102103
p1.col = col1;
103104
if(isPawn(chessBoard[p1.row][p1.col])) {
104-
badMove = dispPawnMovements(chessBoard, &p1, player == 0);
105+
badMove = dispPawnMovements(chessBoard, &(p1), player == 0);
105106
} else if(isHorse(chessBoard[row1][col1])) {
106-
badMove = dispHorseMovements(chessBoard, &p1);
107+
badMove = dispHorseMovements(chessBoard, &(p1));
107108
} else if(isBishop(chessBoard[row1][col1])) {
108-
badMove = dispBishopMovements(chessBoard, &p1);
109+
badMove = dispBishopMovements(chessBoard, &(p1));
109110
} else if(isTower(chessBoard[row1][col1])) {
110-
badMove = dispTowerMovements(chessBoard, &p1);
111+
badMove = dispTowerMovements(chessBoard, &(p1));
111112
} else if(isKing(chessBoard[row1][col1])) {
112-
badMove = dispKingMovements(chessBoard, &p1);
113+
badMove = dispKingMovements(chessBoard, &(p1));
113114
} else if(isQueen(chessBoard[row1][col1])) {
114-
badMove = dispQueenMovements(chessBoard, &p1);
115+
badMove = dispQueenMovements(chessBoard, &(p1));
115116
} else
116117
badMove = false;
117118
if(badMove)

static/chessBoardArchive.dat

512 Bytes
Binary file not shown.

static/chessBoardGames.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Winner: player number 1 (white) with 5 moves (4-05-2022 11:05:00).
2+
Winner: player number 2 (black) with 4 moves (4-05-2022 11:08:06).

utils/chessboard/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ void defineChessBoardMatrix(ChessBoard chessBoard) {
5050

5151
/*
5252
SPECIFICS:
53-
* Description: function that, given as input a (8 * 8) wchar_t matrix and 2 points (coordinates of start and finish), allows one of the two players in the chess game to take his turns.
54-
* Input: a (8 * 8) wchar_t matrix, the memory address of a Point (row, col).
55-
* Pre-condition: chessBoard must is a wchar_t (8 * 8) matrix, Point row and Point col between 0 and 7 (integers).
53+
* Description: function that, given as input a (8 * 8) wchar_t matrix a point (coordinates of start and finish), allows one of the two players in the chess game to take his turns.
54+
* Input: a (8 * 8) wchar_t matrix reference, a Point (row, col) reference.
55+
* Pre-condition: chessBoard must is a wchar_t (8 * 8) matrix reference, Point row and Point col between 0 and 7 (integers).
5656
* Output: a boolean value named "hasWin".
5757
* Post-condition: hasWin holds true if a player eats the opponent's queen.
5858
*/
@@ -635,6 +635,7 @@ bool playerTurn(ChessBoard chessBoard, Point* p1) {
635635
if(isQueenMovement(p1, &(p2)) && !isEqualColor(chessBoard[p1->row][p1->col], chessBoard[p2.row][p2.col])) {
636636
badMove = false;
637637
hasWin = move(chessBoard, p1, &(p2));
638+
// (0, 4) ==> (3, 1)
638639
isWhiteCastlingPossible = false;
639640
} else if(isCastlingMovement(chessBoard, p1, &(p2)) && isWhiteCastlingPossible) {
640641
// arrocco bianco

utils/chessboard/main.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ void chessBoardDealloc(ChessBoard chessBoard);
1616

1717
/*
1818
SPECIFICS:
19-
* Description: function that, given as input a (8 * 8) wchar_t matrix and 2 points (coordinates of start and finish), allows one of the two players in the chess game to take his turns.
20-
* Input: a (8 * 8) wchar_t matrix, the memory address of a Point (row, col).
21-
* Pre-condition: chessBoard must is a wchar_t (8 * 8) matrix, Point row and Point col between 0 and 7 (integers).
19+
* Description: function that, given as input a (8 * 8) wchar_t matrix a point (coordinates of start and finish), allows one of the two players in the chess game to take his turns.
20+
* Input: a (8 * 8) wchar_t matrix reference, a Point (row, col) reference.
21+
* Pre-condition: chessBoard must is a wchar_t (8 * 8) matrix reference, Point row and Point col between 0 and 7 (integers).
2222
* Output: a boolean value named "hasWin".
2323
* Post-condition: hasWin holds true if a player eats the opponent's queen.
2424
*/

utils/movements/main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,15 @@ bool isKingMovement(Point* p1, Point* p2) {
8686
}
8787

8888
bool isQueenMovement(Point* p1, Point* p2) {
89-
return (
89+
return ( // (0, 4) ==> (3, 1)
90+
((abs(p1->row - p2->row) == 1) || (abs(p1->col - p2->col) == 1)) && (
9091
(p1->row == p2->row - 1 && p1->col == p2->col) ||
9192
(p1->row == p2->row + 1 && p1->col == p2->col) ||
9293
(p1->row == p2->row && p1->col == p2->col - 1) ||
9394
(p1->row == p2->row && p1->col == p2->col + 1) ||
9495
(p1->row + p1->col - 2 == p2->row + p2->col && p1->row != p2->row && p1->col != p2->col) ||
9596
(p1->row + p1->col + 2 == p2->row + p2->col && p1->row != p2->row && p1->col != p2->col) ||
96-
(p1->row + p1->col == p2->row + p2->col && p1->row != p2->row && p1->col != p2->col)
97+
(p1->row + p1->col == p2->row + p2->col && p1->row != p2->row && p1->col != p2->col))
9798
);
9899
}
99100

@@ -117,14 +118,15 @@ bool move(ChessBoard chessBoard, Point* p1, Point* p2) {
117118
}
118119

119120
bool isCastlingMovement(ChessBoard chessBoard, Point* p1, Point* p2) {
120-
return
121+
return (
121122
isQueen(chessBoard[p1->row][p1->col]) &&
122123
(p1->row == p2->row && (p1->row == 0 || p1->row == 7)) &&
123124
(p1->col == 4 && p2->col == 6) &&
124125
isFreePosition(chessBoard[p1->row][p1->col + 1]) &&
125126
isFreePosition(chessBoard[p2->row][p2->col]) &&
126127
isTower(chessBoard[p2->row][p2->col + 1]) &&
127-
isEqualColor(chessBoard[p1->row][p1->col], chessBoard[p2->row][p2->col + 1]);
128+
isEqualColor(chessBoard[p1->row][p1->col], chessBoard[p2->row][p2->col + 1])
129+
);
128130
}
129131

130132
void castling(ChessBoard chessBoard, Point* p1, Point* p2) {

0 commit comments

Comments
 (0)