Skip to content

Commit f9d5c5b

Browse files
authored
Merge pull request #166 from Sha0den/master
Document several more AI bug fixes
2 parents aa69eba + 483ea7a commit f9d5c5b

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

bugs_and_glitches.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Fixes are written in the `diff` format.
2727
- [Sam's practice deck does wrong card ID check](#sams-practice-deck-does-wrong-card-id-check)
2828
- [AI does not use Shift properly](#ai-does-not-use-shift-properly)
2929
- [AI does not use Cowardice properly](#ai-does-not-use-cowardice-properly)
30+
- [AI does not pay attention to Acid effect when retreating](#ai-does-not-pay-attention-to-acid-effect-when-retreating)
31+
- [AI has flawed logic when considering MewLv8 as a target for switching](#ai-has-flawed-logic-when-considering-mewlv8-as-a-target-for-switching)
32+
- [AI has flawed logic when considering the Earthquake attack](#ai-has-flawed-logic-when-considering-the-earthquake-attack)
3033
- [Phantom Venusaur will never be obtained through Card Pop!](#phantom-venusaur-will-never-be-obtained-through-card-pop)
3134
- [Graphics](#graphics)
3235
- [Water Club master room uses the wrong void color](#water-club-master-room-uses-the-wrong-void-color)
@@ -552,6 +555,132 @@ HandleAICowardice:
552555
...
553556
```
554557

558+
### AI does not pay attention to Acid effect when retreating
559+
560+
When retreating, the AI completely ignores whether or not its Active Pokémon was attacked with Victreebel's Acid attack during the previous turn. While addressing this oversight, you can also remove some of the extra Asleep/Paralyzed checks within the same function.
561+
562+
**Fix:** Edit `AITryToRetreat` in [src/engine/duel/ai/retreat.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/retreat.asm):
563+
```diff
564+
; input:
565+
; - a = Play Area location (PLAY_AREA_*) of card to retreat to.
566+
AITryToRetreat:
567+
- push af
568+
+ ld b, a
569+
+ call CheckUnableToRetreatDueToEffect
570+
+ ret c
571+
+ bank1call CheckIfActiveCardParalyzedOrAsleep
572+
+ ret c
573+
+ push bc
574+
ld a, [wAIPlayEnergyCardForRetreat]
575+
or a
576+
jr z, .check_id
577+
578+
; AI is allowed to play an energy card
579+
; from the hand in order to provide
580+
; the necessary energy for retreat cost
581+
-
582+
-; check status
583+
- ld a, DUELVARS_ARENA_CARD_STATUS
584+
- call GetTurnDuelistVariable
585+
- and CNF_SLP_PRZ
586+
- cp ASLEEP
587+
- jp z, .check_id
588+
- cp PARALYZED
589+
- jp z, .check_id
590+
-
591+
; if an energy card hasn't been played yet,
592+
; checks if the Pokémon needs just one more energy to retreat
593+
; if it does, check if there are any energy cards in hand
594+
...
595+
pop af
596+
ldh [hTempPlayAreaLocation_ffa1], a
597+
ld a, DUELVARS_ARENA_CARD_STATUS
598+
call GetTurnDuelistVariable
599+
- ld b, a
600+
- and CNF_SLP_PRZ
601+
- cp ASLEEP
602+
- jp z, .set_carry
603+
- cp PARALYZED
604+
- jp z, .set_carry
605+
- ld a, b
606+
ldh [hTemp_ffa0], a
607+
ld a, $ff
608+
ldh [hTempRetreatCostCards], a
609+
...
610+
```
611+
612+
### AI has flawed logic when considering MewLv8 as a target for switching
613+
614+
There is a mistake in the AI logic that affects whether or not Stephanie will choose a Benched MewLv8 to be her new Active Pokémon after retreating. It's supposed to increase MewLv8's score if the player's Active Pokémon isn't a Basic Pokémon, but it mistakenly looks up that Pokémon's deck index in the AI's deck.
615+
616+
**Fix:** Edit `AIDecideBenchPokemonToSwitchTo` in [src/engine/duel/ai/retreat.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/retreat.asm):
617+
```diff
618+
AIDecideBenchPokemonToSwitchTo:
619+
...
620+
jr z, .raise_score
621+
cp MEW_LV8
622+
jr nz, .check_if_has_bench_utility
623+
+ call Swap Turn
624+
ld a, DUELVARS_ARENA_CARD
625+
- call GetNonTurnDuelistVariable
626+
+ call GetTurnDuelistVariable
627+
call LoadCardDataToBuffer2_FromDeckIndex
628+
+ call SwapTurn
629+
ld a, [wLoadedCard2Stage]
630+
or a
631+
jr z, .check_if_has_bench_utility
632+
...
633+
```
634+
635+
### AI has flawed logic when considering the Earthquake attack
636+
637+
There are some mistakes in the AI logic that affects whether or not Gene will decide to use Dugtrio's Earthquake attack.
638+
639+
**Fix:** Edit `HandleSpecialAIAttacks` in [src/engine/duel/ai/special_attacks.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/special_attacks.asm):
640+
```diff
641+
HandleSpecialAIAttacks:
642+
...
643+
.Earthquake:
644+
ld a, DUELVARS_BENCH
645+
call GetTurnDuelistVariable
646+
647+
lb de, 0, PLAY_AREA_BENCH_1 - 1
648+
.loop_earthquake
649+
inc e
650+
ld a, [hli]
651+
cp $ff
652+
jr z, .count_prizes
653+
ld a, e
654+
add DUELVARS_ARENA_CARD_HP
655+
- ; bug, GetTurnDuelistVariable clobbers hl
656+
- ; uncomment the following lines to preserve hl
657+
- ; push hl
658+
+ push hl
659+
call GetTurnDuelistVariable
660+
- ; pop hl
661+
+ pop hl
662+
cp 20
663+
jr nc, .loop_earthquake
664+
inc d
665+
jr .loop_earthquake
666+
667+
.count_prizes
668+
- ; bug, this is supposed to count the player's prize cards
669+
- ; not the opponent's, missing calls to SwapTurn
670+
push de
671+
- ; call SwapTurn
672+
+ call SwapTurn
673+
call CountPrizes
674+
- ; call SwapTurn
675+
+ call SwapTurn
676+
pop de
677+
cp d
678+
jp c, .zero_score
679+
jp z, .zero_score
680+
ld a, $80
681+
ret
682+
```
683+
555684
### Phantom Venusaur will never be obtained through Card Pop!
556685

557686
([Video](https://youtu.be/vr8MZwW6gpI?si=qZuMBGRSrMyoGVJj&t=60))

0 commit comments

Comments
 (0)