[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

AI for a 2D character

Posted on 2011-03-18
13
Medium Priority
?
898 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 37

Accepted Solution

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

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 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

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

In this post we will learn different types of Android Layout and some basics of an Android App.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
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…
Introduction to Processes

656 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