-
Notifications
You must be signed in to change notification settings - Fork 0
/
Win conditions.py
46 lines (42 loc) · 1.35 KB
/
Win conditions.py
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
'''
Used to build the dictionaries in dicts.py
Not a dependency to run the game
'''
wins = {} # Maps win pattern with filled square
coord_win = {} # Matches coordinate with winning pattern
for column in range(7):
for row in range(6):
ls = []
# Horizontal
if -1 < column < 4:
ls.append(f"H{row}_0")
if 0 < column < 5:
ls.append(f"H{row}_1")
if 1 < column < 6:
ls.append(f"H{row}_2")
if 2 < column < 7:
ls.append(f"H{row}_3")
# Vertical
if -1 < row < 4:
ls.append(f"V0_{column}")
if -2 < row < 5:
ls.append(f"V1_{column}")
if -3 < row < 6:
ls.append(f"V2_{column}")
coord_win[(row, column)] = ls
# Vertical win patterns
for column in range(7):
for row in range(3):
wins[f"V{row}_{column}"] = 0
# Horizontal win patterns
for row in range(6):
for column in range(4):
wins[f"H{row}_{column}"] = 0
# Diagonal up and down win patterns
for row in range(3):
for column in range(4):
wins[f"DU{row}_{column}"] = 0
wins[f"DD{row}_{column}"] = 0
for i in range(4):
coord_win[(row + i, column + i)].append(f"DU{row}_{column}")
coord_win[(row+i), column + 3-i].append(f"DD{row}_{column}")