Final version, check bugfix

This commit is contained in:
Marcus Penate 2022-04-19 02:29:01 -04:00
parent 66195867eb
commit 7415fac59b
2 changed files with 23 additions and 16 deletions

View File

@ -420,8 +420,6 @@ std::vector<int> Board::get_moves_for_space(int x, int y, bool check_for_check)
int forward_direction = (game_board[x][y].get_team() == WHITE)?-1:1; int forward_direction = (game_board[x][y].get_team() == WHITE)?-1:1;
bool is_team_in_check = (check_for_check && is_check(game_board[x][y].get_team()));
std::vector<int> out_spaces; std::vector<int> out_spaces;
Type piece_type = (game_board[x][y].get_vis() == HIDDEN)?UNKNOWN:game_board[x][y].get_type(); Type piece_type = (game_board[x][y].get_vis() == HIDDEN)?UNKNOWN:game_board[x][y].get_type();
@ -642,7 +640,7 @@ std::vector<int> Board::get_moves_for_space(int x, int y, bool check_for_check)
out_spaces.push_back(x+y*BOARD_SIZE); out_spaces.push_back(x+y*BOARD_SIZE);
} }
if (is_team_in_check) if (check_for_check)
{ {
std::vector<int>::iterator new_end = std::remove_if(out_spaces.begin(), out_spaces.end(), [this, x, y](const int& target_space){ return !this->does_move_solve_check(x+y*BOARD_SIZE, target_space); }); std::vector<int>::iterator new_end = std::remove_if(out_spaces.begin(), out_spaces.end(), [this, x, y](const int& target_space){ return !this->does_move_solve_check(x+y*BOARD_SIZE, target_space); });
out_spaces.erase(new_end, out_spaces.end()); out_spaces.erase(new_end, out_spaces.end());
@ -854,12 +852,12 @@ int Board::get_attackers_for_space(int space_to)
continue; continue;
} }
if (game_board[xf][yf].get_team() != enemy_team || game_board[xf][yf].get_type() != PAWN) if (game_board[xf][yf].get_team() == NO_TEAM || game_board[xf][yf].get_type() != PAWN)
{ {
continue; continue;
} }
num_attackers++; num_attackers += (game_board[xf][yf].get_team() == enemy_team)?1:-1;
} }
} }
@ -873,12 +871,12 @@ int Board::get_attackers_for_space(int space_to)
continue; continue;
} }
if (game_board[xf][yf].get_team() != enemy_team || game_board[xf][yf].get_type() != PAWN) if (game_board[xf][yf].get_team() == NO_TEAM || game_board[xf][yf].get_type() != PAWN)
{ {
continue; continue;
} }
num_attackers++; num_attackers += (game_board[xf][yf].get_team() == enemy_team)?1:-1;
} }
int king_offsets[8][2] = {{-1,-1},{0,-1},{1,-1},{-1,0},{1,0},{1,-1},{1,0},{1,1}}; int king_offsets[8][2] = {{-1,-1},{0,-1},{1,-1},{-1,0},{1,0},{1,-1},{1,0},{1,1}};
@ -892,12 +890,12 @@ int Board::get_attackers_for_space(int space_to)
continue; continue;
} }
if (game_board[xf][yf].get_team() != enemy_team || (game_board[xf][yf].get_type() != KING && game_board[xf][yf].get_vis() != HIDDEN)) if (game_board[xf][yf].get_team() == NO_TEAM || (game_board[xf][yf].get_type() != KING && game_board[xf][yf].get_vis() != HIDDEN))
{ {
continue; continue;
} }
num_attackers++; num_attackers += (game_board[xf][yf].get_team() == enemy_team)?1:-1;
} }
int knight_offsets[8][2] = {{-1,2},{1,2},{-1,-2},{1,-2},{-2,1},{2,1},{-2,-1},{2,-1}}; int knight_offsets[8][2] = {{-1,2},{1,2},{-1,-2},{1,-2},{-2,1},{2,1},{-2,-1},{2,-1}};
@ -910,12 +908,12 @@ int Board::get_attackers_for_space(int space_to)
continue; continue;
} }
if (game_board[xf][yf].get_team() != enemy_team || game_board[xf][yf].get_type() != KNIGHT) if (game_board[xf][yf].get_team() == NO_TEAM || game_board[xf][yf].get_type() != KNIGHT)
{ {
continue; continue;
} }
num_attackers++; num_attackers += (game_board[xf][yf].get_team() == enemy_team)?1:-1;
} }
int queen_bishop_offsets[28][2] = {{1,1},{2,2},{3,3},{4,4},{5,5},{6,6},{7,7}, int queen_bishop_offsets[28][2] = {{1,1},{2,2},{3,3},{4,4},{5,5},{6,6},{7,7},
@ -931,12 +929,12 @@ int Board::get_attackers_for_space(int space_to)
continue; continue;
} }
if (game_board[xf][yf].get_team() != enemy_team || (game_board[xf][yf].get_type() != QUEEN && game_board[xf][yf].get_type() != BISHOP && game_board[xf][yf].get_vis() != SHOWN)) if (game_board[xf][yf].get_team() == NO_TEAM || (game_board[xf][yf].get_type() != QUEEN && game_board[xf][yf].get_type() != BISHOP && game_board[xf][yf].get_vis() != SHOWN))
{ {
continue; continue;
} }
num_attackers++; num_attackers += (game_board[xf][yf].get_team() == enemy_team)?1:-1;
} }
int queen_rook_offsets[28][2] = {{1,0},{2,0},{3,0},{4,0},{5,0},{6,0},{7,0}, int queen_rook_offsets[28][2] = {{1,0},{2,0},{3,0},{4,0},{5,0},{6,0},{7,0},
@ -953,12 +951,12 @@ int Board::get_attackers_for_space(int space_to)
continue; continue;
} }
if (game_board[xf][yf].get_team() != enemy_team || (game_board[xf][yf].get_type() != QUEEN && game_board[xf][yf].get_type() != ROOK && game_board[xf][yf].get_vis() != SHOWN)) if (game_board[xf][yf].get_team() == NO_TEAM || (game_board[xf][yf].get_type() != QUEEN && game_board[xf][yf].get_type() != ROOK && game_board[xf][yf].get_vis() != SHOWN))
{ {
continue; continue;
} }
num_attackers++; num_attackers += (game_board[xf][yf].get_team() == enemy_team)?1:-1;
} }
return num_attackers; return num_attackers;

View File

@ -439,7 +439,16 @@ int Game::board_heuristic(Board current_board)
int found_attackers = current_board.get_attackers_for_space(x+y*BOARD_SIZE); int found_attackers = current_board.get_attackers_for_space(x+y*BOARD_SIZE);
heuristic += adden/((found_attackers!=0)?2:1); if (found_attackers > 0)
{
adden /= 2;
}
else if (found_attackers < 0)
{
adden = 5*adden/4;
}
heuristic += adden;
} }
} }