def draw_claimed_land(self): for x in range(gcs.NUM_SQ): for y in range(gcs.NUM_SQ): if (gcs.board[x][y][0] == "LAND") and (gcs.board[x][y][1] == self.player_id): pygame.draw.rect(gcs.SCREEN, Player.darker(self.player_color), (x*gcs.PX_per_SQ, y*gcs.PX_per_SQ, gcs.PX_per_SQ-1, gcs.PX_per_SQ-1)) # Now for all my pieces which may have 'ODD_LAND', check. for active_piece in self.out_of_hand: if True: #active_piece.status == "OCCUPIED": # Bugged, but if I needed speed could try it. for piece_point in active_piece.get_neighbor_points(): x = active_piece.position[0] + piece_point[0] y = active_piece.position[1] + piece_point[1] point_neighbors = Piece._get_neighbor_points_for_point((x,y)) point_neighbors = [p for p in point_neighbors if (0 <= p[0] < gcs.NUM_SQ) and (0 <= p[1] < gcs.NUM_SQ)] point_neighbors = [gcs.board[p[0]][p[1]] for p in point_neighbors] if all([pn[0] == 'OCCUPIED' for pn in point_neighbors]) and \ len(list(set([pn[1] for pn in point_neighbors]))) == 1: pygame.draw.rect(gcs.SCREEN, Player.darker(self.player_color), (x * gcs.PX_per_SQ, y * gcs.PX_per_SQ, gcs.PX_per_SQ + 10, gcs.PX_per_SQ + 10))
def sector_land(): #print('Sector land!') unique_player_ids = set() for x in range(gcs.NUM_SQ): for y in range(gcs.NUM_SQ): unique_player_ids.add(gcs.board[x][y][1]) # Exit early if not everyone's played yet. if len(list(unique_player_ids)) < gcs.NUM_PLAYERS + 1: return temporary_board_A = copy.deepcopy(gcs.board) temporary_board_B = copy.deepcopy(gcs.board) # Everything touching your pieces or your land is your land. # Anything touching another player's piece or another player's land is not. for trial in range(gcs.NUM_SQ * gcs.NUM_SQ): for x in range(gcs.NUM_SQ): for y in range(gcs.NUM_SQ): neighboring_values = set( ) # The text labels on each tile: [TYPE, PLAYER_ID] neighboring_points = Piece._get_neighbor_points_for_point( [x, y]) for point in neighboring_points: if (0 <= point[0] < gcs.NUM_SQ) and (0 <= point[1] < gcs.NUM_SQ): neighbor_player_id = temporary_board_A[point[0]][ point[1]][1] neighbor_tile_type = temporary_board_A[point[0]][ point[1]][0] # Ignore free tiles and temporary tiles. if (neighbor_player_id is not None) and \ (neighbor_tile_type not in ["OCCUPIED", "ODD_LAND"]): neighboring_values.add(neighbor_player_id) # If only one player type neighbors us, become their land. unique_player_ids = list(neighboring_values) if len(unique_player_ids ) == 1 and unique_player_ids[0] != "CATHEDRAL": temporary_board_B[x][y] = ['LAND', unique_player_ids[0]] # Exit early, if the there are no more changed to occur. if trial > 5 and all( [A == B for A, B in zip(temporary_board_A, temporary_board_B)]): break temporary_board_A = temporary_board_B # They're separate, to be clear. temporary_board_A = copy.deepcopy(temporary_board_B) temporary_board_B = copy.deepcopy(temporary_board_A) #Now we're going to recede. for trial in range(gcs.NUM_SQ * gcs.NUM_SQ): for x in range(gcs.NUM_SQ): for y in range(gcs.NUM_SQ): neighboring_values = set( ) # The text labels on each tile: [TYPE, PLAYER_ID] neighboring_points = Piece._get_neighbor_points_for_point( [x, y]) for point in neighboring_points: if (0 <= point[0] < gcs.NUM_SQ) and (0 <= point[1] < gcs.NUM_SQ): neighbor_player_id = temporary_board_A[point[0]][ point[1]][1] neighbor_tile_type = temporary_board_A[point[0]][ point[1]][0] # An irksome exception. If a piece of land is secured with one piece and that # piece is removed, the land shouldn't count against the existing land. # Pockets of land stopping a piece from being removed are never supported # by other land, as far as I can tell (unless other shapes of pieces are created). neighbor_neighbors = Piece._get_neighbor_points_for_point( point) neighbor_neighbors = [ p for p in neighbor_neighbors if (0 <= p[0] < gcs.NUM_SQ) and ( 0 <= p[1] < gcs.NUM_SQ) ] neighbor_neighbors_tile_type = [ temporary_board_A[p[0]][p[1]][0] for p in neighbor_neighbors ] # Don't ignore any tiles in this calculation.... neighboring_values.add(neighbor_player_id) # If there are adjacent free tiles, or different player's land # or different player's pieces are adjacent to this tile, revert. # ...unless it's land that is secured by a piece that would be removed. unique_player_ids = list(neighboring_values) if len(unique_player_ids) != 1 or unique_player_ids[0] is None: temporary_board_B[x][y] = gcs.board[x][y] if trial > 5 and all( [A == B for A, B in zip(temporary_board_A, temporary_board_B)]): break temporary_board_A = copy.deepcopy(temporary_board_B) gcs.board = temporary_board_A