AgentGames

Search titles, descriptions, models and tags. Press Enter to see results.

➗ Guide

How to make a math game with AI

Difficulty has to follow the player. Keep a running record of the last few answers and move one step at a time. Aim for a success rate that feels good rather than the edge of what somebody can manage.

Updated 5 October 2026 8 min read By the Agent Games team
Jump to a section
  1. Four steps to sums that land at the right level
  2. Difficulty that follows the player
  3. Aim below the limit, not at it
  4. A wrong answer never takes anything away
  5. Questions whose answers are whole numbers
  6. Reading the question aloud is the real time limit
  7. Common questions
  8. Where to go next

Ask for difficulty bands and a window of recent answers, not a list of questions. The game keeps the last few results, and when nearly all of them are right it moves up one band, when most are wrong it moves down one. That rule is short enough to fit in a prompt and it is the only part of a math game that is hard to get right.

A fixed ladder is wrong for every player

Write the questions out in advance, hardest last, and you have chosen one player's pace. Everyone else meets a wall or dies of boredom, and both happen inside the first minute. A ten year old and their parent will play the same build, so the build has to work out who it is talking to.

Four steps to sums that land at the right level#

Write the bands before the questions

A band is an operation and a range to draw numbers from. Single digit adding at one end, whatever you find hard at the other, in order.

Send the prompt below and play a round badly on purpose

Answer wrongly for a stretch. The questions should get easier within a few of them, and they should never stop coming.

Then play a round properly

Answer well and watch it climb. One band per move. If it leaps to something impossible, the step size is wrong, not the bands.

Check every answer is a whole number

Play until you hit a division. If it ever asks for a decimal you did not plan, the questions are being built in the wrong direction.

PromptCopy this, paste it, send it
Build a mental arithmetic game as ONE self-contained .html file.
Canvas only, no frameworks, no images.

QUESTIONS: build every question backwards from its answer, so the
answer is always a whole number. For a division, choose the divisor
and the answer and multiply them to get the number being divided. For
a subtraction, choose the answer and one part and add them to get the
total. Never choose two numbers and divide one by the other.

BANDS: an array of difficulty bands in order. Each band names the
operations it allows and the range its numbers come from. The first
band is single digit addition. The last is as hard as you like. Put
the whole array in CONFIG.

ADAPTING: keep the results of the last five answers in an array. After
each answer, move up one band if nearly all of them are right, down
one band if most are wrong, and otherwise stay where you are. Move one
band at a time. Empty the array after any move so one move cannot
immediately cause another. Never drop below the first band. Do not
show the band to the player.

SCORING: a wrong answer never takes away points, time or a life. It
shows the correct answer, and the next question comes from a lower
band. The score only ever goes up.

INPUT: the player types the number and presses Enter. No multiple
choice: a lucky guess would corrupt the record of how they are doing.

TIME: the round has one clock and the player answers as many as they
can before it runs out. Do not put a separate countdown on each
question.

PHONE: draw a number pad on the canvas with a backspace and an enter
key. Add canvas { touch-action: none; } to the CSS so tapping the pad
cannot scroll the page.

Run the round clock and any animation from the number of seconds that
passed since the previous frame, held to a ceiling of 0.05 so a tab
returning from the background cannot swallow the round. Keep every
tunable value, band ranges, window length, round length and palette,
in one CONFIG object at the top of the file.

The ADAPTING block and the QUESTIONS block are the two that matter. Reword the bands freely, add operations, change the round length. If you shorten the window below a handful of answers the difficulty starts twitching on every slip, and if you lengthen it much the game takes too long to notice anything.

Difficulty that follows the player#

The mechanism is smaller than it sounds. One short array of recent results, one check after each answer, one step in one direction. What makes it work is the restraint in it.

Fixed ladder against a moving window The same questions, ordered once in advance and ordered by the player. Fixed sequence band = Math.floor(asked / 10)the same ramp for every playertoo easy, then abruptly too hardand no route back down Last few answers window.push(wasRight); maybeStep()nearly all right, go up one bandmostly wrong, go down one bandthe difficulty finds the player One band at a time, judged on the last few answers and not on the whole run.
The fixed ramp on the left is what a model writes if you do not ask for anything else, because it is the obvious reading of the word difficulty.

Judge on the recent window and nothing else. A total score over the whole session describes somebody who was playing minutes ago, and they have warmed up since, or got tired. The last few answers are the only evidence about the player in front of you now.

Step by one. The temptation is to jump several bands when somebody is clearly flying, and it is always a mistake, because the band you land on was never tested against them. One step, then look again. The climb takes a few more questions and never overshoots.

Clear the window after a move. Otherwise the answers that triggered a step are still sitting there, ready to trigger the next one. The difficulty then slides two or three bands on the strength of a single good run.

And make the floor real. Whatever happens, the game keeps asking questions, and the easiest band has to be answerable by whoever opened the page. A math game that stops is a math game that told somebody they failed.

Aim below the limit, not at it#

Here is the part that gets inverted. The goal is not to find the hardest sums a person can just about manage. Hold somebody at their limit and they get most answers wrong, which in arithmetic does not feel like a challenge. It feels like a test they are failing.

