Something went wrong. Try again.
bayes for days
Something went wrong. Try again.
Python
12345678910111213141516171819202122232425262728293031323334353637383940"""Hex geometry, checked against the property that catches the parity bug.
Offset coordinates with a column shift are easy to port wrong in a way thatworks for half the board. Every neighbour of every hex must be distance 1; ifthe parity term is wrong, that fails on odd columns only."""
import osimport sysimport unittest
_REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))sys.path.insert(0, os.path.join(_REPO, "bots"))
from hexes import distance, translated # noqa: E402
class TestHexes(unittest.TestCase): def test_every_neighbour_is_adjacent(self): for x in range(12): for y in range(12): for direction in range(6): nx, ny = translated(x, y, direction) self.assertEqual(distance(x, y, nx, ny), 1, f"({x},{y}) dir {direction}")
def test_opposite_directions_return(self): for x in range(12): for y in range(12): for direction in range(6): nx, ny = translated(x, y, direction) bx, by = translated(nx, ny, (direction + 3) % 6) self.assertEqual((bx, by), (x, y))
def test_straight_line_distance_accumulates(self): for direction in range(6): x, y = 6, 6 for step in range(1, 5): x, y = translated(x, y, direction) self.assertEqual(distance(6, 6, x, y), step)