/
PokerPlus.py
100 lines (80 loc) · 3.55 KB
/
PokerPlus.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
from __future__ import generators
import plus
import AI
from AI import vector3
import Arenas
import Gooey
import math
import Tactics
class PokerPlus(AI.SuperAI):
"Poker strategy"
#Note: it now fires when being immobilized to try to unstuck, as well as firing when stuck on it's rear end. Also you can select the tactic.
name = "PokerPlus"
#Brought to you by Naryar
def __init__(self, **args):
AI.SuperAI.__init__(self, **args)
self.zone = "weapon"
self.triggers = ["Fire"]
self.reloadTime = 0
self.reloadDelay = 4
if 'triggers' in args: self.triggers = args['triggers']
if 'reload' in args: self.reloadDelay = args['reload']
self.triggerIterator = iter(self.triggers)
if 'tactic' in args:
self.theTactic = args['tactic']
if self.theTactic == "Charge" : self.tactics.append(Tactics.Charge(self))
elif self.theTactic == "Ram" : self.tactics.append(Tactics.Ram(self))
elif self.theTactic == "Shove" : self.tactics.append(Tactics.Shove(self))
elif self.theTactic == "Engage" : self.tactics.append(Tactics.Engage(self))
else: self.tactics.append(Tactics.Engage(self))
else: self.tactics.append(Tactics.Engage(self))
def Activate(self, active):
if active:
if AI.SuperAI.debugging:
self.debug = Gooey.Plain("watch", 0, 75, 100, 75)
tbox = self.debug.addText("line0", 0, 0, 100, 15)
tbox.setText("Throttle")
tbox = self.debug.addText("line1", 0, 15, 100, 15)
tbox.setText("Turning")
tbox = self.debug.addText("line2", 0, 30, 100, 15)
tbox.setText("")
tbox = self.debug.addText("line3", 0, 45, 100, 15)
tbox.setText("")
self.RegisterSmartZone(self.zone, 1)
return AI.SuperAI.Activate(self, active)
def Tick(self):
# fire weapon if being counted out, attempting to unstuck
if self.bImmobile and self.GetSpeed < 0.5:
self.Input("Fire", 0, 1)
# fire weapon when stuck on rear end...totally not ripped off FB's Seism 13
if list(plus.getDirection(self.GetID(),0))[1]>0.9:
self.Input("Fire", 0, 1)
# fire weapon
if self.weapons:
targets = [x for x in self.sensors.itervalues() if x.contacts > 0 \
and not plus.isDefeated(x.robot)]
# slight delay between firing
if self.reloadTime > 0: self.reloadTime -= 1
if len(targets) > 0 and self.reloadTime <= 0:
try:
trigger = self.triggerIterator.next()
except StopIteration:
self.triggerIterator = iter(self.triggers)
trigger = self.triggerIterator.next()
self.Input(trigger, 0, 1)
self.reloadTime = self.reloadDelay
return AI.SuperAI.Tick(self)
def InvertHandler(self):
# fire all weapons once per second (until we're upright!)
while 1:
for trigger in self.triggers:
self.Input(trigger, 0, 1)
for i in range(0, 8):
yield 0
def DebugString(self, id, string):
if self.debug:
if id == 0: self.debug.get("line0").setText(string)
elif id == 1: self.debug.get("line1").setText(string)
elif id == 2: self.debug.get("line2").setText(string)
elif id == 3: self.debug.get("line3").setText(string)
AI.register(PokerPlus)