Esempio n. 1
0
    def Human_VS_Human(self):

        C1 = Circle('yellow')
        C2 = Circle('magenta')
        name1 = input("Player 1, please type your name: ")
        Player1 = Player(name1, C1)
        name2 = input("Player 2, please type your name: ")
        Player2 = Player(name2, C2)
        B = Board()
        print(Player1)
        print(Player2)
        print(B)

        while (B.isDraw() == False):
            col1 = input(Player1.getname() + ", choose your column: ")
            while (self.checkColumnInteger(col1) == False):
                col1 = input("Please choose a number between 1 and 7: ")
            col1 = int(col1)
            col1 -= 1
            while B.move(Player1.getcircle(), col1) == False:
                col1 = input("Please choose a column which is not full: ")
                while (self.checkColumnInteger(col1) == False):
                    col1 = input("Please choose a number between 1 and 7: ")
                col1 = int(col1)
                col1 -= 1
            print(B)
            if B.isGameWon() == True:
                print(Player1.getname() + " wins.")
                break
            col2 = input(Player2.getname() + ", choose your column: ")
            while (self.checkColumnInteger(col2) == False):
                col2 = input("Please choose a number between 1 and 7: ")
            col2 = int(col2)
            col2 -= 1
            while B.move(Player2.getcircle(), col2) == False:
                col2 = input("Please choose a column which is not full: ")
                while (self.checkColumnInteger(col2) == False):
                    col2 = input("Please choose a number between 1 and 7: ")
                col2 = int(col2)
                col2 -= 1
            print(B)
            if B.isGameWon() == True:
                print(Player2.getname() + " wins.")
                break

        if B.isDraw() == True:
            print("Draw")

        print("\n")
        print("\n")
Esempio n. 2
0
    def Human_VS_Computer(self):

        C1 = Circle('yellow')
        C2 = Circle('magenta')
        name = input("Please type your name: ")
        Player1 = Player(name, C1)
        Player2 = AI(C2, C1, 4)
        B = Board()
        print(Player1)
        print(Player2)
        print(B)

        while (B.isDraw() == False):
            col1 = input(Player1.getname() + ", choose your column: ")
            while (self.checkColumnInteger(col1) == False):
                col1 = input("Please choose a number between 1 and 7: ")
            col1 = int(col1)
            col1 -= 1
            while B.move(Player1.getcircle(), col1) == False:
                col1 = input("Please choose a column which is not full: ")
                while (self.checkColumnInteger(col1) == False):
                    col1 = input("Please choose a number between 1 and 7: ")
                col1 = int(col1)
                col1 -= 1
            print(B)
            if B.isGameWon() == True:
                print(Player1.getname() + " wins.")
                break
            print("The computer is thinking... ")
            col2 = int(Player2.move(B))
            print("The computer chose column: " + str(col2 + 1))
            B.move(Player2.getcircle(), col2)
            print(B)
            if B.isGameWon() == True:
                print("The computer wins.")
                break

        if B.isDraw() == True:
            print("Draw")

        print("\n")
        print("\n")
Esempio n. 3
0
    def Play(self):
        C1 = Circle("yellow")
        C2 = Circle("red")
        Player1 = Player(C1)
        self.MenuDifficulty()
        difficulty = int(input("<<"))
        diff = {1: 1, 2: 2, 3: 3, 4: 4}
        Robot = AI(C2, C1, diff[difficulty])
        B = Board()
        print(Player1)
        print(Robot)
        print(B)

        while not B.isDraw():
            col1 = input("Choose column<<")
            while not self.checkColumnInteger(col1):
                col1 = input("Choose a number between 1 and 7! <<")
            col1 = int(col1) - 1
            while not B.move(Player1.get_circle, col1):
                col1 = input("Choose a column which is not full! <<")
                while not self.checkColumnInteger(col1):
                    col1 = input("Choose a number between 1 and 7! <<")
                col1 = int(col1) - 1
            print(B)
            if B.isWon():
                raise GameWon
            if difficulty == 1:
                Robot.AI_Move(B)
            else:
                col2 = int(Robot.best_move(B))
                B.move(Robot.get_circle, col2)
            print(B)
            if B.isWon():
                raise GameLost
        if B.isDraw():
            print("Draw!")
        print('\n')
Esempio n. 4
0
    def continue_game(self):
        b = Board()
        b.ReadFromFile("OAC.txt")
        print(b)
        ai = AI()
        while not b.isGameWon("O") and not b.isGameWon("X"):
            inp = 0
            while inp == 0:
                line = int(input("Choose line<<"))
                while not self.check_input1(line):
                    print("Invalid input!")
                    line = int(input("Choose line<<"))
                column = int(input("Choose column<<"))
                while not self.check_input1(column):
                    print("Invalid input!")
                    column = int(input("Choose column<<"))
                if b.board[line][column] == " ":
                    inp = 1
                else:
                    print("This space is already filled! Choose another one")
            symbol = input("Choose symbol<<")
            b.move(symbol, line, column)
            print(b, '\n')
            if b.isGameWon("X") or b.isGameWon("O"):
                print("You won!")
                break
            if b.NoSpacesLeft():
                print("You lost!")
                break
            ai.choose_random(b)
            print(b, '\n')
            if b.isGameWon("X") or b.isGameWon("O"):
                print("You won!")
                break
            if b.NoSpacesLeft():
                print("You lost!")
                break

            print("Do you want to save the game?")
            print("1.Yes")
            print("2.No")
            cmd = int(input("<<"))
            if cmd == 1:
                b.WriteToFile("OAC.txt")
                break