Showing posts with label failure. Show all posts
Showing posts with label failure. Show all posts

Tuesday, October 4, 2011

Elephants Are Scary

Mapped and pathed to the Galura fight.


Galura beats the tar out of us right now. Granted, we're running a group of half-naked level 6 unskilled brain-dead Monks, but it's still a pretty sad fight.

I wanted to see whether something better than starting equipment would tip the scales, so I worked out the code for shop interactions and bought four Training Gis. We can now buy and sell with impunity, but unfortunately it's fairly game specific code for both FF4 and FF5, and I haven't come up with a nice way to generalize it. Some of it could be moved off into configuration, but there's a point at which that stops making sense. For example, in FF4 you choose the quantity of items you want to buy/sell before you choose the item. In FF5, you choose the item first and then the quantity. There's a half-dozen other little differences surrounding this. This sort of procedural difference doesn't convert very nicely into configuration. I will probably end up building a framework for attaching game-specific code to games on startup so the code is cleaned up a bit.

Anyway, the better armor did help - dropped Galura's hits from 130s to 90s - but it's not enough. He just goes nuts in the second half of the fight every time you hit him, and that's all we're ever doing. Even if I wanted to try the Phoenix Down binge strategy, at 1000 GP a pop Phoenix Downs are prohibitively expensive. I could only buy 3 of them now without level grinding. I could also just level grind a bunch until we can stomp him, but it's not worth it; this is a sufficiently compelling problem to solve more intelligently.

Looks like it's time to start implementing Job and Ability support. Galura exclusively uses physical attacks, so it would be a great place to test a Knight Cover/Guard strategy. We'll see if we need it; to start with, I'll probably give everybody Mantra and have them use that when they're low on HP.

It's going to take a while to get this stuff up and running. From a top-level perspective, I want to have the following:
  • A SetJob:[CharacterName]:[JobName]:[ExtraAbilityName]:[etc] command. Examples: "SetJob:Bartz:Knight:Counter" or "SetJob:Lenna:Freelancer:X-Fight:MagicSword".
  • A SetAbility:[CharacterName]:[AbilityName] command.
  • An UntilCharacterReachesJobLevel:[Number] level grind exit condition. Might choose to add UntilCharacterMastersJob later on.
  • An UntilCharacterLearnsAbility:[AbilityName] level grind exit condition.
In addition to all the other internals the borg needs to support this, I also need to be able to read what a character's current battle commands are; a static config file isn't going to cut it anymore. I might as well see if I can sort that out for FF4 while I'm at it.

Later on I may need to add some more sophisticated code to automatically manage job and ability switching. At the very least, I want to avoid situations where three of the characters are spinning their wheels in a level grind while we wait for one to learn a specific skill.

Monday, September 5, 2011

Packrat Intervention

Results of trial run: Inventory management problem.

Details: Inventory was full when we picked up the second Defense Ring. The borg got stuck in the post-battle loot collection screen because there was no space for our loot.

Solution: Added about a dozen more items to the garbage lists. It's really a shame to lose a run because our inventory filled up.

It Was Bound to Happen

Results of trial run: TPK.

Details: Lost to the White Dragon in the Lunar Subterrain. I was wondering if this would ever happen.


After his usual Maelstrom toward the end of the fight, he managed to hit each character that was queued up to use a Phoenix Down right before they used it a few times in a row. Once we got down to 2 live party members, we struggled for a bit to stay afloat and then lost.

In a lot of these fights there seems to be a tipping point at 3, or sometimes even 2 dead party members. If we hit that point and we don't pull it together in the next few actions, there's a good chance the party will go down. Will have to think about that some more; maybe we can add a conditional that checks how many party members are dead and takes more drastic action. Ashura seems like a good choice.

Anyway, part of the problem here is that the White Dragon casts Slow a lot in the lead-up to Maelstrom, which gives him time to pick off healers. Well shoot, we can do something about that, can't we?

Solution: Added a one-time casting of Slow to the default end-game battle strategy.

Sunday, September 4, 2011

Race Conditions

Results of trial run: Battle state bug.

Details: Got stuck in Edge's Ninjutsu menu during the fight with Ashura.



