void gen_moves(const board& b, piece_colour pc, move* movelist, int& num_moves) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { row_col rc(i, j); square s = b.get(rc); if (pc == get_piece_colour(s)) { piece_type pt = get_piece_type(s); switch (pt) { case NONE: assert(0); // only here if square contains one of our pieces break; case PAWN: pawn_moves(pc, rc, b, movelist, num_moves); break; case KNIGHT: knight_moves(pc, rc, b, movelist, num_moves); break; case BISHOP: bishop_moves(pc, rc, b, movelist, num_moves); break; case ROOK: rook_moves(pc, rc, b, movelist, num_moves); break; case KING: king_moves(pc, rc, b, movelist, num_moves); break; case QUEEN: queen_moves(pc, rc, b, movelist, num_moves); break; } } } } }
/* * return the non-eat (simple) moves. * curr = starting coordinate of the move * max_step = length of maximal possible step (1 for man, BOARD_SIZE for king) * in case of an error - return error_moves */ moves get_simple_moves(settings * set, cord curr){ char piece = board_piece(set->board, curr); int color = which_color(piece); int type = tolower(piece); moves all_simple_moves = { 0 }; switch (type) { case PAWN: return pawn_moves(set, curr, color); case BISHOP: return bishop_moves(set, curr, color, FALSE); case ROOK: return rook_moves(set, curr, color, FALSE); case KNIGHT: return knight_moves(set, curr, color); case QUEEN: return queen_moves(set, curr, color, FALSE); case KING: return king_moves(set, curr, color); default: return all_simple_moves; } }