Пример #1
0
    def printState(self):
        # cross-platform clear screen
        os.system(['clear', 'cls'][os.name == 'nt'])
        print(u"{0}!".format(self.game_name))
        print("Round: " + str(self.round))

        for i in range(options.getRows() - 1, -1, -1):
            print("\t", end="")
            for j in range(options.boardSize):
                print("| " + str(self.board[i][j]), end=" ")
            print("|")

        print("\t  ", end="")
        for j in range(options.boardSize):
            print("_", end="   ")
        print("")
        print("\t  ", end="")
        for j in range(options.boardSize):
            print(str(j + 1), end="   ")
        print("")

        if self.finished:
            print("Game Over!")
            if self.winner != None:
                print(str(self.winner.name) + " is the winner")
            else:
                print("Game was a draw")
Пример #2
0
    def __init__(self, players=None):
        self.round = 1
        self.finished = False
        self.winner = None

        if players is None:
            # Initialize via UI
            # do cross-platform clear screen
            os.system(['clear', 'cls'][os.name == 'nt'])
            print("Welcome to {0}!".format(self.game_name))
            print("Should Player 1 be a Human or a Computer?")
            while self.players[0] == None:
                choice = str(input("Type 'H' or 'C': "))
                if choice == "Human" or choice.lower() == "h":
                    name = str(input("What is Player 1's name? "))
                    self.players[0] = Player(name, self.colors[0])
                elif choice == "Computer" or choice.lower() == "c":
                    name = str(input("What is Player 1's name? "))
                    diff = int(input("Enter difficulty for this AI (1 - 4) "))
                    self.players[0] = AIPlayer(name, self.colors[0], diff + 1)
                else:
                    print("Invalid choice, please try again")
            print("{0} will be {1}".format(self.players[0].name,
                                           self.colors[0]))

            print("Should Player 2 be a Human or a Computer?")
            while self.players[1] == None:
                choice = str(input("Type 'H' or 'C': "))
                if choice == "Human" or choice.lower() == "h":
                    name = str(input("What is Player 2's name? "))
                    self.players[1] = Player(name, self.colors[1])
                elif choice == "Computer" or choice.lower() == "c":
                    name = str(input("What is Player 2's name? "))
                    diff = int(input("Enter difficulty for this AI (1 - 4) "))
                    self.players[1] = A20321645(name, self.colors[1], diff + 1)
                    print(type(self.players[1]).__name__)
                else:
                    print("Invalid choice, please try again")
            print("{0} will be {1}".format(self.players[1].name,
                                           self.colors[1]))
        else:
            players[0].setcolor(self.colors[0])
            players[1].setcolor(self.colors[1])
            self.players[0] = players[0]
            self.players[1] = players[1]
            print("{} playing as {} against {} as {}".format(
                self.players[0].name, self.colors[0], self.players[1].name,
                self.colors[1]))

    # x always goes first (arbitrary choice on my part)
        self.turn = self.players[0]

        self.board = []
        for i in range(options.getRows()):
            self.board.append([])
            for j in range(options.getCols()):
                self.board[i].append(' ')
        print(self.board)
Пример #3
0
    def newGame(self):
        """ Function to reset the game, but not the names or colors
        """
        self.round = 1
        self.finished = False
        self.winner = None

        # x always goes first (arbitrary choice on my part)
        self.turn = self.players[0]

        self.board = []
        for i in range(options.getRows()):
            self.board.append([])
            for j in range(options.getCols()):
                self.board[i].append(' ')
Пример #4
0
    def checkForFives(self):
        # for each piece in the board...
        for i in range(options.getRows()):
            for j in range(options.getCols()):
                if self.board[i][j] != ' ':
                    # check if a vertical five-in-a-row starts at (i, j)
                    if self.verticalCheck(i, j):
                        self.finished = True
                        return

                    # check if a horizontal five-in-a-row starts at (i, j)
                    if self.horizontalCheck(i, j):
                        self.finished = True
                        return

                    # check if a diagonal (either way) five-in-a-row starts at (i, j)
                    # also, get the slope of the five if there is one
                    diag_fives, slope = self.diagonalCheck(i, j)
                    if diag_fives:
                        print(slope)
                        self.finished = True
                        return
Пример #5
0
 def __init__(self,players=None):
     self.round = 1
     self.finished = False
     self.winner = None
     
     if players is None:
         # Initialize via UI
         # do cross-platform clear screen
         os.system( [ 'clear', 'cls' ][ os.name == 'nt' ] )
         print("Welcome to {0}!".format(self.game_name))
         print("Should Player 1 be a Human or a Computer?")
         while self.players[0] == None:
             choice = str(input("Type 'H' or 'C': "))
             if choice == "Human" or choice.lower() == "h":
                 name = str(input("What is Player 1's name? "))
                 self.players[0] = Player(name, self.colors[0])
             elif choice == "Computer" or choice.lower() == "c":
                 name = str(input("What is Player 1's name? "))
                 diff = int(input("Enter difficulty for this AI (1 - 4) "))
                 search = str(input("What serach do u want to run ? (AlphaBeta or anything else = Minimax) "))
                 evaluation = str(input("What eval function do u want to run ? (Modified or anything else = Basic) "))
                 if(search != "AlphaBeta"):
                     search = "Minimax"
                 if(evaluation != "Modified"):
                     evaluation = "Basic"
                 self.search = search
                 self.evaluation[0] = evaluation
                 self.players[0] = AIPlayer(name, self.colors[0], diff+1, search, evaluation)
             else:
                 print("Invalid choice, please try again")
         print("{0} will be {1}".format(self.players[0].name, self.colors[0]))
     
         print("Should Player 2 be a Human or a Computer?")
         while self.players[1] == None:
             choice = str(input("Type 'H' or 'C': "))
             if choice == "Human" or choice.lower() == "h":
                 name = str(input("What is Player 2's name? "))
                 self.players[1] = Player(name, self.colors[1])
             elif choice == "Computer" or choice.lower() == "c":
                 name = str(input("What is Player 2's name? "))
                 diff = int(input("Enter difficulty for this AI (1 - 4) "))
                 search = str(input("What serach do u want to run ? (AlphaBeta or anything else = Minimax) "))
                 evaluation = str(input("What eval function do u want to run ? (Modified or anything else = Basic) "))
                 if(search != "AlphaBeta"):
                     search = "Minimax"
                 if(evaluation != "Modified"):
                     evaluation = "Basic"
                 self.search = search
                 self.evaluation[1] = evaluation
                 self.players[1] = AIPlayer(name, self.colors[1], diff+1, search, evaluation)
             else:
                 print("Invalid choice, please try again")
         print("{0} will be {1}".format(self.players[1].name, self.colors[1]))
     else:
         players[0].setcolor(self.colors[0])
         players[1].setcolor(self.colors[1])
         self.players[0] = players[0]
         self.players[1] = players[1]
         print("{} playing as {} against {} as {}".format(self.players[0].name,
                                                          self.colors[0],
                                                          self.players[1].name,
                                                          self.colors[1]))
 # x always goes first (arbitrary choice on my part)
     self.turn = self.players[0]
     
     self.board = []
     for i in range(options.getRows()):
         self.board.append([])
         for j in range(options.getCols()):
             self.board[i].append(' ')