summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/move.h14
-rw-r--r--include/spacebot.h3
-rwxr-xr-x[-rw-r--r--]run.sh2
-rw-r--r--src/spacebot.cpp54
4 files changed, 69 insertions, 4 deletions
diff --git a/include/move.h b/include/move.h
new file mode 100644
index 0000000..e0e9b6b
--- /dev/null
+++ b/include/move.h
@@ -0,0 +1,14 @@
+#ifndef MOVE_H
+#define MOVE_H
+
+enum class Move: int {
+ NOTHING = 0,
+ MOVE_LEFT = 1,
+ MOVE_RIGHT = 2,
+ SHOOT = 3,
+ BUILD_ALIEN_FACTORY = 4,
+ BUILD_MISSILE_CONTROLLER = 5,
+ BUILD_SHIELD = 6
+};
+
+#endif
diff --git a/include/spacebot.h b/include/spacebot.h
index 920eb73..a5c23c2 100644
--- a/include/spacebot.h
+++ b/include/spacebot.h
@@ -2,6 +2,7 @@
#include <iostream>
#include <fstream>
+#include "move.h"
class Spacebot {
public:
@@ -10,4 +11,6 @@ public:
private:
std::ifstream mapStream;
std::ofstream resultStream;
+ void writeMove(const Move& move);
+ Move chooseMove();
};
diff --git a/run.sh b/run.sh
index 34176a6..2118d77 100644..100755
--- a/run.sh
+++ b/run.sh
@@ -1,3 +1,3 @@
#!/bin/bash
-cppbot $1
+./cppbot $1
diff --git a/src/spacebot.cpp b/src/spacebot.cpp
index 0fc39b1..24a5d1e 100644
--- a/src/spacebot.cpp
+++ b/src/spacebot.cpp
@@ -1,12 +1,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)
+ : mapStream(outputPath+"/map.txt", std::ifstream::in)
+ , resultStream(outputPath+"/move.txt", std::ofstream::out)
{
+ std::srand(time(0));
}
void Spacebot::writeNextMove()
{
- resultStream << "Shoot" << std::endl;
+ 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;
+}
+