This site requires JavaScript, please enable it in your browser!
Greenfoot back
m.legere1323
m.legere1323 wrote ...

2011/3/1

Light Cycle AI

m.legere1323 m.legere1323

2011/3/1

#
Can anyone think of any way to approach programming AI into a tron themed light cycle game to make it single player?
JL235 JL235

2011/3/1

#
There are several elements to this. The first thing I would do is just build some helper methods in the Enemy class for simply moving it like 'turnLeft', 'turnRight' or 'turnTowardsPlayer'. Your AI then doesn't need to worry about performing those tasks; it just calls them. This will make the AI easier to write. You can also do similar for detecting possible collisions (like a 'getCollisionDistance' that tells you how far a collision is in front of the enemy) and for tracking the Player (like 'isPlayerOnLeft', 'isPlayerAbove' and so on for right and below). The next thing I would do is to extend the Enemy class with different sub-classes, each implementing a different type of AI. The original version of Pac Mac had multiple AIs and it tends to make the game more fun and varied. You can then offer multiple Enemies in a game, or just use whichever AI works the best. Next for the AI strategies themselves. First you could try a randomly moving enemy that has an internal timer. The timer is set to a random value from say 1 to 5 seconds. When the timer runs out it will randomly turn left, right, or continue straight on. The timer then resets to a new random value and the process repeats. Picking things randomly might sound a little unintelligent, but in some games it can work very well and not seem random at all to the player. A second more intelligent strategy could be to check the difference between the Enemy x and y location, and that of the player. This can tell you which side of the enemy the player is mostly on (above, below, left or right), and then have the Enemy just constantly turn towards the Player as though they are shadowing them. For all AIs I'd also have a bit of sanity code which checks if a wall or another player/enemy is directly ahead, and if so then it randomly moves left or right. You should also include a random chance that the enemy will just continue into the wall (like a 5% or 10% chance) to prevent enemies constantly dodging collisions forever. You can then further improve on this by tracking the distance between the previous turns. If the last turn the AI made was only a few pixels away, then the AI should have a higher chance of failing to avoid the collision on this turn. Just like a real player. I hope you find that useful.
m.legere1323 m.legere1323

2011/3/3

#
"For all AIs I'd also have a bit of sanity code which checks if a wall or another player/enemy is directly ahead, and if so then it randomly moves left or right." This is the trouble I'm having; I'm not sure how to approach this.
wafflepudding wafflepudding

2012/12/14

#
Just commented on the oldest post in Greenfoot history. Feels good.
kiarocks kiarocks

2012/12/14

#
No, topic with id 1 is older.
wafflepudding wafflepudding

2012/12/14

#
oh okay. thanks man I'll go there
You need to login to post a reply.