Ejemplo n.º 1
0
 def setup_headless_game(self):
     self.headless = True
     # player one, same as in game_state_logger.py
     self.now_playing = player.ComputerPlayer(color=BLACK, time_limit=self.timeout, headless=self.headless, strategy=randint(0,2))
     # player two, same as in game_state_logger.py
     self.other_player = player.ComputerPlayer(color=WHITE, time_limit=self.timeout, headless=self.headless, strategy=randint(0,2))
     self.board = board.Board()
     Logger.set_player_names([self.now_playing.name, self.other_player.name])
Ejemplo n.º 2
0
def create_training_game(deck_json):
    yugi_deck = create_deck(deck_json)
    opp_deck = create_deck(deck_json)

    yugi = player.ComputerPlayer("Yugi", yugi_deck, None)
    opponent = player.ComputerPlayer("Opponent", opp_deck, None)

    ygogame = game.Game(yugi, opponent)
    return ygogame
Ejemplo n.º 3
0
def create_training_game(deck_json, model1, model2, scaler):
    yugi_deck = create_deck(deck_json)
    opp_deck = create_deck(deck_json)

    yugi = player.ComputerPlayer("Yugi", yugi_deck, model1, scaler)
    opponent = player.ComputerPlayer("Opponent", opp_deck, model2, scaler)

    ygogame = game.Game(yugi, opponent)
    return ygogame
Ejemplo n.º 4
0
def run_game(deck_json):
    yugi_deck = create_deck(deck_json)
    opp_deck = create_deck(deck_json)

    yugi = player.ComputerPlayer("Yugi", yugi_deck, None)
    opponent = player.ComputerPlayer("Opponent", opp_deck, None)

    ygogame = game.Game(yugi, opponent)
    ygogame.play_game()
    winner = ygogame.winner
    print "The winner is " + winner.name
Ejemplo n.º 5
0
 def setup_game(self):
     options = self.gui.show_options()
     if options['player_1'] == COMPUTER:
         self.now_playing = player.ComputerPlayer(BLACK, int(options['player_1_time']), self.gui)
     else:
         self.now_playing = player.HumanPlayer(BLACK, gui=self.gui)
     if options['player_2'] == COMPUTER:
         self.other_player = player.ComputerPlayer(WHITE, int(options['player_2_time']), self.gui)
     else:
         self.other_player = player.HumanPlayer(WHITE, gui=self.gui)
     if options.has_key('load_file'):
         self.board = board.Board(self.read_board_file(options['load_file']))
     else:
         self.board = board.Board()
Ejemplo n.º 6
0
def create_game():
    with open("decks/yugi.json", "r") as deck:
        deck_json = json.loads(deck.read())
        yugi_deck = create_deck(deck_json)
        
    with open("decks/yugi.json", "r") as deck:
        deck_json = json.loads(deck.read())
        opp_deck = create_deck(deck_json)


    # Create Players
    yugi = player.ComputerPlayer("Yugi", yugi_deck)
    opponent = player.ComputerPlayer("Opponent", opp_deck)

    ygogame = game.Game(yugi, opponent)
    return ygogame
Ejemplo n.º 7
0
def run_training_game(deck_json):
    yugi_deck = create_deck(deck_json)
    opp_deck = create_deck(deck_json)

    yugi = player.ComputerPlayer("Yugi", yugi_deck, None)
    opponent = player.ComputerPlayer("Opponent", opp_deck, None)

    #ygogame = game.Game(yugi, opponent, rollout=True)
    ygogame = game.Game(yugi, opponent)
    ygogame.play_game()
    winner = ygogame.winner
    #print "The winner is " + winner.name
    if winner == yugi:
        victory = True
    else:
        victory = False
    return yugi.memory, victory
Ejemplo n.º 8
0
def game(amount_player_human, amount_player_computer):

    print('Начинаем игру')

    list_players = []
    for n_player in range(amount_player_human):
        player = pl.HumanPlayer(f'{n_player+1}')
        list_players.append(player)

    for n_player in range(amount_player_computer):
        player = pl.ComputerPlayer(f'{n_player+1}')
        list_players.append(player)

    random.shuffle(list_players)

    print()
    print(
        'Внимание!!! Порядок ходов игроков задается сейчас в произвольном порядке'
    )
    print()
    print('Игроки и их карточки:')
    for player in list_players:
        player.print_card()
        print()

    bag = bg.Bag()

    print()
    print('*** ПОЕХАЛАЛИ ***')
    print()

    while True:

        barrel = bag.get_barrel()
        if barrel is None:
            print('Бочонков больше нет. Игра окончена')
            return

        print(
            f'Новый бочонок: {barrel.get_num()} (осталось {bag.get_count()})')
        for player in list_players:
            player.print_card()
            print()

        for player in list_players:
            ret = player.ask_for_barrel(barrel, delegate_ask)
            if not ret:
                print(f'{player.name} - ошибка. Вы проиграли Игра Окончена')
                return
            if player.is_winner():
                print(f'{player.name} - Вы выиграли')
                return

        print()
        print('*** следующий раунд ***')
        print()
