Exemple #1
0
 def setUp(self):
     self.deck = generateDeck()
     self.dealer = Player('DEALER', True)
     self.playerOne = Player('Kevin', False)
     self.normalCard = Card('Three of Hearts', 3)
     self.faceCard = Card('King of Diamonds', 10)
     self.ace = Card('Ace of Spades', [1, 11])
Exemple #2
0
    def button_play_command(self):
        """
        When the button play (or ready is press)
        :return: None
        """

        if self.is_server:
            if self.player_2_is_connected:
                if self.player_2_is_ready:
                    self.export_last_game_settings()
                    self.ui.server.send_message_to_all(Server.encode_message(MESSAGE_PLAY))

                    self.ui.change_panel(
                        ServerGamePanel.ServerGamePanel,
                        player_1=Player.Player(TokenState.Player_1, self.players_tokens[0],
                                               self.players_entry_string_variable[0].get()),
                        player_2=Player.Player(TokenState.Player_2, self.players_tokens[1],
                                               self.players_entry_string_variable[1].get()),
                        is_server=self.is_server
                    )
                else:
                    self.player_1_want_to_start()
        else:
            self.set_player_2_ready(not self.player_2_is_ready)
            self.ui.client.send_message(Server.encode_message(PARAMETER_SEPARATOR.join((MESSAGE_SEND_READY,
                                                                                        str(self.player_2_is_ready)))))
 def test_add_player(self):
     player = Player("Franco")
     self.billboard.add_player(player)
     self.assertEqual(self.billboard.get_players_name(), ['Franco'])
     player = Player("Francois")
     self.billboard.add_player(player)
     self.assertEqual(self.billboard.get_players_name(),
                      ['Franco', 'Francois'])
def test_add(capsys):
    main = Main()
    main.add_player("Carl")
    out, err = capsys.readouterr()
    assert ((Player("Carl", "b") in main.players)
            or (Player("Carl", "y") in main.players))
    assert ("Added: Player(name='Carl', color='y')\n" == out
            or "Added: Player(name='Carl', color='b')\n" == out)
def test_random_color_negative():
    main = Main()
    main.players = {
        Player("Alice", "g"),
        Player("Bob", "r"),
        Player("Carl", "y"),
        Player("Donna", "b")
    }
    with pytest.raises(IndexError):
        main.random_color()
    def client_on_message(self, message):
        """
        When the client receive a message
        :param message: The message receive
        :return: None
        """
        messages = Server.Server.decode_message(message)

        for message in messages:
            message = message.split('_')

            if message[0] == MESSAGE_NEED_STATE:
                self.client_send_player_name()
                self.client_send_token()

            elif message[0] == MESSAGE_SEND_NAME_SELECTED:
                self.players_entry_string_variable[0].set(message[1])
                self.name_string_var_trace_write(False)

            elif message[0] == MESSAGE_SEND_TOKEN_SELECTED:
                try:
                    # noinspection PyTypeChecker
                    self.players_tokens[
                        self.opponent_id] = TokenStyle.TokenStyle(
                            int(message[1]))

                    self.players_tokens_images[self.opponent_id] = \
                        self.ui.image_getter.save_token_photos[self.opponent][self.players_tokens[self.opponent_id]]

                    self.players_tokens_labels[self.opponent_id].config(
                        image=self.players_tokens_images[self.opponent_id])
                except ValueError:
                    pass

            elif message[0] == MESSAGE_PLAYER_1_WANT_START:
                self.player_1_want_to_start()

            elif message[0] == MESSAGE_PLAY:
                game = Game.Game(
                    first_player=(TokenState.Player_2,
                                  TokenState.Player_1)[message[1] == "1"])

                self.export_last_game_settings()

                self.ui.change_panel(
                    ServerGamePanel.ServerGamePanel,
                    player_1=Player.Player(
                        TokenState.Player_1, self.players_tokens[0],
                        self.players_entry_string_variable[0].get()),
                    player_2=Player.Player(
                        TokenState.Player_2, self.players_tokens[1],
                        self.players_entry_string_variable[1].get()),
                    is_server=self.create_game,
                    game=game)
