-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomAI.cpp
More file actions
23 lines (19 loc) · 776 Bytes
/
Copy pathRandomAI.cpp
File metadata and controls
23 lines (19 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//
// Created by Raunak Anand on 2019-06-01.
//
#include "BattleShip.hpp"
std::unique_ptr<BattleShip::Move> BattleShip::RandomAI::getMove() {
std::pair<int, int> pos = *chooseRandom(firingLocations, randomNumberGenerator);
firingLocations.erase(std::remove(firingLocations.begin(), firingLocations.end(), pos), firingLocations.end());
std::unique_ptr<BattleShip::Move> move(new AttackMove(*this, pos.first, pos.second));
return move;
}
BattleShip::RandomAI::RandomAI(const Game& gameAttributes, View& view) : AiPlayer(gameAttributes, view) {
int numCols = gameAttributes.getNumCols();
int numRows = gameAttributes.getNumRows();
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
firingLocations.emplace_back(i, j);
}
}
}