Skip to content

Commit f27208d

Browse files
authored
Merge pull request #39 from jimmyt857/upgrade_adaptive_agent
Upgrade AdaptiveAgent to improve its DPS.
2 parents 7f7db3c + e5f4125 commit f27208d

File tree

6 files changed

+93
-28
lines changed

6 files changed

+93
-28
lines changed

tbc/agents.go

Lines changed: 81 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,57 @@ func NewCastAction(sim *Simulation, sp *Spell) AgentAction {
4141
}
4242
}
4343

44+
// ################################################################
45+
// LB ONLY
46+
// ################################################################
47+
type LBOnlyAgent struct {
48+
lb *Spell
49+
}
50+
51+
func (agent *LBOnlyAgent) ChooseAction(sim *Simulation) AgentAction {
52+
return NewCastAction(sim, agent.lb)
53+
}
54+
55+
func (agent *LBOnlyAgent) OnActionAccepted(sim *Simulation, action AgentAction) {}
56+
func (agent *LBOnlyAgent) Reset(sim *Simulation) {}
57+
58+
func NewLBOnlyAgent(sim *Simulation) *LBOnlyAgent {
59+
return &LBOnlyAgent{
60+
lb: spellmap[MagicIDLB12],
61+
}
62+
}
63+
64+
// ################################################################
65+
// CL ON CD
66+
// ################################################################
67+
type CLOnCDAgent struct {
68+
lb *Spell
69+
cl *Spell
70+
}
71+
72+
func (agent *CLOnCDAgent) ChooseAction(sim *Simulation) AgentAction {
73+
if sim.isOnCD(MagicIDCL6) {
74+
return NewCastAction(sim, agent.lb)
75+
} else {
76+
return NewCastAction(sim, agent.cl)
77+
}
78+
}
79+
80+
func (agent *CLOnCDAgent) OnActionAccepted(sim *Simulation, action AgentAction) {}
81+
func (agent *CLOnCDAgent) Reset(sim *Simulation) {}
82+
83+
func NewCLOnCDAgent(sim *Simulation) *CLOnCDAgent {
84+
return &CLOnCDAgent{
85+
lb: spellmap[MagicIDLB12],
86+
cl: spellmap[MagicIDCL6],
87+
}
88+
}
89+
4490
// ################################################################
4591
// FIXED ROTATION
4692
// ################################################################
4793
type FixedRotationAgent struct {
48-
numLBsPerCL int // If -1, uses LB only
94+
numLBsPerCL int
4995
numLBsSinceLastCL int
5096
lb *Spell
5197
cl *Spell
@@ -62,10 +108,6 @@ func (agent *FixedRotationAgent) temporaryHasteActive(sim *Simulation) bool {
62108
}
63109

64110
func (agent *FixedRotationAgent) ChooseAction(sim *Simulation) AgentAction {
65-
if agent.numLBsPerCL == -1 {
66-
return NewCastAction(sim, agent.lb)
67-
}
68-
69111
if agent.numLBsSinceLastCL < agent.numLBsPerCL {
70112
return NewCastAction(sim, agent.lb)
71113
}
@@ -150,8 +192,9 @@ type AdaptiveAgent struct {
150192
manaSnapshots [manaSnapshotsBufferSize]ManaSnapshot
151193
numSnapshots int32
152194
firstSnapshotIndex int32
153-
lb *Spell
154-
cl *Spell
195+
196+
baseAgent Agent // The agent used most of the time
197+
surplusAgent Agent // The agent used when we have extra mana
155198
}
156199

157200
const manaSpendingWindowNumSeconds = 60
@@ -196,10 +239,6 @@ func (agent *AdaptiveAgent) takeSnapshot(sim *Simulation) {
196239
}
197240

198241
func (agent *AdaptiveAgent) ChooseAction(sim *Simulation) AgentAction {
199-
if sim.isOnCD(MagicIDCL6) {
200-
return NewCastAction(sim, agent.lb)
201-
}
202-
203242
agent.purgeExpiredSnapshots(sim)
204243
oldestSnapshot := agent.getOldestSnapshot()
205244

@@ -217,28 +256,47 @@ func (agent *AdaptiveAgent) ChooseAction(sim *Simulation) AgentAction {
217256
sim.Debug("[AI] CL Ready: Mana/s: %0.1f, Est Mana Cost: %0.1f, CurrentMana: %0.1f\n", manaSpendingRate, projectedManaCost, sim.CurrentMana)
218257
}
219258

220-
// If we have enough mana to burn and CL is off CD, use it.
259+
// If we have enough mana to burn, use the surplus agent.
221260
if projectedManaCost < sim.CurrentMana {
222-
return NewCastAction(sim, agent.cl)
261+
return agent.surplusAgent.ChooseAction(sim)
262+
} else {
263+
return agent.baseAgent.ChooseAction(sim)
223264
}
224-
225-
return NewCastAction(sim, agent.lb)
226265
}
227266
func (agent *AdaptiveAgent) OnActionAccepted(sim *Simulation, action AgentAction) {
228267
agent.takeSnapshot(sim)
268+
agent.baseAgent.OnActionAccepted(sim, action)
269+
agent.surplusAgent.OnActionAccepted(sim, action)
229270
}
230271

231272
func (agent *AdaptiveAgent) Reset(sim *Simulation) {
232273
agent.manaSnapshots = [manaSnapshotsBufferSize]ManaSnapshot{}
233274
agent.firstSnapshotIndex = 0
234275
agent.numSnapshots = 0
276+
agent.baseAgent.Reset(sim)
277+
agent.surplusAgent.Reset(sim)
235278
}
236279

237280
func NewAdaptiveAgent(sim *Simulation) *AdaptiveAgent {
238-
return &AdaptiveAgent{
239-
lb: spellmap[MagicIDLB12],
240-
cl: spellmap[MagicIDCL6],
281+
agent := &AdaptiveAgent{}
282+
283+
clearcastSimRequest := SimRequest{
284+
Options: sim.Options,
285+
Gear: sim.EquipSpec,
286+
Iterations: 100,
241287
}
288+
clearcastSimRequest.Options.AgentType = AGENT_TYPE_CL_ON_CLEARCAST
289+
clearcastResult := RunSimulation(clearcastSimRequest)
290+
291+
if clearcastResult.NumOom >= 5 {
292+
agent.baseAgent = NewAgent(sim, AGENT_TYPE_FIXED_LB_ONLY)
293+
agent.surplusAgent = NewAgent(sim, AGENT_TYPE_CL_ON_CLEARCAST)
294+
} else {
295+
agent.baseAgent = NewAgent(sim, AGENT_TYPE_CL_ON_CLEARCAST)
296+
agent.surplusAgent = NewAgent(sim, AGENT_TYPE_FIXED_CL_ON_CD)
297+
}
298+
299+
return agent
242300
}
243301

244302
type AgentType int
@@ -254,6 +312,7 @@ const (
254312
AGENT_TYPE_FIXED_9LB_1CL
255313
AGENT_TYPE_FIXED_10LB_1CL
256314
AGENT_TYPE_FIXED_LB_ONLY
315+
AGENT_TYPE_FIXED_CL_ON_CD
257316
AGENT_TYPE_ADAPTIVE
258317
AGENT_TYPE_CL_ON_CLEARCAST
259318
)
@@ -268,6 +327,7 @@ var ALL_AGENT_TYPES = []AgentType{
268327
AGENT_TYPE_FIXED_9LB_1CL,
269328
AGENT_TYPE_FIXED_10LB_1CL,
270329
AGENT_TYPE_FIXED_LB_ONLY,
330+
AGENT_TYPE_FIXED_CL_ON_CD,
271331
AGENT_TYPE_ADAPTIVE,
272332
AGENT_TYPE_CL_ON_CLEARCAST,
273333
}
@@ -291,7 +351,9 @@ func NewAgent(sim *Simulation, agentType AgentType) Agent {
291351
case AGENT_TYPE_FIXED_10LB_1CL:
292352
return NewFixedRotationAgent(sim, 10)
293353
case AGENT_TYPE_FIXED_LB_ONLY:
294-
return NewFixedRotationAgent(sim, -1)
354+
return NewLBOnlyAgent(sim)
355+
case AGENT_TYPE_FIXED_CL_ON_CD:
356+
return NewCLOnCDAgent(sim)
295357
case AGENT_TYPE_ADAPTIVE:
296358
return NewAdaptiveAgent(sim)
297359
case AGENT_TYPE_CL_ON_CLEARCAST:

tbc/sim.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ type Simulation struct {
2222
InitialStats Stats
2323
Stats Stats
2424
Equip Equipment // Current Gear
25-
activeEquip []*Item // cache of gear that can activate.
25+
EquipSpec EquipmentSpec
26+
activeEquip []*Item // cache of gear that can activate.
2627

2728
Options Options
2829
Duration time.Duration
@@ -73,6 +74,7 @@ func NewSim(equipSpec EquipmentSpec, options Options) *Simulation {
7374
auras: [MagicIDLen]Aura{},
7475
activeAuraIDs: make([]int32, 0, 10),
7576
Equip: equip,
77+
EquipSpec: equipSpec,
7678
rseed: options.RSeed,
7779
rando: rand.New(rand.NewSource(options.RSeed)),
7880
Debug: nil,

tbc/sim_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ func TestSimulatePreRaidNoBuffs(t *testing.T) {
135135
Gear: preRaidGear,
136136
AgentType: AGENT_TYPE_ADAPTIVE,
137137

138-
ExpectedDpsShort: 868.5,
139-
ExpectedDpsLong: 271,
138+
ExpectedDpsShort: 867,
139+
ExpectedDpsLong: 277,
140140
})
141141
}
142142

@@ -150,7 +150,7 @@ func TestSimulatePreRaid(t *testing.T) {
150150
AgentType: AGENT_TYPE_ADAPTIVE,
151151

152152
ExpectedDpsShort: 1406,
153-
ExpectedDpsLong: 1032,
153+
ExpectedDpsLong: 1017,
154154
})
155155
}
156156

@@ -164,7 +164,7 @@ func TestSimulateP1(t *testing.T) {
164164
AgentType: AGENT_TYPE_ADAPTIVE,
165165

166166
ExpectedDpsShort: 1539.5,
167-
ExpectedDpsLong: 1238,
167+
ExpectedDpsLong: 1359,
168168
})
169169
}
170170

