Days 7 & 8 - Blue vs Red


I got my feet deep into the main issue here: code the AI.
I don't have a lot of experience with AI but I know how they're made, mostly from working with gameplay programmers.

The bad choice that hit me first was that I had designed the game as "Player" vs "Enemy", but actually, it is more something like "Blue" vs "Red", because the AI does the same thing as the player, and therefore shares a lot of the logic: move units, upgrade, attack...etc

I had to remove every instance of "player" and "enemy" in my code and replace them with "blue" and "red" teams.
Then I could use the term "player" to refer to the units of the currently playing team, and "enemy" to refer to units the current team can attack.
The code became much simpler and adding the AI became easier.

Then for the AI, i decided to keep things simple, so I made a list of keys the AI should virtually press this turn.

(constants 'ai-moves-len 16)
'(game 8192 (memstring 1
   ;; a list of keys the IA will press this turn
   ai-moves #xFF #xFF #xFF #xFF #xFF #xFF #xFF #xFF
            #xFF #xFF #xFF #xFF #xFF #xFF #xFF #xFF))

Every turn, the game would populate the list with what seems like the best move, and the AI would just pick every key one by one in the list and press them.

The only thing I had to do now was populate that list correctly....

I also changed the unit list to a fixed size, so that I could add HP and ATK information to each unit, and display them.
I could then finish the attack logic, that removes HP and make the player earn coins for a kill.

Leave a comment

Log in with itch.io to leave a comment.