Exemplo n.º 1
0
    def __init__(self, max_depth: int, num_human: int, random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Each player has a random target colour, and all players share the
        same goal(Players might have same target colour.)

        Precondition:
            2 <= max_depth <= 5
        """
        self.board = random_init(0, max_depth)
        self.board.update_block_locations((0, 0), BOARD_WIDTH)
        num_player = num_human + random_players + len(smart_players)
        self.renderer = Renderer(num_player)
        self.players = []

        random_num = random.randint(0, 1)
        for i in range(num_player):
            if random_num == 0:
                goal = BlobGoal(COLOUR_LIST[random.randint(0, 3)])
            else:
                goal = PerimeterGoal(COLOUR_LIST[random.randint(0, 3)])
            if i < num_human:
                self.players.append(HumanPlayer(self.renderer, i, goal))
            elif num_human <= i < num_human + random_players:
                self.players.append(RandomPlayer(self.renderer, i, goal))
            else:
                self.players.append(
                    SmartPlayer(
                        self.renderer, i, goal,
                        smart_players[i - (num_human + random_players)]))
        # Display each player's goal before starting game.
        for i in range(num_player):
            self.renderer.display_goal(self.players[i])
Exemplo n.º 2
0
    def __init__(self, max_depth: int, num_human: int, random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """
        self.max_depth = max_depth
        self.num_human = num_human
        self.random_players = random_players
        self.smart_players = smart_players
        self.num_players = num_human + random_players + len(smart_players)

        # 1 create a Renderer for this game
        self.renderer = Renderer(self.num_players)

        # 2 Generate a random goal typr, for all players to share
        potential_goal = [
            BlobGoal(COLOUR_LIST[0]),
            PerimeterGoal(COLOUR_LIST[0])
        ]
        self.goal = potential_goal[random.randint(0, 1)]

        # 3 Generate a random board, with the given maximum depth
        self.board = random_init(0, max_depth)
        self.board.update_block_locations((0, 0), 750)

        # 4 Generate the right number of human players, random players,
        # and smart players
        self.players = []
        for human_id in range(num_human):
            self.players.append(HumanPlayer(self.renderer, human_id,
                                            self.goal))
        for ran_id in range(num_human, num_human + random_players):
            self.players.append(RandomPlayer(self.renderer, ran_id, self.goal))
        for smart_id in range(num_human + random_players, self.num_players):
            difficulty_level = smart_players[smart_id - num_human -
                                             random_players]
            self.players.append(
                SmartPlayer(self.renderer, smart_id, self.goal,
                            difficulty_level))

        for player in self.players:
            player.goal.colour = COLOUR_LIST[random.randint(0, 3)]
            if isinstance(self.goal, BlobGoal):
                player.goal = BlobGoal(player.goal.colour)
            else:
                player.goal = PerimeterGoal(player.goal.colour)
            if isinstance(player, HumanPlayer):
                self.renderer.display_goal(player)

        # 5 before returning, draw the board
        for player_id in range(len(self.players)):
            self.renderer.draw(self.board, player_id)
Exemplo n.º 3
0
    def __init__(self, max_depth: int, num_human: int, random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """
        self.board = random_init(0, max_depth)
        self.board.update_block_locations((0, 0), BOARD_WIDTH)
        num_players = num_human + random_players + len(smart_players)
        self.renderer = Renderer(num_players)
        self.players = []
        if random.random() < 0.5:
            for i in range(num_human):
                target = \
                    COLOUR_LIST[int(random.random() * len(COLOUR_LIST))]
                self.players.append(HumanPlayer(self.renderer, \
                                                len(self.players), \
                                                BlobGoal(target)))
            for i in range(random_players):
                target = \
                    COLOUR_LIST[int(random.random() * len(COLOUR_LIST))]
                self.players.append(RandomPlayer(self.renderer, \
                                                 len(self.players), \
                                                 BlobGoal(target)))
            for i in smart_players:
                target = \
                    COLOUR_LIST[int(random.random() * len(COLOUR_LIST))]
                self.players.append(SmartPlayer(self.renderer, \
                                                len(self.players), \
                                                BlobGoal(target), \
                                                i))
        else:
            for i in range(num_human):
                target = \
                    COLOUR_LIST[int(random.random() * len(COLOUR_LIST))]
                self.players.append(HumanPlayer(self.renderer, \
                                                len(self.players), \
                                                PerimeterGoal(target)))
            for i in range(random_players):
                target = \
                    COLOUR_LIST[int(random.random() * len(COLOUR_LIST))]
                self.players.append(RandomPlayer(self.renderer, \
                                                 len(self.players), \
                                                 PerimeterGoal(target)))
            for i in smart_players:
                target = \
                    COLOUR_LIST[int(random.random() * len(COLOUR_LIST))]
                self.players.append(SmartPlayer(self.renderer, \
                                                len(self.players), \
                                                PerimeterGoal(target), \
                                                i))
        self.renderer.draw(self.board, 0)
Exemplo n.º 4
0
    def __init__(self, max_depth: int,
                 num_human: int,
                 random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """
        # Create the board
        self.board = random_init(0, max_depth)
        self.board.update_block_locations((0, 0), BOARD_WIDTH)
        # Generate a goal
        goals = [BlobGoal, PerimeterGoal]
        index = random.randrange(0, 2)
        goal = goals[index]

        # Create render
        num_players = num_human + random_players + len(smart_players)
        self.renderer = Renderer(num_players)

        # Create players
        self.players = []
        val = 0
        for id_ in range(num_human):
            # Create a colour for this player
            index = random.randrange(0, 4)
            colour = COLOUR_LIST[index]
            self.players.append(HumanPlayer(self.renderer, id_, goal(colour)))
            val += 1

        for id_ in range(random_players):
            # Create a colour for this player
            index = random.randrange(0, 4)
            colour = COLOUR_LIST[index]
            self.players.append(RandomPlayer(self.renderer, val, goal(colour)))
            val += 1

        # A SmartPlayer has a difficulty level
        if len(smart_players) > 0:
            for id_ in range(len(smart_players)):
                # Create a colour for this player
                index = random.randrange(0, 4)
                colour = COLOUR_LIST[index]
                self.players.append(SmartPlayer(self.renderer, val,
                                                goal(colour),
                                                smart_players[id_]))
                val += 1
        # Display the goal and draw the board
        for i in self.players:
            self.renderer.display_goal(i)
            self.renderer.draw(self.board, i.id)
Exemplo n.º 5
0
    def __init__(self, max_depth: int, num_human: int, random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """
        self.players = []
        num_players = num_human + random_players + len(smart_players)
        self.renderer = Renderer(num_players)
        decider = random.randint(0, 1)
        # the random value ( 0 or 1 ) which we use it to
        # determine the goal of the game

        for i in range(num_players):
            c = COLOUR_LIST[random.randint(0, len(COLOUR_LIST) - 1)]
            # creating the random colour to assign to the player

            if decider == 0:
                # determining the random goal to the game
                goal = BlobGoal(c)
            else:
                goal = PerimeterGoal(c)

            if i < num_human:
                # first adding the human players
                self.players.append(HumanPlayer(self.renderer, i, goal))
                self.renderer.display_goal(self.players[i])
                # shows the goal of the player to him/her

            elif i < num_human + random_players:
                # adding the random players
                self.players.append(RandomPlayer(self.renderer, i, goal))
                self.renderer.display_goal(self.players[i])
                # shows the goal of the player

            else:

                level = smart_players[i - (num_human + random_players)]
                # it determines the difficulty level of the smartplayer which
                # is actualy the value of the smartplayer[index]

                # adding the smart players
                self.players.append(SmartPlayer(self.renderer, i, goal, level))
                self.renderer.display_goal(self.players[i])
                # shows the goal of the player

        self.board = random_init(0, max_depth)
        # make the board game with the given max_depth
        self.board.update_block_locations((0, 0), BOARD_WIDTH)
Exemplo n.º 6
0
    def __init__(self, max_depth: int, num_human: int, random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """
        num_players = num_human + random_players + len(smart_players)
        self.renderer = Renderer(num_players)
        self.board = random_init(0, max_depth)
        self.board.update_block_locations((0, 0), BOARD_WIDTH)
        self.players = []
        self.set_players(num_human, random_players, smart_players)
        self.renderer.draw(self.board, 0)
Exemplo n.º 7
0
    def __init__(self, max_depth: int, num_human: int, random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """
        game_goal = []
        self.players = []
        num_players = num_human + random_players + len(smart_players)
        self.renderer = Renderer(num_players)

        # rand_num = random.randint(0, 1)
        # for i in range(num_players):
        #     game_goal.append([
        #                       PerimeterGoal(
        #                           COLOUR_LIST[random.randint(0, 3)]
        #                                     ),
        #                       BlobGoal(
        #                           COLOUR_LIST[random.randint(0, 3)]
        #                                 )
        #                       ][rand_num]
        #                      )

        if random.randint(0, 1) == 0:
            for i in range(num_players):
                game_goal.append(
                    PerimeterGoal(COLOUR_LIST[random.randint(0, 3)]))
        else:
            for i in range(num_players):
                game_goal.append(BlobGoal(COLOUR_LIST[random.randint(0, 3)]))

        self.board = random_init(0, max_depth)
        self.board.update_block_locations((0, 0), BOARD_WIDTH)
        for i in range(num_players):
            if i < num_human:
                self.players.append(HumanPlayer(self.renderer, i,
                                                game_goal[i]))
            elif i < random_players + num_human:
                self.players.append(
                    RandomPlayer(self.renderer, i, game_goal[i]))
            else:
                self.players.append(
                    SmartPlayer(self.renderer, i, game_goal[i],
                                smart_players[i - random_players - num_human]))
        for player in self.players:
            self.renderer.display_goal(player)
        # self.renderer.draw(self.board, 0)
        for i in range(num_players):
            self.renderer.draw(self.board, i)
Exemplo n.º 8
0
    def __init__(self, max_depth: int, num_human: int, random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """
        # Store the total number of players
        num_player = num_human + random_players + len(smart_players)

        # Create the renderer
        self.renderer = Renderer(num_player)

        # Create players with random goal and random target colour
        self._create_player(num_human, random_players, smart_players)

        # Create a random board and update it locations
        self.board = random_init(0, max_depth)
        self.board.update_block_locations((0, 0), BOARD_WIDTH)

        # Draw the board
        self.renderer.draw(self.board, 0)
Exemplo n.º 9
0
    def __init__(self, max_depth: int,
                 num_human: int,
                 random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """
        num_players = num_human + random_players + len(smart_players)
        self.renderer = Renderer(num_players)
        goal_type = [BlobGoal, PerimeterGoal][random.randint(0, 1)]
        self.players = []
        player_id = 0
        for _ in range(num_human):
            # Make human players
            colour = COLOUR_LIST[random.randint(0, 3)]
            goal = goal_type(colour)
            self.players.append(HumanPlayer(self.renderer, player_id, goal))
            #self.renderer.display_goal(self.players[-1])
            player_id += 1
        for _ in range(random_players):
            # Make random players
            colour = COLOUR_LIST[random.randint(0, 3)]
            goal = goal_type(colour)
            self.players.append(RandomPlayer(self.renderer, player_id, goal))
            #self.renderer.display_goal(self.players[-1])
            player_id += 1
        for difficulty in smart_players:
            # Make smart players
            colour = COLOUR_LIST[random.randint(0, 3)]
            goal = goal_type(colour)
            self.players.append(SmartPlayer(self.renderer, player_id, goal,
                                            difficulty))
            #self.renderer.display_goal(self.players[-1])
            player_id += 1
        self.board = random_init(0, max_depth)
        self.board.update_block_locations((0, 0), BOARD_WIDTH)
Exemplo n.º 10
0
    def __init__(self, max_depth: int, num_human: int, random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """
        self.renderer = Renderer(num_human + random_players +
                                 len(smart_players))
        self.board = random_init(0, max_depth)
        self.board.update_block_locations((0, 0), BOARD_WIDTH)
        self.players = []

        # Choose a random goal
        if random.randint(1, 2) == 1:
            goal_type = 'blob'
        else:
            goal_type = 'perimeter'

        # Use the _generate_players helper method to create the players.
        # Iterate through the two following lists to insert the proper amount,
        # and type parameters into the method.
        player_types = ['human', 'random', 'smart']
        player_amounts = [num_human, random_players, len(smart_players)]
        for i in range(0, 3):
            # By using len(self.players) as the start_id for each batch of
            # players, it guarantees that the ids are consecutive and start
            # from 0.
            self.players.extend(
                self._generate_players(player_amounts[i], player_types[i],
                                       goal_type, len(self.players)))
        # Set difficulties for SmartPlayers and display goals
        for player in self.players:
            if isinstance(player, SmartPlayer):
                player.difficulty = smart_players.pop()
            self.renderer.display_goal(player)

        self.renderer.draw(self.board, 0)
Exemplo n.º 11
0
    def __init__(self, max_depth: int, num_human: int, random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """
        # Creates and stores a renderer
        self.renderer = \
            Renderer(num_human + random_players + len(smart_players))

        # Stores a random number that represents either:
        # 0. The blob goal. 1. The perimeter goal.
        goal_id = random.randint(0, 1)

        # Generates a random board.
        self.board = random_init(0, max_depth)

        # Sets the players as an empty list
        self.players = []

        # Stores the number of human AND random players (to save space later)
        num_human_rand = num_human + random_players

        for i in range(num_human_rand + len(smart_players)):
            # Loops once for every player, i represents the player ID.

            # Generates a random colour id (representing a colour)
            colour_id = random.randint(0, len(COLOUR_LIST) - 1)

            # If the goal id is 0, create a BlobGoal.
            # Otherwise, create a PerimeterGoal.
            if goal_id == 0:
                goal = BlobGoal(COLOUR_LIST[colour_id])
            else:
                goal = PerimeterGoal(COLOUR_LIST[colour_id])

            # Because players are created in the following order:
            # 1. Human 2. Random 3. Smart players.
            # We can tell which type of player it is based on the index <i>

            if i < num_human:
                # If the player is a human, store a human player
                self.players.append(HumanPlayer(self.renderer, i, goal))
            elif i < num_human_rand:
                # If the player is a random player, store a random player
                self.players.append(RandomPlayer(self.renderer, i, goal))
            else:
                # If the player is a smart player, store a smart player
                # with the specified difficulty
                self.players.append(
                    SmartPlayer(smart_players[i - num_human_rand],
                                self.renderer, i, goal))

            # Displays the goal to the player.
            self.renderer.display_goal(self.players[i])

        # Update the board locations, so everything shows up at the right place
        # and draw the board.
        self.board.update_block_locations((0, 0), BOARD_WIDTH)
        self.renderer.draw(self.board, 0)
Exemplo n.º 12
0
    def __init__(self, max_depth: int,
                 num_human: int,
                 random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """

        goals = (BlobGoal, PerimeterGoal)

        total_num = num_human + random_players + len(smart_players)
        # Initialize renderer
        self.renderer = Renderer(total_num)

        # Generate and update board
        self.board = random_init(0, max_depth)
        self.board.update_block_locations((0, 0), BOARD_WIDTH)

        # Generate a random goal for all players
        goal = random.choice(goals)

        self.players = []
        # Generate and add some HumanPlayers
        id_offset = 0
        human_list: List[HumanPlayer] = [
            HumanPlayer(
                self.renderer,
                i + id_offset,
                goal(random.choice(COLOUR_LIST)))
            # iterate <num_human> times
            for i in range(num_human)
        ]
        self.players.extend(human_list)

        # Generate and add some RandomPlayers
        id_offset += num_human
        random_list: List[RandomPlayer] = [
            RandomPlayer(
                self.renderer,
                i + id_offset,
                goal(random.choice(COLOUR_LIST)))
            # iterate <random_players> times
            for i in range(random_players)
        ]
        self.players.extend(random_list)

        # Generate and add some SmartPlayers according to
        # their corresponding difficulty levels
        id_offset += random_players
        smart_list: List[SmartPlayer] = [
            SmartPlayer(
                self.renderer,
                i + id_offset,
                goal(random.choice(COLOUR_LIST)), difficulty)
            # iterates <len(smart_players)> times,
            # capturing difficulty levels
            for i, difficulty in enumerate(smart_players)
        ]
        self.players.extend(smart_list)