From 90483e4f3d0f7b95b3846bf1d0ff410ebd930011 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Mon, 25 May 2015 22:00:39 +0200 Subject: Made output random --- src/spacebot.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'src') 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 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(Move::NOTHING); + int max = static_cast(Move::BUILD_SHIELD); + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(min, max); + return static_cast(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; +} + -- cgit v1.2.3