STR Coding Club logo STR Coding ClubLearn to code, together
Games

Explore What Python Can Predict in Online Games and What Stays Random

When a club member learns enough Python to write a loop and read a file, a certain question tends to follow within a week: "Could I write a program that predicts what happens in my game?" Sometimes they mean the outcome of a ranked match.

Illustration of a scale running from fixed gears to a cloud of random dots

When a club member learns enough Python to write a loop and read a file, a certain question tends to follow within a week: "Could I write a program that predicts what happens in my game?" Sometimes they mean the outcome of a ranked match. Sometimes the next rare spawn. Sometimes the numbers in a draw. The honest answer is that some of these are very predictable, some are partly predictable, and some cannot be predicted at all, by any program, ever.

Players run into prediction claims constantly. Our club's data enthusiast has a folder of them: match outcome bots, spawn timers, tier list "forecasts" and number picking sites like ankertoto, all of which present their guesses with equal confidence. She uses that folder to set up this session, which is built around three small projects that sit at three different points on the predictability scale.

The Predictability Scale

Before writing code, we sketch a scale on the whiteboard with three zones:

  • Determined: the outcome follows fixed rules from known inputs. Given the inputs, you can calculate the result exactly.
  • Probable: the outcome depends on things you can measure, plus noise. You can estimate likelihoods, but individual results will surprise you.
  • Random: the outcome is generated to be independent of anything you can observe. The best you can do is describe the distribution.

Each project lands in one zone.

Project One: Cooldown Timers, Fully Determined

Many online games have abilities with fixed cooldowns and buffs that reduce them by a set percentage. If a spell has a 12 second cooldown and you have 25 percent cooldown reduction, the effective cooldown is 9 seconds, every time.

Members write a function that takes a base cooldown and a list of reductions, and returns the effective time and how many casts fit in a 60 second fight. This is pure arithmetic, perfect for practising functions with clear inputs and outputs, and a good fit for the idea in why first functions should do only one thing.

The predictions here are exact. If the program says 6 casts, a player who follows the rotation perfectly gets 6 casts. The only error comes from the player, or from the game changing its rules in a patch.

Project Two: Match Outcomes, Probable

Next, members build a simple rating system. Each player starts at 1,000 points. After a match, the winner gains points and the loser drops, more if the result was unexpected. The standard formula gives an expected score for player A against player B of 1 divided by 1 plus 10 to the power of the rating difference over 400.

Members feed in a season of match results from a club tournament, about 300 games, and then use the ratings to predict the next 50. The results are always instructive:

Predicted win chance of favouriteMatchesFavourite actually won
50 to 60 percent1910
60 to 75 percent2114
Above 75 percent108

The model is useful. Favourites win more often, and strong favourites win more often still. But it gets many individual matches wrong, and it is supposed to. A 65 percent favourite should lose about a third of the time. Members who expected the program to "know" who would win are usually surprised, and then, once they think about it, satisfied that the model is behaving honestly.

This zone is where most of competitive gaming lives. Skill is real and measurable, which makes outcomes partly predictable. Form, nerves, lag and lucky moments add noise that no rating can capture.

Project Three: Draws and Drops, Random

The final project is a number draw. The program picks 5 numbers from 1 to 40, using Python's random module, once per "day," for 1,000 days. Members then try to build predictors. Common ideas include:

  1. Pick the numbers that came up most often so far ("hot numbers").
  2. Pick the numbers that have not come up for longest ("due numbers").
  3. Pick numbers that follow a pattern in recent draws.
  4. Pick completely at random.

Each predictor makes a pick for every day after the first 100, and the program counts how many numbers each one matched. After 900 days, all four strategies average almost exactly the same: about 0.625 matches per draw, which is what pure chance gives (5 picks times 5 drawn over 40). The hot, due and pattern strategies are no better than random, because the draw has no memory.

Members often run it several times hoping one strategy will pull ahead. Occasionally one does for a few hundred days, then falls back. That temporary lead is the source of most prediction claims in the real world.

The Common Misunderstanding

You will often hear that "with enough data, you can predict anything." That idea comes from areas where it is partly true, like weather or sales, where outcomes depend on measurable causes. It does not apply to outcomes generated to be random. A fair random number generator is designed so that past results carry no information about future ones. More data just gives you a more precise picture of the distribution, never a forecast of the next draw.

The useful skill is recognising which zone a question falls in before trying to predict it. Determined questions deserve exact answers. Probable questions deserve likelihoods with honest uncertainty. Random questions deserve a description of the odds and nothing more.

Bringing It Back to the Games You Play

We finish by asking members to classify things from their own games: boss attack patterns, ranked match results, crafting outcomes, loot boxes, enemy spawn locations. The discussion is lively. Some bosses follow fixed scripts and are fully determined. Others pick attacks at random from a weighted list, so only the distribution is knowable. Ranked matches sit in the middle.

Puzzle games tend to be fully determined, which is part of why programmers love them, as we explored in the appeal of programming and logic puzzle games. Members who want more practice with the rules side can work through how game logic teaches loops and conditions.

Prediction is one of the most rewarding things code can do. Knowing when it cannot be done is just as valuable.

SD
Selene Dragomir

Selene coaches students for programming contests. She writes about practice problems, debugging and the habits that help beginners get unstuck on their own.

More posts by Selene

More in Games

01doorganico 084goad 3hot8 4465456 after5internprogram ahandfulofblessings ahmadpc ahomcybersecurity allodialresources annodex antiquesandperiodcollectibles aotc asianworldkashmir beedlectrics bloggertemplatefree bluefeatheragency bodyweightsolution campaign08blog carfixadvisor catstreetcollective cbstvsports cnfanspurchasing committeeof500yearsofdignityandresistance covertopsdjs cs-kaiyuangame cuestacomunicaciontotal cxoutlet dancebetgame deskgearhub destinyvillastay detectmagazine di33 diamondsteelbuildings donmo dyanadropship emarsysfinance emimattl escapechan eskitarih evautoplay everythingweddings-orlando farmzone feedviewerapp foxstudiosscratch gamevui123 gleasongrade greetingsday hacklabasu haskell iw-kaiyun jagoanproperti jilidskripsi joltbusinessfinance juegodepokergratis juegospucca kaeru-festival latestmehndidesigns lestanzediottaviano litemagazines localcommunityhero lustrsazan mariashebets menswheels newwebstechs1 nikkit ootheday oxigenvpn plurfitness prefetial probudgetcarpetcleaning psychicmrsmartin pyaten qvantor rejoignezlogis rexzbot riselayouts ruchin rwxqsgd5 sakaltime shibiaowang shop-bot skrtips spotlesshaven tetapatrium topselller uneplanteartificielle vipertechcr webtech1223411 wo-kygaming yamaha-mekar yeknava yoybuysheets zenunwa yamaha-mekar jilidskripsi ankertoto ankertoto ankertoto