aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRossTheRoss <mstrapp@protonmail.com>2021-04-13 17:21:39 -0500
committerRossTheRoss <mstrapp@protonmail.com>2021-04-13 17:21:39 -0500
commit39edbd96c8bce8c8f76bbb911ee7e4a76c835c44 (patch)
tree64f63e23b3df060c173bb2905a31af451778b225
parentAdd files via upload (diff)
downloadcsci4511w-39edbd96c8bce8c8f76bbb911ee7e4a76c835c44.tar
csci4511w-39edbd96c8bce8c8f76bbb911ee7e4a76c835c44.tar.gz
csci4511w-39edbd96c8bce8c8f76bbb911ee7e4a76c835c44.tar.bz2
csci4511w-39edbd96c8bce8c8f76bbb911ee7e4a76c835c44.tar.lz
csci4511w-39edbd96c8bce8c8f76bbb911ee7e4a76c835c44.tar.xz
csci4511w-39edbd96c8bce8c8f76bbb911ee7e4a76c835c44.tar.zst
csci4511w-39edbd96c8bce8c8f76bbb911ee7e4a76c835c44.zip
Rearrange things more I guess
Diffstat (limited to '')
-rw-r--r--Not Jack/Board.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/Not Jack/Board.py b/Not Jack/Board.py
new file mode 100644
index 0000000..bd32cf4
--- /dev/null
+++ b/Not Jack/Board.py
@@ -0,0 +1,78 @@
+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