![]() |
|
Beginner's AI - Printable Version +- Little Fighter Empire - Forums (https://lf-empire.de/forum) +-- Forum: Little Fighter 2 Zone (https://lf-empire.de/forum/forumdisplay.php?fid=7) +--- Forum: AI Scripting (https://lf-empire.de/forum/forumdisplay.php?fid=56) +--- Thread: Beginner's AI (/showthread.php?tid=10240) |
Beginner's AI - T.O.R.N.A.D.O - 02-20-2016 So I tried making a simple and basic AI for a character called Naruto from my mod. Here is the code: Code: int ego(){Now the problem I am getting is - the computer spams J+J+A for no reason. I haven't put anything like that in the ego function and the basic character AI cannot be THAT retarded. So why is he behaving like that? Any thoughts? PS: The id used here is 1. RE: Beginner's AI - Ramond - 02-20-2016 Code: if(lxdist<10 || rxdist<10 && self.mp>100 && random<=30)Most likely this causes it. It's always dangerous to use multiple conditional || and && without proper bracketing, so maybe use more brackets to specify the exact conditions. Currently, seeing how you defined lxdist and rxdist, the following will always hold: lxdist = -rxdist And you have following two conditions: lxdist<10, rxdist<10 But since lxdist = -rxdist: lxdist<10, -lxdist<10 Obviously, one of both is non-positive and therefore always fulfilled, so that || doesn't seem to make much sense anyway. Except if you didn't mean to bracket (lxdist<10 || rxdist<10) like that. Perhaps you meant to use rxdist>10, or forgot to use absolute function on the dist values? RE: Beginner's AI - A-Man - 02-20-2016 For all languages I've encountered, the precedence of `&&` is greater than `||`, so that would be parsed as (lxdist<10) || (rxdist<10 && self.mp>100 && random<=30). What you probably want is (lxdist<10 || rxdist<10) && self.mp>100 && random<=30 RE: Beginner's AI - T.O.R.N.A.D.O - 02-20-2016 But that doesn't really make any sense. Granted the brackets are wrong there but that is telling the computer to press J while holding A. But computer just spams J+A+A which is other way around. RE: Beginner's AI - A-Man - 02-20-2016 The order you execute these functions doesn't matter; as all of this is happening in 1 frame. And even if it that wasn't, it also depends on when the character starts responding to inputs. Consider you let your character tap A and D at some random state: 15 frames. If the character's frame control lands on a frame with a hit_d, that will activate, even though there might be a hit_a in the next frame to come. I am not very knowledgeable about the inner-workings of this, but the fact that you're using 'ego' might as well mean that they do click, or even release buttons from time to time. Guess what holding a button and releasing it continuously would do. RE: Beginner's AI - T.O.R.N.A.D.O - 02-20-2016 So how do you propose to make it execute that move using AI? I thought that was the best way to execute 2 button moves like AJ, AD, etc. RE: Beginner's AI - A-Man - 02-20-2016 I suggest you simply let the AI only press the first key when the condition is satisfied, and somewhere else in your code you do the second key click based on a check on your current frame, like so: if (self.frame == some_frame && (lxdist<10 || rxdist<10) && self.mp>100 && random<=30) If you need more precision (more characters have a similar move, but not different frames), I think you can go into depths by checking if there is a particular hit_j in a frame: if (game.objects[self.num].data.frames[self.frame].hit_j == something) |