From 77a99164bb53b207ba8efec1a37238379f595f44 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 13 Apr 2021 17:22:52 -0500 Subject: Rearrange and add more --- Not Jack/DotsNBoxes.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Not Jack/DotsNBoxes.py (limited to 'Not Jack/DotsNBoxes.py') diff --git a/Not Jack/DotsNBoxes.py b/Not Jack/DotsNBoxes.py new file mode 100644 index 0000000..6674762 --- /dev/null +++ b/Not Jack/DotsNBoxes.py @@ -0,0 +1,63 @@ +from random import * +import collections +from Algorithm import * +from Board import * +from Nodes import * + + +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)] + + print("Current Score =====>> Your Score - AI Score = " + str(self.State.CurrentScore),end ="\n\n\n") + + self.Computer() + + + def Computer(self): # Defining the Computer player and its actions/Choices + self.State.Draw() + + move = Algo.miniMax(self.State, self.Ply_num) + + self.State = self.State.children[(move[0], move[1])] + + print("AI 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!") + exit() + elif self.State.CurrentScore < 0: + print("!!! Inevitable Doom!!! You were crushed by the AI!! ") + exit() + else: + print("Draw! Well Congratulations! you are as smart as the AI!") + exit() + + def start(self): + self.Human() -- cgit v1.2.3