jQuery in Action, 3rd edition
The moose likes Game Development and the fly likes Artifical intelagene for fighting games Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Artifical intelagene for fighting games" Watch "Artifical intelagene for fighting games" New topic

Artifical intelagene for fighting games

Adam Bell

Joined: Apr 10, 2009
Posts: 3
Hello im new here and need somehelp. i am working on a project and need soem help

I woul like to know how tlo program the cpus charicter to make its own desition. unfortuanatly the way i have tryed with k=logic bjects makes it to good at working out how it could win.Could you please tell me how i make it so that the computrer makes good desitions but also makes bad desitioions. Ive trryed a artifical intelegence object and logic operaters but no luck

If someone could tell me the basics so i can get started i would be highly greatful

Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
Well if you've already got a bot that is "too good" to beat then it sounds like you've got the logic in place already. As for making him beatable I would add 3 parts to the AI's decision process.

1) I would add a delay variable called thinkTimeMin that would block the bot from making a new decision (ie attack/block) until a certain amount of time passed. I am assuming your using a state engine design for the decision process? I would edit the method that changes the bot move from upperAttack, block, etc to make a check against the thinkTimeMin to make sure the bot isn't impossibly skilled. As you get further in the game and the bots get more skilled just decrease the think time or give them more moves or whatever. Remember Street Fighter 2 for Super Nintendo, one of the most popular fighting games of all time? The beginning enemies are so easy... you would do a jump kick and they would still be firing a shot at you, but by the end then would be flying around the screen stopping just about anything you could throw at them.

2) Your bot is probably making choices based off what the player is doing... for example: if player is throwing a high punch then do low kick and other rules. I would make a freeWill setting that is a % chance that the bot will do a move that is not based on anything the player is doing. Obviously it can't be just a random move or he'll be running against the wall out of nowhere or start healing when he's not hurt so you'll have to decide how to implement it but I would keep the % under 50% but not to low either and I would keep lowering it as the player got further in the game.

3) The last thing I would add/change is to do checks against attacks vs defence moves. You don't want your bot to be 100% agressive or 100% defensive, both will make players angry and would not be fun. Each time an attack or defense move is thrown I would add or subtract to a variable called agressiveness..... when your bot makes a new decision you can check to see if the number is too negative (too agressive) or too high (too defensive), Idealy you would want the number to stay near 0 but not be on 0 exactly. As the player gets further you could allow the number to go more negative then before to make the bot choose more agressive moves.

Depending on your engine your bot is most likely making 100's of decisions a second... remember that doing nothing is also an option sometimes. If your on one side of the screen and he's on the other there's nothing wrong with the bot just standing there waiting for a few instead of going crazy

I hope that gives you some ideas.

~Currently preparing for SCJP6
Adam Bell

Joined: Apr 10, 2009
Posts: 3
Thank you for the sagestion. its a start i was wondering if i could do it like this

//Logical ioperation object
logicfinder logic = new Logicaloperation();
timetothink = new variable();
timetothink = animationplay.0;
System.testfor(playerkeyinput) {
if (player move = true) {
cpu.dologicalmove or unlogicalmove();
System.randomise(cpu.logicalmove or unlogicalmove) {
else if (distance == > 2 matrixgrids) {
timetothink = true();
when (case == player.moving) {
randoimselogical and unlogicalActions.true;
if (easyselected = true) {
if (lifebar == < 30%) {
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
Looks good. I tend to avoid randomize though.... I like my games to be realistic and things are rarely ever random irl. GL
I agree. Here's the link: http://aspose.com/file-tools
subject: Artifical intelagene for fighting games
It's not a secret anymore!