summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/main.c b/src/main.c
index 786c882..cbdd862 100644
--- a/src/main.c
+++ b/src/main.c
@@ -114,7 +114,7 @@ int generate_legal_moves(int origin, int* board) {
int piece = board[origin];
int* move;
- switch (piece) {
+ switch (piece & NO_COLOR) {
case KNIGHT:
move = knightMoves;
break;
@@ -131,21 +131,20 @@ int generate_legal_moves(int origin, int* board) {
move = kingMoves;
break;
case PAWN:
- move = pawnMoves;
+ if (piece & BLACK) move = blackPawnMoves;
+ else move = pawnMoves;
break;
default:
+ puts("No piece found!");
move = NULL;
}
while(*move) {
- for (int square = origin; !(square & 0x88); square += *move) {
- if (square != origin) {
- if (board[square] != EMPTY) break;
- board[square] = VISUAL;
- if (piece == PAWN || piece == KNIGHT || piece == KING) break;
- }
+ for (int square = origin + *move; !(square & 0x88); square += *move) {
+ if (board[square] != EMPTY) break;
+ board[square] = VISUAL;
+ if ((piece & NO_COLOR) == PAWN || piece == KNIGHT || piece == KING) break;
}
-
move++;
}
}