Пример #1
0
    def set_start_game(self):
        """
        Presents the player with the menu where he or she can start a new game in various forms.
        The player can also choose to return to the main menu or quit the game.
        :return: returns nothing.
        """
        answer = self.tournament.ask_action(
            "Start new game \n\n" +
            "What type of game do you want to play? \n\n" +
            "[P] Player vs. Player \n" + "[C] Player vs. Computer \n" +
            "[T] Tournament \n" + "[B] Back \n" + "[Q] Quit\n\n" +
            "Please type a command and press enter:",
            ["P", "C", "T", "B", "Q"])
        self.main_menu = False
        self.change_name = False
        player1Name = self.tournament.backend.getPlayerName(1)
        if answer == "p":

            print("The new game " + player1Name +
                  " vs. Player2 is going to start.")
            player1 = g.RealPlayer(player1Name, 'X')
            player2 = g.RealPlayer('Player2', 'O')
            #Returns winner but is not needed?
            g.Game(player1, player2).enter_game_loop()
            time.sleep(5)
        elif answer == "c":
            difficulty = self.tournament.set_difficulty(False, 1)
            Playerone = g.PlayerAI(player1Name, False, 3)
            tier = ["undef", "Easy", "Medium", "Hard"]
            if difficulty:
                #print ("The new game player vs. computer ("+
                #tier[difficulty]+
                #") is going to start.")
                #time.sleep(10)
                if difficulty == 1:
                    AIplayer1 = g.PlayerAI("AI", True, 1)
                    AIdiff1 = g.AIGame(Playerone, AIplayer1)
                    winner = AIdiff1.startGame()
                    time.sleep(5)
                elif difficulty == 2:
                    AIplayer2 = g.PlayerAI("AI", True, 2)
                    AIdiff2 = g.AIGame(Playerone, AIplayer2)
                    winner = AIdiff2.startGame()
                    time.sleep(5)
                elif difficulty == 3:
                    AIplayer3 = g.PlayerAI("AI", True, 3)
                    AIdiff3 = g.AIGame(Playerone, AIplayer3)
                    winner = AIdiff3.startGame()
                    time.sleep(5)
        elif answer == "t":
            self.quit_game = self.tournament.Main()

        elif answer == "b":
            self.start_game = False
            self.main_menu = True

        elif answer == "q":
            self.quit_game = True

        os.system('clear')  # on linux / os x
Пример #2
0
    def test_hard_bot_time(self):

        p1_name = "HAL-9000"
        p2_name = "HAL-9001"

        p1 = player.AIPlayer(p1_name, gameengine.Difficulty.HIGH)
        p2 = player.AIPlayer(p2_name, gameengine.Difficulty.HIGH)
        for i in range(self.rounds):
            g = gameplatform.Game(p1, p2)
            self.assertEqual("Game Over", g.start_with_timer(10))
Пример #3
0
    def test_medium_bot_time(self):

        p1_name = "Pumba"
        p2_name = "Timon"

        p1 = player.AIPlayer(p1_name, gameengine.Difficulty.MEDIUM)
        p2 = player.AIPlayer(p2_name, gameengine.Difficulty.MEDIUM)
        for i in range(self.rounds):
            g = gameplatform.Game(p1, p2)
            self.assertEqual("Game Over", g.start_with_timer(10))
Пример #4
0
    def test_easy_bot_time(self):

        p1_name = "Alfred"
        p2_name = "Derfla"

        p1 = player.AIPlayer(p1_name, gameengine.Difficulty.LOW)
        p2 = player.AIPlayer(p2_name, gameengine.Difficulty.LOW)
        for i in range(self.rounds):
            g = gameplatform.Game(p1, p2)
            self.assertEqual("Game Over", g.start_with_timer(10))
Пример #5
0
def HAL_9000_vs_Pumba(rounds):
    draw_counter = 0
    pumba_win_count = 0
    hal_win_count = 0
    pumba_name = "Pumba"
    hal_name = "HAL 9000"

    p3 = player.AIPlayer("Alfred", gameengine.Difficulty.LOW)
    pumba = player.AIPlayer("Pumba", gameengine.Difficulty.MEDIUM)
    hal = player.AIPlayer("HAL 9000", gameengine.Difficulty.HIGH)
    
    for i in range(rounds):
        g = gameplatform.Game(pumba, hal)
        g.start()
        winner = g.get_winner()
        if winner:
            if pumba_name == winner:
                pumba_win_count += 1
            else:
                hal_win_count += 1
        else:
            draw_count += 1
    return hal_win_count, pumba_win_count, draw_counter
