-
Notifications
You must be signed in to change notification settings - Fork 0
/
Command.py
143 lines (113 loc) · 5.13 KB
/
Command.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/python3
import colorama
colorama.init()
def commandPrint(text):
#print(text)
print(colorama.Fore.YELLOW + text + colorama.Style.RESET_ALL)
class Command():
TargetNames = {'house',
'sheep',
'tree',
'boat',
'train',
'tree',
'fence'
}
ForbiddenPluralNames = {'trees',
'boats',
'trains',
'fences',
'houses',
}
#thats funny: if i specify 99999999 fps is very low
inftyDistance = 999
import Synonyms
shootSynonyms = Synonyms.shoot
rideSynonyms = Synonyms.ride
refillSynonyms = Synonyms.refill
ammoSynonyms = Synonyms.ammo
fuelSynonyms = Synonyms.fuel
backSynonyms = Synonyms.back
goSynonyms = Synonyms.go
killSynonyms = Synonyms.kill
stopSynonyms = Synonyms.stop
def __init__(self, massage):
massage=massage.replace('?',' ?')
massage=massage.replace('.',' .')
massage=massage.replace(',',' ,')
self.text = set(massage.lower().split())
#SHOOT STH
def interpret(self):
if Command.ForbiddenPluralNames.intersection(self.text):
commandPrint("One command at a time. Don't use plural form")
if Command.rideSynonyms.intersection(self.text) or Command.shootSynonyms.intersection(self.text):
return 'stop()'
self.text = self.text.difference(Command.ForbiddenPluralNames.intersection(self.text))
#shoot a target
if Command.shootSynonyms.intersection(self.text):
if Command.TargetNames.intersection(self.text):
return "shootTarget('"+ Command.TargetNames.intersection(self.text).pop() +"', tank, Target.targets)"
if Command.stopSynonyms.intersection(self.text):
return 'stop()'
#JUST SHOOT
if Command.shootSynonyms.intersection(self.text):
return"shoot()"
#RIDE OVER STH
if Command.rideSynonyms.intersection(self.text):
if Command.TargetNames.intersection(self.text):
return "rideOver('"+ Command.TargetNames.intersection(self.text).pop() +"', tank, Target.targets)"
#KILL STH
if Command.killSynonyms.intersection(self.text):
if len(Command.TargetNames.intersection(self.text))==0:
commandPrint("What should I " + Command.killSynonyms.intersection(self.text).pop() + '?')
whatToKill = set(input().lower().split())
self.text.update(whatToKill)
return self.interpret()#returning THIS function
commandPrint ("Tell me how I should " + Command.killSynonyms.intersection(self.text).pop() + ' the '+Command.TargetNames.intersection(self.text).pop()+ '.')
howToKill = set(input().lower().split())
self.text.update(howToKill)
return self.interpret()
#no return here, the command will be grabber by SHOOT STH OR RIDE OVER STH
#DO STH WITH TARGET BUT NO ACTION NOT SPECIFIED
if Command.TargetNames.intersection(self.text):
commandPrint("What should I do with the " + Command.TargetNames.intersection(self.text).pop()+ " ?")
what = set(input().lower().split())
self.text.update(what)
return self.interpret()
#REFILL AMMO OR FUEL
if Command.refillSynonyms.intersection(self.text):
if Command.ammoSynonyms.intersection(self.text):
return "refillAmmo(tank, Target.targets)"
if Command.fuelSynonyms.intersection(self.text):
return "refillFuel(tank, Target.targets)"
commandPrint ("Tell me what I should " + Command.refillSynonyms.intersection(self.text).pop() +'.')
whatToRefill = set(input().lower().split())
if Command.ammoSynonyms.intersection(whatToRefill):
return "refillAmmo(tank, Target.targets)"
if Command.fuelSynonyms.intersection(whatToRefill):
return "refillFuel(tank, Target.targets)"
#TURRET TO LEFT OR RIGHT
if 'turret' in self.text:
if 'left' in self.text:
return 'towerLeft()'
if 'right' in self.text:
return 'towerRight()'
commandPrint('Which direction should I turn that turret at?')
#TURN LEFT
if 'left' in self.text:
return 'turnLeft()'
#TURN RIGHT
if 'right' in self.text:
return 'turnRight()'
#TURN BACK
if Command.backSynonyms.intersection(self.text):
return 'back()'
#GO SPECIFIED DISTANCE OR JUST GO
if Command.goSynonyms.intersection(self.text):
digitList = [x for x in self.text if x.isdigit()]
if len(digitList) == 1:
return 'go(' + digitList[0] + ',tank)'
else:
return 'go(' + str(Command.inftyDistance) + ',tank)'
commandPrint('Can You repeat, please?')
return []