This is for my board game. I am now at the final stage before it can be considered a working prototype. This is also the hardest stage: creating the computer behavior.
I've created AI systems in the past, and computer behavior is an area that greatly fascinates me. Here are my notes regarding how the computer should behave.
Computer program selection order:
1. Computer uses programs in order of highest range (ComputerPrograms.Range) to shortest range.
Priority order:
1. Destroy player programs if they are in range and capable of being killed by a computer program this turn.
2. (Default) Move toward and attack the nearest player program.
Local variables:
TargetPlayerProgram: The UID of the player program targeted by the computer program.
Destruction potential check:
1. Loop through each player program and compare its active parts (PlayerPrograms.PartsActive) to the currently selected computer program's damage (ComputerPrograms.Damage).
2. If a player program is able to be killed by the currently selected computer program (PlayerPrograms.PartsActive = ComputerPrograms.Damage), then set its UID to TargetPlayerProgram.
Highlight all movable squares (call function "HighlightMove") and pick the highlighted square closest to the player program, then do a range calculation for X and Y (squares are 64px in size, so closest square X + ComputerPrograms.Range * 64 >= PlayerPrograms.X OR PlayerProgramParts.X; repeat for Y).
3. If no player program is able to be killed this turn, proceed to 'Default behavior'
4. If range calculation succeeds, then move computer program to nearest square and attack.
5. If range calculation fails, then proceed to 'Default behavior'
Default behavior:
1. Loop through each player program and compare distance along X and Y axes (distance(PlayerPrograms, ComputerPrograms)). Set closest player program to TargetPlayerProgram.
2. Move computer program to the closest square.
3. Try to attack the player program. Call 'AttackHighlight' and check if target program is overlapping an attack indicator.
If so, then deal damage. If not, then do nothing (set ComputerPrograms.Finished = true).
This thread is intended to keep all my questions in a single location instead of spreading them out over several 'How To' posts in the forum.
First issue: How do I pick the program with the highest range? In the case of conflicts, I am seeking to just pick randomly among the ones that are tied for the highest.
<img src="http://i.imgur.com/kzSfBUF.png" border="0">
BoardGame.capx
Basically you have to compare the variable ComputerPrograms.Range. ComputerPrograms is a family, and Range is a family instance variable. I'm having trouble figuring out how I would compare family members against each other.