Exemplo n.º 1
0
    def update_current_tile_action(self):
        action = self.gamestate.current_tile_action

        action.distance_moved += self.tile_speed
        if action.distance_moved > TILE_SIZE:
            action.distance_moved = TILE_SIZE
            HelpFunctions.apply_tile_action(gamestate=self.gamestate)
            self.gamestate.next_phase()
Exemplo n.º 2
0
 def adjust_board(gamestate, adjustments: [(int, int, str, int)]):
     board = gamestate.board
     for (row, column, url, rotation_n) in adjustments:
         tile = HelpFunctions.get_tile_by_url(board, url)
         tile.turn_clock_wise(rotation_n)
         old_tile = board[row][column]
         board[row][column] = tile
         board[tile.row][tile.column] = old_tile
Exemplo n.º 3
0
    def get_children_of_state(self, state):
        children = []
        for side in ['top', 'bottom', 'left', 'right']:
            for index in [1, 3, 5]:
                for rotate_n in range(4):
                    child_state_for_tile_action = HelpFunctions.copy_gamestate(state)
                    child_state_for_tile_action.current_tile.turn_clock_wise(rotate_n)

                    # Create a TileAction
                    tile_action = TileAction(selected_side=side, selected_index=index, player=child_state_for_tile_action.current_player)
                    child_state_for_tile_action.current_tile_action = tile_action
                    HelpFunctions.apply_tile_action(gamestate=child_state_for_tile_action)
                    child_state_for_tile_action.recalculate_state_variables()

                    routes = child_state_for_tile_action.current_player.possible_routes(
                        gamestate=child_state_for_tile_action,
                        tile=child_state_for_tile_action.current_player.current_location,
                        routes=[[child_state_for_tile_action.current_player.current_location]])

                    for route in routes:
                        # Create a MoveAction
                        child_state = HelpFunctions.copy_gamestate(child_state_for_tile_action)
                        move_action = MoveAction(player=child_state.current_player, route=route, current_tile=child_state.current_player.current_location)
                        child_state.current_move_action = move_action
                        HelpFunctions.apply_full_move_action(gamestate=child_state, player=child_state.current_player)
                        child_state.recalculate_state_variables
                        children.append(child_state)

        return children
Exemplo n.º 4
0
    def place_tiles_on_board(board: [[Tile]], tiles: Tile,
                             location: (int, int)):

        for i, tile in enumerate(tiles):
            tile_old_location = HelpFunctions.get_location_of_tile(board, tile)
            r_old = tile_old_location[0]
            c_old = tile_old_location[1]
            r = location[i][0]
            c = location[i][1]
            old_tile = board[r][c]
            board[r][c] = tile

            board[r_old][c_old] = old_tile
Exemplo n.º 5
0
    def determine_route(self, gamestate):
        routes = self.possible_routes(gamestate, self.current_location,
                                      [[self.current_location]])
        all_tiles = [item for sublist in gamestate.board for item in sublist]
        if self.going_back_to_starting_point():
            color_str = HelpFunctions.color_to_str(self.color)
            starting_location_tile = next(
                (t for t in all_tiles if t.starting_point_color == color_str),
                None)
            route = self.route_to_tile(starting_location_tile, gamestate)
        else:
            tile_with_objective = next(
                (t for t in all_tiles
                 if t.objective == self.current_card.objective), None)
            route = self.route_to_tile(tile_with_objective, gamestate)

        if route is None:
            route = random.choice(routes)

        return route
