Sub topic 1
What win, lose, and fail states are and why they matter
Prerequisites
This chapter assumes you know three things:
- What a game mechanic is and how the core gameplay loop works (act, get a result, act again).
- Simple programming ideas: conditionals (
if) and functions. - How several game genres play, so you can recognize the examples. The examples draw on platformers, roguelikes, puzzle games, and shooters.
You do not need to know any engine or library. The code in this chapter is plain Python and runs as shown.
The three end states
Every game answers a question for the player: "Where do I stand right now?" Most of the time the answer is "still playing." Three kinds of moments change that answer.
- A win state is a condition that ends the game, or a major section of it, in the player's favor. Examples: reaching the exit, defeating the final boss, holding the most points when time expires.
- A lose state is a condition that ends the game, or a major section of it, against the player. Examples: health reaching zero, running out of lives, a rival reaching the goal first.
- A fail state is a setback that costs the player something but does not end the attempt. Examples: falling off a ledge and respawning at a checkpoint, failing a stealth section and being sent to the last save, losing a unit in a strategy game.
The line between lose and fail is not a property of the event. It is a property of what the game does next. Dying in a platformer is the same event whether the player has three lives left or none. With lives left, the game treats it as a fail state and sends the player back. With none left, the game treats it as a lose state and ends the run.
A term you will see often is end state. In this tutorial it means any condition the game checks to decide that something has finished. Win and lose states are terminal for the attempt. Fail states are non-terminal: play continues.
Why these states matter
End states do more than stop the game. They set what the player is trying to do, how much risk they are willing to take, and how they feel when they put the controller down.
They define the goal
A game without a clear win condition gives the player nothing to aim at. Sandbox games sometimes ship this way on purpose, and then players invent goals of their own. In most games the win condition is the answer to "what am I supposed to be doing?" and it shapes every decision between the start and the end.
They give choices weight
A choice only matters if something can go wrong. If the player cannot lose, no decision carries risk, and tension disappears. The lose and fail states supply the cost side of every risk-and-reward decision. A player will only feel clever for sneaking past a guard if being caught means something.
They control the emotional arc
Players remember how an attempt ended. A narrow win after several near-failures tends to feel better than an easy win. A loss that the player understands and can learn from feels motivating. A loss that feels random or unexplained feels like the game cheated. The same mechanics can produce either result, depending on how the end states are designed and shown.
They shape session length and pacing
Fail states set the rhythm of play. A game with cheap, instant retries (a fast platformer) invites many short attempts. A game where failure costs an hour of progress pushes players toward caution and long, deliberate sessions. You are choosing the pace of play whenever you choose what happens on failure.
Comparing the three states
The table shows how the three kinds of state differ along the questions a designer has to answer.
| Question | Win | Lose | Fail |
|---|---|---|---|
| Does the attempt end? | Yes | Yes | No |
| Who benefits? | The player | The game or an opponent | Neither, it is a cost |
| What does the player usually do next? | Stop, celebrate, or start a new run | Restart or quit | Retry immediately |
| Typical cost | None | Loss of the run's progress | A small to moderate penalty |
| Typical example | Boss defeated | Out of lives | Respawn at checkpoint |
A worked example: one game, three states
Imagine a small dungeon game called Relic Run. The player explores rooms, collects relics, and avoids traps.
- Win: collect 5 relics.
- Lose: health reaches 0.
- Fail: falling into a pit trap costs 1 life and returns the player to the last checkpoint.
The first rule is easy to state as code. This function reads the game state and returns one of three outcomes. It is the first of two examples that appear in this chapter.
from enum import Enum, auto
class Outcome(Enum):
PLAYING = auto()
WON = auto()
LOST = auto()
def evaluate(health, relics, relics_needed):
# Check the lose condition first, so a simultaneous win and loss
# resolves as a loss. Reverse the order to favor the player.
if health <= 0:
return Outcome.LOST
if relics >= relics_needed:
return Outcome.WON
return Outcome.PLAYING
print(evaluate(health=3, relics=2, relics_needed=5)) # Outcome.PLAYING
print(evaluate(health=3, relics=5, relics_needed=5)) # Outcome.WON
print(evaluate(health=0, relics=5, relics_needed=5)) # Outcome.LOSTThe last call matters most. The player collects the fifth relic with the same hit that takes their last health point. Both conditions are true at the same moment. Because the lose check comes first, the player loses. If you reverse the two if statements, the player wins. Neither answer is wrong. They are different design choices, and the order of the checks is where you make that choice. Many games favor the player here because losing at the instant of success feels unfair. A hard survival game might choose the opposite to keep tension high.
Now the fail state. Pit traps should not end the run, at least not at first.
class Run:
def __init__(self, lives, checkpoint):
self.lives = lives
self.checkpoint = checkpoint
self.position = checkpoint
def on_player_death(self):
# A death is a fail state while lives remain and a lose state when they run out.
self.lives -= 1
if self.lives == 0:
return Outcome.LOST
self.position = self.checkpoint
return Outcome.PLAYING
run = Run(lives=2, checkpoint=(4, 7))
run.position = (9, 3)
print(run.on_player_death(), run.position) # Outcome.PLAYING (4, 7)
print(run.on_player_death(), run.position) # Outcome.LOST (4, 7)The first death is a fail state. The player loses a life and returns to (4, 7), and play continues. The second death uses up the last life, so the same event becomes a lose state. The function returns Outcome.LOST and leaves it to the rest of the game to end the run.
The two examples together show the key idea of this chapter: lose and fail are two responses to the same kind of event, and a counter such as lives decides which one the player sees.
How the states relate over time
A player moves through these states in a predictable pattern. The diagram shows the flow for Relic Run.
Notice the loop on Playing. A fail state is an arrow that leaves Playing and returns to it. Win and lose are arrows that leave for good. Later chapters turn this picture into a full state machine with precedence rules.
Choosing which states a game needs
Not every game needs all three states, and some need more than one version of each.
- Win only, with no real lose. Many exploration and narrative games let the player proceed without any way to be defeated. Tension then comes from the story or the puzzles, not from risk. This is a valid choice, but it means you give up the weight that comes from lose states.
- Lose only, with no win. Endless games such as arcade survival titles have no final victory. The player plays until a lose state ends the run, and the score replaces the win condition.
- Fail states only inside a larger structure. Checkpoint-based platformers treat most deaths as fail states and keep a lose state for the rare case when lives or continues run out, or have none at all.
- Several win or lose conditions. A strategy game may let you win by conquest, by score, or by completing a project, and lose by losing your capital or by running out of turns. Multiple conditions need clear rules about which one counts when two trigger together.
When you decide, ask these questions in order:
- What is the player trying to achieve, and how will they know they have achieved it? That is your win condition.
- Can the player be defeated, or does the game end only by success or by quitting? That decides whether you need a lose condition.
- For each bad event, does the attempt end or continue? Events that continue are fail states. Events that end the attempt are lose states.
- If a bad event is a fail state, what does it cost, and how fast can the player try again?
Common errors
These mistakes appear often in early designs.
- An unstated win condition. The designer knows the goal, but the player does not. If a tester cannot tell you the goal after five minutes, the win condition is not communicated, whatever the code says.
- Treating every failure as a lose state. Ending the run for a minor mistake makes players feel punished out of proportion. Ask whether the attempt really needs to end.
- Treating every failure as a fail state. If nothing ever ends the attempt and retries are free, risk disappears and wins feel unearned.
- Hidden precedence. When two end conditions can trigger together, the result depends on code order. If you did not choose that order on purpose, you made the choice by accident. The first code example shows how to make it deliberate.
- Unmeasurable conditions. "Survive for a while" cannot be tested. "Survive 120 seconds" can. A condition you cannot check in code or in a playtest is a condition you cannot tune.
What comes next
The rest of this tutorial takes each idea further. Later chapters cover how to write clear win and lose conditions, how to design fail states and recovery, how to model outcomes as a state machine, and how to make failure feel fair, readable, and worth retrying. The last chapters cover difficulty, multiplayer outcomes, and playtesting. Everything builds on the three-way split in this chapter: win, lose, and fail.
Exercise
In a roguelike, the player has 3 hit points. A trap deals 1 damage, and the player stays where they are. When hit points reach 0, the run ends and the player starts a new dungeon. Classify each of these events as a win, lose, or fail state: (a) taking 1 damage from a trap with 3 hit points left, (b) taking 1 damage with 1 hit point left, (c) reaching the dungeon's final stairs. Then explain what would change if the game gave the player one free revive at the start of each run.
Show answer
(a) is a fail state: it costs something, but the attempt continues. (b) is a lose state: hit points reach 0 and the run ends. (c) is a win state: it ends the attempt in the player's favor. With one free revive, event (b) becomes a fail state the first time it happens, because the attempt continues (for example, the player returns with partial health). A second occurrence would become a lose state. The event is the same, and the remaining revive count decides which state the player sees.
Exercise
In the evaluate function from this chapter, a player collects the last relic and takes lethal damage in the same frame. The function returns Outcome.LOST. Describe one change that makes the player win in this case, and give one reason a designer might still prefer the original order.
Show answer
Move the if relics >= relics_needed check above the if health <= 0 check, so a simultaneous win and loss resolves as a win. A designer might keep the original order in a survival game where the tension depends on the player truly not being able to afford the last hit, or where the relic and the damage come from the same risky action that should have a price. The main point is that the order is a deliberate design decision, not an accident of code layout.