diff options
author | RossTheRoss <mstrapp@protonmail.com> | 2021-04-25 14:54:51 -0500 |
---|---|---|
committer | RossTheRoss <mstrapp@protonmail.com> | 2021-04-25 14:54:51 -0500 |
commit | d40e0d02c955e97738615314443704d94219cff4 (patch) | |
tree | 14539c6b942f3293da6fd3dfd3187f5f69c422cc | |
parent | Add files via upload (diff) | |
download | csci4511w-d40e0d02c955e97738615314443704d94219cff4.tar csci4511w-d40e0d02c955e97738615314443704d94219cff4.tar.gz csci4511w-d40e0d02c955e97738615314443704d94219cff4.tar.bz2 csci4511w-d40e0d02c955e97738615314443704d94219cff4.tar.lz csci4511w-d40e0d02c955e97738615314443704d94219cff4.tar.xz csci4511w-d40e0d02c955e97738615314443704d94219cff4.tar.zst csci4511w-d40e0d02c955e97738615314443704d94219cff4.zip |
Remove redundant folder
Diffstat (limited to '')
-rw-r--r-- | Not Jack/Algorithm.py | 67 | ||||
-rw-r--r-- | Not Jack/Board.py | 78 | ||||
-rw-r--r-- | Not Jack/DotsNBoxes.py | 63 | ||||
-rw-r--r-- | Not Jack/Nodes.py | 18 | ||||
-rw-r--r-- | Not Jack/main.py | 40 |
5 files changed, 0 insertions, 266 deletions
diff --git a/Not Jack/Algorithm.py b/Not Jack/Algorithm.py deleted file mode 100644 index de4fbc0..0000000 --- a/Not Jack/Algorithm.py +++ /dev/null @@ -1,67 +0,0 @@ - -class Algo: # A class for defining algorithms used (minimax and alpha-beta pruning) - - def miniMax(State, Ply_num): # Function for the minimax algorithm - - for i in range(State.Current.dimY): - for j in range(State.Current.dimX): - if State.Current.Mat[i][j] == ' ' and (j, i) not in State.children: - State.Make(j, i, True) - if Ply_num < 2: - return (i, j) - - Minimum_Score = 1000 - i = 0 - j = 0 - for k, z in State.children.items(): - Result = Algo.Maximum(z, Ply_num - 1, Minimum_Score) - if Minimum_Score > Result: - Minimum_Score = Result - i = k[0] - j = k[1] - - return (i, j) - - - def Maximum(State, Ply_num, Alpha): # Alpha-beta pruning function for taking care of Alpha values - if Ply_num == 0: - return State.CurrentScore - - for i in range(State.Current.dimY): - for j in range(State.Current.dimX): - if State.Current.Mat[i][j] == ' ' and (j, i) not in State.children: - State.Make(j, i, False) - - Maximum_Score = -1000 - i = 0 - j = 0 - for k, z in State.children.items(): - Result = Algo.Minimum(z, Ply_num - 1, Maximum_Score) - if Maximum_Score < Result: - Maximum_Score = Result - if Result > Alpha: - return Result - - return Maximum_Score - - - def Minimum(State, Ply_num, Beta): # Alpha-beta pruning function for taking care of Beta values - if Ply_num == 0: - return State.CurrentScore - - for i in range(State.Current.dimY): - for j in range(State.Current.dimX): - if State.Current.Mat[i][j] == ' ' and (j, i) not in State.children: - State.Make(j, i, True) - - Minimum_Score = 1000 - i = 0 - j = 0 - for k, z in State.children.items(): - Result = Algo.Maximum(z, Ply_num - 1, Minimum_Score) - if Minimum_Score > Result: - Minimum_Score = Result - if Result < Beta: - return Result - - return Minimum_Score diff --git a/Not Jack/Board.py b/Not Jack/Board.py deleted file mode 100644 index bd32cf4..0000000 --- a/Not Jack/Board.py +++ /dev/null @@ -1,78 +0,0 @@ -from random import * - - -class Game: #A class for managing different situations and states happening in the game and on the board - def __init__(self, Mat, dimX, dimY): - self.Mat = Mat - self.dimX = dimX - self.dimY = dimY - - def Initiate(self): #initiating the game board with X and Y dimensions - for i in range(0, self.dimY): - R = [] - for j in range (0, self.dimX): - if i % 2 == 1 and j % 2 == 1: - R.append(randint(1, 9)) # Assigning a random number from 1 to 9 to the spots in the board as the points - elif i % 2 == 0 and j % 2 == 0: - R.append('*') # printing asterisks as the dots in the board - else: - R.append(' ') # adding extra space for actions in the game - self.Mat.append(R) - - def Get_matrix(self): # Board matrix - ans = [] - for i in range(0, self.dimY): - R = [] - for j in range(0, self.dimX): - R.append(self.Mat[i][j]) - ans.append(R) - return ans - - def Draw_mat(self): # Drawing the board matrix as dots and lines - - if self.dimX > 9: - print(" ", end='') - print(" ", end='') - for i in range(0, self.dimX): - print(str(i), end=' ') - print() - - if self.dimX > 9: - print(" ", end='') - print(" ", end='') - for i in range(0, self.dimX + 1): - print("___", end='') - print() - for j in range(self.dimY): - if self.dimX > 9 and j < 10: - print(" ", end='') - print(str(j) + "| ", end='') - for z in range(self.dimX): - print(str(self.Mat[j][z]), end=' ') - print() - print(" _________________________\n") - - def Get_currentState(self): - return Game(self.Get_matrix(), self.dimX, self.dimY) - - def action(self, i, j): # Applying the actions made by the human or the computer - Sum = 0 - - if j % 2 == 0 and i % 2 == 1: - self.Mat[j][i] = '-' - if j < self.dimY - 1: - if self.Mat[j+2][i] == '-' and self.Mat[j+1][i+1] == '|' and self.Mat[j+1][i-1] == '|': - Sum += self.Mat[j+1][i] - if j > 0: - if self.Mat[j-2][i] == '-' and self.Mat[j-1][i+1] == '|' and self.Mat[j-1][i-1] == '|': - Sum += self.Mat[j-1][i] - - else: - self.Mat[j][i] = '|' - if i < self.dimX - 1: - if self.Mat[j][i+2] == '|' and self.Mat[j+1][i+1] == '-' and self.Mat[j-1][i+1] == '-': - Sum += self.Mat[j][i+1] - if i > 0: - if self.Mat[j][i-2] == '|' and self.Mat[j+1][i-1] == '-' and self.Mat[j-1][i-1] == '-': - Sum += self.Mat[j][i-1] - return Sum diff --git a/Not Jack/DotsNBoxes.py b/Not Jack/DotsNBoxes.py deleted file mode 100644 index 6674762..0000000 --- a/Not Jack/DotsNBoxes.py +++ /dev/null @@ -1,63 +0,0 @@ -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() diff --git a/Not Jack/Nodes.py b/Not Jack/Nodes.py deleted file mode 100644 index da01944..0000000 --- a/Not Jack/Nodes.py +++ /dev/null @@ -1,18 +0,0 @@ -class Thing: # A class for Node related operations - def __init__(self, currentState): - self.Current = currentState - self.CurrentScore = 0 - self.children = {} - - def Make(self, i, j, player): # Function for generating a child node - self.children[(i, j)] = Thing(self.Current.Get_currentState()) - mul = 1 - if player: - mul *= -1 - self.children[(i, j)].CurrentScore = (self.children[(i, j)].Current.action(i, j) * mul) + self.CurrentScore - - def Populate(self, i, j, Child): # Function for adding a node - self.children[(i,j)] = Child - - def Draw(self): # function for drawing the board - self.Current.Draw_mat() diff --git a/Not Jack/main.py b/Not Jack/main.py deleted file mode 100644 index 4e37684..0000000 --- a/Not Jack/main.py +++ /dev/null @@ -1,40 +0,0 @@ -from Algorithm import * -from DotsNBoxes import * -from Board import * -from Nodes import * - -def main(): - while True: - - print("\t\t!! Welcome to the game of Dots and Boxes !!\n\n Be prepared to be crushed by the power of Artificial Intelligence ... !!\n\n\ - Kidding! You totally can beat it!\n\n\n") - - x = input("Press 1 to start the game or press 2 to escape from the inevitable doom!!\n\n") - if x == "1": - - Board_Xdim = int(input("\nPlease enter the number of rows for the board: \n")) * 2 + 1 - - if Board_Xdim < 5: - print("\nthe number of rows should atleast be 2\n") - exit() - - Board_Ydim = int(input("\nPlease enter the number of columns for the board: \n")) * 2 + 1 - - if Board_Ydim < 5: - print("\nthe number of columns should atleast be 2\n") - exit() - - Ply_num = int(input("\nPlease enter the number of plies used by the AI: \n")) - - if Ply_num < 2: - print("\nThe number of plies should be higher than 1\n") - exit() - - Match = DotsNBoxes(Board_Xdim, Board_Ydim, Ply_num) - Match.start() - else: - print ("\n\nEscape it is!") - exit() - -if __name__ == "__main__": - main() |