Ejemplo n.º 9
0
    def test_computer_player_ask_for_barrel_and_winner(self):

        test_player = player.ComputerPlayer('www')
        i = 0
        for line in range(3):
            for pos in test_player.card.lines[line]:
                i += 1
                if i < 5:
                    self.assertFalse(test_player.is_winner())
                if isinstance(pos, int):
                    test_player.ask_for_barrel(barrel.Barrel(int(pos)), None)

        self.assertEqual(test_player.card.amount_num(), 0)
        self.assertTrue(test_player.is_winner())
Ejemplo n.º 10
0
	def __init__(self,size,p1_name,p2_name):
		super().__init__(size)
		self.players = [player.ComputerPlayer(21,1,p1_name),player.ComputerPlayer(21,1,p2_name)]
Ejemplo n.º 11
0
def main():
    # create the board based on player specifications
    print "The board will be an nxm grid."
    n = raw_input("Please choose n: ")
    m = raw_input("Please choose m: ")
    print "The winner is the first player to get k marks in a row"
    k = raw_input("Please choose k: ")

    ck_board = board.Board(int(n), int(m), int(k))

    print ck_board

    # get player info
    player1_type = raw_input("Player1 is a Computer or Human? (c/h) ")
    if player1_type == "h":
        name1 = raw_input("Player 1's name: ")
        symbol1 = raw_input("Player 1's symbol: ")
    else:
        name1 = "P1: Computer"
        symbol1 = "o"

    player2_type = raw_input("Player2 is a Computer or Human? (c/h) ")
    if player2_type == "h":
        name2 = raw_input("Player 2's name: ")
        symbol2 = raw_input("Player 2's symbol: ")
        while symbol1 == symbol2:
            symbol2 = raw_input("Use a different symbol from Player 1: ")
    else:
        name2 = "P2: Computer"
        symbol2 = "o"
        if symbol1 == symbol2:
            symbol2 = "x"

    # Create players as humans or computers
    if player1_type == "h":
        player1 = player.HumanPlayer(name1, symbol1)
    else:
        player1 = player.ComputerPlayer(name1, symbol1, symbol2, ck_board)

    if player2_type == "h":
        player2 = player.HumanPlayer(name2, symbol2)
    else:
        player2 = player.ComputerPlayer(name2, symbol2, symbol1, ck_board)

    # set playing order
    curr_player = player1
    next_player = player2

    # gameplay, players switch off turns until there is a winner or tie game
    while not ck_board.has_winner() and not ck_board.is_full():
        print ck_board
        move = curr_player.prompt_move()
        while not ck_board.accepts_move(move):
            move = curr_player.prompt_move()
        (curr_player, next_player) = (next_player, curr_player)

    print ck_board

    if ck_board.has_winner():
        print "{} wins!".format(next_player)
    else:
        print "It's a draw!"
