blob: 24a5d1e6325f463fe40e1af72399da96d1ce69ec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#include "spacebot.h"
#include <random>
Spacebot::Spacebot(const std::string& outputPath)
: mapStream(outputPath+"/map.txt", std::ifstream::in)
, resultStream(outputPath+"/move.txt", std::ofstream::out)
{
std::srand(time(0));
}
void Spacebot::writeNextMove()
{
Move move = chooseMove();
writeMove(move);
}
Move Spacebot::chooseMove()
{
int min = static_cast<int>(Move::NOTHING);
int max = static_cast<int>(Move::BUILD_SHIELD);
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(min, max);
return static_cast<Move>(dis(gen));
}
void Spacebot::writeMove(const Move& move)
{
switch (move)
{
case Move::NOTHING:
resultStream << "Nothing";
break;
case Move::MOVE_LEFT:
resultStream << "MoveLeft";
break;
case Move::MOVE_RIGHT:
resultStream << "MoveRight";
break;
case Move::SHOOT:
resultStream << "Shoot";
break;
case Move::BUILD_ALIEN_FACTORY:
resultStream << "BuildAlienFactory";
break;
case Move::BUILD_MISSILE_CONTROLLER:
resultStream << "BuildMissileController";
break;
case Move::BUILD_SHIELD:
resultStream << "BuildShield";
break;
default:
resultStream << "MoveLeft";
}
resultStream << std::endl;
resultStream.flush();
return;
}
|