const bool AlphaBeta::pruneMove(GameState & state, const IDType & playerToMove, const MoveArray & moves, const MoveTuple & tuple) const { IDType enemy(getEnemy(playerToMove)); // damage assigned to each enemy unit so far int hpRemaining[Search::Constants::Max_Units]; for (IDType u(0); u<state.numUnits(enemy); ++u) { hpRemaining[u] = state.getUnit(enemy,u).currentHP(); } // for each unit in the tuple for (size_t u(0); u<moves.numUnits(); u++) { // get its move const Move & m(moves.getTupleMove(tuple, u)); if (m.type() == MoveTypes::ATTACK) { // if the target unit has already been killed then return prune if (hpRemaining[m.index()] <= 0) { return true; } hpRemaining[m.index()] -= state.getUnit(playerToMove, u).damage(); } } return false; }
void AlphaBeta::doTupleMoves(GameState & state, MoveArray & moves, const MoveTuple & tuple) { // for each simultaneous move in this tuple for (size_t u(0); u<moves.numUnitsInTuple(); ++u) { Move m = moves.getTupleMove(tuple, u); state.makeMove(m, state); } }
// causes playerToMove() to make the moves in the tuple void LargeGame::makeMoves(const MoveTuple & tuple, MoveArray & arr) { // for each simultaneous move in this tuple for (size_t u(0); u<arr.numUnitsInTuple(); ++u) { Move m = arr.getTupleMove(tuple, u); //printf(" Move (%d, %d) (%s, %s)\n", (int)tuple, (int)u, state.getUnit(m.player(), m.unit()).name().c_str(), m.moveString().c_str()); state.makeMove(m, state); } }
void GameState::printMoveTuple(const IDType & player, const MoveTuple & t) const { printf("\n"); MoveArray moves; generateMoves(moves, player); for (size_t u(0); u<moves.numUnitsInTuple(); ++u) { Move m = moves.getTupleMove(t, u); std::cout << "Player " << (int)m.player() << " " << getUnit(m.player(), m.unit()).name() << " (id=" << (int)m.unit() << ")" << " " << m.moveString() ; if (m.type() == MoveTypes::ATTACK) { std::cout << " target " << getUnit(getEnemy(m.player()), m.index()).name() << " (id=" << (int)m.index() << ")"; } std::cout << "\n"; } }