The locations in memory that store character stats in battle, like current HP and MP, don't change at exactly the same time as they do on-screen. When an enemy attacks you or you heal yourself, you have to wait for the whole animation to be complete before you see the new balance for your hit points. However, in memory, this balance has already been changed to reflect the new value when the animation starts. There's probably some other location in memory that stores the displayed HP/MP values separately, but I haven't tried to track it down.

The consequence of all this is that the borg makes decisions based on what it sees for character HP and MP, which may not be reflected in the game interface yet. Most of the time this is fine, but if you time it just right, you can get into a situation where a character is given orders to cast a spell right before we see another character use an Ether on them, because the borg thinks they have enough MP.

This brings us to the other half of the problem: once you're in the menu to choose a spell, which spells are disabled and the available MP won't update until you back out of the menu and choose it again. This brings us to the screenshot above. The borg thinks Edge has enough MP to use Raijin because Cecil is using an Ether on him now, but he makes it into the Ninjustu menu before the Ether animation is finished. The borg still thinks it can cast Raijin, and technically it's right, but it doesn't know to back out of the menu and try again, so it just sits there mashing the A button.

Solution: There's at least two ways I could approach this problem: I could find where the displayed HP/MP values are stored in memory, or I could figure out how to tell if a menu option is disabled, and if our choice is disabled we bail on the command and choose a different one. I chose the second option; that may solve a few other potential problems as well. I spent some time digging around the game's RAM and where spell statuses are stored for battle. There's some other interesting information there that might be worth deciphering in the future.

Saturday, September 3, 2011

Second Verse, Same as the First

Results of trial run: TPK.

Details: Lost to the monster that came from a trap door in the Sealed Cave. We went into the fight with all members nearly dead. Starting to sound familiar? I added more Recovery statements in for the Sealed Cave, and I'm just about ready to give up and add a Recovery interrupt.

Almost.

Take One for the Team

Results of trial run: TPK.

Details: Lost while fighting two Red Dragons for the Crystal Gauntlets.


We did come into the fight with one party member dead and one nearly dead, which put us at a serious disadvantage. I don't think that was what killed us, but I went back and put a couple more Recovery commands in our command queue for looting the Lunar Subterrain.

The problem here was that we managed to get 3 party members dead with 1 Red Dragon left, and spent all of our time bringing them back to life to get lasered down again. Occasionally we'd pull back up a bit, but it just wasn't quite enough.

The borg has a single battle strategy for this whole section of the game, and so far it's worked pretty well. Up until now, Rosa's part of the strategy has followed something similar to what we've done for most of the game:
  • If someone's dead, bring them back with Life or a Phoenix Down.
  • If someone's near dead, heal just them.
  • If someone's just kind of hurt, heal everybody.
For most of the end game boss fights, I wrote a custom strategy to manage them instead of using the default settings.

This strategy doesn't work for end-game stuff, and here's why: the real threats to the survival of the party are attacks that hit everybody, not big hits on single party members. We can handle one party member dying at a time pretty well. We get in trouble when a big group of them go down at once because they were near dead to begin with and the party got hit with an AOE.

Solution: Changed the strategy for this section. Now, if Rosa's going to do any healing, it's Cure 3 on all allies if a live party member is below 70% HP, or use a Phoenix Down otherwise. No more Cure 3 on individuals.

Back to the Training, Yeah!

Results of trial run: TPK.

Details: Lost to Zeromus.


This is a great example of a fight where a lot of little things could have gone better, but the screenshot above illustrates the final mistake we made.

Currently, the DeadAlly target (as well as most of the other options that target allies) will choose the first character in the party that meets the conditions, starting from the top of the list. In our current party arrangement, that means that if 4 characters are dead and one of them is Rosa, Rosa will be the last one brought back. This is very, very bad planning.

I could write some code that lets me prioritize which party members get raised first, but I'd like to avoid adding more code if it's not necessary to get what we need, and in this case, it's not; we can just arrange the party so the most important characters to raise are at the top.