Exemplo n.º 6
0
    def draw_tile_placeholders(self, gamestate):
        rects = []
        for r in [1, 3, 5]:
            rect_left = p.Rect(LEFT_MARGIN - TILE_SIZE - PLACEHOLDERS_MARGIN,
                               TOP_MARGIN + r * TILE_SIZE, TILE_SIZE,
                               TILE_SIZE)
            rect_right = p.Rect(
                LEFT_MARGIN + BOARD_WIDTH + PLACEHOLDERS_MARGIN,
                TOP_MARGIN + r * TILE_SIZE, TILE_SIZE, TILE_SIZE)
            rects.extend([(rect_left, r, 'left'), (rect_right, r, 'right')])

        for c in [1, 3, 5]:
            rect_top = p.Rect(LEFT_MARGIN + c * TILE_SIZE,
                              TOP_MARGIN - TILE_SIZE - PLACEHOLDERS_MARGIN,
                              TILE_SIZE, TILE_SIZE)
            rect_bottom = p.Rect(
                LEFT_MARGIN + c * TILE_SIZE,
                TOP_MARGIN + BOARD_HEIGHT + PLACEHOLDERS_MARGIN, TILE_SIZE,
                TILE_SIZE)
            rects.extend([(rect_top, c, 'top'), (rect_bottom, c, 'bottom')])

        for (rect, index, side) in rects:
            rounded_rect = HelpFunctions.make_rounded_rect(self.screen,
                                                           rect,
                                                           p.Color('grey'),
                                                           radius=0.4)
            phase = gamestate.current_phase
            if phase == Phase.CHOOSING_TILE and self.is_in_rect(
                    p.mouse.get_pos(), rect):
                cur_tile = gamestate.current_tile
                self.draw_tile(gamestate, cur_tile, (rect[0], rect[1]), 200)
            if phase == Phase.CHOOSING_TILE and gamestate.last_mouse_click_location is not None and self.is_in_rect(
                    gamestate.last_mouse_click_location, rect):
                action = TileAction(selected_side=side,
                                    selected_index=index,
                                    player=gamestate.current_player)
                gamestate.current_tile_action = action
                gamestate.last_mouse_click_location = None
Exemplo n.º 7
0
    def test_possible_routes(self):
        for i in range(0, 100):
            players_ = {'random1': 'RandomBot', 'minimax': 'MinimaxBot'}
            nr_of_runs = 100
            logging_on = True
            visuals_on = True
            tile_speed = 10
            move_speed = 1
            seed = 6989004  # random.randint(0, 10000000)
            print('seed: ' + str(seed))
            board, tile_left = Generator.generate_random_full_board(seed)
            all_tiles = [item for sublist in board for item in sublist]
            red_tile = next(
                (t for t in all_tiles if t.starting_point_color == 'RED'),
                None)
            blue_tile = next(
                (t for t in all_tiles if t.starting_point_color == 'BLUE'),
                None)
            green_tile = next(
                (t for t in all_tiles if t.starting_point_color == 'GREEN'),
                None)
            players = []
            for name in players_:
                if players_[name] == 'FirstBot':
                    first_bot = FirstBot(name=name,
                                         current_location=red_tile,
                                         color=p.Color(255, 0, 0, 150),
                                         seed=seed)
                    players.append(first_bot)
                elif players_[name] == 'RandomBot':
                    random_bot = RandomBot(name=name,
                                           current_location=blue_tile,
                                           color=p.Color(0, 0, 255, 150),
                                           seed=seed)
                    players.append(random_bot)
                elif players_[name] == 'Human':
                    human = Human(name=name,
                                  current_location=green_tile,
                                  color=p.Color(0, 255, 0, 150),
                                  seed=seed)
                    players.append(human)
                elif players_[name] == 'MinimaxBot':
                    minimaxBot = MinimaxBot(name=name,
                                            current_location=green_tile,
                                            color=p.Color(0, 255, 0, 150),
                                            seed=seed)
                    players.append(minimaxBot)
                else:
                    raise ValueError('Player has no valid type')
            Generator.deal_cards(players=players, nr_of_cards_pp=1)
            # for pl in players:
            #     print(pl.name + ' has cards: ')
            #     print([c.objective for c in pl.cards])
            gs = GameState(players=players,
                           board=board,
                           current_tile=tile_left,
                           current_player=players[1])
            gs.recalculate_state_variables()
            tile_action = TileAction('top', 1, players[1])
            gs.current_tile_action = tile_action
            HelpFunctions.apply_tile_action(gs)

            #game = Game(gs, tile_speed=self.tile_speed, move_speed=self.move_speed, visuals_on=self.visuals_on)

            for pl in players:
                pl.update_properties(gs)

            for pl in players:
                routes = pl.possible_routes(gamestate=gs,
                                            tile=pl.current_location,
                                            routes=[[pl.current_location]])
                last_tiles = [item[-1] for item in routes]