-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMicromouseMove.py
More file actions
100 lines (93 loc) · 2.96 KB
/
MicromouseMove.py
File metadata and controls
100 lines (93 loc) · 2.96 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
import csv
Pos = 0
i_j_current = [0, 0]
def movememnt(i_new, i_current, j_new, j_current): # resets current position and communicates movement
if (i_new != i_current) and pos = 1:
if (i_new < i_current):
i_j_current[0] -= 1
print(1)
elif (i_new > i_current):
i_j_current[0] += 1
print(2)
elif (j_new != j_current) and pos = 1:
if (j_new < j_current):
i_j_current[1] -= 1
print(3)
elif (j_new > j_current):
i_j_current[1] +=1
print(4)
elif (i_new < i_current) and pos = 2:
i_j_current[0] -= 1
print(1)
elif (i_new > i_current):
i_j_current[0] += 1
print(2)
elif (j_new != j_current) and pos = 2:
if (j_new < j_current):
i_j_current[1] -= 1
print(3)
elif (j_new > j_current):
i_j_current[1] +=1
print(4)
elif (i_new != i_current) and pos = 3:
if (i_new < i_current):
i_j_current[0] -= 1
print(4)
elif (i_new > i_current):
i_j_current[0] += 1
print(3)
elif (j_new != j_current) and pos = 3:
if (j_new < j_current):
i_j_current[1] -= 1
print(2)
elif (j_new > j_current):
i_j_current[1] +=1
print(1)
elif (i_new < i_current) and pos = 4:
i_j_current[0] -= 1
print(3)
elif (i_new > i_current):
i_j_current[0] += 1
print(4)
elif (j_new != j_current) and pos = 4:
if (j_new < j_current):
i_j_current[1] -= 1
print(1)
elif (j_new > j_current):
i_j_current[1] +=1
print(2)
def csvWriter(node, i_j): # writes input to csv file
with open("node.csv", "w") as f:
fwrt = csv.writer(f, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
fwrt.writerow([str(node), str(i_j[0]), str(i_j[1])])
def csvReader(rownum): # reads entirety of file and returns row
with open("node.csv", "r") as f:
csvr = csv.reader(f)
csvr = list(csvr)
return(csvr[int(rownum)])
def csvLister():
with open("node.csv", r) as f:
csvr = csv.reader(f)
csvr = list(csvr)
return(csvr)
#def csvLength(): # returns the length of the file
# with open("node.csv", "r") as f:
# csvr = csv.reader(f)
# csvr = list(csvr)
# return(len(csvr))
class Nodes():
def __init__(self):
self.ijstuff = []
self.nodeName = 'n'
self.nodeNumber = 0
self.nodeNode = ""
def AddNodes(self, i_j = 0):
for x in csvLister():
if x == i_j:
pass
elif x != i_j:
self.ijstuff.append(i_j)
self.nodeNode = str(self.nodeName) + str(self.nodeNumber)
csvWriter(self.nodeNode, self.ijstuff)
self.nodeNumber += 1