src/chess/rules.c

changeset 51
84f2e380a434
parent 50
41017d0a72c5
child 55
54ea19938d57
equal deleted inserted replaced
50:41017d0a72c5 51:84f2e380a434
38 if (simulation.lastmove) { 38 if (simulation.lastmove) {
39 MoveList *lastmovecopy = malloc(sizeof(MoveList)); 39 MoveList *lastmovecopy = malloc(sizeof(MoveList));
40 *lastmovecopy = *(simulation.lastmove); 40 *lastmovecopy = *(simulation.lastmove);
41 simulation.movelist = simulation.lastmove = lastmovecopy; 41 simulation.movelist = simulation.lastmove = lastmovecopy;
42 } 42 }
43 43
44 return simulation; 44 return simulation;
45 } 45 }
46 46
47 void gamestate_init(GameState *gamestate) { 47 void gamestate_init(GameState *gamestate) {
48 memset(gamestate, 0, sizeof(GameState)); 48 memset(gamestate, 0, sizeof(GameState));
419 canescape |= is_protected(&simulation, 419 canescape |= is_protected(&simulation,
420 row, threat->tofile, opponent_color(piececolor)); 420 row, threat->tofile, opponent_color(piececolor));
421 } 421 }
422 } else { 422 } else {
423 /* bishop aspect */ 423 /* bishop aspect */
424 int dr = move->torow > move->fromrow ? 1 : -1; 424 int dr = threat->torow > threat->fromrow ? 1 : -1;
425 int df = move->tofile > move->fromfile ? 1 : -1; 425 int df = threat->tofile > threat->fromfile ? 1 : -1;
426 426
427 uint8_t row = move->fromrow; 427 uint8_t row = threat->fromrow;
428 uint8_t file = move->fromfile; 428 uint8_t file = threat->fromfile;
429 while (!canescape && file != move->tofile - df 429 while (!canescape && file != threat->tofile - df
430 && row != move->torow - dr) { 430 && row != threat->torow - dr) {
431 row += dr; 431 row += dr;
432 file += df; 432 file += df;
433 canescape |= is_protected(&simulation, row, file, 433 canescape |= is_protected(&simulation, row, file,
434 opponent_color(piececolor)); 434 opponent_color(piececolor));
435 } 435 }

mercurial