-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngine.py
More file actions
108 lines (82 loc) · 2.99 KB
/
Copy pathEngine.py
File metadata and controls
108 lines (82 loc) · 2.99 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import random
from MoveCalculator import MoveCalculator
from MoveCalculator import LinkedList
class TreeNode:
def __init__(self, rank, x, y, xa, ya):
self.rank = rank
self.x = x
self.y = y
self.xa = xa
self.ya = ya
self.leftTreeNode = None
self.rightTreeNode = None
class Tree:
def __init__(self):
self.head = None
def addTreeNode(self, rank, x, y, xa, ya):
newTreeNode = TreeNode(rank,x,y,xa,ya)
if (self.head == None):
self.head = newTreeNode
else:
current = self.head
parent = None
while (True):
parent = current
if (rank < current.rank):
current = current.leftTreeNode
if (current == None):
parent.leftTreeNode = newTreeNode
break
else:
current = current.rightTreeNode
if (current == None):
parent.rightTreeNode = newTreeNode
break
class Engine:
def __init__(self):
self.treeList = []
def moveVector(self, localRoot, base):
if(localRoot != None):
self.moveVector(localRoot.leftTreeNode, base)
if(localRoot.rank == base):
self.treeList.append(localRoot.x)
self.treeList.append(localRoot.y)
self.treeList.append(localRoot.xa)
self.treeList.append(localRoot.ya)
self.moveVector(localRoot.rightTreeNode, base)
def returnRank(self, localRoot):
if(localRoot != None):
index = localRoot.rank
self.returnRank(localRoot.rightTreeNode)
else:
return index
def resolveMove(self, gameBoard):
moveTree = Tree()
calc = MoveCalculator()
base = 0
for e in range(0, 8):
for i in range(0, 8):
if(gameBoard.returnSquare(e, i).find("Black")):
list = calc.possibleSquares2DArray(e,i, gameBoard)
moveVector2 = list.returnWeightedVector()
for j in range(0, len(moveVector2), 3):
a = moveVector2[j]
b = moveVector2[j+1]
c = moveVector2[j+2]
if c > base:
base = c
if (c >= 0 and c <= 10):
moveTree.addTreeNode(c,e,i,a,b)
self.moveVector(moveTree.head, base)
if(len(self.treeList) > 4):
test = int(len(self.treeList) / 4)
choice = random.randint(1, test)
choice = choice * 4
else:
choice = 0
move = []
move.append(self.treeList[int(choice)-4])
move.append(self.treeList[int(choice)-3])
move.append(self.treeList[int(choice)-2])
move.append(self.treeList[int(choice)-1])
return move