def test_no_add(capsys):
    main = Main()
    main.players = {
        Player("Alice", "g"),
        Player("Bob", "r"),
        Player("Carl", "y"),
        Player("Donna", "b")
    }
    main.add_player("Eric")
    out, err = capsys.readouterr()
    assert "Can't have more than 4 players\n" == out
Exemple #8
0
def gameLoop():
    time.sleep(1)
    game_exit = False
    tictactoe = TicTacToe()
    points = (((300, 25), (300, 575)), ((500, 25), (500, 575)),
              ((125, 200), (675, 200)), ((125, 400), (675, 400)))
    qplayer = QPlayer('o', q_path='pretrained_model.npy')
    curr_turn = 'o'
    player = Player()
    global clicked

    while not game_exit:
        game_display.fill(white)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                quitGame()

        if tictactoe.terminal:
            if tictactoe.winning != 0:
                time.sleep(2)
            terminalScreen(tictactoe.winning)

        for start, end in points:
            pygame.draw.line(game_display, black, start, end, 8)

        if curr_turn == 'o':
            action = qplayer.choose(tictactoe, False)
            tictactoe.update(action, 'o', False)
        else:
            position = 0
            for i in [4, 204, 404]:
                for j in [104, 304, 504]:
                    if player.validMove(position, tictactoe.board):
                        button('', j, i, 192, 192, white, white, human_move, {
                            'position': position,
                            'tictactoe': tictactoe
                        })
                    position += 1

        position = 0
        for i in [4, 204, 404]:
            for j in [104, 304, 504]:
                curr_pos = tictactoe.board[position]
                if curr_pos == 'o':
                    game_display.blit(circle_image, (j + 49, i + 49))
                elif curr_pos == 'x':
                    game_display.blit(cross_image, (j + 49, i + 49))
                position += 1

        if (clicked and curr_turn == 'x') or curr_turn == 'o':
            curr_turn = 'o' if curr_turn == 'x' else 'x'
            clicked = False
        pygame.display.update()
        clock.tick(15)
def test_winner():
    alice = Player("Alice", "g")
    bob = Player("Bob", "r")
    game = Game([alice, bob])
    game.board.move_piece(Piece("g", 1, Field("A", color="g")),
                          Field("B1", "g"))
    game.board.move_piece(Piece("g", 2, Field("A", color="g")),
                          Field("B2", "g"))
    game.board.move_piece(Piece("g", 3, Field("A", color="g")),
                          Field("B3", "g"))
    game.board.move_piece(Piece("g", 4, Field("A", color="g")),
                          Field("B4", "g"))
    assert game.has_winner()
Exemple #10
0
 def test_buy_card_valid(self):
     player = Player("Name", 100)
     initialBudget = player.getBudget()
     card = YuGiOhMaster.getCardByName("Blue-Eyes White Dragon")
     player.buyCard("Blue-Eyes White Dragon")
     self.assertEqual(
         player.getBudget(),
         float(initialBudget) - float(card["card_prices"]["ebay_price"]))
     self.assertEqual(len(player.getDeck()), 1)
     self.assertEqual(len(player.getTransactions()), 1)
    def __init__(self,
                 master,
                 ui,
                 is_server=False,
                 player_1=Player.Player(TokenState.TokenState.Player_1,
                                        TokenStyle.TokenStyle.Blue),
                 player_2=Player.Player(TokenState.TokenState.Player_2,
                                        TokenStyle.TokenStyle.Green),
                 game=Game.Game()):
        """
        Constructor
        """
        super().__init__(master,
                         ui,
                         player_1,
                         player_2,
                         game,
                         disable_end_button=not is_server)

        self.is_server = is_server

        if self.is_server:
            self.button_main_menu.configure(
                text=self.ui.translation.get_translation("quit"))

            # Set server functions
            self.ui.server.on_message_function = self.server_on_message
            self.ui.server.on_client_connect_function = self.server_on_client_connect_function
            self.ui.server.on_client_disconnect_function = self.server_on_client_disconnect_function

        else:
            tkinter.tix.Label(self.win_text_frame,
                              text=self.ui.translation.get_translation(
                                  "server_game_wait_host")).grid(row=1,
                                                                 column=0)

            # Set client functions
            self.ui.client.on_message_function = self.client_on_message
            self.ui.client.on_connection_function = self.client_on_connection_function
            self.ui.client.on_disconnection_function = self.client_on_disconnection_function
