Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# AI for a 2D character

Posted on 2011-03-18
Medium Priority
908 Views
I am new to game programming and would like to implement a 2d java applet game in which a person will compete with an hero  (with AI)  to collect all the golds in a platform without being detected to creatures.  The basic game scenario  is shown in the image (without the human character included). In the game:

-There are creatures moving on their path (red line) with different speeds and moving to opposite directions
- Both the creatures and the hero (AI) will have line of sight but hero's line of sight is larger than the creatures'.
-If any of the character (human or hero(ai) ) gets into creatures' line of sight it loses.

My question is  how can I make the hero collect all the golds in the map by reacting to creatures (hiding,direction changing etc.) without being detected by creatures.is it hard to implement this kind of ai? Do I also need to implement a path finding algorithm, can't I give the route to him, if so how?Can you recommend me algorithms, examples etc.?

Thank you
0
Question by:BitHunt
• 3
• 3
• 2

LVL 12

Expert Comment

ID: 35167647
Are all of the levels going to be circular?
0

LVL 12

Expert Comment

ID: 35167736
Does the hero AI know when they player takes some gold, so that it ignores the areas where could has been taken by the player.

Do the creatures move consistently?  I understand they aren't the same speed, but do they stop, or change directions?

From the diagram it looks as though the hero should follow the same path as the creatures.  The main path would have connected paths that lead to the gold.  The AI moves along the main path until it reached one of the connected paths.  It's decision about what to do is based on the positions of the creature on the path and the distance/time to the available gold.
0

Author Comment

ID: 35168220
-An answer for rectangular structured  levels is perfectly fine. I think i should start with that since it seems easier.

-Hero AI and the player will have their own golds with different colors. They can't take each others golds.

-Creatures move consistently, they can randomly stop, wait for a couple of seconds and continue in the same direction  (it doesn't change its direction)

Thank you
0

LVL 37

Accepted Solution

TommySzalapski earned 2000 total points
ID: 35181690
Any kind of AI is usually difficult. Since you are new to it, I would recommend starting with something easy and making it more complicated as you go. You could take each approach and work it into a difficulty level. (So the first, simple approach is "Easy" and when you add some more intelligence, make it "Hard").
The first thing I would do is just use structured levels and draw a fixed path for the hero. Then he just looks and waits until the coast is clear (can't see an enemy) before moving. That could be the entire first AI step.
The next step would be to have the hero go different directions based on where the enemy is.
0

Assisted Solution

BitHunt earned 0 total points
ID: 35185239
I think I'll be implementing A* algorithm and keeping the goal points (gold places) in a list and also visit them sequentially. To implement an ai that you recommend, after getting a gold I think I should stop in the entrance of the room  (it can be another goal point for A* I guess) and   check if the guards are there or not. If not I'll continue to next gold place. After deciding to  move to next gold place ( on my way to next gold place) if I detect a guard  I should go and hide to last visited goal point (entrance) and continue like that. Is it an ok solution?
0

LVL 37

Assisted Solution

TommySzalapski earned 2000 total points
ID: 35201018
That would certainly work. To make the AI better, you could have the hero have a variable speed and let him follow the enemy out of the enemy's sight range, but that would be for a more complicated solution.
0

LVL 37

Expert Comment

ID: 35729741
Sorry, DHaest, I missed your first comment when you made it. http:#a35181690 gives a good solution to the original problem and http:#a35201018 answers the askers most recent question quite fully.
0

LVL 12

Expert Comment

ID: 35731951
I wish to support TommySzalapski's solution.  If I had more time I would posted a more complete description of a very similar idea.  BitHunt's answer (using A*) will work, but it's neither necessary or especially effective in this case.  A case of sledgehammer to crack a nut, final result is a smashed nut.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Six Sigma Control Plans
###### Suggested Courses
Course of the Month10 days, 16 hours left to enroll