This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Artifical intelagene for fighting games

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Adam Bell
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks good. I tend to avoid randomize though.... I like my games to be realistic and things are rarely ever random irl. GL
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic