From 2e6ecf423c8228ac8de4badf4fc2d037a876b7ff Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 1 Aug 2015 22:50:00 +0200 Subject: Reading network from file --- src/spacebot.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/spacebot.cpp') diff --git a/src/spacebot.cpp b/src/spacebot.cpp index 5f87df9..1f8f2b8 100644 --- a/src/spacebot.cpp +++ b/src/spacebot.cpp @@ -1,11 +1,12 @@ #include "spacebot.h" #include "move_string_mapper.h" -#include +#include "brain/neural_network.h" #include Spacebot::Spacebot(std::string outputPath) - : outputFilename(outputPath+"/move.txt"), - gameState(std::ifstream(outputPath+"/map.txt")) + : _outputFilename(outputPath+"/move.txt"), + _networkConfigFilename("brain.nn"), + _gameState(std::ifstream(outputPath+"/map.txt")) { } @@ -17,17 +18,24 @@ void Spacebot::writeNextMove() 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)); + auto sensorInputs = _gameState.toBitArray(); + + NeuralNetwork network(std::ifstream(_networkConfigFilename), + sensorInputs.size(), + static_cast(Move::BUILD_SHIELD)); + + for (int i=0; i(moveInt); } void Spacebot::writeMove(const Move& move) { - std::ofstream resultStream(outputFilename); + std::ofstream resultStream(_outputFilename); resultStream << MoveStringMapper().toString(move) << std::endl; return; } -- cgit v1.2.3