Solution: Added commands to rearrange the party before the final battle to this order, from top to bottom: Rosa, Cecil, Kain, Edge, Rydia. I also made a few more adjustments to the battle strategy.
  • Rosa no longer fires off a one-time Shell on all allies. I think it might actually not help at all against Big Bang. This has been replaced with a one-time Haste on herself.
  • Kain now has a one-time command to use Spiderweb (Slow effect item) on first target. Ideally, we'd reapply Slow every time Zeromus wipes statuses, but I haven't written any code to determine enemy statuses, and I don't want to. That flirts with the boundary of what a human player would be able to tell about an enemy, and I'm trying to build this borg to only use information available to a human player. Still, getting Slow out once gives us a bit of an edge for the first part of the fight.
  • If all live party members are above 70% HP and someone is dead, Rosa will cast Life 2 on them instead of using a Phoenix Down (unless she doesn't have the MP; then she'll use the Phoenix Down). It takes a bit longer to cast than to use an item, but this is a fight where having someone go from dead to full HP is very useful.
  • If everyone is alive and at least one party member is below 30% HP, Rydia will summon Ashura instead of Bahamut. A bit of a long shot move since Ashura is so unpredictable, but in those crevices where the fight isn't faring well, it can help quite a bit. Might choose to bump this up above using Phoenix Down, but probably not: If Rosa is dead, I don't want to cast Ashura and hope that maybe she'll bring everybody back to life. I want Rosa back on her feet.

Valor of the Royal

Results of trial run: Battle state bug resulting in TPK.

Details: Lost during the level grind at Damycam, of all places.


I probably should have anticipated this the last time we had a problem with Gilbert. His default command here is to Fight, but he ran and hid because he's low on HP and now Show is the only option. So the borg is just pressing up repeatedly here until that one Mini Mage whittles the other two party members down. Then Gilbert comes out, gets off one attack, and succumbs to Hold and a couple more shots.

Solution: Added a top-priority conditional for Gilbert to come out of hiding whenever he has the Hide status for all parts of the game where we have Gilbert. It's a bit silly watching him run back and forth, but it means the other party members can take actions while Gilbert is running laps.

Friday, September 2, 2011

A Curious State

Results of trial run: Battle state bug.

Details: In the Ashura fight, Rosa kept rapidly switching between deciding to cast Reflect a second time and deciding that our once-per-battle command had already been used and she needed to choose another.

I'm not entirely sure why this was happening. As soon as I put logging statements around our used_commands counter, it stops happening and everything behaves as it should. I have a shred of a guess about using += or -= on a std::map<std::string, int>, but it still doesn't make any sense to me.

"Solution": Changed to using value = value + 1 instead of value += 1, and it stopped happening. Not at all convinced that this is the end of this particular problem, but I'm not sure what else to do with it at the moment.

Thursday, September 1, 2011

Not a Grenade, Horseshoe, or the Government

Results of trial run: TPK.

Details: Lost to Zeromus fight. The core of the problem was that Rosa was using a Phoenix Down when she should have been casting Cure 4. This wasn't a problem before because we had Cure 4 as a higher-priority conditional.

Solution: Added a conditional Cure 4 on top of the default Cure 4; now if any live party member is less than 70% on HP, Rosa will cast Cure 4, even if someone is dead. I ran this strategy several times to see how it works out, and I'm feeling pretty good about it.



While I was at it, I thought I would make Edge pull his weight, so I added support for the Dart command and added conditionals to have him throw all of our expensive weapons and Hellwinds during the fight.

Meaningless

Results of trial run: TPK.

Details: Died somewhere in Upper Babil running from fights. Probably was too weakened after an unfortunate SteelGolems fight. Yes, I need more Recovery calls during that section, and no, I still don't want to write a Recovery interrupt.

Solution: Using a tent soon after the SteelGolems fight, and sprinkled some Recovery calls from there until we butcher Edge's parents.

Wednesday, August 31, 2011

Bringing a Knife to a Pudding Feed

Results of trial run: TPK.

Details: The borg got into a fight it thought it was supposed to win in the Tower of Babil. This might have been fine, but Rydia was set to defend instead of summon, and we got into a fight with three of those white marshmallow things that are essentially immune to physical attacks. Lost at the end of a long, embarrassing fight.



