diff --git a/src/python/src/gamestate.cpp b/src/python/src/gamestate.cpp index 7f7592b5..8a0d5915 100644 --- a/src/python/src/gamestate.cpp +++ b/src/python/src/gamestate.cpp @@ -122,6 +122,8 @@ namespace stratega .def("set_game_type", &SGA::GameState::setGameType, py::arg("gt"), "Sets the type of game (enum type GameType)") .def("get_game_type", &SGA::GameState::getGameType, "Returns the type of the game, of GameType") + .def("get_board_state", &SGA::GameState::getBoardState, "Returns a string representation of the board") + //Print information .def("print_state_info", &SGA::GameState::printStateInfo, "Print all the entities of the current state") .def("print_board", py::overload_cast(&SGA::GameState::printBoard, py::const_), "Print view of the map of the current state") diff --git a/src/stratega/include/Stratega/Representation/GameState.h b/src/stratega/include/Stratega/Representation/GameState.h index c01774ab..c176404d 100644 --- a/src/stratega/include/Stratega/Representation/GameState.h +++ b/src/stratega/include/Stratega/Representation/GameState.h @@ -353,6 +353,11 @@ namespace SGA /// void printStateInfo() const; + /// + /// Return board state as a string + /// + std::string getBoardState() const; + /// // /Print view of the map of the current state /// diff --git a/src/stratega/src/Representation/GameState.cpp b/src/stratega/src/Representation/GameState.cpp index 3decd15f..ba743584 100644 --- a/src/stratega/src/Representation/GameState.cpp +++ b/src/stratega/src/Representation/GameState.cpp @@ -743,8 +743,36 @@ namespace SGA } - /* PRINTS */ + std::string GameState::getBoardState() const + { + std::string map; + for (size_t y = 0; y < board.getHeight(); ++y) + { + for (size_t x = 0; x < board.getWidth(); ++x) + { + map += gameInfo->getTileType(board.get(static_cast(x), static_cast(y)).getTileTypeID()).getSymbol(); + map += " "; + } + map += "\n"; + } + + for (auto& entity : entities) + { + auto& pos = entity.getPosition(); + const char symbol = gameInfo->getEntityType(entity.getEntityTypeID()).getSymbol(); + const char ownerID = std::to_string(entity.getOwnerID())[0]; + const int entityMapIndex = static_cast((pos.y * static_cast(board.getWidth()) + pos.x) * 3 + pos.y); + + map[entityMapIndex] = symbol; + + if (!entity.isNeutral()) + map[static_cast(static_cast(entityMapIndex) + 1)] = ownerID; + } + return map; + } + + /* PRINTS */ void GameState::printStateInfo() const {