↑↓ move · ↵ open · esc close

← All algorithms/Choosing a move

Greedy and random baselines

How much does a smarter search actually add?

Two trivial players: one plays any legal move, the other the move that looks best right now. Every real algorithm has to beat them.

TimeO(1) · O(b)
MemoryO(1)
The idea

The random player chooses a legal move uniformly. It has no idea what is good, which makes it a floor.

The greedy player looks exactly one move ahead. It tries each legal move, scores the resulting position with the evaluation function and plays the highest. It never considers the reply, so it walks into a trap that is obvious two moves later.

They earn their place twice: as opponents of different strengths, and as a measuring stick. If minimax at depth four cannot beat greedy, the evaluation is the problem, not the search.

Try it

Loading the demo…

Connect Four against the greedy player. It only ever scores its own next move, so try setting up a threat it has to answer two moves from now.

Step by step
  1. 01List the legal moves.
  2. 02Random: pick one of them at random and stop.
  3. 03Greedy: play each move on a copy of the position and score the result.
  4. 04Greedy: play the move with the highest score, breaking ties at random.
In pseudocode
function random_move(position):
    return random_choice(moves(position))

function greedy_move(position):
    me = turn(position)
    return argmax over m in moves(position) of evaluate(play(position, m), me)
What it costs
Time: O(1) · O(b)Memory: O(1)

Random takes one step; greedy scores each of the b legal moves once. Both answer instantly.

Strengths
  • Instant, even on large boards.
  • A fair test of the evaluation function.
  • Opponents a beginner can beat.
Limits
  • Greedy cannot see the opponent’s reply.
  • Random is no challenge at all.
  • Neither plans.
Where it is used
  • 01OthelloGreedy plays the move that scores best right now; random plays anything legal.
  • 02Connect FourGreedy picks the column whose resulting position scores best; random drops anywhere.
Related algorithms

Minimax

Choosing a move →

Alpha-beta pruning

Choosing a move →

Monte Carlo tree search

Choosing a move →