def get_line(start, k): tiles = [] coord = Hex.hex_neighbor(start, k) if Board.is_on_board(coord): tiles.append(coord) Board.get_line_step(coord, k, tiles) return tiles
def has_neighbor(game, coord, current_rot): Board.update_blocked(game) coord_neighs = [] for k in range(6): if k != current_rot: coord_neighs.append(Hex.hex_neighbor(coord, k)) par_rot = (current_rot + 3) % 6 neigh_coord = Hex.hex_neighbor(coord, current_rot) for k in range(6): if k != par_rot: coord_neighs.append(Hex.hex_neighbor(neigh_coord, k)) # print(coord_neighs) for cn in coord_neighs: if cn in Board.blocked: return True return False
def update_blocked(game): for pt in game.placed_tiles: (q, r, k) = pt[0] coord = (q, r) if Board.is_on_board(coord): Board.blocked.add(coord) neigh = Hex.hex_neighbor(coord, k) if Board.is_on_board(neigh): Board.blocked.add(neigh)
def is_free_pair_overlay(coord, k, overlay_blocked): if coord in overlay_blocked: return False if not Board.is_on_board(coord): return False neighbor = Hex.hex_neighbor(coord, k) # print("testing neighbor ", neighbor) if neighbor in overlay_blocked: return False if not Board.is_on_board(neighbor): return False return True
def draw_pair(coords, cols): # Draw under-layer (q, r, k) = coords (c1, c2) = cols Board.draw_empty_tile(q, r, k) # Draw coloured shapes primary_points = Shapes.plot_primary(Board.board_size, Board.size, q, r, c1) Board.draw_shape(c1, primary_points) (nq, nr) = Hex.hex_neighbor((q, r), k) secondary_points = Shapes.plot_primary(Board.board_size, Board.size, nq, nr, c2) Board.draw_shape(c2, secondary_points)
def is_free_pair(coord, k, free=False): # print("testing coord ", coord) if coord in Board.blocked: return False if not free and not Board.is_on_board(coord): return False neighbor = Hex.hex_neighbor(coord, k) # print("testing neighbor ", neighbor) if neighbor in Board.blocked: return False if not free and not Board.is_on_board(neighbor): return False return True
def count_available_pairs(): count = 0 overlay_blocked = set(Board.blocked) for k in range(0, 3): for r in range(-6, 7): for q in range(-6, 7): if Board.is_free_pair_overlay((q, r), k, overlay_blocked): Board.overlays.append((q, r, k)) overlay_blocked.add((q, r)) overlay_blocked.add(Hex.hex_neighbor((q, r), k)) count += 1 # Prevent drawing the overlays Board.overlays = [] # print(f'Available pairs: {count} ({Board.count_available()})') return count
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 get_other_coord(tile): return Hex.hex_neighbor(tile[0][0:2], tile[0][2])
def get_line_step(coord, k, tiles): coord = Hex.hex_neighbor(coord, k) if Board.is_on_board(coord): tiles.append(coord) Board.get_line_step(coord, k, tiles)