diff --git a/board.cpp b/board.cpp index 5862880..a184292 100755 --- a/board.cpp +++ b/board.cpp @@ -420,8 +420,6 @@ std::vector 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; - bool is_team_in_check = (check_for_check && is_check(game_board[x][y].get_team())); - std::vector out_spaces; Type piece_type = (game_board[x][y].get_vis() == HIDDEN)?UNKNOWN:game_board[x][y].get_type(); @@ -642,7 +640,7 @@ std::vector Board::get_moves_for_space(int x, int y, bool check_for_check) out_spaces.push_back(x+y*BOARD_SIZE); } - if (is_team_in_check) + if (check_for_check) { std::vector::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()); @@ -854,12 +852,12 @@ int Board::get_attackers_for_space(int space_to) 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; } - 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; } - 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; } - 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}}; @@ -892,12 +890,12 @@ int Board::get_attackers_for_space(int space_to) 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; } - 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}}; @@ -910,12 +908,12 @@ int Board::get_attackers_for_space(int space_to) 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; } - 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}, @@ -931,12 +929,12 @@ int Board::get_attackers_for_space(int space_to) 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; } - 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}, @@ -953,12 +951,12 @@ int Board::get_attackers_for_space(int space_to) 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; } - num_attackers++; + num_attackers += (game_board[xf][yf].get_team() == enemy_team)?1:-1; } return num_attackers; diff --git a/game.cpp b/game.cpp index 2c85683..86b0ce2 100644 --- a/game.cpp +++ b/game.cpp @@ -439,7 +439,16 @@ int Game::board_heuristic(Board current_board) 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; } }