src/chess/rook.c

changeset 23
824c9522ce66
parent 21
2e5846019b4f
child 47
d726e4b46c33
     1.1 --- a/src/chess/rook.c	Mon Mar 31 14:08:00 2014 +0200
     1.2 +++ b/src/chess/rook.c	Mon Mar 31 15:03:25 2014 +0200
     1.3 @@ -34,14 +34,14 @@
     1.4      return move->torow == move->fromrow || move->tofile == move->fromfile;
     1.5  }
     1.6  
     1.7 -_Bool rook_isblocked(Board board, Move *move) {
     1.8 +_Bool rook_isblocked(GameState *gamestate, Move *move) {
     1.9      
    1.10      if (move->torow == move->fromrow) {
    1.11          int d = move->tofile > move->fromfile ? 1 : -1;
    1.12          uint8_t f = move->fromfile;
    1.13          while (f != move->tofile-d) {
    1.14              f += d;
    1.15 -            if (board[move->fromrow][f]) {
    1.16 +            if (gamestate->board[move->fromrow][f]) {
    1.17                  return 1;
    1.18              }
    1.19          }
    1.20 @@ -50,7 +50,7 @@
    1.21          uint8_t r = move->fromrow;
    1.22          while (r != move->torow - d) {
    1.23              r += d;
    1.24 -            if (board[r][move->fromfile]) {
    1.25 +            if (gamestate->board[r][move->fromfile]) {
    1.26                  return 1;
    1.27              }
    1.28          }
    1.29 @@ -59,10 +59,10 @@
    1.30      return 0;
    1.31  }
    1.32  
    1.33 -static int rook_getloc_fixedrow(Board board, Move *move) {
    1.34 +static int rook_getloc_fixedrow(GameState *gamestate, Move *move) {
    1.35      uint8_t file = POS_UNSPECIFIED;
    1.36      for (uint8_t f = 0 ; f < 8 ; f++) {
    1.37 -        if (board[move->fromrow][f] == move->piece) {
    1.38 +        if (gamestate->board[move->fromrow][f] == move->piece) {
    1.39              if (file == POS_UNSPECIFIED) {
    1.40                  file = f;
    1.41              } else {
    1.42 @@ -78,10 +78,10 @@
    1.43      }
    1.44  }
    1.45  
    1.46 -static int rook_getloc_fixedfile(Board board, Move *move) {
    1.47 +static int rook_getloc_fixedfile(GameState *gamestate, Move *move) {
    1.48      uint8_t row = POS_UNSPECIFIED;
    1.49      for (uint8_t r = 0 ; r < 8 ; r++) {
    1.50 -        if (board[r][move->fromfile] == move->piece) {
    1.51 +        if (gamestate->board[r][move->fromfile] == move->piece) {
    1.52              if (row == POS_UNSPECIFIED) {
    1.53                  row = r;
    1.54              } else {
    1.55 @@ -97,13 +97,13 @@
    1.56      }
    1.57  }
    1.58  
    1.59 -int rook_getlocation(Board board, Move *move) {
    1.60 +int rook_getlocation(GameState *gamestate, Move *move) {
    1.61      
    1.62      if (move->fromfile != POS_UNSPECIFIED) {
    1.63          if (move->fromfile == move->tofile) {
    1.64 -            return rook_getloc_fixedfile(board, move);
    1.65 +            return rook_getloc_fixedfile(gamestate, move);
    1.66          } else {
    1.67 -            if (board[move->torow][move->fromfile] == move->piece) {
    1.68 +            if (gamestate->board[move->torow][move->fromfile] == move->piece) {
    1.69                  move->fromrow = move->torow;
    1.70                  return VALID_MOVE_SYNTAX;
    1.71              } else {
    1.72 @@ -114,9 +114,9 @@
    1.73      
    1.74      if (move->fromrow != POS_UNSPECIFIED) {
    1.75          if (move->fromrow == move->torow) {
    1.76 -            return rook_getloc_fixedrow(board, move);
    1.77 +            return rook_getloc_fixedrow(gamestate, move);
    1.78          } else {
    1.79 -            if (board[move->fromrow][move->tofile] == move->piece) {
    1.80 +            if (gamestate->board[move->fromrow][move->tofile] == move->piece) {
    1.81                  move->fromfile = move->tofile;
    1.82                  return VALID_MOVE_SYNTAX;
    1.83              } else {
    1.84 @@ -128,10 +128,10 @@
    1.85      Move chkrowmove = *move, chkfilemove = *move;
    1.86      
    1.87      chkrowmove.fromrow = move->torow;
    1.88 -    int chkrow = rook_getloc_fixedrow(board, &chkrowmove);
    1.89 +    int chkrow = rook_getloc_fixedrow(gamestate, &chkrowmove);
    1.90      
    1.91      chkfilemove.fromfile = move->tofile;
    1.92 -    int chkfile = rook_getloc_fixedfile(board, &chkfilemove);
    1.93 +    int chkfile = rook_getloc_fixedfile(gamestate, &chkfilemove);
    1.94      
    1.95      if ((chkrow == VALID_MOVE_SYNTAX && chkfile == VALID_MOVE_SYNTAX) ||
    1.96          chkrow == AMBIGUOUS_MOVE || chkfile == AMBIGUOUS_MOVE) {

mercurial