Exemple #12
0
    def __init__(self, master, ui, is_server=False,
                 player_1=Player.Player(TokenState.TokenState.Player_1, TokenStyle.TokenStyle.Blue),
                 player_2=Player.Player(TokenState.TokenState.Player_2, TokenStyle.TokenStyle.Green),
                 game=None):
        """
        Constructor
        """
        super().__init__(master, ui, player_1, player_2, game, disable_end_button=not is_server)

        self.is_server = is_server

        self.button_syn = tkinter.tix.Button(
            self, image=self.ui.image_getter.syn_icon, command=self.button_syn_command)
        self.button_syn.place(relx=1., rely=0., x=0, y=0, anchor=tkinter.N + tkinter.E)
        self.button_syn_lock = False

        if self.is_server:
            self.after(100, lambda: self.ui.server.send_message_to_all(Server.encode_message(
                PARAMETER_SEPARATOR.join((MESSAGE_SET_TURN, str(self.game.current_turn.value))))))
            self.button_main_menu.configure(
                text=self.ui.translation.get_translation("quit"), command=self.button_back_dialog_command
            )

            # Set server functions
            self.ui.server.on_message_function = self.server_on_message
            self.ui.server.on_client_connect_function = self.server_on_client_connect_function
            self.ui.server.on_client_disconnect_function = self.server_on_client_disconnect_function

        else:
            tkinter.tix.Label(
                self.win_text_frame,
                text=self.ui.translation.get_translation("server_game_wait_host")
            ).grid(row=1, column=0)

            # Set client functions
            self.ui.client.on_message_function = self.client_on_message
            self.ui.client.on_connection_function = self.client_on_connection_function
            self.ui.client.on_disconnection_function = self.client_on_disconnection_function
    def button_play_command(self):
        """
        When the button play (or ready is press)
        :return: None
        """

        if self.create_game:
            if self.player_2_is_connected:
                if self.player_2_is_ready:
                    self.export_last_game_settings()

                    self.ui.change_panel(
                        ServerGamePanel.ServerGamePanel,
                        player_1=Player.Player(
                            TokenState.Player_1, self.players_tokens[0],
                            self.players_entry_string_variable[0].get()),
                        player_2=Player.Player(
                            TokenState.Player_2, self.players_tokens[1],
                            self.players_entry_string_variable[1].get()),
                        is_server=self.create_game,
                        game=Game.Game(
                            first_player=random.choice((TokenState.Player_1,
                                                        TokenState.Player_2))))

                    self.ui.server.send_message_to_all(
                        Server.Server.encode_message('_'.join(
                            (MESSAGE_PLAY,
                             str(self.ui.current_panel.game.current_turn.value)
                             ))))
                else:
                    self.player_1_want_to_start()
        else:
            self.set_player_2_ready(not self.player_2_is_ready)
            self.ui.client.send_message(
                Server.Server.encode_message('_'.join(
                    (MESSAGE_SEND_READY, str(self.player_2_is_ready)))))
def test_remove(capsys):
    main = Main()
    main.players = {
        Player("Alice", "g"),
        Player("Bob", "r"),
        Player("Carl", "y"),
        Player("Donna", "b")
    }
    main.remove_player("Donna")
    out, err = capsys.readouterr()
    assert "Removed: Player(name='Donna', color='b')\n" == out
    assert {Player("Alice", "g"),
            Player("Bob", "r"),
            Player("Carl", "y")} == main.players
