summaryrefslogtreecommitdiff
path: root/src/spacebot.cpp
blob: e18078b42be2fde93ff436cdc1b2edea2f7e002b (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
#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();
    
    NeuralNetwork network(std::ifstream(_brainFilename),
			  sensorInputs,
			  5);

    return static_cast<Move>(network.findMaxOutputIndex());
}

void Spacebot::writeMove(const Move& move)
{
    std::ofstream resultStream(_outputFilename);
    resultStream << MoveStringMapper().toString(move) << std::endl;
    return;
}