# AI turn based targetting

Hello all,

so i know this is quite a broad question but i will break down what i am asking the best i can.

so each team has 3 balls. You take it in turns and the goal is to knock all 3 of the opposite team off of a podium. On your go, you swipe to pull back, choose your power and aim (similar to say angry birds) then you let go to fire your ball at the opponent. Then on the AI’s go, it picks one of its balls to fire at one of your balls to try to knock it off. game is over when one team has been eliminated. I’ve attached a terrible picture below to try and add a visualization.

any help is appreciated

Do you have an actual question? Are you having trouble implementing some specific part of this?

sorry mate, not sure what happened to the other half of my post?

yes so i can do the turn based side of things, what i cant do is the AI choosing which ball it wants to use on its turn and which of my balls it wants to target to knock off and it also choosing the power and aiming side of it. i’ve no idea how to go about it and all i can find online is AI follow or AI shooting gun information.

any help is appreciated and welcome

Well you need to decide on some kind of heuristics for the AI. This can be anything really. Here’s some examples (I == the AI). I would probably split this up into at least three parts:

Part 1 would be picking which of the AI’s own balls it should use. You could use a bunch of different heuristics for this:

• pick random AI ball
• Pick AI ball that is closest to any edge
• Pick AI ball that is closest to any player ball
• Pick AI ball that is closest to the player ball that is closest to any edge
• Pick balls in a round-robin order. e.g. turn 1 use ball 1, turn 2 ball 2, turn 3 ball 3, turn 4 ball 1, etc…

Part 2 would be picking which of the player’s ball to shoot at. Again, there are infinite different heuristics you could use. Here are some examples:

• Pick a random player ball
• Pick the closest player ball to the AI ball
• Pick the closest player ball to the AI ball that is not obstructed by any other balls
• Pick the player ball that is closest to the edge that is not obstructed by any other balls

Part 3 would be actually lining up the shot. I.e. choosing exactly where the AI will aim and how much power it will use. Again, there are more heuristics here to choose from:

• Use a random amount of power and shoot in a random direction
• Use a medium amount of power and shoot directly at the center of the player’s ball
• Use a varying amount of power based on how far away the player’s ball is from the chosen AI ball, and aim directly for the center of the player ball
• Aim for the part of the player ball that will reflect the player ball towards the nearest unobstructed edge to the player’s ball. Use a varying amount of power based on how far away the player’s ball is.

You can also do things to reduce the difficulty like give the AI a random chance to miss their shot.

This is just a few ideas I came up with off the top of my head. You need to decide exactly what it is you want your AI to do. Once you’ve decided that, then you can think about coding it. But it starts with the defined behavior.

The other thing to think about it maybe you want different AI difficulties. In this case you may choose different behaviors for any or all of the above for different levels of difficulty.

my original thought was a round robin type selection for the AI ball but i think a random choice will add an element of not being able to plan your shots head knowing which ball will strike next.

so Random AI ball choice
Random Target
Random Power

I hope to implement a stat based system for the difficulty including ball weight, ball power and different types of balls so a smaller ball will be more accurate but not as powerful as a heavy ball but the heavy ball wont be as accurate etc.

well thats my plan anyway. got to try and implement it now haha