Exemple #15
0
def add_player(session, team_id_in, jersey_num, first_name_in, last_name_in,
               mpg_in, ppg_in, rpg_in, apg_in, spg_in, bpg_in):
    from main import State, Team, Color, Player
    new_player = Player(team_id=int(team_id_in),
                        uniform_num=int(jersey_num),
                        first_name=first_name_in,
                        last_name=last_name_in,
                        mpg=int(mpg_in),
                        ppg=int(ppg_in),
                        rpg=int(rpg_in),
                        apg=int(apg_in),
                        spg=float(spg_in),
                        bpg=float(bpg_in))
    session.add(new_player)
    session.commit()
    return
Exemple #16
0
def test1():
    llist = CircularLinkedList([Player('name', 'username'), Player('name1','username1')])    
    player = llist.head
    player.data.add_word('lol')
Exemple #17
0
from main import Player
import json
import pickle

obj = Player("frank", "1", [0, 2, 1, 0], 7, [])
list = [1, 2, 34, 54, 5, 48]
dict = {"key": "value", "tuber": 3}

with open("testsave.json", "w") as f:
    json.dump([obj.__dict__, obj.__dict__], f)
f.close()

with open("testsave.json", "r") as f:
    jsondata = json.load(f)
    print(jsondata)
f.close()

with open('testpickle.dat', 'wb') as f:
    pickle.dump([obj, list, dict], f)

with open('testpickle.dat', 'rb') as f:
    newplayer, newlist, newdict = pickle.load(f)

print(newplayer)
print(newlist)
print(newdict)
Exemple #18
0
 def setUp(self):
     self.player = Player()
Exemple #19
0
    def __init__(self, master, ui,
                 player_1=Player.Player(TokenState.TokenState.Player_1, TokenStyle.TokenStyle.Blue),
                 player_2=Player.Player(TokenState.TokenState.Player_2, TokenStyle.TokenStyle.Green),
                 game=Game.Game(), disable_end_button=False, delay=Preferences.DEFAULT_DELAY):
        """
        Constructor
        :param player_1: the player 1
        :param player_2: the player 2
        :param game: a link to the game
        :param disable_end_button: if need to disable end buttons (for the client)
        :param delay: the delay between click in ms
        :param master: see Panel class
        :param ui: see Panel class
        """
        super().__init__(master, ui)

        self.turn_text_format = self.ui.translation.get_translation("game_panel_turn_format")
        self.win_text_format = self.ui.translation.get_translation("game_panel_win_format")

        self.grid_canvas = tkinter.tix.Canvas(self)
        self.grid_canvas.pack(expand=True, fill=tkinter.tix.BOTH)

        self.after(500, lambda: self.grid_canvas.bind("<Button>", self.grid_canvas_on_click))

        self.game = game

        self.players = {
            TokenState.TokenState.Player_1: player_1,
            TokenState.TokenState.Player_2: player_2
        }

        self.token_square_size = 0

        self.height_center = 0
        self.width_center = 0

        self.button_main_menu = tkinter.tix.Button(
            self,
            # text=self.ui.translation.get_translation("game_panel_main_menu_button"),
            command=self.button_main_menu_command, image=self.ui.image_getter.door_exit_icon)
        self.button_main_menu.place(x=0, y=0)

        self.grid_image_create = []
        self.turn_text_id = -1
        self.turn_image_id = - 1
        self.win_line_id = -1
        self.win_icon_id = -1
        self.win_icon_background_id = -1

        self.win_text_frame = tkinter.tix.Frame(self, relief=tkinter.tix.RAISED, borderwidth=2)

        self.win_text_label = tkinter.tix.Label(self.win_text_frame)
        self.win_text_label.grid(row=0, column=0)

        if not disable_end_button:
            self.end_buttons_frame = tkinter.tix.Frame(self.win_text_frame)
            self.end_buttons_frame.columnconfigure(0, weight=1)
            self.end_buttons_frame.columnconfigure(1, weight=1)
            self.end_buttons_frame.grid(row=1, column=0)

            max_width = max(len(self.ui.translation.get_translation("back")),
                            len(self.ui.translation.get_translation("restart")),
                            len(self.ui.translation.get_translation("main_menu")))

            self.button_main_menu_end = tkinter.tix.Button(
                self.end_buttons_frame,
                text=self.ui.translation.get_translation("main_menu"),
                command=self.button_main_menu_command, width=max_width
            )
            self.button_main_menu_end.grid(row=0, column=0, sticky=tkinter.tix.NSEW, padx=5)

            self.back_button = tkinter.tix.Button(
                self.end_buttons_frame,
                text=self.ui.translation.get_translation("back"),
                command=self.button_back_command, width=max_width
            )
            self.back_button.grid(row=0, column=1, sticky=tkinter.tix.NSEW, padx=5)

            self.restart_button = tkinter.tix.Button(
                self.end_buttons_frame,
                text=self.ui.translation.get_translation("restart"),
                command=self.button_restart_command, width=max_width
            )
            self.restart_button.grid(row=0, column=2, sticky=tkinter.tix.NSEW, padx=5)

        for x in range(0, self.game.grid_width):
            self.grid_image_create.append([])
            for y in range(0, self.game.grid_height):
                self.grid_image_create[x].append(-1)

        self.token_animation_list = []

        self.delay = delay / 1000.  # convert in second
        self.last_click_time = time.time()

        self.ai_turn_start_time = time.time()

        self.ai_progress_bar = tkinter.ttk.Progressbar(self.grid_canvas, orient=tkinter.tix.HORIZONTAL,
                                                       mode='determinate')
        self.ai_progress_bar_show = False