The real problem here was that the borg thought it was supposed to fight in the first place. It had just entered a room with a monster-in-a-box treasure chest. The convention up to this point has been: Walk into a room with a monster-in-a-box, switch from running to fighting, open the chest and fight, switch from fighting to running. Most of the time this works, even though it picks up the occasional extra fight on the way to the chest. But if we get into one of these fiddly fights that require a specific strategy, that could put us in trouble.

Solution: Our GetLoot:[Item Name] and GetAccessibleLoot commands now switches to fighting mode when opening a treasure chest, and back to whatever our strife specibus was before after the treasure chest is open. Not only does this avoid trying to win unnecessary fights, but it also cleans up our command queue in a few places.

Tuesday, August 30, 2011

Couldn't You Just ... You Know ...

Results of Trial Run: Battle state bug.

Details: We were fighting one of the Behemoths on the way to Bahamut, and Rosa ran out of arrows. Her default command was still Aim, and we don't know how to cancel out of trying to use disabled menu options, so we just sat there while Rosa fiddled with her bow trying to figure out how to Aim with no arrows.

Solution: I don't feel like solving the disabled menu option problem; we're already avoiding it when a caster is unable to cast spells. Just changed Rosa's default command to Defend in this section.

Sleeping Under the Stars

Results of trial run: Inventory management problem.

Details: We had no tents left when we went to use one after the first Scarmiglione fight. I have no idea how this happened, but it's easy to fix; we're buying two tents earlier on now.

Really More of a Taupe Elf

Results of trial run: TPK.

Details: Lost to the Dark Elf. Tellah's first Tornado in the second stage failed. The second Tornado connected, but again, we were too busy using Phoenix Downs to deliver the final blow. We really need someone dedicated to striking during the second stage.

Solution: Cecil no longer casts Cure on Tellah during the second stage of the fight. Since we're still Covering him, this should work okay.

Der Dunkelelfen

Results of trial run: TPK.

Details: Lost to the Dark Elf.


Everything goes great during the first stage. Then he turns into a dragon and hits Tellah for more than his maximum HP. We do eventually get him alive long enough to deliver a Tornado, but then everyone is too busy using Phoenix Downs to poke the Dark Elf once in the ribs, and we get Dark Breathed down.

Tellah going down in one hit made me really sit back and reconsider what needs to happen to make this a reliable fight. I still really, really don't want to have to add another level grind before the the Golbeze fight.

Solution: So what else can we do? Well, maybe we can increase his armor rating. I added some commands back in Baron to buy him a Kenpou and Bandanna; that raises his armor a little bit, but not by a whole lot. However, there's another solution that I don't normally consider; Cecil's Cover command. Firing that off once at the beginning of the fight makes Tellah very, very hard to kill in stage two, assuming he isn't near dead from a Tornado in stage one.


A Journey of a Thousand Miles Often Ends Very, Very Badly

Result of trial run: TPK.

Details: Made it all the way to Zeromus and lost.


We simply got Big Banged more than the party can handle. No, stop it, this is serious. The real problem was that I thought I could cut down on MP usage by having Rosa default to Cure 3 and use Cure 4 if anyone is even moderately injured. This is insufficient; without a human behind the wheel or writing some code to estimate when the next Big Bang is coming, we need it to be Cure 4 all the time.
Solution: Rosa's default command is to use Cure 4 on everyone, and the conditional Cure 4 command is gone.

Slow and Steady Wins a Brace

Results of Trial Run: TPK.

Details: Lost against the Giant CPU.


Our strategy up to this point has been for Rydia to spam Bahamut, Cecil and Edge to attack, and Rosa and Fusoya to provide healing. Everyone is on Phoenix Down duty, and Cecil is in charge of using Ethers when casters get low on MP. Most of the time, this works just fine for this fight. The problem comes if the CPU chooses Rosa and Fusoya for its insta-kill attack before bringing it's bits back. If that happens, then we get into a situation where we bring Rosa and Fusoya back just in time to get lasered down by the Attack System, and the rest of the party withers away waiting for a healing spell that will never come.

Solution: After some deliberation, I decided to rewrite the strategy for this fight to the much more boring but much more reliable track: kill just the Defense System and then peck away at the CPU with melee, periodically healing from laser damage. It's boring, but it means the CPU never uses its insta-kill attacks because we never kill the Attack System until the end of the fight.

