Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a turn based game where one part is pretty much like playing "Memory": remember where a specific card is located in a grid.

My AI works like this:

  • If a card is peeked (turned around and looked at) -by the player or AI - the AI remembers the location of this card 100%.
  • If the next card is peeked, a "dementia" factor will be applied to all the previous remembered cards. This means, card one is now only remembered with 80%, card two with 100%.
  • This information is kept in an array. Over time, chances to remember a card location decreases.

Now in order to figure out if the AI remembers a specific card X, I get the chance for the card X from the array, let's say the chance is 60%, or 0.6.

I then generate a random float number between 0 and 1. If the random float is lower than or equal to 0.6, I let the AI remember the location.

Is this a valid approach? I'm assuming here that the randomization in .NET is uniformly distributed.

share|improve this question
So your question is essentially, "Does the .NET random float uniformly distributed?" (which is a question for The rest of your question can only be addressed by you, since it's your design, it's up to you if that's how you want to do it. – Byte56 Oct 2 '13 at 18:30
@Byte56 Not really. I want to know: if we assume that randomization is uniformly distributed, is the approach correct? Is it a valid way to calculate a chance, or are there other methods? – Krumelur Oct 2 '13 at 18:38
From what I read, @Krumelur , you are basically asking "If something should happen 60% of the time, is generating a float between 0 and 1.0 and checking whether it is 0.6 or less a valid way of checking whether it happened?" Is that a correct interpretation of what you are asking? – fnord Oct 2 '13 at 18:44
@fnord In short words, yes. – Krumelur Oct 2 '13 at 19:11
up vote 1 down vote accepted

Yes it is. What you described is the standard way of determining if an event which happens with X% probability occurs for any given trial.

share|improve this answer

Your approach is quite good. But, doesn't completely simulate "everything" that a human player would be like. So, if you want to simulate a human player, you should try to think about the following:

"Remembering" a cards position isn't like true or false. Remembering it "correctly" is of course be true/false. But, forgetting about a card is more like losing accuracy about its definite location. So you'll be able to remind the "region" where it has been, but this region grows with time. This "reminding model" also simulates the following effects: If a card is at the border or in one of the corners, you'll remind it better. The region grows (imaging a circle around the cards center increases) but there are no cards at the outside, so the probability is higher to turn the correct card. This also applies, if a card is isolated (many other cards next to it have already been removed).

Your approach still also lacks the fact, that your rate of forgetting becomes less, if the number of cards on the table reduce.

I would apply the following algorithm:

Cards in memory are stored as exact position (when last turned) and a variance. Assume a Gaussian distribution of the remembered card location. So when trying to turn the card, calculate the chance for each card to be turned by the Gaussian distribution. Then calculate the sum off all probabilities and divide the probabilities by that sum (so the sum of them is 1 == 100%).

Then choose a card by generating a float between 0 and 1.0 and iterate through all cards. For each card, reduce the random value by the probability of the current card and check if the value is below 0. If the value becomes lower than zero, take that card.

The probabilities above can also be used for "planing", that means: The AI can "guess" in advance how well it remembers the location of a card (probability to take the correct one). If it needs to turn two matching cards, the probabilities need to be multiplied. This way, the AI can choose the cards with highest probability to be reminded correctly.

The formula for the Gaussian distribution can be found at:

As the distribution is 2-dimensional use: f(delta_x)*f(delta_y) for the probability. You can assume the average to be zero, if you use the relative position to the real position. This way the only parameter to the function is the offset and the variance.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.