From 821f2940981ab9aeadd2e39b4982e37f9b140f21 Mon Sep 17 00:00:00 2001 From: szdytom Date: Mon, 5 Feb 2024 21:41:26 +0800 Subject: [PATCH] use InitInfo in GameBoard() Signed-off-by: szdytom --- processor/logic/GameBoard.cpp | 33 +++++++++++++++++++++++++++++---- processor/logic/GameBoard.h | 8 ++++++-- processor/pc/basictypes.h | 2 ++ processor/pc/pctypes.cpp | 7 +++++++ processor/pc/pctypes.h | 6 +++++- 5 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 processor/pc/pctypes.cpp diff --git a/processor/logic/GameBoard.cpp b/processor/logic/GameBoard.cpp index d0fdb44..39f5484 100644 --- a/processor/logic/GameBoard.cpp +++ b/processor/logic/GameBoard.cpp @@ -1,13 +1,13 @@ #include "GameBoard.h" #include -GameBoard::GameBoard(std::uint8_t n, std::uint8_t t, pos_t w, pos_t h - , const std::vector &player_team) - : n(n), t(t), w(w), h(h), players(n + 1) +GameBoard::GameBoard(pos_t w, pos_t h, const InitInfo &info) + : n(info.n), t(0), players(info.n + 1), w(w), h(h), board(w * h) { for (std::uint8_t i = 1; i <= n; ++i) { players[i].id = i; - players[i].team = player_team[i]; + players[i].team = info.player_team[i]; + t = std::max(t, players[i].team); } } @@ -57,6 +57,7 @@ void GameBoard::capitalCaptured(Player tt, Player sc) { tile.owner = sc; tile.unit = std::max(tile.unit / 2, 1); + updatedPosition(x, y); } } } @@ -111,6 +112,30 @@ std::uint8_t GameBoard::numTeams() const { return t; } +std::vector GameBoard::leaderboard() const { + std::vector res(t); + std::vector prank(n); + for (Player i = 1; i <= n; ++i) + prank[i - 1].player = i; + + for (Team i = 1; i <= t; ++i) + res[i - 1].team = i; + + 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; + prank[tile.owner - 1].land += 1; + prank[tile.owner - 1].unit += tile.unit; + } + } + +// for (auto &p : prank) { +// res[teamOf(p.player) - 1] + // TODO +} + PlayerState::PlayerState() { is_defeated = false; } diff --git a/processor/logic/GameBoard.h b/processor/logic/GameBoard.h index ebbdf21..0238d7e 100644 --- a/processor/logic/GameBoard.h +++ b/processor/logic/GameBoard.h @@ -21,14 +21,18 @@ struct PlayerState { class GameBoard { public: - GameBoard(std::uint8_t n, std::uint8_t t, pos_t w, pos_t h, const std::vector &player_team); + GameBoard(pos_t w, pos_t h, const InitInfo &info); const Tile& at(pos_t x, pos_t y) const; Tile& at(pos_t x, pos_t y); bool attack(const PlayerMove &o); + void turnUpdate(); void roundUpdate(); + + std::vector leaderboard() const; + bool isTeammate(Player x, Player y) const; Team teamOf(Player x) const; std::uint8_t numPlayers() const; @@ -44,7 +48,7 @@ private: pos_t w, h; std::vector board; std::set updated_tiles; - std::vector defeated_players; + std::set defeated_players; }; #endif diff --git a/processor/pc/basictypes.h b/processor/pc/basictypes.h index d7cbcd9..f4942c6 100644 --- a/processor/pc/basictypes.h +++ b/processor/pc/basictypes.h @@ -8,6 +8,8 @@ using Player = std::uint8_t; using Team = std::uint8_t; using pos_t = std::uint8_t; using Void = std::tuple<>; + const Player neutral_player = 0; +const Team neutral_team = 0; #endif diff --git a/processor/pc/pctypes.cpp b/processor/pc/pctypes.cpp new file mode 100644 index 0000000..cd42537 --- /dev/null +++ b/processor/pc/pctypes.cpp @@ -0,0 +1,7 @@ +#include "pctypes.h" + +PlayerRanking::PlayerRanking() : player(neutral_player) + , is_defeated(false), land(0), unit(0) {} + +TeamRanking::TeamRanking() : team(neutral_team), land(0), unit(0) {} + diff --git a/processor/pc/pctypes.h b/processor/pc/pctypes.h index 2979cbc..7b92cb0 100644 --- a/processor/pc/pctypes.h +++ b/processor/pc/pctypes.h @@ -35,6 +35,8 @@ struct PlayerRanking { std::uint16_t land; std::int32_t unit; + PlayerRanking(); + OGPC_DECLARE_ASTUPLE(player, is_defeated, land, unit) }; @@ -44,6 +46,8 @@ struct TeamRanking { std::int32_t unit; std::vector players; + TeamRanking(); + OGPC_DECLARE_ASTUPLE(team, land, unit, players) }; @@ -107,7 +111,7 @@ struct PlayerInfo { struct InitInfo { std::uint8_t n; - std::int32_t player_team; + std::vector player_team; std::vector modifiers; OGPC_DECLARE_ASTUPLE(n, player_team, modifiers)