add player info methods of GameBoard

Signed-off-by: szdytom <szdytom@qq.com>
This commit is contained in:
方而静 2024-02-04 21:53:16 +08:00
parent a3d235b10b
commit 4046abd656
Signed by: szTom
GPG Key ID: 072D999D60C6473C
2 changed files with 44 additions and 7 deletions

View File

@ -62,22 +62,56 @@ void GameBoard::capitalCaptured(Player tt, Player sc) {
}
bool GameBoard::isTeammate(Player x, Player y) const {
// TODO
}
PlayerState::PlayerState() {
is_defeated = false;
return teamOf(x) == teamOf(y);
}
void GameBoard::turnUpdate() {
// TODO
for (pos_t x = 0; x < h; ++x) {
for (pos_t y = 0; y < w; ++y) {
auto &tile = at(x, y);
if (tile.owner == neutral_player)
continue;
if (tile.type == TileType::Stronghold || tile.type == TileType::Capital)
tile.unit += 1;
if (tile.type == TileType::Swamp) {
tile.unit -= 1;
if (tile.unit == 0)
tile.owner = neutral_player;
}
}
}
}
void GameBoard::roundUpdate() {
// TODO
for (pos_t x = 0; x < h; ++x) {
for (pos_t y = 0; y < w; ++y) {
auto &tile = at(x, y);
if (tile.owner == neutral_player)
continue;
tile.unit += 1;
}
}
}
void GameBoard::updatedPosition(pos_t x, pos_t y) {
updated_tiles.emplace(x, y);
}
Team GameBoard::teamOf(Player x) const {
return players[x].team;
}
std::uint8_t GameBoard::numPlayers() const {
return n;
}
std::uint8_t GameBoard::numTeams() const {
return t;
}
PlayerState::PlayerState() {
is_defeated = false;
}

View File

@ -30,6 +30,9 @@ public:
void turnUpdate();
void roundUpdate();
bool isTeammate(Player x, Player y) const;
Team teamOf(Player x) const;
std::uint8_t numPlayers() const;
std::uint8_t numTeams() const;
private:
void capitalCaptured(Player target, Player source);