I'm working on a 2-player puzzle game where each player can swap any block around on their grid, and then click a block to destroy it and any same-colored blocks attached to it. I'm having trouble creating the events to make a working AI, let alone a believable one.

pfexample.png

On the left, player 1's grid. On the right, the computer's grid.

The player is able to swap and destroy blocks on their grid just fine. I've managed to get the 'computer' to move their counter/block-selector icon around their grid aimlessly enough via random(), and when the computer finds a 'connected' block then it destroys it and moves on. Simple enough, but I can't get my head around 'hunting' down combinations of blocks, or deciding when to swap blocks on the grid - general pathfinding stuff, maybe?

Things I'm having trouble with at the moment or may need help with in future
  • getting a list of the combinations on the grid, information to use in future events - this may involve arrays, but I have no practical experience with these
  • from there, selecting from one of the combinations; either picking the lowest and adding to it via swapping blocks around, or picking the highest and swapping more blocks in or just destroying it, etc
  • actually making the icon move towards the target block, e.g. having a target destination and receiving instructions to making your way explicitly towards it, sort of like a bullet homing in on a target


Things I should be able to manage
  • swapping blocks - deciding what block types on the field should be targeted and made into pairs or combos (deciding is one thing, but moving and targeting, like above, is another)