forked from SigmaProductions/sigmaChess
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpathing.py
More file actions
51 lines (43 loc) · 1.39 KB
/
pathing.py
File metadata and controls
51 lines (43 loc) · 1.39 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
def piecePath(x, y, boardArray, coordHorizontal, coordVert):
if coordHorizontal - x == 0:
return xIsZero(y, boardArray, coordHorizontal, coordVert)
if coordVert - y == 0:
return yIsZero(x, boardArray,coordHorizontal, coordVert)
else:
return linearFunction(x, y, boardArray, coordHorizontal, coordVert)
def xIsZero(y, boardArray, coordHorizontal, coordVert):
if y >= coordVert:
high = y
low = coordVert
else:
low = y
high = coordVert
for squarey in range(low+1, high):
if boardArray[coordHorizontal][squarey] is not None:
return False
return True
def yIsZero(x, boardArray,coordHorizontal, coordVert):
if x >= coordHorizontal:
high = x
low = coordHorizontal
else:
low = x
high = coordHorizontal
for squarex in range(low+1, high):
if boardArray[squarex][coordVert] is not None:
return False
return True
def linearFunction(x,y, boardArray, coordHorizontal, coordVert):
a = int((coordHorizontal - x) / (coordVert - y))
b = int(y - (x * a))
if x >= coordHorizontal:
high = x
low = coordHorizontal
else:
high = coordHorizontal
low = x
for squarex in range(low + 1, high):
squarey = squarex * a + b
if boardArray[squarex][squarey] is not None:
return False
return True