Move explanations out of code and into bugs_and_glitches.md

This commit is contained in:
ElectroDeoxys
2023-07-25 13:27:33 +01:00
parent 43b7b92206
commit ef0bff677a
8 changed files with 69 additions and 166 deletions

View File

@@ -22,7 +22,7 @@ Fixes are written in the `diff` format.
- [AI Pokemon Trader may result in unintended effects](#ai-pokemon-trader-may-result-in-unintended-effects)
- [AI never uses Energy Trans in order to retreat Arena card](#ai-never-uses-energy-trans-in-order-to-retreat-arena-card)
- [Sam's practice deck does wrong card ID check](#sams-practice-deck-does-wrong-card-id-check)
- [AI does not account for Mysterious Fossil or Clefairy Doll when using Shift Pkmn Power](#ai-does-not-account-for-mysterious-fossil-or-clefairy-doll-when-using-shift-pkmn-power)
- [AI does not use Shift Pkmn Power properly](#ai-does-not-use-shift-pkmn-power-properly)
- [Challenge host uses wrong name for the first rival](#challenge-host-uses-wrong-name-for-the-first-rival)
## AI wrongfully adds score twice for attaching energy to Arena card
@@ -31,8 +31,8 @@ When the AI is scoring each Play Area Pokémon card to attach an Energy card, it
**Fix:** Edit `DetermineAIScoreOfAttackEnergyRequirement` in [src/engine/duel/ai/energy.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/energy.asm):
```diff
DetermineAIScoreOfAttackEnergyRequirement: ; 16695 (5:6695)
...
DetermineAIScoreOfAttackEnergyRequirement:
...
-; if the attack KOs player and this is the active card, add to AI score.
+; if the attack KOs player add to AI score.
- ldh a, [hTempPlayAreaLocation_ff9d]
@@ -52,24 +52,20 @@ DetermineAIScoreOfAttackEnergyRequirement: ; 16695 (5:6695)
-; this is possibly a bug.
-; this is an identical check as above to test whether this card is active.
-; in case it is active, the score gets added 10 more points,
-; in addition to the 20 points already added above.
-; what was probably intended was to add 20 points
-; plus 10 in case it is the Arena card.
+; add 10 more in case it's the Arena card
ldh a, [hTempPlayAreaLocation_ff9d]
or a
jr nz, .check_evolution
ld a, 10
call AddToAIScore
...
...
```
## Cards in AI decks that are not supposed to be placed as Prize cards are ignored
Each deck AI lists some card IDs that are not supposed to be placed as Prize cards in the beginning of the duel. If the deck configuration after the initial shuffling results in any of these cards being placed as Prize cards, the game is supposed to reshuffle the deck. An example of such a list, for the Go GO Rain Dance deck, is:
```
.list_prize ; 14fe6 (5:4fe6)
.list_prize
db GAMBLER
db ENERGY_RETRIEVAL
db SUPER_ENERGY_RETRIEVAL
@@ -77,21 +73,19 @@ Each deck AI lists some card IDs that are not supposed to be placed as Prize car
db $00
```
However, the routine to iterate these lists and look for these cards is buggy, which results in the game ignoring it completely.
However, the routine to iterate these lists and look for these cards is buggy, as it will always return no carry because when checking terminating byte in wAICardListAvoidPrize ($00), it wrongfully uses 'cp a' instead of 'or a'. This results in the game ignoring it completely.
**Fix:** Edit `SetUpBossStartingHandAndDeck` in [src/engine/duel/ai/boss_deck_set_up.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/boss_deck_set_up.asm):
```diff
SetUpBossStartingHandAndDeck: ; 172af (5:72af)
SetUpBossStartingHandAndDeck:
...
-; expectation: return carry if card ID corresponding
+; return carry if card ID corresponding
; to the input deck index is listed in wAICardListAvoidPrize;
-; reality: always returns no carry because when checking terminating
-; byte in wAICardListAvoidPrize ($00), it wrongfully uses 'cp a' instead of 'or a',
-; so it always ends up returning in the first item in list.
-; reality: always returns no carry
; input:
; - a = deck index of card to check
.CheckIfIDIsInList ; 17366 (5:7366)
.CheckIfIDIsInList
ld b, a
ld a, [wAICardListAvoidPrize + 1]
or a
@@ -125,7 +119,7 @@ SetUpBossStartingHandAndDeck: ; 172af (5:72af)
Each deck AI lists some Pokémon card IDs that have an associated score for retreating. That way, the game can fine-tune the likelihood that the AI duelist will retreat to a given Pokémon from the bench. For example, the Legendary Dragonite deck has the following list of retreat score modifiers:
```
.list_retreat ; 14d99 (5:4d99)
.list_retreat
ai_retreat CHARMANDER, -1
ai_retreat MAGIKARP, -5
db $00
@@ -148,17 +142,12 @@ However, the game never actually stores the pointer to these lists (a notable ex
## AI handles Basic Pokémon cards in hand wrong when scoring the use of Professor Oak
When the AI is checking whether to play Professor Oak or not, it does a hand check to see if there are any Basic/Evolved Pokémon cards. One of these checks is supposed to add to the score if there are Basic Pokémon in hand, but as it is coded, it will never execute the score addition.
When the AI is checking whether to play Professor Oak or not, it does a hand check to see if there are any Basic/Evolved Pokémon cards. One of these checks is supposed to add to the score if there are any Basic Pokémon in hand, but as it is written, it will never execute the score addition.
**Fix:** Edit `AIDecide_ProfessorOak` in [src/engine/duel/ai/trainer_cards.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/trainer_cards.asm):
```diff
AIDecide_ProfessorOak: ; 20cc1 (8:4cc1)
...
-; this part seems buggy
-; the AI loops through all the cards in hand and checks
-; if any of them is not a Pokemon card and has Basic stage.
-; it seems like the intention was that if there was
-; any Basic Pokemon still in hand, the AI would add to the score.
AIDecide_ProfessorOak:
...
.check_hand
call CreateHandCardList
ld hl, wDuelTempList
@@ -172,7 +161,7 @@ AIDecide_ProfessorOak: ; 20cc1 (8:4cc1)
cp TYPE_ENERGY
- jr c, .loop_hand ; bug, should be jr nc
+ jr nc, .loop_hand
...
...
```
## Rick never plays Energy Search
@@ -181,8 +170,8 @@ The AI's decision to play Energy Search has two special cases: one for the Heate
**Fix:** Edit `AIDecide_EnergySearch` in [src/engine/duel/ai/trainer_cards.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/trainer_cards.asm):
```diff
AIDecide_EnergySearch: ; 211aa (8:51aa)
...
AIDecide_EnergySearch:
...
-; this subroutine has a bug.
-; it was supposed to use the .CheckUsefulGrassEnergy subroutine
-; but uses .CheckUsefulFireOrLightningEnergy instead.
@@ -195,7 +184,7 @@ AIDecide_EnergySearch: ; 211aa (8:51aa)
jr c, .no_carry
scf
ret
...
...
```
## Rick uses wrong Pokédex AI subroutine
@@ -204,8 +193,8 @@ Seems Rick can't catch a break. When deciding which cards to prioritize in the P
**Fix:** Edit `AIDecide_Pokedex` in [src/engine/duel/ai/trainer_cards.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/trainer_cards.asm):
```diff
AIDecide_Pokedex: ; 212dc (8:52dc)
...
AIDecide_Pokedex:
...
.pick_cards
-; the following comparison is disregarded
-; the Wonders of Science deck was probably intended
@@ -219,29 +208,29 @@ AIDecide_Pokedex: ; 212dc (8:52dc)
; picks order of the cards in deck from the effects of Pokedex.
; prioritizes Pokemon cards, then Trainer cards, then energy cards.
; stores the resulting order in wce1a.
-PickPokedexCards_Unreferenced: ; 212ff (8:52ff)
-PickPokedexCards_Unreferenced:
-; unreferenced
xor a
ld [wAIPokedexCounter], a ; reset counter
...
...
```
## Chris never uses Revive on Kangaskhan
Because of an error in the AI logic, Chris never considers using Revive on a Kangaskhan card in the Discard Pile, even though it is listed as one of the cards for the AI to check.
Because of an error in the AI logic, Chris never considers using Revive on a Kangaskhan card in the Discard Pile, even though it is listed as one of the cards for the AI to check. This works fine for Hitmonchan and Hitmonlee, but in case it's a Tauros card, the routine will fallthrough into the Kangaskhan check and then will fallthrough into the set carry branch (since it fails this check). In case it's a Kangaskhan card, the check will fail in the Tauros check and jump back into the loop. So the Tauros check works by accident, while Kangaskhan will never be correctly checked because of this.
**Fix:** Edit `AIDecide_Revive` in [src/engine/duel/ai/trainer_cards.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/trainer_cards.asm):
```diff
AIDecide_Revive: ; 218a9 (8:58a9)
...
-; these checks have a bug.
-; it works fine for Hitmonchan and Hitmonlee,
-; but in case it's a Tauros card, the routine will fallthrough
-; into the Kangaskhan check. since it will never be equal to Kangaskhan,
-; it will fallthrough into the set carry branch.
-; in case it's a Kangaskhan card, the check will fail in the Tauros check
-; and jump back into the loop. so just by accident the Tauros check works,
-; but Kangaskhan will never be correctly checked because of this.
AIDecide_Revive:
...
; look in Discard Pile for specific cards.
ld hl, wDuelTempList
.loop_discard_pile
ld a, [hli]
cp $ff
jr z, .no_carry
ld b, a
call LoadCardDataToBuffer1_FromDeckIndex
cp HITMONCHAN
jr z, .set_carry
cp HITMONLEE
@@ -252,17 +241,17 @@ AIDecide_Revive: ; 218a9 (8:58a9)
cp KANGASKHAN
- jr z, .set_carry ; bug, these two lines should be swapped
+ jr nz, .loop_discard_pile
...
...
```
## AI Pokemon Trader may result in unintended effects
A missing line in AI logic might result in strange behavior when executing the effect of Pokémon Trader for Power Generator deck.
A missing line in AI logic might result in strange behavior when executing the effect of Pokémon Trader for Power Generator deck. Since the last check falls through regardless of result, register a might hold an invalid deck index, which might lead to incorrect (and hilarious) results like Brandon trading a Pikachu with a Grass Energy from the deck. However, since it's deep in a tower of conditionals, reaching here is extremely unlikely.
**Fix:** Edit `AIDecide_PokemonTrader_PowerGenerator` in [src/engine/duel/ai/trainer_cards.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/trainer_cards.asm):
```diff
AIDecide_PokemonTrader_PowerGenerator: ; 2200b (8:600b)
...
AIDecide_PokemonTrader_PowerGenerator:
...
ld a, RAICHU_LV40
call LookForCardIDInDeck_GivenCardIDInHandAndPlayArea
- jr c, .find_duplicates
@@ -275,13 +264,6 @@ AIDecide_PokemonTrader_PowerGenerator: ; 2200b (8:600b)
- ; bug, missing jr .no_carry
+ jr .no_carry
-; since this last check falls through regardless of result,
-; register a might hold an invalid deck index,
-; which might lead to hilarious results like Brandon
-; trading a Pikachu with a Grass Energy from the deck.
-; however, since it's deep in a tower of conditionals,
-; reaching here is extremely unlikely.
; a card in deck was found to look for,
; check if there are duplicates in hand to trade with.
...
@@ -294,23 +276,18 @@ AIDecide_PokemonTrader_PowerGenerator: ; 2200b (8:600b)
## AI never uses Energy Trans in order to retreat Arena card
There is a mistake in the AI retreat logic, in [src/engine/duel/ai/decks/general.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/decks/general.asm):
There is a mistake in the AI retreat logic, in [src/engine/duel/ai/decks/general.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/decks/general.asm). HandleAIEnergyTrans for retreating doesn't make sense being at the end, since at this point Switch Trainer card was already used to retreat the Pokemon. What the routine will do is just transfer Energy cards to the Arena Pokemon for the purpose of retreating, and then not actually retreat, resulting in unusual behaviour. This would only work placed right after the AI checks whether they have Switch card in hand to use and doesn't have one (and probably that was the original intention).
```
; handles AI retreating logic
AIProcessRetreat:
...
.used_switch
; if AI used switch, unset its AI flag
ld a, [wPreviousAIFlags]
and ~AI_FLAG_USED_SWITCH ; clear Switch flag
ld [wPreviousAIFlags], a
; bug, this doesn't make sense being here, since at this point
; Switch Trainer card was already used to retreat the Pokemon.
; what the routine will do is just transfer Energy cards to
; the Arena Pokemon for the purpose of retreating, and
; then not actually retreat, resulting in unusual behaviour.
; this would only work placed right after the AI checks whether
; they have Switch card in hand to use and doesn't have one.
; (and probably that was the original intention.)
ld a, AI_ENERGY_TRANS_RETREAT ; retreat
ld a, AI_ENERGY_TRANS_RETREAT
farcall HandleAIEnergyTrans
ret
```
@@ -319,18 +296,8 @@ There is a mistake in the AI retreat logic, in [src/engine/duel/ai/decks/general
## Sam's practice deck does wrong card ID check
There is a mistake in the AI logic for deciding which Pokémon for Sam to switch to, in [src/engine/duel/ai/decks/sams_practice.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/decks/sams_practice.asm):
There is a mistake in the AI logic for deciding which Pokémon for Sam to switch to in [src/engine/duel/ai/decks/sams_practice.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/decks/sams_practice.asm). It attempts to compare a card ID with a deck index. The intention was to change the card to switch to depending on whether the first Machop was KO'd at this point in the Duel or not. Because of the buggy comparison, this will always skip the 'inc a' instruction and switch to PLAY_AREA_BENCH_1. In a normal Practice Duel following Dr. Mason's instructions, this will always lead to the AI correctly switching Raticate with Machop, but in case of a "Free" Duel where the first Machop is not KO'd, the intention was to switch to PLAY_AREA_BENCH_2 instead.
```
; this is a bug, it's attempting to compare a card ID with a deck index.
; the intention was to change the card to switch to depending on whether
; the first Machop was KO'd at this point in the Duel or not.
; because of the buggy comparison, this will always jump the
; 'inc a' instruction and switch to PLAY_AREA_BENCH_1.
; in a normal Practice Duel following Dr. Mason's instructions,
; this will always lead to the AI correctly switching Raticate with Machop,
; but in case of a "Free" Duel where the first Machop is not KO'd,
; the intention was to switch to PLAY_AREA_BENCH_2 instead.
; but due to 'inc a' always being skipped, it will switch to Raticate.
ld a, DUELVARS_ARENA_CARD
call GetTurnDuelistVariable
cp MACHOP ; wrong
@@ -341,18 +308,8 @@ There is a mistake in the AI logic for deciding which Pokémon for Sam to switch
**Fix:** Edit `AIPerformScriptedTurn` in [src/engine/duel/ai/decks/sams_practice.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/decks/sams_practice.asm):
```diff
AIPerformScriptedTurn: ; 1483a (5:483a)
...
-; this is a bug, it's attempting to compare a card ID with a deck index.
-; the intention was to change the card to switch to depending on whether
-; the first Machop was KO'd at this point in the Duel or not.
-; because of the buggy comparison, this will always jump the
-; 'inc a' instruction and switch to PLAY_AREA_BENCH_1.
-; in a normal Practice Duel following Dr. Mason's instructions,
-; this will always lead to the AI correctly switching Raticate with Machop,
-; but in case of a "Free" Duel where the first Machop is not KO'd,
-; the intention was to switch to PLAY_AREA_BENCH_2 instead.
-; but due to 'inc a' always being skipped, it will switch to Raticate.
AIPerformScriptedTurn:
...
ld a, DUELVARS_ARENA_CARD
call GetTurnDuelistVariable
+ call GetCardIDFromDeckIndex
@@ -366,53 +323,51 @@ AIPerformScriptedTurn: ; 1483a (5:483a)
.retreat
call AITryToRetreat
ret
...
...
```
## AI does not account for Mysterious Fossil or Clefairy Doll when using Shift Pkmn Power
## AI does not use Shift Pkmn Power properly
The AI misuses the Shift Pkmn Power. It reads garbage data if there is a Clefairy Doll or Mysterious Fossil in play and also does not account for already changed types (including its own Shift effect).
**Fix:** Edit `HandleAIShift` in [src/engine/duel/ai/pkmn_powers.asm](https://github.com/pret/poketcg/blob/master/src/engine/duel/ai/pkmn_powers.asm):
```diff
HandleAIShift: ; 22476 (8:6476)
...
.CheckWhetherTurnDuelistHasColor ; 224c6 (8:64c6)
HandleAIShift:
...
.CheckWhetherTurnDuelistHasColor
ld a, [wAIDefendingPokemonWeakness]
ld b, a
ld a, DUELVARS_ARENA_CARD
call GetTurnDuelistVariable
+ ld c, PLAY_AREA_ARENA
.loop_play_area
ld a, [hli]
cp $ff
jr z, .false
push bc
call GetCardIDFromDeckIndex
call GetCardType
- ; in case this is a Mysterious Fossil or Clefairy Doll card,
- ; AI might read the type of the card incorrectly here.
- ; uncomment the following lines to account for this
- ; cp TYPE_TRAINER
- ; jr nz, .not_trainer
- ; pop bc
- ; jr .loop_play_area
-; .not_trainer
+ cp TYPE_TRAINER
+ jr nz, .not_trainer
+ pop bc
+ jr .loop_play_area
+.not_trainer
- call GetCardIDFromDeckIndex
- call GetCardType ; bug, this could be a Trainer card
+ ld a, c
+ call GetPlayAreaCardColor
call TranslateColorToWR
pop bc
and b
jr z, .loop_play_area
; true
- jr z, .loop_play_area
+ jr nz, .true
+ inc c
+ jr .loop_play_area
-; true
+.true
scf
ret
.false
or a
ret
...
...
```
## Challenge host uses wrong name for the first rival
When playing the challenge cup, player name is used instead of rival name before the first fight, as seen here: https://www.youtube.com/watch?v=1igDbNxRfUw&t=17310s
**Fix:** Edit `Text0533` in `text6.asm`:

View File

@@ -1,4 +1,4 @@
BoosterSetRarityAmountsTable: ; 1e4d4 (7::64d4)
BoosterSetRarityAmountsTable:
; db energies, commons, uncommons, rares
; commons + uncommons + rares needs to be equal to 10 minus the number of energy cards
; defined in the pack's data below; otherwise, the number of cards in the pack won't be 10.

View File

@@ -133,9 +133,7 @@ SetUpBossStartingHandAndDeck:
; expectation: return carry if card ID corresponding
; to the input deck index is listed in wAICardListAvoidPrize;
; reality: always returns no carry because when checking terminating
; byte in wAICardListAvoidPrize ($00), it wrongfully uses 'cp a' instead of 'or a',
; so it always ends up returning in the first item in list.
; reality: always returns no carry
; input:
; - a = deck index of card to check
.CheckIfIDIsInList

View File

@@ -181,14 +181,6 @@ AIProcessRetreat:
and ~AI_FLAG_USED_SWITCH ; clear Switch flag
ld [wPreviousAIFlags], a
; bug, this doesn't make sense being here, since at this point
; Switch Trainer card was already used to retreat the Pokemon.
; what the routine will do is just transfer Energy cards to
; the Arena Pokemon for the purpose of retreating, and
; then not actually retreat, resulting in unusual behaviour.
; this would only work placed right after the AI checks whether
; they have Switch card in hand to use and doesn't have one.
; (and probably that was the original intention.)
ld a, AI_ENERGY_TRANS_RETREAT ; retreat
ld a, AI_ENERGY_TRANS_RETREAT
farcall HandleAIEnergyTrans
ret

View File

@@ -171,16 +171,6 @@ AIPerformScriptedTurn:
ld e, FIGHTING_ENERGY
call AIAttachEnergyInHandToCardInBench
; this is a bug, it's attempting to compare a card ID with a deck index.
; the intention was to change the card to switch to depending on whether
; the first Machop was KO'd at this point in the Duel or not.
; because of the buggy comparison, this will always jump the
; 'inc a' instruction and switch to PLAY_AREA_BENCH_1.
; in a normal Practice Duel following Dr. Mason's instructions,
; this will always lead to the AI correctly switching Raticate with Machop,
; but in case of a "Free" Duel where the first Machop is not KO'd,
; the intention was to switch to PLAY_AREA_BENCH_2 instead.
; but due to 'inc a' always being skipped, it will switch to Raticate.
ld a, DUELVARS_ARENA_CARD
call GetTurnDuelistVariable
cp MACHOP ; wrong

View File

@@ -532,9 +532,6 @@ DetermineAIScoreOfAttackEnergyRequirement:
; this is possibly a bug.
; this is an identical check as above to test whether this card is active.
; in case it is active, the score gets added 10 more points,
; in addition to the 20 points already added above.
; what was probably intended was to add 20 points
; plus 10 in case it is the Arena card.
ldh a, [hTempPlayAreaLocation_ff9d]
or a
jr nz, .check_evolution

View File

@@ -677,15 +677,7 @@ HandleAIShift:
jr z, .false
push bc
call GetCardIDFromDeckIndex
call GetCardType
; in case this is a Mysterious Fossil or Clefairy Doll card,
; AI might read the type of the card incorrectly here.
; uncomment the following lines to account for this
; cp TYPE_TRAINER
; jr nz, .not_trainer
; pop bc
; jr .loop_play_area
; .not_trainer
call GetCardType ; bug, this could be a Trainer card
call TranslateColorToWR
pop bc
and b

View File

@@ -2365,11 +2365,6 @@ AIDecide_ProfessorOak:
add $0a
ld [wce06], a
; this part seems buggy
; the AI loops through all the cards in hand and checks
; if any of them is not a Pokemon card and has Basic stage.
; it seems like the intention was that if there was
; any Basic Pokemon still in hand, the AI would add to the score.
.check_hand
call CreateHandCardList
ld hl, wDuelTempList
@@ -4634,15 +4629,6 @@ AIDecide_Revive:
jr z, .no_carry
ld b, a
call LoadCardDataToBuffer1_FromDeckIndex
; these checks have a bug.
; it works fine for Hitmonchan and Hitmonlee,
; but in case it's a Tauros card, the routine will fallthrough
; into the Kangaskhan check. since it will never be equal to Kangaskhan,
; it will fallthrough into the set carry branch.
; in case it's a Kangaskhan card, the check will fail in the Tauros check
; and jump back into the loop. so just by accident the Tauros check works,
; but Kangaskhan will never be correctly checked because of this.
cp HITMONCHAN
jr z, .set_carry
cp HITMONLEE
@@ -5906,13 +5892,6 @@ AIDecide_PokemonTrader_PowerGenerator:
jr c, .find_duplicates
; bug, missing jr .no_carry
; since this last check falls through regardless of result,
; register a might hold an invalid deck index,
; which might lead to hilarious results like Brandon
; trading a Pikachu with a Grass Energy from the deck.
; however, since it's deep in a tower of conditionals,
; reaching here is extremely unlikely.
; a card in deck was found to look for,
; check if there are duplicates in hand to trade with.
.find_duplicates