src/chess/knight.c

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

mercurial