Пример #6
0
    def start_tournament_show(self):
        """
        Draws the current tournament state with upcoming
        match and current alternativs.
        :return:nothing
        """
        self.backend.startTournament(self.tournamnet_diff)
        a,b = self.backend.getNextMatch()
        ended = not a[0] and not b[0]
        if ended:
            winner = self.backend.getWinner()
            question = "All Games in this tournament have been played. Winner is " + winner + "\n\n"
            question += "\n\nCongratulations! \n\n[B] Back to Main Menu \n"
            alts = ["B","S","L","Q"]
        else:
            question = "Tournament - Next Match \n\nNext Match will be "
            question += str(a[0]) + " vs. " + str(b[0]) + "\n\n[M] Start match \n"
            alts = ["M","S","L","Q"]

        answer = self.ask_action(question +
                                 "[S] Show Scoreboard \n"+
                                 "[L] Show Leaderboard \n"+
                                 "[Q] Quit\n\n"+
                                "Please type a command and press enter:",alts)
        
        if answer == "m":
            print("The new tournament game "+
                  str(a[0])+
                  " vs. "+
                  str(b[0])+
                  " is going to start.")
         #   time.sleep(3)
            os.system('clear')  # on linux / os x
            players = self.backend.getListOfPlayerNames()
            
            if a[1] and b[1]:
                #BOTH AI, a[1] is 1-3 if AI, same for b[1]
                #winner = self.gameModule.start_game_AIAI(players,a[1],b[1])
                AIplayer1 = g.PlayerAI(a[0],True,a[1])
                AIplayer2 = g.PlayerAI(b[0],True,b[1])
                AIGame = g.AIGame(AIplayer1,AIplayer2)
                winner = AIGame.startGame()
                self.report_winner(a[0],b[0],winner)
                time.sleep(5)
                                 
            elif a[1]:
                #a = AI
                #winner = self.gameModule.start_game_AI(players,a[1],b[1])
                AIplayer1 = g.PlayerAI(a[0],True,a[1])
                Playerone = g.PlayerAI(b[0],False,3)
                PvAIGame = g.AIGame(Playerone,AIplayer1)
                winner = PvAIGame.startGame()
                self.report_winner(b[0],a[0],winner)
                time.sleep(5)                

            elif b[1]:
                #b = AI
                Playerone = g.PlayerAI(a[0],False,3)
                AIplayer1 = g.PlayerAI(b[0],True,b[1])
                PvAIGame = g.AIGame(Playerone,AIplayer1)
                winner = PvAIGame.startGame()
                self.report_winner(a[0],b[0],winner)
                time.sleep(5)                
            else:
                player1 = g.RealPlayer(a[0], 'X')
                player2 = g.RealPlayer(b[0], 'O')
                game = g.Game(player1, player2)
                winner = game.enter_game_loop()
                self.report_winner(a[0],b[0],winner)
                time.sleep(5)                
            pass
        
        elif answer == "b":
            self.end_tournament = True
            self.start_tournament = False
            self.back = True
            pass
        elif answer == "s":
            self.start_tournament = False
            self.show_scoreboard  = True
        elif answer == "l":
            self.start_tournament = False
            self.show_leaderboard = True
        elif answer == "q":
            self.quit_game = True
