src/chess/rook.c

changeset 47
d726e4b46c33
parent 23
824c9522ce66
child 55
54ea19938d57
     1.1 --- a/src/chess/rook.c	Thu Apr 17 12:16:14 2014 +0200
     1.2 +++ b/src/chess/rook.c	Wed May 28 15:47:57 2014 +0200
     1.3 @@ -58,95 +58,3 @@
     1.4      
     1.5      return 0;
     1.6  }
     1.7 -
     1.8 -static int rook_getloc_fixedrow(GameState *gamestate, Move *move) {
     1.9 -    uint8_t file = POS_UNSPECIFIED;
    1.10 -    for (uint8_t f = 0 ; f < 8 ; f++) {
    1.11 -        if (gamestate->board[move->fromrow][f] == move->piece) {
    1.12 -            if (file == POS_UNSPECIFIED) {
    1.13 -                file = f;
    1.14 -            } else {
    1.15 -                return AMBIGUOUS_MOVE;
    1.16 -            }
    1.17 -        }
    1.18 -    }
    1.19 -    if (file == POS_UNSPECIFIED) {
    1.20 -        return INVALID_POSITION;
    1.21 -    } else {
    1.22 -        move->fromfile = file;
    1.23 -        return VALID_MOVE_SYNTAX;
    1.24 -    }
    1.25 -}
    1.26 -
    1.27 -static int rook_getloc_fixedfile(GameState *gamestate, Move *move) {
    1.28 -    uint8_t row = POS_UNSPECIFIED;
    1.29 -    for (uint8_t r = 0 ; r < 8 ; r++) {
    1.30 -        if (gamestate->board[r][move->fromfile] == move->piece) {
    1.31 -            if (row == POS_UNSPECIFIED) {
    1.32 -                row = r;
    1.33 -            } else {
    1.34 -                return AMBIGUOUS_MOVE;
    1.35 -            }
    1.36 -        }   
    1.37 -    }
    1.38 -    if (row == POS_UNSPECIFIED) {
    1.39 -        return INVALID_POSITION;
    1.40 -    } else {
    1.41 -        move->fromrow = row;
    1.42 -        return VALID_MOVE_SYNTAX;
    1.43 -    }
    1.44 -}
    1.45 -
    1.46 -int rook_getlocation(GameState *gamestate, Move *move) {
    1.47 -    
    1.48 -    if (move->fromfile != POS_UNSPECIFIED) {
    1.49 -        if (move->fromfile == move->tofile) {
    1.50 -            return rook_getloc_fixedfile(gamestate, move);
    1.51 -        } else {
    1.52 -            if (gamestate->board[move->torow][move->fromfile] == move->piece) {
    1.53 -                move->fromrow = move->torow;
    1.54 -                return VALID_MOVE_SYNTAX;
    1.55 -            } else {
    1.56 -                return INVALID_POSITION;
    1.57 -            }
    1.58 -        }
    1.59 -    }
    1.60 -    
    1.61 -    if (move->fromrow != POS_UNSPECIFIED) {
    1.62 -        if (move->fromrow == move->torow) {
    1.63 -            return rook_getloc_fixedrow(gamestate, move);
    1.64 -        } else {
    1.65 -            if (gamestate->board[move->fromrow][move->tofile] == move->piece) {
    1.66 -                move->fromfile = move->tofile;
    1.67 -                return VALID_MOVE_SYNTAX;
    1.68 -            } else {
    1.69 -                return INVALID_POSITION;
    1.70 -            }
    1.71 -        }
    1.72 -    }
    1.73 -    
    1.74 -    Move chkrowmove = *move, chkfilemove = *move;
    1.75 -    
    1.76 -    chkrowmove.fromrow = move->torow;
    1.77 -    int chkrow = rook_getloc_fixedrow(gamestate, &chkrowmove);
    1.78 -    
    1.79 -    chkfilemove.fromfile = move->tofile;
    1.80 -    int chkfile = rook_getloc_fixedfile(gamestate, &chkfilemove);
    1.81 -    
    1.82 -    if ((chkrow == VALID_MOVE_SYNTAX && chkfile == VALID_MOVE_SYNTAX) ||
    1.83 -        chkrow == AMBIGUOUS_MOVE || chkfile == AMBIGUOUS_MOVE) {
    1.84 -        return AMBIGUOUS_MOVE;
    1.85 -    }
    1.86 -    
    1.87 -    if (chkrow == VALID_MOVE_SYNTAX) {
    1.88 -        *move = chkrowmove;
    1.89 -        return VALID_MOVE_SYNTAX;
    1.90 -    }
    1.91 -    
    1.92 -    if (chkfile == VALID_MOVE_SYNTAX) {
    1.93 -        *move = chkfilemove;
    1.94 -        return VALID_MOVE_SYNTAX;
    1.95 -    }
    1.96 -    
    1.97 -    return INVALID_POSITION;
    1.98 -}

mercurial