def is_legal(coords): (q, r, k) = coords tile = (q, r) if Board.is_on_board((q, r)): neighbor = Hex.hex_neighbor((q, r), k) # Check if clicked on 2-player board => distance 6 if Board.is_on_board(neighbor): # exit if square is non-empty if tile in Board.blocked: return False elif neighbor in Board.blocked: return False else: distances_tile = [Hex.hex_distance(tile, pt[0][0:2]) for pt in Board.placed_tiles] distances_other = [Hex.hex_distance(tile, Board.get_other_coord(pt)) for pt in Board.placed_tiles] neighbor_tile = [Hex.hex_distance(neighbor, pt[0][0:2]) for pt in Board.placed_tiles] neighbor_other = [Hex.hex_distance(neighbor, Board.get_other_coord(pt)) for pt in Board.placed_tiles] distances = distances_tile + distances_other + neighbor_tile + neighbor_other if min(distances) > 1: return False else: return True
def is_touching(a, b): return Hex.hex_distance(a, b) == 1
def is_on_board(coord): if Hex.hex_distance((0, 0), coord) > 6: return False else: return True
def get_distance(h, s=(0, 0)): return Hex.hex_distance(s, h)