I am making a simple AI and I am really new to this realm. What I need is an algorithm to make some sort of decisions based on some parameters; but with a little bit of randomness. What I have been doing so far is to generate a random number and based on the different values I get; take different execution paths. I somehow think there's a much better way to do this sort of thing. Can you g开发者_JAVA百科ive me some pointers?
I don't think there's "a" better way than what you're doing, because the problem description is quite vague, and whether it's actually an artificial intelligence problem or a simulation problem is not clear.
For the decision part, it's usually fine to have a simple heuristic system (based on your intuitive understanding of the behaviour being modelled) that is a sequence of conditional statements with possibly some random factors to vary it up a bit. You could have a weighted average system that picks several options, ranks them according to perceived quality, then picks an option at random while being biased towards the better values. (This is called roulette wheel selection or fitness proportionate selection in genetic algorithm circles but is very useful outside of GAs too.)
For the simulation part you typically want to model the process and then introduce the randomness to model the more subtle parts of the process. This means defining clearly your inputs (backhand power, ball direction, ...) and your outputs (ball travel vector?), and considering how they relate to each other. This means you get given some outputs of known values, and then you can modify them with your random number generator. Things get more complicated if you're trying to model a human's choice rather than just a physical simulation, since that often takes precedence over all the other inputs.
A simplified example I might start with would be that the player AI picks where they want to hit the ball to. I calculate the ball's intended direction as a vector that would send the ball exactly where planned. The system then calculates a difficulty score from 0% to 100% based on the ball direction, speed, player's ability, etc. I generate an 'inaccuracy' modifier that is a random number between 0% and the difficulty%, meaning a perfectly easy shot will be completely accurate, whereas a half-difficult shot will vary between being 0% and 50% accurate. Then I calculate a random normalised unit-length 3D vector, scale that by the inaccuracy value, and add it to the intended direction. This means more difficult shots will tend to fly further off target.
As with most questions on randomness it's worth while asking if what you're looking for is true randomness, i.e. white noise, or turbulence (aka Perlin Noise). Generally in most domains you're more likely to get something that looks like more 'natural' behaviour from turbulence than white noise.
Give scores to each of the execution paths depending on how close is the outcome to an optimal, "desired" state or result. Make your algorithm choose its future execution paths depending on the average score of the former decisions, giving a larger probability of outcome to the decision with the highest score. This way, it will appear as if your algorithm is not only learning, but also exploring randomly other possibilities, but with a lower probability than doing what seems to be the best. Of course, you could make this adaptive, by taking into account not only the score of each decision path but also its rate of growth or shrinkage. If a decision starts being good, but then after a number of iterations, it gets lower and lower scores, it should be avoided more often in favor of another decision who's score has a growing trend.
精彩评论