FUNDAMENTALS OF GAME DESIGN, SECOND EDITION

Random Numbers and the Gaussian Curve

So many games use random numbers that, although you may not know any pro­gramming, you should understand how to use random numbers in a computer game.

When a computer generates random numbers, by convention it always does so as a real number value greater than or equal to 0 but less than 1. In statistical calcula­tions, probabilities are always expressed as a fractional value between 0 and 1, so an event with a probability of 0.1 has 1 chance in 10, or 10 percent, of occurring.

To see if an event with a given probability occurs, the computer generates a random number, then checks to see if the random number is less than the event's probabil­ity. If so, the event happens. The random number is always less than 1, so if an event's probability is exactly 1, the event always happens. The random number is never less than 0, so if an event's probability is 0, it never happens.

The "Numeric Attributes" section of Chapter 14 discusses a number of ways to use random numbers when computing things such as whether a weapon hits the point at which it's aimed. A weapon with an accuracy rating of 0.8 hits its mark 80 per­cent of the time. To see whether a particular shot hits, generate a random number and compare the number to the weapon's accuracy rating. If the random number is less than the rating, the weapon hits.

Pseudo-Random Numbers

Random-number generation algorithms normally take an input value, called a seed, that determines the sequence of random numbers the algorithm produces. If the seed is identical each time the game is played, the sequence of random numbers that the algorithm generates is identical each time, too. In other words, it's as if each time you play a board game, you get the exact same sequence of die rolls that you got the last time you played. Each roll is different from the previous roll, but the sequence of rolls is identical. Such numbers are called pseudo-random.

This feature is extremely useful when you're tuning the game's mechanics. When you make adjustments to the mechanics, it is difficult to determine what the effect of your change is if the operation of chance keeps changing the game. By using the same seed each time you play, you always get the same random numbers, so the effects of chance don't change from one playing to the next. The mechanics become deterministic and predictable. This quality is also essential for bug-fixing.

If a bug happens by chance, it might not happen the next time someone plays the game, so the programmer won't be able to find it and fix it. If the game uses pseudo-random numbers, the bug should be easier to reproduce.

Naturally, in the final version of the game that the customer buys, you won't want the effects of chance to be the same on each play through. Just before the game is ready to ship, the programmers will change the code to take the seed from some random source, such as the system clock, so the player will get a different experi­ence each time he plays.

Добавить комментарий

FUNDAMENTALS OF GAME DESIGN, SECOND EDITION

Arcade Mode Versus Simulation Mode

Switching into arcade mode skews the play toward lots of action and relatively few slow-paced game states, such as strikeouts or walks. Arcade mode makes the game more exciting at …

THE SECRET OF MONKEY ISLAND

The Secret of Monkey Island, now nearly 20 years old, remains worth studying because it spawned a highly successful franchise. Although it is ostensibly set on a Caribbean island in …

Human Intelligence Instead of Artificial Intelligence

In single-player games, the player competes against the computer, so the computer has to have enough artificial intelligence (AI) to be a good opponent; building the AI for a complex …

Как с нами связаться:

Украина:
г.Александрия
тел./факс +38 05235  77193 Бухгалтерия

+38 050 457 13 30 — Рашид - продажи новинок
e-mail: msd@msd.com.ua
Схема проезда к производственному офису:
Схема проезда к МСД

Партнеры МСД

Контакты для заказов оборудования:

Внимание! На этом сайте большинство материалов - техническая литература в помощь предпринимателю. Так же большинство производственного оборудования сегодня не актуально. Уточнить можно по почте: Эл. почта: msd@msd.com.ua

+38 050 512 1194 Александр
- телефон для консультаций и заказов спец.оборудования, дробилок, уловителей, дражираторов, гереторных насосов и инженерных решений.