Solved

AI for a 2D character

Posted on 2011-03-18
13
880 Views
Last Modified: 2013-12-26
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 my plan, hero, creatures
0
Comment
Question by:BitHunt
  • 3
  • 3
  • 2
13 Comments
 
LVL 12

Expert Comment

by:satsumo
ID: 35167647
Are all of the levels going to be circular?
0
 
LVL 12

Expert Comment

by:satsumo
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

by:BitHunt
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 37

Accepted Solution

by:
TommySzalapski earned 500 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

by:BitHunt
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

by:TommySzalapski
TommySzalapski earned 500 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

by:TommySzalapski
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

by:satsumo
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question