-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaux_funcs.py
More file actions
46 lines (37 loc) · 1.41 KB
/
Copy pathaux_funcs.py
File metadata and controls
46 lines (37 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Utilidades para el juego HEX."""
def available_positions(game_board):
"""Extrae todas las casillas disponibles en el tablero."""
output = []
for i in range(game_board.size):
for j in range(game_board.size):
if game_board.board[i][j] == 0:
output.append((i, j))
return output
def adjacent_cells(game_board, x: int, y: int):
"""Itera sobre celdas adyacentes considerando disposición hexagonal even-r."""
if x % 2 == 0:
deltas = [(-1, 0), (-1, 1), (0, -1), (0, 1), (1, 0), (1, 1)]
else:
deltas = [(-1, -1), (-1, 0), (0, -1), (0, 1), (1, -1), (1, 0)]
for dx, dy in deltas:
nx, ny = x + dx, y + dy
if 0 <= nx < game_board.size and 0 <= ny < game_board.size:
yield nx, ny
def is_board_full(game_board):
"""Determina si todas las celdas están ocupadas."""
for fila in game_board.board:
for celda in fila:
if celda == 0:
return False
return True
def display_board(game_board):
"""Convierte el tablero a una representación textual."""
output_lines = []
for i in range(game_board.size):
espacios = " " * i
simbolos = []
for j in range(game_board.size):
val = game_board.board[i][j]
simbolos.append("*" if val == 0 else str(val))
output_lines.append(espacios + " ".join(simbolos))
return "\n".join(output_lines)