src/chess/knight.c

changeset 23
824c9522ce66
parent 19
6a26114297a1
child 47
d726e4b46c33
--- a/src/chess/knight.c	Mon Mar 31 14:08:00 2014 +0200
+++ b/src/chess/knight.c	Mon Mar 31 15:03:25 2014 +0200
@@ -38,12 +38,12 @@
     return (dx == 2 && dy == 1) || (dx == 1 && dy == 2);
 }
 
-static int knight_getloc_fixedrow(Board board, Move *move) {
+static int knight_getloc_fixedrow(GameState *gamestate, Move *move) {
     int d = 3 - abs(move->fromrow - move->torow);
     
     if (d == 1 || d == 2) {
         if (move->tofile < 6 &&
-            board[move->fromrow][move->tofile + d] == move->piece) {
+            gamestate->board[move->fromrow][move->tofile + d] == move->piece) {
             if (move->fromfile == POS_UNSPECIFIED) {
                 move->fromfile = move->tofile + d;
                 return VALID_MOVE_SYNTAX;
@@ -52,7 +52,7 @@
             }
         }
         if (move->tofile > 1 &&
-            board[move->fromrow][move->tofile - d] == move->piece) {
+            gamestate->board[move->fromrow][move->tofile - d] == move->piece) {
             if (move->fromfile == POS_UNSPECIFIED) {
                 move->fromfile = move->tofile - d;
                 return VALID_MOVE_SYNTAX;
@@ -65,12 +65,12 @@
     return INVALID_POSITION;
 }
 
-static int knight_getloc_fixedfile(Board board, Move *move) {
+static int knight_getloc_fixedfile(GameState *gamestate, Move *move) {
     int d = 3 - abs(move->fromfile - move->tofile);
     
     if (d == 1 || d == 2) {
         if (move->torow < 6 &&
-            board[move->torow + d][move->fromfile] == move->piece) {
+            gamestate->board[move->torow + d][move->fromfile] == move->piece) {
             if (move->fromrow == POS_UNSPECIFIED) {
                 move->fromrow = move->torow + d;
                 return VALID_MOVE_SYNTAX;
@@ -79,7 +79,7 @@
             }
         }
         if (move->torow > 1 &&
-            board[move->torow - d][move->fromfile] == move->piece) {
+            gamestate->board[move->torow - d][move->fromfile] == move->piece) {
             if (move->fromrow == POS_UNSPECIFIED) {
                 move->fromrow = move->torow - d;
                 return VALID_MOVE_SYNTAX;
@@ -92,14 +92,14 @@
     return INVALID_POSITION;
 }
 
-int knight_getlocation(Board board, Move *move) {
+int knight_getlocation(GameState *gamestate, Move *move) {
     
     if (move->fromfile != POS_UNSPECIFIED) {
-        return knight_getloc_fixedfile(board, move);
+        return knight_getloc_fixedfile(gamestate, move);
     }
     
     if (move->fromrow != POS_UNSPECIFIED) {
-        return knight_getloc_fixedrow(board, move);
+        return knight_getloc_fixedrow(gamestate, move);
     }
     
     for (int x = -2 ; x <= 2 ; x++) {
@@ -113,7 +113,8 @@
             uint8_t cx = move->tofile + x;
             uint8_t cy = move->torow + y;
 
-            if (isidx(cx) && isidx(cy) && board[cy][cx] == move->piece) {
+            if (isidx(cx) && isidx(cy)
+                && gamestate->board[cy][cx] == move->piece) {
                 if (move->fromfile == POS_UNSPECIFIED
                     && move->fromrow == POS_UNSPECIFIED) {
                     move->fromfile = cx;

mercurial