Skip to content

Commit a2fb81c

Browse files
authored
Merge pull request #4 from CharlesCNorton/ttt-unbeatable
Prove tic-tac-toe AI is unbeatable
2 parents 2324223 + 70af17f commit a2fb81c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

theories/TicTacToe.v

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,22 @@ Definition score (g : game) : nat :=
318318
| ongoing => 1
319319
end.
320320

321+
(* The minimax value of tic-tac-toe is 1 (a draw).
322+
This means the maximizer (X) can guarantee at least a draw,
323+
and the minimizer (O) can guarantee at most a draw.
324+
Combined with [eval_ab_correct], this proves the AI is unbeatable:
325+
it computes exact minimax via alpha-beta on the complete game tree,
326+
so it always plays optimally and never loses.
327+
328+
We evaluate on [complete_tree_again] (the cotree-based construction)
329+
because [complete_tree] uses well-founded [Acc] recursion that
330+
does not reduce under [vm_compute]. Both represent the same
331+
complete game tree — [ttt_is_finite] proves the cotree stabilises
332+
at depth 10. *)
333+
Theorem ttt_minimax_draw :
334+
eval_ab players_le_ge score (fun _ => false) complete_tree_again = 1.
335+
Proof. vm_compute. reflexivity. Qed.
336+
321337
(* Score children on-the-fly using alpha-beta pruning
322338
instead of pre-computing the entire scored tree. *)
323339

0 commit comments

Comments
 (0)