summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorElectroDeoxys <ElectroDeoxys@gmail.com>2020-05-01 17:28:57 +0100
committerElectroDeoxys <ElectroDeoxys@gmail.com>2020-05-02 09:11:26 +0100
commit17b8a2fdc29ff221b18533f06966b02ad0883fb2 (patch)
tree9a25d9222902788fe9b3c6d94029a3b6c56aa384 /src
parent8c1acff885f6c0292a50efecb966f52732836cb9 (diff)
Document AI Anti Mill strategy
Diffstat (limited to 'src')
-rw-r--r--src/constants/duel_constants.asm5
-rw-r--r--src/engine/bank05.asm83
-rw-r--r--src/engine/bank08.asm44
-rw-r--r--src/engine/deck_ai.asm40
-rw-r--r--src/wram.asm8
5 files changed, 112 insertions, 68 deletions
diff --git a/src/constants/duel_constants.asm b/src/constants/duel_constants.asm
index 9cdc73b..47ca1ad 100644
--- a/src/constants/duel_constants.asm
+++ b/src/constants/duel_constants.asm
@@ -263,3 +263,8 @@ AI_ENERGY_FLAG_SKIP_ARENA_CARD EQU 1 << 7 ; whether to include Arena card in det
const AI_TRAINER_CARD_PHASE_13 ; $d
const AI_TRAINER_CARD_PHASE_14 ; $e
const AI_TRAINER_CARD_PHASE_15 ; $f
+
+; used by wAIBarrierFlagCounter to determine
+; whether Player is running Mewtwo1 mill deck.
+; flag set means true, flag not set means false.
+AI_FLAG_MEWTWO_MILL EQU 1 << 7
diff --git a/src/engine/bank05.asm b/src/engine/bank05.asm
index 989225e..7162983 100644
--- a/src/engine/bank05.asm
+++ b/src/engine/bank05.asm
@@ -1233,7 +1233,7 @@ _AIMainTurnLogic: ; 1468b (5:468b)
ld a, AI_TRAINER_CARD_PHASE_01
call AIProcessHandTrainerCards
- farcall Func_227d3
+ farcall HandleAIAntiMewtwoDeckStrategy
jp nc, .try_attack
farcall HandleAIGoGoRainDanceEnergy
@@ -1719,10 +1719,11 @@ InitAIDuelVars: ; 15636 (5:5636)
ld [wcda5], a
ret
-; initializes some variables and
-; sets value of wcda7.
+; initializes some variables and sets value of wAIBarrierFlagCounter.
+; if Player uses Barrier 3 times in a row, AI checks if Player's deck
+; has only Mewtwo1 Pokemon cards (running a Mewtwo1 mill deck).
InitAITurnVars: ; 15649 (5:5649)
-; increase Pokedex counter by one
+; increase Pokedex counter by 1
ld a, [wAIPokedexCounter]
inc a
ld [wAIPokedexCounter], a
@@ -1733,30 +1734,43 @@ InitAITurnVars: ; 15649 (5:5649)
ld [wcddc], a
ld [wce03], a
+; checks if the Player used an attack last turn
+; and if it was the second attack of their card.
ld a, [wPlayerAttackingMoveIndex]
cp $ff
- jr z, .asm_156b1
+ jr z, .check_flag
or a
- jr z, .asm_156b1
+ jr z, .check_flag
ld a, [wPlayerAttackingCardIndex]
cp $ff
- jr z, .asm_156b1
+ jr z, .check_flag
+; if the card is Mewtwo1, it means the Player
+; used its second attack, Barrier.
call SwapTurn
call GetCardIDFromDeckIndex
call SwapTurn
ld a, e
cp MEWTWO1
- jr nz, .asm_156b1
+ jr nz, .check_flag
+ ; Player used Barrier last turn
-; handle Mewtwo1-only deck
- ld a, [wcda7]
+; check if flag was already set, if so,
+; reset wAIBarrierFlagCounter to $80.
+ ld a, [wAIBarrierFlagCounter]
bit 7, a
- jr nz, .asm_156aa
+ jr nz, .set_flag
+
+; if not, increase it by 1 and check if it exceeds 2.
inc a
- ld [wcda7], a
- cp $03
+ ld [wAIBarrierFlagCounter], a
+ cp 3
jr c, .done
+
+; this means that the Player used Barrier
+; at least 3 turns in a row.
+; check if Player is running Mewtwo1-only deck,
+; if so, set wAIBarrierFlagCounter flag.
ld a, DUELVARS_ARENA_CARD
call GetNonTurnDuelistVariable
call SwapTurn
@@ -1764,31 +1778,33 @@ InitAITurnVars: ; 15649 (5:5649)
call SwapTurn
ld a, e
cp MEWTWO1
- jr nz, .asm_156a4
+ jr nz, .reset_1
farcall CheckIfPlayerHasPokemonOtherThanMewtwo1
- jr nc, .asm_156aa
-.asm_156a4
-; reset wcda7
+ jr nc, .set_flag
+.reset_1
+; reset wAIBarrierFlagCounter
xor a
- ld [wcda7], a
+ ld [wAIBarrierFlagCounter], a
jr .done
-.asm_156aa
- ld a, $80
- ld [wcda7], a
+
+.set_flag
+ ld a, AI_FLAG_MEWTWO_MILL + 0
+ ld [wAIBarrierFlagCounter], a
jr .done
-.asm_156b1
- ld a, [wcda7]
+.check_flag
+; increase counter by 1 if flag is set
+ ld a, [wAIBarrierFlagCounter]
bit 7, a
- jr z, .asm_156be
+ jr z, .reset_2
inc a
- ld [wcda7], a
+ ld [wAIBarrierFlagCounter], a
jr .done
-.asm_156be
-; reset wcda7
+.reset_2
+; reset wAIBarrierFlagCounter
xor a
- ld [wcda7], a
+ ld [wAIBarrierFlagCounter], a
.done
ret
; 0x156c3
@@ -4520,11 +4536,12 @@ AIProcessEnergyCards: ; 164fc (5:64fc)
jr nz, .bench
; arena
- ld a, [wcda7]
+ ld a, [wAIBarrierFlagCounter]
bit 7, a
jr z, .add_to_score
-; subtract from score
+; subtract from score instead
+; if Player is running Mewtwo1 mill deck.
ld a, 5
call SubFromAIScore
jr .check_defending_can_ko
@@ -5455,8 +5472,10 @@ AIProcessAttacks: ; 169fc (5:69fc)
jr .attack_chosen
.no_pluspower
- ld a, [wcda7]
- cp $80
+; if Player is running Mewtwo1 mill deck,
+; skip attack if Barrier counter is 0.
+ ld a, [wAIBarrierFlagCounter]
+ cp AI_FLAG_MEWTWO_MILL + 0
jp z, .dont_attack
; determine AI score of both attacks.
diff --git a/src/engine/bank08.asm b/src/engine/bank08.asm
index 1c6f82a..8d6d462 100644
--- a/src/engine/bank08.asm
+++ b/src/engine/bank08.asm
@@ -4698,19 +4698,22 @@ AIPlay_Gambler: ; 2182d (8:582d)
; 0x21875
; checks whether to play Gambler.
-; aside from Imakuni, all other opponents only
-; play if there's less than 4 cards in the deck.
+; aside from Imakuni?, all other opponents only
+; play this card if Player is running Mewtwo1-only deck.
AIDecide_Gambler: ; 21875 (8:5875)
; Imakuni? has his own routine
ld a, [wOpponentDeckID]
cp IMAKUNI_DECK_ID
jr z, .imakuni
- ld a, [wcda7]
- and $80
+; check if flag is set for Player using Mewtwo1 only deck
+ ld a, [wAIBarrierFlagCounter]
+ and AI_FLAG_MEWTWO_MILL
jr z, .no_carry
-; set carry if number of cards in deck <= 4
+; set carry if number of cards in deck <= 4.
+; this is done to counteract the deck out strategy
+; of Mewtwo1 deck, by replenishing the deck with hand cards.
ld a, DUELVARS_NUMBER_OF_CARDS_NOT_IN_DECK
call GetTurnDuelistVariable
cp DECK_SIZE - 4
@@ -7487,26 +7490,37 @@ CheckIfPlayerHasPokemonOtherThanMewtwo1: ; 227a9 (8:67a9)
ret
; 0x227d3
-; checks wcda7 and Pokemon in Play Area that are set up.
-; if there's at least 4, goes to AI_TRAINER_CARD_PHASE_05.
-; else, returns carry.
-Func_227d3: ; 227d3 (8:67d3)
- ld a, [wcda7]
+; returns no carry if, given the Player is using a Mewtwo1 mill deck,
+; the AI already has a Bench fully set up, in which case it
+; will process some Trainer cards in hand (namely Energy Removals).
+; this is used to check whether to skip some normal AI routines
+; this turn and jump right to the attacking phase.
+HandleAIAntiMewtwoDeckStrategy: ; 227d3 (8:67d3)
+; return carry if Player is not playing Mewtwo1 mill deck
+ ld a, [wAIBarrierFlagCounter]
bit 7, a
jr z, .set_carry
- cp %10000010
- jr c, .asm_227e4
-; reset wcda7
+; else, check if there's been less than 2 turns
+; without the Player using Barrier.
+ cp AI_FLAG_MEWTWO_MILL + 2
+ jr c, .count_bench
+
+; if there has been, reset wAIBarrierFlagCounter
+; and return carry.
xor a
- ld [wcda7], a
+ ld [wAIBarrierFlagCounter], a
jr .set_carry
-.asm_227e4
+; else, check number of Pokemon that are set up in Bench
+; if less than 4, return carry.
+.count_bench
farcall CountNumberOfSetUpBenchPokemon
cp 4
jr c, .set_carry
+; if there's at least 4 Pokemon in the Bench set up,
+; process Trainer hand cards of AI_TRAINER_CARD_PHASE_05
ld a, AI_TRAINER_CARD_PHASE_05
farcall AIProcessHandTrainerCards
or a
diff --git a/src/engine/deck_ai.asm b/src/engine/deck_ai.asm
index e4edfdf..c93b8ce 100644
--- a/src/engine/deck_ai.asm
+++ b/src/engine/deck_ai.asm
@@ -58,8 +58,8 @@ Func_148ff: ; 148ff (5:48ff)
call InitAITurnVars
ld a, AI_TRAINER_CARD_PHASE_01
call AIProcessHandTrainerCards
- farcall Func_227d3
- jp nc, .asm_149de
+ farcall HandleAIAntiMewtwoDeckStrategy
+ jp nc, .try_attack
farcall HandleAIGoGoRainDanceEnergy
farcall HandleAIDamageSwap
farcall HandleAIPkmnPowers
@@ -105,7 +105,7 @@ Func_148ff: ; 148ff (5:48ff)
call AIProcessHandTrainerCards
ld a, [wPreviousAIFlags]
and AI_FLAG_USED_PROFESSOR_OAK
- jr z, .asm_149de
+ jr z, .try_attack
ld a, AI_TRAINER_CARD_PHASE_01
call AIProcessHandTrainerCards
ld a, AI_TRAINER_CARD_PHASE_02
@@ -142,7 +142,7 @@ Func_148ff: ; 148ff (5:48ff)
farcall HandleAIGoGoRainDanceEnergy
ld a, AI_TRAINER_CARD_PHASE_13
call AIProcessHandTrainerCards
-.asm_149de
+.try_attack
call AIProcessAndTryToUseAttack
ret c
ld a, OPPACTION_FINISH_NO_ATTACK
@@ -277,7 +277,7 @@ Func_14a4a: ; 14a4a (5:4a4a)
Func_14a81: ; 14a81 (5:4a81)
call InitAITurnVars
- farcall Func_227d3
+ farcall HandleAIAntiMewtwoDeckStrategy
jp nc, .try_attack
ld a, AI_TRAINER_CARD_PHASE_02
@@ -474,8 +474,8 @@ Func_14b6c: ; 14b6c (5:4b6c)
Func_14b9a: ; 14b9a (5:4b9a)
call InitAITurnVars
- farcall Func_227d3
- jp nc, .asm_14c01
+ farcall HandleAIAntiMewtwoDeckStrategy
+ jp nc, .try_attack
ld a, AI_TRAINER_CARD_PHASE_01
call AIProcessHandTrainerCards
ld a, AI_TRAINER_CARD_PHASE_04
@@ -522,7 +522,7 @@ Func_14b9a: ; 14b9a (5:4b9a)
ret c
ld a, AI_TRAINER_CARD_PHASE_13
call AIProcessHandTrainerCards
-.asm_14c01
+.try_attack
call AIProcessAndTryToUseAttack
ret c
ld a, OPPACTION_FINISH_NO_ATTACK
@@ -720,8 +720,8 @@ Func_14cf7: ; 14cf7 (5:4cf7)
call InitAITurnVars
ld a, AI_TRAINER_CARD_PHASE_01
call AIProcessHandTrainerCards
- farcall Func_227d3
- jp nc, .asm_14d56
+ farcall HandleAIAntiMewtwoDeckStrategy
+ jp nc, .try_attack
ld a, AI_TRAINER_CARD_PHASE_02
call AIProcessHandTrainerCards
call AIDecidePlayPokemonCard
@@ -741,7 +741,7 @@ Func_14cf7: ; 14cf7 (5:4cf7)
call AIProcessHandTrainerCards
ld a, [wPreviousAIFlags]
and AI_FLAG_USED_PROFESSOR_OAK
- jr z, .asm_14d56
+ jr z, .try_attack
ld a, AI_TRAINER_CARD_PHASE_01
call AIProcessHandTrainerCards
ld a, AI_TRAINER_CARD_PHASE_02
@@ -757,7 +757,7 @@ Func_14cf7: ; 14cf7 (5:4cf7)
call AIProcessAndTryToPlayEnergy
.asm_14d53
call AIDecidePlayPokemonCard
-.asm_14d56
+.try_attack
call AIProcessAndTryToUseAttack
ret c
ld a, OPPACTION_FINISH_NO_ATTACK
@@ -883,8 +883,8 @@ Func_14def: ; 14def (5:4def)
call InitAITurnVars
ld a, AI_TRAINER_CARD_PHASE_01
call AIProcessHandTrainerCards
- farcall Func_227d3
- jp nc, .asm_14e7f
+ farcall HandleAIAntiMewtwoDeckStrategy
+ jp nc, .try_attack
ld a, AI_TRAINER_CARD_PHASE_02
call AIProcessHandTrainerCards
call AIDecidePlayPokemonCard
@@ -923,7 +923,7 @@ Func_14def: ; 14def (5:4def)
call AIProcessHandTrainerCards
ld a, [wPreviousAIFlags]
and AI_FLAG_USED_PROFESSOR_OAK
- jr z, .asm_14e7f
+ jr z, .try_attack
ld a, AI_TRAINER_CARD_PHASE_01
call AIProcessHandTrainerCards
ld a, AI_TRAINER_CARD_PHASE_02
@@ -943,7 +943,7 @@ Func_14def: ; 14def (5:4def)
call AIProcessAndTryToPlayEnergy
.asm_14e7c
call AIDecidePlayPokemonCard
-.asm_14e7f
+.try_attack
call AIProcessAndTryToUseAttack
ret c
ld a, OPPACTION_FINISH_NO_ATTACK
@@ -2328,7 +2328,7 @@ Func_15507: ; 15507 (5:5507)
call LookForCardIDInHandList_Bank5
jr nc, .asm_15540
ldh [hTemp_ffa0], a
- ld a, $01
+ ld a, OPPACTION_PLAY_BASIC_PKMN
bank1call AIMakeDecision
.asm_15540
call AIDecidePlayPokemonCard
@@ -2351,7 +2351,7 @@ Func_15507: ; 15507 (5:5507)
call AIProcessHandTrainerCards
ld a, [wPreviousAIFlags]
and AI_FLAG_USED_PROFESSOR_OAK
- jr z, .asm_155c8
+ jr z, .try_attack
ld a, AI_TRAINER_CARD_PHASE_01
call AIProcessHandTrainerCards
ld a, AI_TRAINER_CARD_PHASE_02
@@ -2373,7 +2373,7 @@ Func_15507: ; 15507 (5:5507)
call LookForCardIDInHandList_Bank5
jr nc, .asm_155a5
ldh [hTemp_ffa0], a
- ld a, $01
+ ld a, OPPACTION_PLAY_BASIC_PKMN
bank1call AIMakeDecision
.asm_155a5
call AIDecidePlayPokemonCard
@@ -2392,7 +2392,7 @@ Func_15507: ; 15507 (5:5507)
.asm_155c4
call AIDecidePlayPokemonCard
ret c
-.asm_155c8
+.try_attack
call AIProcessAndTryToUseAttack
ret c
ld a, OPPACTION_FINISH_NO_ATTACK
diff --git a/src/wram.asm b/src/wram.asm
index cae7f88..5614b54 100644
--- a/src/wram.asm
+++ b/src/wram.asm
@@ -1192,7 +1192,13 @@ wcda5:: ; cda5
wAIPokedexCounter:: ; cda6
ds $1
-wcda7:: ; cda7
+; variable to keep track of Mewtwo1's Barrier usage during Player' turn.
+; AI_FLAG_MEWTWO_MILL set means Player is running Mewtwo1 mill deck.
+; - when flag is not set, this counts how many turns in a row
+; Player used Mewtwo1's Barrier attack;
+; - when flag is set, this counts how many turns in a row
+; Player has NOT used Barrier attack.
+wAIBarrierFlagCounter:: ; cda7
ds $1
wcda8:: ; cda8