47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
"""Das Spielfeld: Entfernungen und Nachbarn."""
|
|
|
|
from tft.sim import hexgrid as H
|
|
|
|
|
|
def test_neighbours_are_all_one_step_away():
|
|
"""Wenn das nicht gilt, bewegen sich Units in Sprüngen."""
|
|
for col in range(H.COLS):
|
|
for row in range(H.ROWS):
|
|
for n in H.neighbours(col, row):
|
|
assert H.distance((col, row), n) == 1
|
|
|
|
|
|
def test_offset_rows_are_not_a_grid():
|
|
"""Versetzte Reihen: gleicher Spaltenabstand, andere Entfernung.
|
|
|
|
Genau dafür ist die Umrechnung da — mit rohen Spalten wäre beides 1.
|
|
"""
|
|
assert H.distance((2, 0), (1, 1)) == 1
|
|
assert H.distance((2, 0), (3, 1)) == 2
|
|
|
|
|
|
def test_distance_along_a_row_counts_columns():
|
|
assert H.distance((0, 0), (6, 0)) == 6
|
|
assert H.distance((3, 4), (3, 4)) == 0
|
|
|
|
|
|
def test_neighbour_count_is_six_in_the_middle():
|
|
assert len(H.neighbours(3, 3)) == 6
|
|
# Am Rand fallen Felder weg.
|
|
assert len(H.neighbours(0, 0)) < 6
|
|
|
|
|
|
def test_neighbour_order_is_stable():
|
|
"""Sonst hängt der Ausgang eines Kampfes an der Iterationsreihenfolge."""
|
|
assert H.neighbours(3, 3) == H.neighbours(3, 3)
|
|
|
|
|
|
def test_mirror_swaps_the_halves():
|
|
assert H.mirror(0, 0) == (H.COLS - 1, H.ROWS - 1)
|
|
assert H.mirror(*H.mirror(2, 5)) == (2, 5)
|
|
|
|
|
|
def test_halves_are_split_evenly():
|
|
assert H.own_half(0, "a") and not H.own_half(4, "a")
|
|
assert H.own_half(7, "b") and not H.own_half(3, "b")
|