Strategická: Dodělání stepu v herní logice.
This commit is contained in:
parent
15e1e861ad
commit
2227b559c3
1 changed files with 16 additions and 4 deletions
|
@ -89,7 +89,7 @@ class Occupy(Logic):
|
||||||
# # "left", "right", "up", "down"
|
# # "left", "right", "up", "down"
|
||||||
# ]
|
# ]
|
||||||
# }
|
# }
|
||||||
# VALIDITU MOVES NEOVĚŘUJU
|
# Předpokládám validitu `state`
|
||||||
# Metoda funguje velmi primitivně po krocích:
|
# Metoda funguje velmi primitivně po krocích:
|
||||||
# * zaznamená se poloha objektů na mapě
|
# * zaznamená se poloha objektů na mapě
|
||||||
# * vojáky se pohne podle moves
|
# * vojáky se pohne podle moves
|
||||||
|
@ -107,11 +107,14 @@ class Occupy(Logic):
|
||||||
highest_ids = [0] * self.teams_count
|
highest_ids = [0] * self.teams_count
|
||||||
# homes jednotlivých týmů
|
# homes jednotlivých týmů
|
||||||
home_positions = [None] * self.teams_count
|
home_positions = [None] * self.teams_count
|
||||||
|
# 2D array s `True`s tam, kde je hill
|
||||||
|
hills = [[False] * self.map_width for _ in range(self.map_height)]
|
||||||
|
|
||||||
y = 0
|
y = 0
|
||||||
for row in state["map"]:
|
for row in state["map"]:
|
||||||
x = 0
|
x = 0
|
||||||
for field in row:
|
for field in row:
|
||||||
|
hills[y][x] = field["hill"]
|
||||||
if field["home_for_team"] is not None:
|
if field["home_for_team"] is not None:
|
||||||
home_positions[field["home_for_team"]] = [y, x]
|
home_positions[field["home_for_team"]] = [y, x]
|
||||||
for member in field["members"]:
|
for member in field["members"]:
|
||||||
|
@ -125,6 +128,9 @@ class Occupy(Logic):
|
||||||
for team_id, move in enumerate(moves):
|
for team_id, move in enumerate(moves):
|
||||||
if move is not None:
|
if move is not None:
|
||||||
for member in move["members"]:
|
for member in move["members"]:
|
||||||
|
if member["id"] not in id_positions:
|
||||||
|
# Neplatné ID vojáka
|
||||||
|
continue
|
||||||
id_moves[team_id][member["id"]] = member["action"]
|
id_moves[team_id][member["id"]] = member["action"]
|
||||||
|
|
||||||
# Místo mapy tabulka seznamů vojáků pro každý tým
|
# Místo mapy tabulka seznamů vojáků pro každý tým
|
||||||
|
@ -135,9 +141,15 @@ class Occupy(Logic):
|
||||||
for team_id in range(self.teams_count):
|
for team_id in range(self.teams_count):
|
||||||
for soldier_id in all_ids[team_id]:
|
for soldier_id in all_ids[team_id]:
|
||||||
move_vect = self.MOVE_VECTORS[id_moves[team_id][soldier_id]]
|
move_vect = self.MOVE_VECTORS[id_moves[team_id][soldier_id]]
|
||||||
new_y = (id_positions[team_id][soldier_id][0] + move_vect[0]) % self.map_height
|
orig_y = id_positions[team_id][soldier_id][0]
|
||||||
new_x = (id_positions[team_id][soldier_id][1] + move_vect[1]) % self.map_width
|
orig_x = id_positions[team_id][soldier_id][1]
|
||||||
soldier_lists[new_y][new_x][team_id].append(soldier_id)
|
new_y = (orig_y + move_vect[0]) % self.map_height
|
||||||
|
new_x = (orig_x + move_vect[1]) % self.map_width
|
||||||
|
if hills[new_y][new_x]:
|
||||||
|
# Voják se snažil lézt na skálu, zůstane na původním místě
|
||||||
|
soldier_lists[orig_y][orig_x][team_id].append(soldier_id)
|
||||||
|
else:
|
||||||
|
soldier_lists[new_y][new_x][team_id].append(soldier_id)
|
||||||
|
|
||||||
# Přidáme vojáky v homes:
|
# Přidáme vojáky v homes:
|
||||||
for team_id in range(self.teams_count):
|
for team_id in range(self.teams_count):
|
||||||
|
|
Loading…
Reference in a new issue