Ejemplo n.º 12
0
    def __init__(self):

        #Creates the person and computer players
        self.__human = player.Player('X')
        self.__computer = player.ComputerPlayer('O')

        #Says if there is a winner yet
        self.__has_winner = False

        #Creates the main window
        self.__game_wn = Tk()

        #Renames title of the main window
        self.__game_wn.title('Tic Tac Toe')

        #Creates labels for Player1 to show who they are and their wins
        self.__player_1_label = Label(self.__game_wn,
                                      font=('Times 15 bold'),
                                      text='Player')
        self.__player_1_wins_label = Label(self.__game_wn,
                                           font=('Times 13'),
                                           text='Wins: ')

        #Creates labels for Player2 to show it is the computer
        #  and its wins
        self.__player_2_label = Label(self.__game_wn,
                                      font=('Times 15 bold'),
                                      text='Computer')
        self.__player_2_wins_label = Label(self.__game_wn,
                                           font=('Times 13'),
                                           text='Wins: ')

        #Creates a label to show player1's number of wins
        self.__player_1_num_wins = IntVar()
        self.__player_1_num_wins.set(0)
        self.__player_1_wins_count = Label(
            self.__game_wn,
            font='Times 13',
            textvariable=self.__player_1_num_wins)

        #Creates a label to show player2's number of wins
        self.__player_2_num_wins = IntVar()
        self.__player_2_num_wins.set(0)
        self.__player_2_wins_count = Label(
            self.__game_wn,
            font='Times 13',
            textvariable=self.__player_2_num_wins)

        #Sets up the buttons on the tic-tac-toe board
        self.__space_1_2_str = StringVar()
        self.__space_1_2_str.set('\t\n\t')
        self.__space_1_2 = Button(self.__game_wn,
                                  font=('Times 15 bold'),
                                  fg='red',
                                  height=3,
                                  width=6,
                                  textvariable=self.__space_1_2_str,
                                  command=self.set_space_1_2)

        self.__space_1_7_str = StringVar()
        self.__space_1_7_str.set('\t\n\t')
        self.__space_1_7 = Button(self.__game_wn,
                                  font=('Times 15 bold'),
                                  fg='red',
                                  height=3,
                                  width=6,
                                  textvariable=self.__space_1_7_str,
                                  command=self.set_space_1_7)

        self.__space_1_6_str = StringVar()
        self.__space_1_6_str.set('\t\n\t')
        self.__space_1_6 = Button(self.__game_wn,
                                  font=('Times 15 bold'),
                                  fg='red',
                                  height=3,
                                  width=6,
                                  textvariable=self.__space_1_6_str,
                                  command=self.set_space_1_6)

        self.__space_2_9_str = StringVar()
        self.__space_2_9_str.set('\t\n\t')
        self.__space_2_9 = Button(self.__game_wn,
                                  font=('Times 15 bold'),
                                  fg='red',
                                  height=3,
                                  width=6,
                                  textvariable=self.__space_2_9_str,
                                  command=self.set_space_2_9)

        self.__space_2_5_str = StringVar()
        self.__space_2_5_str.set('\t\n\t')
        self.__space_2_5 = Button(self.__game_wn,
                                  font=('Times 15 bold'),
                                  fg='red',
                                  height=3,
                                  width=6,
                                  textvariable=self.__space_2_5_str,
                                  command=self.set_space_2_5)

        self.__space_2_1_str = StringVar()
        self.__space_2_1_str.set('\t\n\t')
        self.__space_2_1 = Button(self.__game_wn,
                                  font=('Times 15 bold'),
                                  fg='red',
                                  height=3,
                                  width=6,
                                  textvariable=self.__space_2_1_str,
                                  command=self.set_space_2_1)

        self.__space_3_4_str = StringVar()
        self.__space_3_4_str.set('\t\n\t')
        self.__space_3_4 = Button(self.__game_wn,
                                  font=('Times 15 bold'),
                                  fg='red',
                                  height=3,
                                  width=6,
                                  textvariable=self.__space_3_4_str,
                                  command=self.set_space_3_4)

        self.__space_3_3_str = StringVar()
        self.__space_3_3_str.set('\t\n\t')
        self.__space_3_3 = Button(self.__game_wn,
                                  font=('Times 15 bold'),
                                  fg='red',
                                  height=3,
                                  width=6,
                                  textvariable=self.__space_3_3_str,
                                  command=self.set_space_3_3)

        self.__space_3_8_str = StringVar()
        self.__space_3_8_str.set('\t\n\t')
        self.__space_3_8 = Button(self.__game_wn,
                                  font=('Times 15 bold'),
                                  fg='red',
                                  height=3,
                                  width=6,
                                  textvariable=self.__space_3_8_str,
                                  command=self.set_space_3_8)

        #Sets up a button that allows the user to change some of the game settings
        self.__gear_img = PhotoImage(file='smallGear.png')
        self.__settings_button = Button(image=self.__gear_img,
                                        command=self.open_settings)

        #Creates spacer labels for the game board
        self.__vertical_space_1 = Label(self.__game_wn,
                                        text='|\n|\n|\n|\n|\n|\n|')
        self.__vertical_space_2 = Label(self.__game_wn,
                                        text='|\n|\n|\n|\n|\n|\n|')
        self.__vertical_space_3 = Label(self.__game_wn,
                                        text='|\n|\n|\n|\n|\n|\n|')
        self.__vertical_space_4 = Label(self.__game_wn,
                                        text='|\n|\n|\n|\n|\n|\n|')
        self.__vertical_space_5 = Label(self.__game_wn,
                                        text='|\n|\n|\n|\n|\n|\n|')
        self.__vertical_space_6 = Label(self.__game_wn,
                                        text='|\n|\n|\n|\n|\n|\n|')

        self.__horizontal_space_1 = Label(self.__game_wn,
                                          text='------------------')
        self.__horizontal_space_2 = Label(self.__game_wn,
                                          text='------------------')
        self.__horizontal_space_3 = Label(self.__game_wn,
                                          text='------------------')
        self.__horizontal_space_4 = Label(self.__game_wn,
                                          text='------------------')
        self.__horizontal_space_5 = Label(self.__game_wn,
                                          text='------------------')
        self.__horizontal_space_6 = Label(self.__game_wn,
                                          text='------------------')

        #Creates a button if user wants to start a new game
        self.__new_game_button = Button(self.__game_wn, text = 'New\nGame', \
          font = 'Times 11', command = self.start_new_game)
        #Creates a button if user wants to reset the game information
        self.__reset_button = Button(self.__game_wn, text = 'Reset', \
          font = 'Times 11', command = self.reset_everything)

        #Creates a label to show who won the past game
        self.__winner_var = StringVar()
        self.__winner_var.set('')
        self.__winner_label = Label(self.__game_wn,
                                    font='Times 15 bold',
                                    textvariable=self.__winner_var)

        #Sets up widgets in the window
        self.__player_1_label.grid(row=0, column=0)
        self.__player_1_wins_label.grid(row=1, column=0)
        self.__player_2_label.grid(row=2, column=0)
        self.__player_2_wins_label.grid(row=3, column=0)

        self.__player_1_wins_count.grid(row=1, column=1)
        self.__player_2_wins_count.grid(row=3, column=1)

        self.__space_1_2.grid(row=0, column=2, sticky=S + N + E + W)
        self.__horizontal_space_1.grid(row=1, column=2)
        self.__space_2_9.grid(row=2, column=2, sticky=S + N + E + W)
        self.__horizontal_space_2.grid(row=3, column=2)
        self.__space_3_4.grid(row=4, column=2, sticky=S + N + E + W)

        self.__vertical_space_1.grid(row=0, column=3)
        self.__vertical_space_2.grid(row=2, column=3)
        self.__vertical_space_3.grid(row=4, column=3)

        self.__space_1_7.grid(row=0, column=4, sticky=S + N + E + W)
        self.__horizontal_space_3.grid(row=1, column=4)
        self.__space_2_5.grid(row=2, column=4, sticky=S + N + E + W)
        self.__horizontal_space_4.grid(row=3, column=4)
        self.__space_3_3.grid(row=4, column=4, sticky=S + N + E + W)

        self.__vertical_space_4.grid(row=0, column=5)
        self.__vertical_space_5.grid(row=2, column=5)
        self.__vertical_space_6.grid(row=4, column=5)

        self.__space_1_6.grid(row=0, column=6, sticky=S + N + E + W)
        self.__horizontal_space_5.grid(row=1, column=6)
        self.__space_2_1.grid(row=2, column=6, sticky=S + N + E + W)
        self.__horizontal_space_6.grid(row=3, column=6)
        self.__space_3_8.grid(row=4, column=6, sticky=S + N + E + W)

        self.__new_game_button.grid(row=0, column=7)
        self.__reset_button.grid(row=2, column=7)

        self.__winner_label.grid(row=4, column=0)

        self.__settings_button.grid(row=4, column=7)

        #Runs the mainloop
        mainloop()
Ejemplo n.º 13
0
import cards
import player
import game 
import json

def create_deck(json):
    deck_list = []
    for c in json:
        card = cards.MonsterCard(c.get('name'), c.get('id'), c.get('atk'), c.get('defn'), c.get('level'))
        deck_list.append(card)
    deck = cards.Deck(deck_list)
    return deck

if __name__ == "__main__":
    with open("decks/yugi.json", "r") as deck:
        deck_json = json.loads(deck.read())
        yugi_deck = create_deck(deck_json)
        
    with open("decks/yugi.json", "r") as deck:
        deck_json = json.loads(deck.read())
        opp_deck = create_deck(deck_json)


    # Create Players
    yugi = player.ComputerPlayer("Yugi", yugi_deck)
    opponent = player.ComputerPlayer("Opponent", opp_deck)

    ygogame = game.Game(yugi, opponent)
    ygogame.play_game()

    print "The winner is " + ygogame.winner.name
Ejemplo n.º 14
0
    def test_computer_player_init(self):

        test_player = player.ComputerPlayer('www')
        self.assertEqual(test_player.name, 'Компьютер www')
        self.assertIsInstance(test_player.card, card.Card)