fix some bugs
This commit is contained in:
parent
688a2d8145
commit
f785493ec2
@ -30,7 +30,7 @@ bool GameBoard::attack(const PlayerMove& o) {
|
|||||||
if (sc_tile.unit <= 1)
|
if (sc_tile.unit <= 1)
|
||||||
return false;
|
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;
|
sc_tile.unit -= moving_unit;
|
||||||
auto isfriend = isTeammate(o.player, tt_tile.owner);
|
auto isfriend = isTeammate(o.player, tt_tile.owner);
|
||||||
auto delta
|
auto delta
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
#include "pc/commcode.h"
|
#include "pc/commcode.h"
|
||||||
|
|
||||||
bool PlayerMove::isValid(pos_t w, pos_t h) const {
|
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;
|
return false;
|
||||||
|
|
||||||
if ((int)dir >= 4)
|
if ((int)dir >= 4)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto xx = tx(), yy = ty();
|
auto xx = tx(), yy = ty();
|
||||||
if (xx < 0 || xx >= h || yy < 0 || yy >= w)
|
if (xx >= h || yy >= w)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -37,35 +37,35 @@ void upmin(T& x, const T& y) {
|
|||||||
bool findCut(pos_t w, pos_t h, vector<vector<VertexType>>& vertex_type) {
|
bool findCut(pos_t w, pos_t h, vector<vector<VertexType>>& vertex_type) {
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
vector<vector<int>> dfn(h, vector<int>(w)), low = dfn;
|
vector<vector<int>> dfn(h, vector<int>(w)), low = dfn;
|
||||||
function<void(int, int, int, int, bool)> tarjan
|
function<void(pos_t, pos_t, pos_t, pos_t, bool)> tarjan =
|
||||||
= [&](int x, int y, int fx, int fy, bool rt) {
|
[&](pos_t x, pos_t y, pos_t fx, pos_t fy, bool rt) {
|
||||||
dfn[x][y] = low[x][y] = ++idx;
|
dfn[x][y] = low[x][y] = ++idx;
|
||||||
int ch = 0;
|
int ch = 0;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
const int xx = x + direction_dx[i], yy = y + direction_dy[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;
|
continue;
|
||||||
|
|
||||||
if (vertex_type[xx][yy] == VertexType::Capital)
|
if (vertex_type[xx][yy] == VertexType::Capital)
|
||||||
vertex_type[x][y] = VertexType::Cut;
|
vertex_type[x][y] = VertexType::Cut;
|
||||||
|
|
||||||
if (ban(vertex_type[xx][yy]) || (xx == fx && yy == fy))
|
if (ban(vertex_type[xx][yy]) || (xx == fx && yy == fy))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!dfn[xx][yy]) {
|
if (!dfn[xx][yy]) {
|
||||||
ch++;
|
ch++;
|
||||||
tarjan(xx, yy, x, y, 0);
|
tarjan(xx, yy, x, y, 0);
|
||||||
upmin(low[x][y], low[xx][yy]);
|
upmin(low[x][y], low[xx][yy]);
|
||||||
if (!rt && low[xx][yy] >= dfn[x][y])
|
if (!rt && low[xx][yy] >= dfn[x][y])
|
||||||
vertex_type[x][y] = VertexType::Cut;
|
vertex_type[x][y] = VertexType::Cut;
|
||||||
} else {
|
} else {
|
||||||
upmin(low[x][y], dfn[xx][yy]);
|
upmin(low[x][y], dfn[xx][yy]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rt && ch >= 2)
|
if (rt && ch >= 2)
|
||||||
vertex_type[x][y] = VertexType::Cut;
|
vertex_type[x][y] = VertexType::Cut;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool flag = false;
|
bool flag = false;
|
||||||
for (pos_t i = 0; i < h; i++) {
|
for (pos_t i = 0; i < h; i++) {
|
||||||
@ -169,9 +169,9 @@ GameBoard ImportedTerrain::makeGameBoard(const InitInfo& init_info) {
|
|||||||
for (pos_t y = 0; y < w; y++) {
|
for (pos_t y = 0; y < w; y++) {
|
||||||
if (g.at(x, y).type == TileType::Capital) {
|
if (g.at(x, y).type == TileType::Capital) {
|
||||||
for (int i = 0; i < 4; i++) {
|
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];
|
yy = y + direction_dy[i];
|
||||||
if (xx < 0 || xx >= h || yy < 0 || yy >= w)
|
if (xx >= h || yy >= w)
|
||||||
continue;
|
continue;
|
||||||
if (g.at(xx, yy).type == TileType::Capital)
|
if (g.at(xx, yy).type == TileType::Capital)
|
||||||
throw BadCapitalAssign();
|
throw BadCapitalAssign();
|
||||||
|
@ -5,3 +5,5 @@ PlayerRanking::PlayerRanking() : player(neutral_player)
|
|||||||
|
|
||||||
TeamRanking::TeamRanking() : team(neutral_team), land(0), unit(0) {}
|
TeamRanking::TeamRanking() : team(neutral_team), land(0), unit(0) {}
|
||||||
|
|
||||||
|
Tile::Tile() : owner(neutral_player), unit(0) {}
|
||||||
|
|
||||||
|
@ -56,6 +56,8 @@ struct Tile {
|
|||||||
TileType type;
|
TileType type;
|
||||||
std::int32_t unit;
|
std::int32_t unit;
|
||||||
|
|
||||||
|
Tile();
|
||||||
|
|
||||||
OGPC_DECLARE_ASTUPLE(owner, type, unit)
|
OGPC_DECLARE_ASTUPLE(owner, type, unit)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user