-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameSolver.py
72 lines (57 loc) · 1.96 KB
/
gameSolver.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
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
import sys
from copy import deepcopy
rows = 3
columns = 3
colorAmount = 3
def manageColor(color):
return (color + 1) % colorAmount
def click(row, column, board):
tempBoard = deepcopy(board)
tempBoard[row][column] = manageColor(tempBoard[row][column])
for offset in [-1, 1]:
if(0 <= row+offset < rows):
tempBoard[row +
offset][column] = manageColor(tempBoard[row+offset][column])
if(0 <= column+offset < columns):
tempBoard[row][column +
offset] = manageColor(tempBoard[row][column+offset])
return tempBoard
def checkWin(board):
a = board[0][0]
for row in range(rows):
for column in range(columns):
if a != board[row][column]:
return False
return True
def findSolution(history, clickAmount):
# recursion which tests all possible clicks and checks the result of a given board/latest in History
# checks only for the exact given clickAmount
board = deepcopy(history[-1])
# base case
if clickAmount <= 0:
if checkWin(board):
print(f"gg@ ")
print(history)
else:
pass
return
# main recursion
for row in range(rows):
for column in range(columns):
tempBoard = click(row, column, deepcopy(board))
tempHistory = deepcopy(history)
tempHistory.append(tempBoard)
# pp.pprint(tempHistory)
findSolution(tempHistory, clickAmount-1)
a = 1
testBoard = [[1, 1, 1],
[1, 1, a],
[1, a, a]]
if __name__ == "__main__":
if(len(sys.argv) not in [2, 4]):
print(
f"Usage: python {__file__} [number of clicks aka depth] ")
print(f"You used {len(sys.argv)} arguments")
else:
clickAmount = int(sys.argv[1])
findSolution([deepcopy(testBoard)], clickAmount)