diff options
author | RossTheRoss <mstrapp@protonmail.com> | 2021-04-13 17:22:52 -0500 |
---|---|---|
committer | RossTheRoss <mstrapp@protonmail.com> | 2021-04-13 17:22:52 -0500 |
commit | 77a99164bb53b207ba8efec1a37238379f595f44 (patch) | |
tree | 47f95873e3f005749853efb5d9e2c6f986c077a8 /Jack | |
parent | Rearrange things more I guess (diff) | |
download | csci4511w-77a99164bb53b207ba8efec1a37238379f595f44.tar csci4511w-77a99164bb53b207ba8efec1a37238379f595f44.tar.gz csci4511w-77a99164bb53b207ba8efec1a37238379f595f44.tar.bz2 csci4511w-77a99164bb53b207ba8efec1a37238379f595f44.tar.lz csci4511w-77a99164bb53b207ba8efec1a37238379f595f44.tar.xz csci4511w-77a99164bb53b207ba8efec1a37238379f595f44.tar.zst csci4511w-77a99164bb53b207ba8efec1a37238379f595f44.zip |
Rearrange and add more
Diffstat (limited to 'Jack')
-rw-r--r-- | Jack/board2.py | 73 | ||||
-rw-r--r-- | Jack/game.py | 0 | ||||
-rw-r--r-- | Jack/main2.py | 20 | ||||
-rw-r--r-- | Jack/node2.py | 17 |
4 files changed, 110 insertions, 0 deletions
diff --git a/Jack/board2.py b/Jack/board2.py new file mode 100644 index 0000000..3aecaa5 --- /dev/null +++ b/Jack/board2.py @@ -0,0 +1,73 @@ +from random import *
+
+class Board: #A class for managing different situations and states happening in the game and on the board
+ def __init__(self, board):
+ self.board=board
+ def get_board(self):
+ return self.board
+ def print_board(self):
+ for i in self.board:
+ for j in i:
+ print(j,end="")
+ print()
+ def play_move(self,v1,v2): #v1 and v2 correlate to the first and second vertex that you would draw to on the board vertex 1 is always smaller than vertex 2
+ if((v2-v1)==1):
+ if(v1<5):
+ c=0
+ elif(v1<9):
+ c=2
+ v1=v1-4
+ v2=v2-4
+ elif(v1<13):
+ c=4
+ v1=v1-8
+ v2=v2-8
+ else:
+ c=6
+ v1=v1-12
+ v2=v2-12
+
+ x1=v1+3*(v1-1)
+ x2=v2+3*(v2-1)
+ for i in range (x1,x2-1):
+ self.board[c][i]="-"
+ else:
+ if(v2<9):
+ c=1
+ elif(v2<13):
+ c=3
+ else:
+ c=5
+ if(v2%4==1):
+ self.board[c][0]="|"
+ elif(v2%4==2):
+ self.board[c][4]="|"
+ elif(v2%4==3):
+ self.board[c][8]="|"
+ else:
+ self.board[c][12]="|"
+ if(self.check_fill()):
+ return 1
+ else:
+ return 0
+ def check_fill(self):
+ x=0
+ while(x<=4):
+ y=0
+ while(y<=8):
+ if(self.board[x][y+2]=='-' and self.board[x+1][y]=='|' and self.board[x+1][y+4]=='|' and self.board[x+2][y+2]=='-'):
+ if(self.board[x+1][y+2]!='X'):
+ self.board[x+1][y+2]='X'
+ return True
+
+ y=y+4
+ x=x+2
+
+ return False
+ def is_legal(self,v1,v2): # we might not need this
+ if(v1<v2 and (v2-v1==4 or ((v2%4 != 1) and (v2-v1==1))):
+ return True
+ else:
+ return False
+
+
diff --git a/Jack/game.py b/Jack/game.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Jack/game.py diff --git a/Jack/main2.py b/Jack/main2.py new file mode 100644 index 0000000..771e24e --- /dev/null +++ b/Jack/main2.py @@ -0,0 +1,20 @@ +from board2 import *
+
+def main():
+ board =[["*", " ", " ", " ","*", " ", " ", " ","*", " ", " ", " ","*"],[" "," "," "," "," "," "," "," "," "," "," "," "," "],["*", " ", " ", " ","*", " ", " ", " ","*", " ", " ", " ","*"],[" "," "," "," "," "," "," "," "," "," "," "," "," "],["*", " ", " ", " ","*", " ", " ", " ","*", " ", " ", " ","*"],[" "," "," "," "," "," "," "," "," "," "," "," "," "],["*", " ", " ", " ","*", " ", " ", " ","*", " ", " ", " ","*"]]
+ Board1 = Board(board)
+ Board1.print_board()
+ Board1.play_move(11,12)
+ Board1.play_move(11,15)
+ Board1.play_move(15,16)
+ Board1.play_move(12,16)
+ print()
+ print()
+ Board1.print_board()
+ Board1.check_fill()
+ print()
+ print()
+ Board1.print_board()
+
+
+main()
diff --git a/Jack/node2.py b/Jack/node2.py new file mode 100644 index 0000000..6ce82fc --- /dev/null +++ b/Jack/node2.py @@ -0,0 +1,17 @@ +from board2 import *
+
+class Node:
+ def __init__(self, currentState):
+ self.curr = currentState #this is a board
+ self.score = 0
+ self.children = {}
+
+ def make_state(self, v1, v2, p1): # Function for generating a child node
+ self.children[(v1, v2)] = Node(self.curr.get_board)
+ if (not p1):
+ self.children[(v1, v2)].score = (self.children[(v1, v2)].curr.play_move(v1, v2) * -1) + self.score
+ else:
+ self.children[(v1, v2)].score = (self.children[(v1, v2)].curr.play_move(v1, v2)) + self.score
+
+ def print(self): # function for drawing the board
+ self.curr.print_board()
\ No newline at end of file |