This course teaches how to install and configure Windows Server 2012 R2. It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

I'm trying to design a simulated sports game. I have come a long way, but I am stuck at the most important part - What goes into deciding what happens each play.

I am looking for something like heuristics, fuzzy logic, artificial intelligence, etc. for php. Could anyone please offer some advice?

Please let me know if you need more information. Thanks!

I am looking for something like heuristics, fuzzy logic, artificial intelligence, etc. for php. Could anyone please offer some advice?

Please let me know if you need more information. Thanks!

Do more with

EXPERT OFFICE^{®} is a registered trademark of EXPERTS EXCHANGE^{®}

The evaluation could look like:

a1*P1 + a2*P2 + ... an*Pn = x

where P1,...Pn are some player team preferences or diffrence of teams preferences. for example p1 could be (offence_of_team_1 - defence_of_team_2)

and

a1...an are some parameters which show how important is particular part of game. for example multiplier of offence will be bigger than multiplier of home filed advantage.

x is a score, which you need to interpret. If you set everything symmetrically, then if x > 0 wins team 1 and if x< 0 wins team 2.

team1 passing =1

team2 pass defense = 2

passingdifference = 1

team1homefield = 1

turf = 3 (whatever that may mean)

weatherfactor = -1

etc.

then sum the numbers up in a formula and generate a random number between 1 and the sum. Say the total comes out to 12 out of a possible 18.

So the number generated is between 1 and 12, but the simulation expects between 1 and 18, so that limits the results based on the factors.

If the team/player value is 4, add a random number between -2 and 2.

I think if this idea is already in place and not working as you wish, you just need to work more on the formulas for the results. Put random numbers in all the factors, instead of just the final calculation.

First, dealing with the average attributes of each player means you are necessarily depending on a generalization. That is why you are seeing such repetition. To achieve better accuracy, and a wider range of possibilities, establish a curve of that player's actual performance (based on play history), break it into percentile groups, then use a cumulative random to select an "offensive power" for that player during that play. Do the same thing for the defense. The random selection should reflect the curve's statistical probability for the result, such that the likelihood of an "average" play is greater than something on the extremes. This can be easily achieved by simulating dice rolls, such as the sum of 10 random numbers between 0 and 10. Each percentile group should associate with a definite amount of yardage gained or lost.

Once you have the offensive and defensive power, whichever is greater is the "winner" for that play. Now you need a separate algorithm to determine the actual result of the win. That algorithm should probably consider offensive power, defensive power, and random conditions you introduce into the play (someone left a banana on the field, high wind pushes a pass into a defensive receiver, etc), as well as a standard random deviation.

Using your example of the running back vs. defensive line, the RB has an average of 5.2 yards per carry, but his actual performance on a play-by-play basis ranges from -10 yards (pwned!) to a 60-yard sprint for TD. After creating his curve and selecting a percentile, say his "power" comes out to 10 yards. On the defensive side, the power can range from complete failure (that 60-yard sprint) to overrunning the offensive line. Say defensive power comes out to 3 yards, just a little above average. The difference is 7, in favor of offense. The random deviation of the play "instance" can be another random, say -5 to +5. You could even modify the range of the deviation based on the difference in powers. That would allow for a defensive power of -2 combined with an offense power of 50 yielding the 100+ yard punt return. For this example, say you get -3, so +7 + (-3) = +4 yards as your initial baseline play result. Add whatever other modifiers you want into the play, adjust for our universe's chaotic nature, so on, ad nauseum. Some teams statistically do extremely poor on 3rd down conversions...

At the end, the play goes into the play history, thus acting as a subtle modifier on future plays. This allows average good players to (normally) improve over time. In the long run, you will need to limit that effect with some kind of aging mechanism. At the same time, you may need to "boost" poor players in order to show improvement through experience. Statistically, players' abilities will tend to migrate away from the center norm towards the extreme of their initial bias (good player vs bad player). Without some kind of limiting on this effect, you will eventually end up with gods vs. dweebs.

This is all computationally expensive, but the results tend to follow strong over weak, with just enough random to provide the occasional upset without being too "WTF?!". (For you Civ fans: what do you mean my tank was killed by a longbowman?)

Basically, each player will have a history of yardage gained/lost per play. Take the detail of that history and plot it on a graph, with yardage as the X-axis and frequency as the Y-axis. That should yield a nice statistical curve, on which you can use the normal statistical methods. The particular method I'm thinking of is percentiles. If you 'roll' your dice and come up with 36, then look for the 36th percentile on the graph, and use the related yardage as the base power of that player for that play. With 10 random numbers between 0 and 10, you should be generating the same kind of selection frequency as indicated by a standard, centered bell curve.

I'd have to locate and dig through my stats 101 book to give any kind of formula help, but I recall this being a relatively standard operation in analysis. In terms of flow/pseudo-code:

1) fetch player history details and organize as a normal distribution (http://en.wikipedia.org/wiki/Normal_distribution)

2) generate random between 0 and 100 for percentile. Percentile selection should represent a standard "centered" normal distribution (typical bell curve)

3) modify percentile based on game conditions, such as a "good" day for the player, home field advantage, etc.

4) translate percentile into yardage using (1)

5) a. steps 1-4 for offense

5) b. steps 1-4 for defense

6) compare 5a and 5b for general outcome (gain/loss)

7) modify (6) with random deviations, arbitrary adjustments, and universal entropy (i.e., inject chaos into your order)

http://z.hubpages.com/u/324995_f520.jpg

Your player's history graph will not be quite so symmetric, of course, but you will still be able to divide into percentile groups. IIRC, this is an expression of standard deviations from the norm. Or maybe vice versa. In any case, you generate your percentile, find where that percentile lies on the player's graph, which should pinpoint a discrete value as the median of that percentile group. That value becomes your base power.

I do hope someone here knows a bit about statistics and can explain this in proper terms. I knew enough to pass my final on it about 7-8 years ago, and have not used it since... :/

Once plotted, break the graph up into percentiles. With 365 observations, each percentile will own 3.65 data points. It is up to you to determine the rounding or interpolation. From your data, for example, (-4) has a frequency of 4, which is just over 1 percentile. (-3) has a frequency of 11, which is about 3.5 percentiles.

Now you need to select the random percentile which will form the basis of that player's power. Do this by generating 10 random numbers between 0 and 10. The sum is the percentile you need. The matching x-axis value will be the base power. Repeat the same process for the other player, and you have the unmodified result of the play.

## Premium Content

You need an Expert Office subscription to comment.Start Free Trial