diff -r 4dcfb4c58b6d -r d726e4b46c33 src/chess/bishop.c --- a/src/chess/bishop.c Thu Apr 17 12:16:14 2014 +0200 +++ b/src/chess/bishop.c Wed May 28 15:47:57 2014 +0200 @@ -52,77 +52,3 @@ return 0; } - -static int bishop_getloc_fixedfile(GameState *gamestate, Move *move) { - uint8_t d = abs(move->fromfile - move->tofile); - if (gamestate->board[move->torow - d][move->fromfile] == move->piece) { - move->fromrow = move->torow - d; - } - if (gamestate->board[move->torow + d][move->fromfile] == move->piece) { - if (move->fromrow == POS_UNSPECIFIED) { - move->fromrow = move->torow + d; - } else { - return AMBIGUOUS_MOVE; /* rare situation after promotion */ - } - } - return move->fromrow == POS_UNSPECIFIED ? - INVALID_POSITION : VALID_MOVE_SYNTAX; -} - -static int bishop_getloc_fixedrow(GameState *gamestate, Move *move) { - uint8_t d = abs(move->fromrow - move->torow); - if (gamestate->board[move->fromrow][move->tofile - d] == move->piece) { - move->fromfile = move->tofile - d; - } - if (gamestate->board[move->fromrow][move->tofile + d] == move->piece) { - if (move->fromfile == POS_UNSPECIFIED) { - move->fromfile = move->tofile + d; - } else { - return AMBIGUOUS_MOVE; /* rare situation after promotion */ - } - } - return move->fromfile == POS_UNSPECIFIED ? - INVALID_POSITION : VALID_MOVE_SYNTAX; -} - -int bishop_getlocation(GameState *gamestate, Move *move) { - - if (move->fromfile != POS_UNSPECIFIED) { - return bishop_getloc_fixedfile(gamestate, move); - } - - if (move->fromrow != POS_UNSPECIFIED) { - return bishop_getloc_fixedrow(gamestate, move); - } - - _Bool amb = 0; - for (int d = -7 ; d < 8 ; d++) { - uint8_t row = move->torow + d; - if (isidx(row)) { - uint8_t file = move->tofile + d; - if (isidx(file) && gamestate->board[row][file] == move->piece) { - if (amb) { - return AMBIGUOUS_MOVE; - } - amb = 1; - move->fromrow = row; - move->fromfile = file; - } - file = move->tofile - d; - if (isidx(file) && gamestate->board[row][file] == move->piece) { - if (amb) { - return AMBIGUOUS_MOVE; - } - amb = 1; - move->fromrow = row; - move->fromfile = file; - } - } - } - - if (move->fromrow == POS_UNSPECIFIED || move->fromfile == POS_UNSPECIFIED) { - return INVALID_POSITION; - } else { - return VALID_MOVE_SYNTAX; - } -}