summaryrefslogtreecommitdiff
path: root/2015-spacebot/src/spacebot.cpp
diff options
context:
space:
mode:
Diffstat (limited to '2015-spacebot/src/spacebot.cpp')
-rw-r--r--2015-spacebot/src/spacebot.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/2015-spacebot/src/spacebot.cpp b/2015-spacebot/src/spacebot.cpp
new file mode 100644
index 0000000..17d20b5
--- /dev/null
+++ b/2015-spacebot/src/spacebot.cpp
@@ -0,0 +1,48 @@
+#include "spacebot.h"
+#include "move_string_mapper.h"
+#include "brain/neural_network.h"
+#include <fstream>
+#include <iostream>
+
+Spacebot::Spacebot(std::string outputPath, std::string brainFilename)
+ : _outputFilename(outputPath+"/move.txt"),
+ _brainFilename(brainFilename),
+ _gameState(std::ifstream(outputPath+"/map.txt"))
+{
+}
+
+void Spacebot::writeNextMove()
+{
+ Move move = chooseMove();
+ writeMove(move);
+}
+
+Move Spacebot::chooseMove()
+{
+ auto sensorInputs = _gameState.toBitArray();
+
+ if (!sensorInputs.at(51) || !sensorInputs.at(53))
+ {
+ return Move::BUILD_SHIELD;
+ }
+ else if (sensorInputs.at(55))
+ {
+ return Move::SHOOT;
+ }
+ else if (sensorInputs.at(60) && !sensorInputs.at(59))
+ {
+ return Move::BUILD_MISSILE_CONTROLLER;
+ }
+ else
+ {
+ return Move::NOTHING;
+ }
+}
+
+void Spacebot::writeMove(const Move& move)
+{
+ std::ofstream resultStream(_outputFilename);
+ resultStream << MoveStringMapper().toString(move) << std::endl;
+ return;
+}
+