Solved

AI for a 2D character

Posted on 2011-03-18
13
871 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
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…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now