use InitInfo in GameBoard()

Signed-off-by: szdytom <szdytom@qq.com>
This commit is contained in:
方而静 2024-02-05 21:41:26 +08:00
parent 36488d7704
commit 821f294098
Signed by: szTom
GPG Key ID: 072D999D60C6473C
5 changed files with 49 additions and 7 deletions

View File

@ -1,13 +1,13 @@
#include "GameBoard.h"
#include <algorithm>
GameBoard::GameBoard(std::uint8_t n, std::uint8_t t, pos_t w, pos_t h
, const std::vector<Team> &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<TeamRanking> GameBoard::leaderboard() const {
std::vector<TeamRanking> res(t);
std::vector<PlayerRanking> 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;
}

View File

@ -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<Team> &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<TeamRanking> 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<Tile> board;
std::set<Point> updated_tiles;
std::vector<Player> defeated_players;
std::set<Player> defeated_players;
};
#endif

View File

@ -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

7
processor/pc/pctypes.cpp Normal file
View File

@ -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) {}

View File

@ -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<PlayerRanking> 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> player_team;
std::vector<Modifier> modifiers;
OGPC_DECLARE_ASTUPLE(n, player_team, modifiers)