aboutsummaryrefslogtreecommitdiffstats
path: root/Jack/board2.py
blob: 3aecaa5fdcceb45961b09130cd11c6d6bcb9a879 (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
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