Exemple #20
0
def test():
    # Test all of the possible outcomes of a comparison
    pool=['r', 'a', 'c', 'd', 'x', 'z']
    # Comparison is valid
    print("LUMEN -> NUMERAL: {}".format(compare("lumen", "numeral", pool)))  # Returns ['r', 'a']
    # No tiles from the pool are used
    print("LISTEN -> SILENT: {}".format(compare("listen", "silent", pool)))  # Returns []
    # At least one letter does not show in test_word or in pool
    print("ELITE -> ELICITED: {}".format(compare("elite", "elicited", pool)))  # Returns []
    # Not all of the letters in test_word are used
    print("ULTIMATE -> LAME: {}".format(compare("ultimate", "lame", pool)))  # Returns []
    print()
    print()

    # Test adding and removing words and accessing class variables from Player
    p1=Player("Carson")
    p1.add_word("neat")
    p1.add_word("epic")
    p1.add_word("cool")
    print("{}: {}".format(p1.name, p1.words))
    print()
    p2=Player("Chase")
    p2.add_word("discombobulate")
    p1.remove_word("cool")
    print("{}: {}".format(p1.name, p1.words))
    print("{}: {}".format(p2.name, p2.words))
    print()
    print()

    llist=CircularLinkedList(['a', 'b', 'c', 'd', 'e'])
    print(llist)

    llist.add_node(Node('f'))
    print(llist)

    llist.remove_node(Node('b'))
    print(llist)
    print()
    print()

    llist2 = CircularLinkedList()
    print(llist2)
    llist2.add_node(Node('a'))
    print(llist2)
    llist2.add_node(Node('b'))
    print(llist2)