Aim for four answers right out of five, roughly. That is the rate where a player feels quick and is still being stretched, and it is well short of the edge of what they can do. The band that produces it is one below the band you would pick if you were measuring them.

  • Move up on nearly all right, down on most wrong. Those two thresholds are not mirror images, and the gap between them is what keeps the game from oscillating between two bands.
  • Keep the window short. Long enough that one slip means nothing, short enough to react within a handful of questions. A player who notices the game adjusting is a player who stops noticing the sums.
  • Hide the band. Show it and people treat it as a score, then deliberately answer badly to keep it low or chase it upward past what they can read. The number is for the game, not the player.
  • Let it fall as fast as it rises. Tiredness is real. A player half an hour in needs the easier band they needed at the start, and getting there should not take a run of failures.

A wrong answer never takes anything away#

Subtract points for a mistake and you have taught the player a lesson you did not mean to teach. The lesson is to stop answering when unsure. In a shooter that is caution. In a practice game it is the exact behaviour the game exists to undo.

The same goes for time drained on a wrong answer, a life taken, or a streak that was earned being wiped. All of them make the safest move no move at all. The cost of being wrong is already built in: the question took a turn and got nowhere, and the next one will be easier.

What a wrong answer should do is tell the player the answer. Not a cross and a shrug. Show the sum with its result filled in, hold it for a beat, and move on. That beat is where the learning happens, and skipping it is the reason so many practice games teach nothing.

If you want a counter that can go backwards, use a separate one for the current run and keep a best figure that only ever rises. Losing a run is fine. Losing a record is what stings, and nothing about arithmetic practice is improved by stinging.

Questions whose answers are whole numbers#

Pick two numbers at random and divide them and you get a question nobody can answer in their head. The fix is to generate the question from the answer rather than the answer from the question, and it costs one extra line per operation.

Build the question from the answer Choose the answer you want first, then find a question that has it. 1 Division Pick the divisor and the answer, multiply for the total. 2 Subtraction Pick the answer and one part, then add to get the total. 3 Multiplication Pick both factors. The answer looks after itself. 4 Fractions Pick the result first, then a denominator that fits it. 5 Anything decimal Compare within a tolerance, never with an equals test. Two random numbers and a divide sign is how a quiz ends up asking for 2.3333333.
Choose what you want the answer to be, then build a sum that produces it. This is also how you keep a subtraction from going negative before you have taught negatives.

Decimals deserve their own warning. Adding a tenth to two tenths in binary floating point does not give exactly three tenths, so a typed answer compared with an equals test can be rejected while being correct. If your bands include decimals, compare the difference against a small tolerance instead.

Two smaller traps. Anything multiplied by zero or one is filler, and a band that keeps producing them reads as broken rather than easy, so exclude them past the first band. And the same question arriving twice in a row looks like a bug, so keep the last one and draw again if it matches.

Multiple choice is the other thing to avoid, and the reason is the window rather than the maths. With four options a guess is right some of the time, so a player who has stopped thinking still looks capable, and the difficulty climbs away from them. Typed answers keep the record honest.

Reading the question aloud is the real time limit#

Put a countdown on each question and you have to decide how long one takes. There is no such number. Seven times eight is read in an instant. A hundred and thirty seven minus sixty eight takes longer to read than some people need to solve it.

So a fixed per question allowance punishes the harder question twice, once for being hard and once for being long. Early bands feel generous, later bands feel impossible, and the thing you are now measuring is reading speed.

Use one clock for the round instead. The player answers as many as they can before it stops, and a quick answer is rewarded by getting another question rather than by beating a bar. Nobody is cut off mid thought, and the pressure comes from the player's own pace.

Test it by reading each question out loud in your head at a comfortable speed, then answering. If the game has already moved on, the allowance is wrong. This is also why the answer box must be focused from the start and Enter must submit, so none of that time goes on finding where to type.

➗Math games written by AI

Common questions#

Can AI make a math game?

Yes, and quickly. The sums, the input and the scoring are routine. What a model will not do unless you ask is make the difficulty respond to the player, so it writes a fixed ramp instead. Specify the bands and the window of recent answers in the prompt.

How does adaptive difficulty actually work?

Keep the results of the last few answers in a short array. After each one, move up a band if nearly all are right, down a band if most are wrong, and otherwise stay. Step once, empty the array after a step, and never fall below the easiest band.

What success rate should a math game aim for?

Around four right out of five, which is comfortably short of the player's limit. Held at their limit, a player gets most answers wrong, and in arithmetic that reads as a test being failed rather than a game being hard.

Should a wrong answer cost points?

No. Taking points, time or lives for a mistake teaches the player to stop answering when unsure, which is the opposite of practice. Show the correct answer, make the next question easier, and let the score only go up.

How do I stop the game asking for decimal answers?

Build each question from its answer. Choose the divisor and the answer and multiply to get the dividend, choose the answer and one part and add to get a subtraction total. Pick two numbers and divide them and sooner or later you ask for a recurring decimal.

Should questions have their own countdown?

Better not to. Questions differ in how long they take to read, so one allowance punishes the longer ones twice. Give the round a single clock and let the player answer as many as they can, which rewards speed without cutting anybody off mid thought.

Where to go next#

Once a round feels like it is reading you, publish it. The page records which model wrote the code and the prompt behind it, so somebody can see how the adapting rule was asked for before they play.

The general method is in how to make a game with AI. If the point is teaching rather than drilling something already learned, the educational guide argues for making the lesson the mechanic. For content that has to be valid rather than just varied, see the puzzle guide. Prompts for common faults are in the prompt guide, and the math games here show the range.