Angus-Fan / TurnBasedStrategyGame

My Unity project for a turn-based strategy game. This is an 'open-source' version which has the basic code for the game's core functions.
MIT License
195 stars 55 forks source link

AI enemy #3

Open Yi-noah opened 4 months ago

Yi-noah commented 4 months ago

Hello,I hope that the other team (red or blue) can automatically find the player's soldiers and attack, instead of two players manipulating each other. Do you have any good ideas or opinions?

Angus-Fan commented 4 months ago

Hello Yi-Noah, sorry it's been a while since I've taken a look at this code. I specifically remembered not trying implement it because it would be a bit too much for my timeline. However if you plan on trying to implement it I think these steps may help you start.

  1. Create an Enum to distinguish between the two players (real players / CPUs)
  2. You can set this value, when switching between turns.
  3. Once it's the CPU's turn, gather all usable units for the CPU.
  4. For each unit, find the closest enemy unit and then find the closest tile that the unit can move to / attack if they're close enough.

There's probably a lot of nitty gritty details that I'm skipping, however I think this would be a good start into looking at how to implement such behavior. Best of luck!