Exemple #21
0
class PlayerTestCase(unittest.TestCase):

    def setUp(self):
        self.player = Player()

    def tearDown(self):
        pass

    def test_accelerate_successfulWithLowTemperatureAndVelocity(self):
        oldVelocity = self.player.velocity
        self.player.accelerate()
        self.assertFalse(self.player.velocity == oldVelocity)

    def test_accelerate_failsWhenMaxVelocityExceeded(self):
        self.player.velocity += self.player.max_velocity
        oldVelocity = self.player.velocity
        self.player.accelerate()
        self.assertTrue(self.player.velocity == oldVelocity)

    def test_accelerate_failsWhenMaxTemperatureExceeded(self):
        self.player.temperature += self.player.max_temperature
        oldTemperature = self.player.temperature
        self.player.accelerate()
        self.assertTrue(self.player.temperature == oldTemperature)

    def test_accelerate_temperatureUnchangedOnFailDueToExcessiveVelocity(self):
        self.player.velocity = self.player.max_velocity+1
        oldTemperature = self.player.temperature
        self.player.accelerate()
        self.assertTrue(self.player.temperature == oldTemperature)

    def test_accelerate_temperatureUnchangedOnFailDueToExcessiveTemperature(self):
        self.player.temperature = self.player.max_temperature+1
        oldTemperature = self.player.temperature
        self.player.accelerate()
        self.assertTrue(self.player.temperature == oldTemperature)

    def test_decelerate_successfulWithLowTemperatureAndVelocity(self):
        oldVelocity = self.player.velocity
        self.player.decelerate()
        self.assertFalse(self.player.velocity == oldVelocity)

    def test_decelerate_failsWhenMinVelocityExceeded(self):
        self.player.velocity = self.player.min_velocity-1
        oldVelocity = self.player.velocity
        self.player.decelerate()
        self.assertTrue(self.player.velocity == oldVelocity)

    def test_decelerate_failsWhenMaxTemperatureExceeded(self):
        self.player.temperature += self.player.max_temperature
        oldTemperature = self.player.temperature
        self.player.decelerate()
        self.assertTrue(self.player.temperature == oldTemperature)

    def test_decelerate_temperatureUnchangedOnFailDueToLowVelocity(self):
        self.player.velocity = self.player.min_velocity-1
        oldTemperature = self.player.temperature
        self.player.decelerate()
        self.assertTrue(self.player.temperature == oldTemperature)

    def test_decelerate_temperatureUnchangedOnFailDueToExcessiveTemperature(self):
        self.player.temperature = self.player.max_temperature+1
        oldTemperature = self.player.temperature
        self.player.decelerate()
        self.assertTrue(self.player.temperature == oldTemperature)
Exemple #22
0
 def setUp(self):
     self.billboard = BillBoard()
     self.player1 = Player("Franco")
     self.billboard.add_player(self.player1)
     self.player2 = Player("Francois")
     self.billboard.add_player(self.player2)
Exemple #23
0
# font
font = pygame.font.Font(None, 40)

#opening the json file and loading all packages
with open("presets.json") as f:
    packages = json.load(f)

#getting all characters from the chosen packages into one list
chosen_packages = ["Anime_Female"]
characters = []
for package in chosen_packages:
    characters.extend(packages[package])

#replacing the raw names with objects of the class Player
for i in range(len(characters)):
    characters[i] = Player(name=characters[i])

# mainloop-boolean
go = True
turn_ended = False

#creating window#
window = pygame.display.set_mode((WIDTH, HEIGHT), 0, 0)
window.fill(grass_green)
clock = pygame.time.Clock()

#Surfaceproperties
top_surface_properties = (WIDTH, HEIGHT * (1 / 5))
tile_size = (WIDTH * (1 / 3), HEIGHT * (4 / 5))
left_surface_properties = tile_size
middle_surface_properties = tile_size
Exemple #24
0
 def test_player_instantiation(self):
     player = Player("Franco")
     self.assertEqual(player.name, "Franco")
     self.assertEqual(player.position, 0)
