-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequence.py
48 lines (41 loc) · 1.58 KB
/
sequence.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
from position import Position
class Sequence:
def __init__(self, pos):
self.startingPos = pos
self.finalPos = pos
self.length = 1
self.direction = "single"
self.player = pos.fill
# Add piece to the end of the sequence if the sequence was previously a single set the direction
def addPieceAtTheEnd(self, pos):
if self.length < 2:
if(pos.x == self.startingPos.x):
self.direction = "vertical"
if(pos.y == self.startingPos.y):
self.direction = "horizontal"
if(pos.y == self.finalPos.y+1 and pos.x == self.finalPos.x+1):
self.direction = "perp+"
if(pos.y == self.finalPos.y+1 and pos.x == self.finalPos.x-1):
self.direction = "perp-"
self.finalPos = pos
self.length = self.length+1
# Add piece to the start of a sequence if the sequence was previously a single set the direction
def addPieceAtTheStart(self,pos):
if self.length < 2:
if(pos.y == self.startingPos.y):
self.direction = "horizontal"
if(pos.y == self.startingPos.y-1 and pos.x == self.startingPos.x+1):
self.direction = "perp-"
if(pos.y == self.startingPos.y-1 and pos.x == self.startingPos.x-1):
self.direction = "perp+"
self.startingPos = pos
self.length = self.length+1
# Check if two positions are in sequence
def allows(self, pos):
if self.finalPos.inSequence(pos, self.direction):
return 1
if self.startingPos.inReverseSequence(pos, self.direction):
return 2
return 0
def print(self):
return self.startingPos.print() + " - " + self.finalPos.print()