aboutsummaryrefslogtreecommitdiffstats
path: root/DotsNBoxes.py
blob: 14cdd2a72417fde32e3169bc0b6b4fbb6011603c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from random import *
import collections
from Algorithm import *
from Board import *
from Nodes import *
import MCTS


class DotsNBoxes: # A class for managing the moves made by the human and the computer
    def __init__(self, Board_Xdim, Board_Ydim, Ply_num):
        currentState = Game([], Board_Xdim, Board_Ydim)
        currentState.Initiate()
        self.State = Thing(currentState)
        self.Ply_num = Ply_num
        self.Score = 0

    def Human(self): # Defining the Human player and his actions/Choices
        self.State.Draw()
        
        # HumanX = int(input("Please enter the 'X' coordinate of your choice (an integer such as 4): "))
        # HumanY = int(input("Please enter the 'Y' coordinate of your choice (an integer such as 4): "))
        # if (HumanX, HumanY) not in self.State.children:
        #    self.State.Make(HumanX, HumanY, False)
        #    self.State = self.State.children[(HumanX, HumanY)]
           
        # else:
        #    self.State = self.State.children[(HumanX, HumanY)]
        
        move = Algo.miniMax(self.State, 2)

        self.State = self.State.children[(move[0], move[1])]

        print("AI1 selected the following coordinates to play:\n" + "(" ,str(move[0]), ", " + str(move[1]), ")", end = "\n\n")

        print("Current Score =====>> Your Score - AI Score = " + str(self.State.CurrentScore), end = "\n\n\n")

        if len(self.State.children) == 0:
            self.State.Draw()
            self.Evaluation()
            return

        self.Computer()


    def Computer(self): # Defining the Computer player and its actions/Choices
        self.State.Draw()

        # Temporarily commented out. TODO hardcore MCTS into working then alternate comments lol 
        move = Algo.miniMax(self.State, 3)
        self.State = self.State.children[(move[0], move[1])]

        # move = MCTS.MCTSGameController() # check what MCTSGameController returns?
        

        print("AI2 selected the following coordinates to play:\n" + "(" ,str(move[0]), ", " + str(move[1]), ")", end = "\n\n")

        print("Current Score =====>> Your Score - AI Score = " + str(self.State.CurrentScore), end = "\n\n\n")

        if len(self.State.children) == 0:
            self.State.Draw()
            self.Evaluation()
            return

        self.Human()

    def Evaluation(self): # Evaluation function for taking care of the final scores
        print("Stop this Madness!!!\n")
        if self.State.CurrentScore > 0:
            print("You won you crazy little unicorn!! You are the new hope for the mankind!" + str(self.State.CurrentScore))
            exit()
        elif self.State.CurrentScore < 0:
            print("!!! Inevitable Doom!!! You were crushed by the AI!! "+ str(self.State.CurrentScore))
            exit()
        else:
            print("Draw! Well Congratulations! you are as smart as the AI!")
            exit()

    def start(self):
        self.Human()