Browse Source

Strategická: Dodělání stepu v herní logice.

master
Martin Koreček 2 years ago
parent
commit
2227b559c3
  1. 20
      server/hra/game.py

20
server/hra/game.py

@ -89,7 +89,7 @@ class Occupy(Logic):
# # "left", "right", "up", "down"
# ]
# }
# VALIDITU MOVES NEOVĚŘUJU
# Předpokládám validitu `state`
# Metoda funguje velmi primitivně po krocích:
# * zaznamená se poloha objektů na mapě
# * vojáky se pohne podle moves
@ -107,11 +107,14 @@ class Occupy(Logic):
highest_ids = [0] * self.teams_count
# homes jednotlivých týmů
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
for row in state["map"]:
x = 0
for field in row:
hills[y][x] = field["hill"]
if field["home_for_team"] is not None:
home_positions[field["home_for_team"]] = [y, x]
for member in field["members"]:
@ -125,6 +128,9 @@ class Occupy(Logic):
for team_id, move in enumerate(moves):
if move is not None:
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"]
# 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 soldier_id in all_ids[team_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
new_x = (id_positions[team_id][soldier_id][1] + move_vect[1]) % self.map_width
soldier_lists[new_y][new_x][team_id].append(soldier_id)
orig_y = id_positions[team_id][soldier_id][0]
orig_x = id_positions[team_id][soldier_id][1]
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:
for team_id in range(self.teams_count):

Loading…
Cancel
Save