fix some bugs

This commit is contained in:
lcw 2024-02-11 00:34:05 +08:00
parent 688a2d8145
commit f785493ec2
5 changed files with 35 additions and 31 deletions

View File

@ -30,7 +30,7 @@ bool GameBoard::attack(const PlayerMove& o) {
if (sc_tile.unit <= 1)
return false;
auto moving_unit = o.half ? sc_tile.unit : sc_tile.unit / 2;
auto moving_unit = o.half ? sc_tile.unit - 1 : sc_tile.unit / 2;
sc_tile.unit -= moving_unit;
auto isfriend = isTeammate(o.player, tt_tile.owner);
auto delta

View File

@ -3,14 +3,14 @@
#include "pc/commcode.h"
bool PlayerMove::isValid(pos_t w, pos_t h) const {
if (x < 0 || x >= h || y < 0 || y >= w)
if (x >= h || y >= w)
return false;
if ((int)dir >= 4)
return false;
auto xx = tx(), yy = ty();
if (xx < 0 || xx >= h || yy < 0 || yy >= w)
if (xx >= h || yy >= w)
return false;
return true;

View File

@ -37,13 +37,13 @@ void upmin(T& x, const T& y) {
bool findCut(pos_t w, pos_t h, vector<vector<VertexType>>& vertex_type) {
int idx = 0;
vector<vector<int>> dfn(h, vector<int>(w)), low = dfn;
function<void(int, int, int, int, bool)> tarjan
= [&](int x, int y, int fx, int fy, bool rt) {
function<void(pos_t, pos_t, pos_t, pos_t, bool)> tarjan =
[&](pos_t x, pos_t y, pos_t fx, pos_t fy, bool rt) {
dfn[x][y] = low[x][y] = ++idx;
int ch = 0;
for (int i = 0; i < 4; i++) {
const int xx = x + direction_dx[i], yy = y + direction_dy[i];
if (xx < 0 || xx >= h || yy < 0 || yy >= w)
const pos_t xx = x + direction_dx[i], yy = y + direction_dy[i];
if (xx >= h || yy >= w)
continue;
if (vertex_type[xx][yy] == VertexType::Capital)
@ -169,9 +169,9 @@ GameBoard ImportedTerrain::makeGameBoard(const InitInfo& init_info) {
for (pos_t y = 0; y < w; y++) {
if (g.at(x, y).type == TileType::Capital) {
for (int i = 0; i < 4; i++) {
const int xx = x + direction_dx[i],
const pos_t xx = x + direction_dx[i],
yy = y + direction_dy[i];
if (xx < 0 || xx >= h || yy < 0 || yy >= w)
if (xx >= h || yy >= w)
continue;
if (g.at(xx, yy).type == TileType::Capital)
throw BadCapitalAssign();

View File

@ -5,3 +5,5 @@ PlayerRanking::PlayerRanking() : player(neutral_player)
TeamRanking::TeamRanking() : team(neutral_team), land(0), unit(0) {}
Tile::Tile() : owner(neutral_player), unit(0) {}

View File

@ -56,6 +56,8 @@ struct Tile {
TileType type;
std::int32_t unit;
Tile();
OGPC_DECLARE_ASTUPLE(owner, type, unit)
};