Пример #7
0
    def start_tournament_show(self):
        """
        Draws the current tournament state with upcoming
        match and current alternativs.
        :return:nothing
        """
        self.backend.startTournament(self.tournamnet_diff)
        a,b = self.backend.getNextMatch()
        ended = not a and not b
        if ended:
            winner = self.backend.getWinner()
            question = "All Games in this tournament have been played. Winner is " + winner + "\n\n"
            question += "\n\nCongratulations! \n\n[B] Back to Main Menu \n"
            alts = ["B","S","L","Q"]
        else:
            question = "Tournament - Next Match \n\nNext Match will be "
            question += str(a[0]) + " vs. " + str(b[0]) + "\n\n[M] Start match \n"
            alts = ["M","S","L","Q"]

        answer = self.ask_action(question +
                                 "[S] Show Scoreboard \n"+
                                 "[L] Show Leaderboard \n"+
                                 "[Q] Quit\n\n"+
                                "Please type a command and press enter:",alts)
        
        if answer == "m":
           # print("The new tournament game "+
            #      str(a[0])+
             #     " vs. "+
              #    str(b[0])+
               #   " is going to start.")
           # time.sleep(3)
            os.system('clear')  # on linux / os x
            players = self.backend.getListOfPlayerNames()
            """
            In the following if statements there is an bridged version of the player objects.
            This since backend.py keeps the tournament players but 
            GE and GP reuqires player objects according to their specs.
            """
            if a[1] and b[1]:
                #AI vs AI
                AIplayer1 = g.PlayerAI(a[0],True,a[1], 'X')
                AIplayer2 = g.PlayerAI(b[0],True,b[1], 'O')
                AIGame = g.GameEngine()
                winner = AIGame.AIvsAI(AIplayer1,AIplayer2)
                self.report_winner(a[0],b[0],winner)
                print ("Winner of this match is "+winner+"!")
                time.sleep(5)
                                 
            elif a[1]:
                #a = AI
                AIplayer1 = g.PlayerAI(a[0],True,a[1], 'X')
                Playerone = g.PlayerAI(b[0],False,3, 'O')
                PvAIGame = g.AIGame(AIplayer1,Playerone,True)
                winner = PvAIGame.startGame()
                self.report_winner(b[0],a[0],winner)
                time.sleep(5)                

            elif b[1]:
                #b = AI
                Playerone = g.PlayerAI(a[0],False,3, 'X')
                AIplayer1 = g.PlayerAI(b[0],True,b[1], 'O')
                PvAIGame = g.AIGame(Playerone,AIplayer1,True)
                winner = PvAIGame.startGame()
                self.report_winner(a[0],b[0],winner)
                time.sleep(5)                
            else:
                player1 = g.RealPlayer(a[0], 'X')
                player2 = g.RealPlayer(b[0], 'O')
                game = g.Game(player1, player2, True)
                winner = game.enter_game_loop()
                self.report_winner(a[0],b[0],winner)
                time.sleep(5)                
            pass
        
        elif answer == "b":
            if ended:
                self.backend.endTournament()
                self.backend.deletePlayerSet()
            self.end_tournament = True
            self.start_tournament = False
            self.back = True
            pass
        elif answer == "s":
            self.start_tournament = False
            self.show_scoreboard  = True
        elif answer == "l":
            self.start_tournament = False
            self.show_leaderboard = True
        elif answer == "q":
            self.quit_game = True
Пример #8
0
 def setUp(self):
     self.g = gameplatform.Game()
Пример #9
0
import gameplatform as g
from Player import PlayerAI

#Intiate Player1 and player2
player1 = g.RealPlayer('foo', 'X')
player2 = g.RealPlayer('bar', 'O')
game = g.Game(player1, player2)

# Initiate AI and Players
Playerone = g.PlayerAI("Player", False, 3)
AIplayer1 = g.PlayerAI("AI", True, 1)
AIplayer2 = g.PlayerAI("AI", True, 2)
AIplayer3 = g.PlayerAI("AI", True, 3)
AIdiff1 = g.AIGame(Playerone, AIplayer1)
AIdiff2 = g.AIGame(Playerone, AIplayer2)
AIdiff3 = g.AIGame(Playerone, AIplayer3)

ask = True
while ask == True:
    playerchoice = input(
        'Do you wish to play vs a Player (P) or Computer (C)').strip()
    if (playerchoice == 'P' or playerchoice == 'p'):
        print("You will now play vs another player")
        ask = False
        winner = game.enter_game_loop()

    if (playerchoice == 'c' or playerchoice == 'C'):
        while ask == True:
            AIdifficulity = input(
                'Which difficulity do you want to play against (1-3)').strip()
            if (AIdifficulity == '1'):