def test_rename(capsys):
    main = Main()
    main.rename_player("Alice", "Alex")
    out, err = capsys.readouterr()
    assert {Player("Alex", "g"), Player("Bob", "r")} == main.players
    assert "Renamed: Player(name='Alice', color='g')\n" == out
    def button_play_command(self):
        """
        The command of the play button
        :return: None
        """
        self.export_last_game_settings()

        if len(self.players_entry_string_variable[0].get().strip()) < 3:
            tkinter.messagebox.showerror(
                self.ui.translation.get_translation("configure_game_panel_dialog_name_blank_title"),
                self.ui.translation.get_translation("configure_game_panel_dialog_name_blank_message").format("1")
            )
            return None

        if len(self.players_entry_string_variable[1].get().strip()) < 3:
            tkinter.messagebox.showerror(
                self.ui.translation.get_translation("configure_game_panel_dialog_name_blank_title"),
                self.ui.translation.get_translation("configure_game_panel_dialog_name_blank_message").format("2")
            )
            return None

        if self.players_entry_string_variable[0].get().strip() == self.players_entry_string_variable[1].get().strip():
            tkinter.messagebox.showerror(
                self.ui.translation.get_translation("configure_game_panel_dialog_same_name_title"),
                self.ui.translation.get_translation("configure_game_panel_dialog_same_name_message")
            )
            return None

        if self.players_tokens[0] == self.players_tokens[1]:
            if not tkinter.messagebox.askokcancel(
                    self.ui.translation.get_translation("configure_game_panel_dialog_same_token_title"),
                    self.ui.translation.get_translation("configure_game_panel_dialog_same_token_message")):
                return None

        game = Game.Game()
        game.current_turn = random.choice((TokenState.Player_1, TokenState.Player_2))

        if self.player_ai_choose_var[0].get():
            player_1 = AIPlayer.AIPlayer(
                self.ui.preference.get_preference(PREFERENCE_DIFFICULTY_DEPTH_LEVEL)[self.difficulty_selected_button],
                self.ui.preference.get_preference(PREFERENCE_DIFFICULTY_ROUND_LEVEL)[self.difficulty_selected_button],
                game, TokenState.Player_1,
                self.players_tokens[0], self.players_entry_string_variable[0].get().strip())
        else:
            player_1 = Player.Player(TokenState.Player_1, self.players_tokens[0],
                                     self.players_entry_string_variable[0].get().strip())

        if self.player_ai_choose_var[1].get():
            player_2 = AIPlayer.AIPlayer(
                self.ui.preference.get_preference(PREFERENCE_DIFFICULTY_DEPTH_LEVEL)[self.difficulty_selected_button],
                self.ui.preference.get_preference(PREFERENCE_DIFFICULTY_ROUND_LEVEL)[self.difficulty_selected_button],
                game, TokenState.Player_2,
                self.players_tokens[1], self.players_entry_string_variable[1].get().strip())
        else:
            player_2 = Player.Player(TokenState.Player_2, self.players_tokens[1],
                                     self.players_entry_string_variable[1].get().strip())

        self.ui.change_panel(GamePanel.GamePanel,
                             player_1=player_1,
                             player_2=player_2,
                             game=game, delay=self.ui.preference.get_preference(PREFERENCE_DELAY))
Exemple #27
0
s.bind((server, port))
s.listen(2)
print("Waiting for a connection, Server Started")

# Set up random pictionary word
with open("pictionary.txt", "r") as pictionary:
    w = pictionary.read().split()


def randomWord():
    return random.choice(w)


picWord = randomWord()

players = [Player(800, 600, 1, picWord), Player(800, 600, 2, picWord)]


def nextRound(pW, gW):
    if pW == gW:
        print("drawP.picWord({0}) = guessP.guessWord({1})".format(pW, gW))
        return randomWord()


def threaded_client(conn, playerID):
    reply = ""
    conn.send(pickle.dumps(players[playerID]))

    while True:
        global pW
        data = pickle.loads(conn.recv(2048))
Exemple #28
0
def create_player(name: str):
    return Player(name)
Exemple #29
0
 def setUp(self):
     self.player1 = Player.Player("Ein")
     self.player2 = Player.Player("Rome")
     self.rock_paper_scissors_game = RockPaperScissorsGame.RockPaperScissorsGame(
         self.player1, self.player2)
def test_no_winner():
    alice = Player("Alice", "g")
    bob = Player("Bob", "r")
    game = Game([alice, bob])
    assert not game.has_winner()