Skip to content

Commit 57e0b71

Browse files
Beautify map in python client debug method
1 parent 70a1ee6 commit 57e0b71

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Clients/main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ def __init__(self) -> None:
4242
self.data: int
4343
self.coordinates: tuple(int, int)
4444

45+
def __str__(self) -> str:
46+
res = self.type.name
47+
if self.type in [MapType.OUT_OF_SIGHT, MapType.OUT_OF_MAP]:
48+
return res.center(16)
49+
elif self.type in [MapType.AGENT, MapType.GOLD]:
50+
res += f':{self.data}'
51+
res += f' ({self.coordinates[0]},{self.coordinates[1]})'
52+
return res.center(16)
53+
4554

4655
class Map:
4756
def __init__(self) -> None:
@@ -51,6 +60,15 @@ def __init__(self) -> None:
5160
self.sight_range: int
5261
self.grid: list
5362

63+
def __str__(self) -> str:
64+
res = f'sight range -> {self.sight_range}\n'
65+
for i in range(self.sight_range):
66+
res += '\t'
67+
for j in range(self.sight_range):
68+
res += str(self.grid[i * self.sight_range + j])
69+
res += '*' if j < 4 else '\n'
70+
return res[:-1]
71+
5472
def set_grid_size(self) -> None:
5573
self.grid = [MapTile() for _ in range(self.sight_range ** 2)]
5674

@@ -74,6 +92,7 @@ def set_info(self) -> None:
7492
self.location = tuple(map(int, input().split())) # (row, column)
7593
for tile in self.map.grid:
7694
tile.type, tile.data, *tile.coordinates = map(int, input().split())
95+
tile.type = MapType(tile.type)
7796
self.agent_id = int(input()) # player1: 0,1 --- player2: 2,3
7897
self.current_round = int(input()) # 1 indexed
7998
self.attack_ratio = float(input())
@@ -88,6 +107,7 @@ def debug(self) -> None:
88107
# Customize to your needs
89108
self.debug_log += f'round: {str(self.current_round)}\n'
90109
self.debug_log += f'location: {str(self.location)}\n'
110+
self.debug_log += f'Map: {str(self.map)}\n'
91111
self.debug_log += f'attack ratio: {str(self.attack_ratio)}\n'
92112
self.debug_log += f'defence level: {str(self.deflvl)}\n'
93113
self.debug_log += f'attack level: {str(self.atklvl)}\n'

0 commit comments

Comments
 (0)