summaryrefslogtreecommitdiff
path: root/src/game_state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game_state.cpp')
-rw-r--r--src/game_state.cpp43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/game_state.cpp b/src/game_state.cpp
index 5fed683..e6deae7 100644
--- a/src/game_state.cpp
+++ b/src/game_state.cpp
@@ -2,9 +2,11 @@
#include <iostream>
#include <fstream>
#include <limits>
+#include <bitset>
const int OPENING_LINES = 6;
const int GAME_AREA_LINES = 25;
+const int GAME_WIDTH = 19;
void moveToNextChar(int &x, int &y, int &width, char &nextChar, std::istream &mapFile)
{
@@ -91,5 +93,44 @@ void GameState::logState()
std::vector<bool> GameState::toBitArray() const
{
- return std::vector<bool>();
+ std::vector<bool> result;
+
+ std::vector<bool> alienNodes((GAME_AREA_LINES-2) * (GAME_WIDTH-2), false);
+ for (auto alien : _aliens)
+ {
+ alienNodes.at((alien.y()-1)*(GAME_WIDTH-2)+(alien.x()-1)) = true;
+ }
+ result.insert(result.end(), alienNodes.begin(), alienNodes.end());
+
+ std::vector<bool> bulletNodes((GAME_AREA_LINES-2) * (GAME_WIDTH-2), false);
+ for (auto bullet : _bullets)
+ {
+ bulletNodes.at((bullet.y()-1)*(GAME_WIDTH-2)+(bullet.x()-1)) = true;
+ }
+ result.insert(result.end(), bulletNodes.begin(), bulletNodes.end());
+
+ std::vector<bool> missileNodes((GAME_AREA_LINES-2) * (GAME_WIDTH-2), false);
+ for (auto missile : _missiles)
+ {
+ missileNodes.at((missile.y()-1)*(GAME_WIDTH-2)+(missile.x()-1)) = true;
+ }
+ result.insert(result.end(), missileNodes.begin(), missileNodes.end());
+
+ std::vector<bool> shieldNodes(2 * (GAME_WIDTH-2), false);
+ for (auto shield : _shields)
+ {
+ int row = shield.y() > GAME_AREA_LINES/2 ? 1 : 0;
+ shieldNodes.at(row*(GAME_WIDTH-2)+(shield.x()-1)) = true;
+ }
+
+ for (auto spaceship : _spaceships)
+ {
+ std::bitset<5> spaceshipBits(spaceship.x());
+ for (int i=0; i<spaceshipBits.size(); ++i)
+ {
+ result.push_back(spaceshipBits[i]);
+ }
+ }
+
+ return result;
}