@@ -180,7 +180,7 @@ func TestMultiTarget(t *testing.T) {
180180
},
181181
AGENT_TYPE_ADAPTIVE),
182182
p1Gear,
183-
1372)
183+
1678.5)
184184
}
185185

186186
func TestLBOnlyAgent(t *testing.T) {

ui/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ <h4>Standard Elemental Build</h4>
288288
<div id="pullout">
289289
<div class="dtl" style="height:100%;width:100%;padding:10px">
290290
<div id="themetoggle" style="height:20px; bottom: 10px; cursor: pointer;" onclick="toggletheme()">
291-
<text>v1.1.11</text>
291+
<text>v1.1.13</text>
292292
<img id="themebulb" style="height: 20px; width: 20px" src="icons/light-bulb.svg"></img>
293293
</div>
294294
<div style="margin-top:10px">

ui/lib.wasm

7.1 KB
Binary file not shown.

ui/ui.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ const AGENT_TYPES = {
3434
"FIXED_9LB_1CL": 6,
3535
"FIXED_10LB_1CL": 7,
3636
"FIXED_LB_ONLY": 8,
37-
"ADAPTIVE": 9,
38-
"CL_ON_CLEARCAST": 10
37+
"FIXED_CL_ON_CD": 9,
38+
"ADAPTIVE": 10,
39+
"CL_ON_CLEARCAST": 11
3940
};
4041

4142
// This must be kept in sync with the const values in stats.go

0 commit comments

Comments
 (0)