src/chess/bishop.c

changeset 47
d726e4b46c33
parent 23
824c9522ce66
child 55
54ea19938d57
     1.1 --- a/src/chess/bishop.c	Thu Apr 17 12:16:14 2014 +0200
     1.2 +++ b/src/chess/bishop.c	Wed May 28 15:47:57 2014 +0200
     1.3 @@ -52,77 +52,3 @@
     1.4      
     1.5      return 0;
     1.6  }
     1.7 -
     1.8 -static int bishop_getloc_fixedfile(GameState *gamestate, Move *move) {
     1.9 -    uint8_t d = abs(move->fromfile - move->tofile);
    1.10 -    if (gamestate->board[move->torow - d][move->fromfile] == move->piece) {
    1.11 -        move->fromrow = move->torow - d;
    1.12 -    }
    1.13 -    if (gamestate->board[move->torow + d][move->fromfile] == move->piece) {
    1.14 -        if (move->fromrow == POS_UNSPECIFIED) {
    1.15 -            move->fromrow = move->torow + d;
    1.16 -        } else {
    1.17 -            return AMBIGUOUS_MOVE; /* rare situation after promotion */
    1.18 -        }
    1.19 -    }
    1.20 -    return move->fromrow == POS_UNSPECIFIED ?
    1.21 -        INVALID_POSITION : VALID_MOVE_SYNTAX;
    1.22 -}
    1.23 -
    1.24 -static int bishop_getloc_fixedrow(GameState *gamestate, Move *move) {
    1.25 -    uint8_t d = abs(move->fromrow - move->torow);
    1.26 -    if (gamestate->board[move->fromrow][move->tofile - d] == move->piece) {
    1.27 -        move->fromfile = move->tofile - d;
    1.28 -    }
    1.29 -    if (gamestate->board[move->fromrow][move->tofile + d] == move->piece) {
    1.30 -        if (move->fromfile == POS_UNSPECIFIED) {
    1.31 -            move->fromfile = move->tofile + d;
    1.32 -        } else {
    1.33 -            return AMBIGUOUS_MOVE; /* rare situation after promotion */
    1.34 -        }
    1.35 -    }
    1.36 -    return move->fromfile == POS_UNSPECIFIED ?
    1.37 -        INVALID_POSITION : VALID_MOVE_SYNTAX;
    1.38 -}
    1.39 -
    1.40 -int bishop_getlocation(GameState *gamestate, Move *move) {
    1.41 -    
    1.42 -    if (move->fromfile != POS_UNSPECIFIED) {
    1.43 -        return bishop_getloc_fixedfile(gamestate, move);
    1.44 -    }
    1.45 -    
    1.46 -    if (move->fromrow != POS_UNSPECIFIED) {
    1.47 -        return bishop_getloc_fixedrow(gamestate, move);
    1.48 -    }
    1.49 -    
    1.50 -    _Bool amb = 0;
    1.51 -    for (int d = -7 ; d < 8  ; d++) {
    1.52 -        uint8_t row = move->torow + d;
    1.53 -        if (isidx(row)) {
    1.54 -            uint8_t file = move->tofile + d;
    1.55 -            if (isidx(file) && gamestate->board[row][file] == move->piece) {
    1.56 -                if (amb) {
    1.57 -                    return AMBIGUOUS_MOVE;
    1.58 -                }
    1.59 -                amb = 1;
    1.60 -                move->fromrow = row;
    1.61 -                move->fromfile = file;
    1.62 -            }
    1.63 -            file = move->tofile - d;
    1.64 -            if (isidx(file) && gamestate->board[row][file] == move->piece) {
    1.65 -                if (amb) {
    1.66 -                    return AMBIGUOUS_MOVE;
    1.67 -                }
    1.68 -                amb = 1;
    1.69 -                move->fromrow = row;
    1.70 -                move->fromfile = file;
    1.71 -            }
    1.72 -        }
    1.73 -    }
    1.74 -    
    1.75 -    if (move->fromrow == POS_UNSPECIFIED || move->fromfile == POS_UNSPECIFIED) {
    1.76 -        return INVALID_POSITION;
    1.77 -    } else {
    1.78 -        return VALID_MOVE_SYNTAX;
    1.79 -    }
    1.80 -}

mercurial