Packrat

Results of trial run: Inventory management failure.

Details: We tried to buy a Kotetsu for Edge at the Summonville weapon shop, but our inventory was full. Looks like we just got a little bit junk on this run than we normally do.

Solution: Added a SellGarbage command and a SortItems command before buying anything in Summonville. Also, it looks like we weren't loading the mid-game garbage list during the Summonville milestone, so I added that as well.

Monday, August 29, 2011

Traffic Jams

Results of trial run: Pathing/routing failure.

Details: This is where the borg got stuck:


The obvious problem is that our party is trying to walk North, and we've managed to pin an NPC between us and the stairway to the North. However, to really understand everything that's going on here, you're going to need to know more about how FF4 maps and mobile NPCs work.

Every map in FF4 that isn't an overworld map has a byte of layer information for each tile of the map. This layer info helps the game know which tiles you can walk on and when. To help visualize this, here's a picture of the save room in the Antlion's Den:


And here's an ASCII representation of the movement layers of that map:
                                 
   ###                           
  #,,,T#                         
 T,,__,_#                        
 #,,##_#                         
 #,##._.#                        
 #,.....T                        
  #.#.#.#                        
  #..S..#                        
  #.#.#.#                        
  #.....#                        
   ##.##                         
     +                           
                                 
  • Pound signs (#) are layer 0 - obstacles. These are never passable under any circumstances. The capital Ts are actually layer 0 as well, but I've marked them differently because they contain treasures.
  • Periods (.) and commas (,) are layers 1 and 2 respectively. Both can be walked on, but you can't step directly from layer 1 to layer 2 and vise versa. To get between them, you need to step onto layer 3, which is represented here by underscores (_). Layer 3 acts as a connecting layer - you can always step on and off of it.
  • Save points (S) are layer 11, but they are essentially always accessible.
  • Layers 17 and 19 represent transition squares - if you step onto one of these, you'll end up on a different map. I've chosen to mark these with plus signs (+) and greater than signs (>) respectively. Layer 17 is only accessible from layer 1. Layer 19 can be reached from anything.
  • There's one other layer, layer 5, that acts as a bridge layer. You can always step on a bridge layer from layer 1 or 2, but when you leave the bridge you have to step off onto the same layer you entered on. This allows bridges that can be walked over or under, with different rules for where you can walk for each.
So that's how the movement rules work.  Except that that's only how they work for the player, which is where our movement bug comes in.

When the borg chooses a path to a destination and starts moving down it, at every step it checks for NPCs in the way. If someone's in the way, it checks to see if the NPC would get pinned in the players path if we took the next step. If so, it politely waits until the NPC moves out of the way before moving forward. Without this politeness, all too often the borg would get itself into situations like this:


Our destination is the square the NPC is standing on, they have no way to get out of the way, and the borg doesn't know how to solve the situation. The borg eventually gives up and panics.

The problem the borg ran into in this last run is that NPCs don't have the same movement rules as the player does. NPCs are restricted to either layer 1 or layer 2; they can't transition to any layer other than the one they started on, including layer 3. So when you have a map like the top floor of Summonville, whose movement layers look like this:

             ########                  
        #####........#                 
       #.......#####.##                
      T........#   #...#               
    ##..######>#   #...##              
   #...#     #.#######...#             
  #....#     #.......#...#             
  #...#       ######.###..##           
   #.#              T  #....#    
   #_#                 #....#    
   #.T####              ##.#           
   #......#####          #_#           
    #..........#     ####T.#           
    #..........#    #......#           
     ###....>..#   ##......#           
        #......####>#......#           
         ##.####....##.####            
          #_####....##_#               
          #.............#              
           ###.........#               
             #........#                
              ####T###              


...there's a few opportunities scattered about for the borg to pin an NPC in a place that it believes the NPC can escape.

Solution: The borg method that looks for a way for an NPC to escape the player's path, pathToAvoidPlayer(), now starts with all layer 3 tiles on the current map blacklisted. This gets us 99% of the truth for NPC mobility, and should help us avoid any more pinned NPCs.