diff -r 4d030da07c88 -r 3ab0c2e1a4e2 src/chess/rules.c --- a/src/chess/rules.c Tue Apr 01 10:28:08 2014 +0200 +++ b/src/chess/rules.c Tue Apr 01 12:30:25 2014 +0200 @@ -90,6 +90,30 @@ } } +_Bool is_covered(GameState *gamestate,uint8_t row,uint8_t file,uint8_t color) { + Move threats[16]; + int threatcount = 0; + for (uint8_t r = 0 ; r < 8 ; r++) { + for (uint8_t f = 0 ; f < 8 ; f++) { + if ((gamestate->board[r][f] & COLOR_MASK) == color) { + threats[threatcount].piece = gamestate->board[r][f]; + threats[threatcount].fromrow = r; + threats[threatcount].fromfile = f; + threats[threatcount].torow = row; + threats[threatcount].tofile = file; + threatcount++; + } + } + } + + for (int i = 0 ; i < threatcount ; i++) { + if (validate_move(gamestate, &(threats[i]))) { + return 1; + } + } + + return 0; +} void apply_move(GameState *gamestate, Move *move) { uint8_t piece = move->piece & PIECE_MASK; @@ -190,10 +214,15 @@ result = 0; } + /* cancel processing to avoid recursion overflow with is_covered() */ + if (!result) { + return 0; + } + /* is piece pinned */ // TODO: make it so - /* correct check and checkmate flags */ + /* correct check and checkmate flags (move is still valid) */ // TODO: make it so return result;