[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"5FlKORnK9V":3},"# Formalized tic-tac-toe, using Lean 4\n\n### Play\n\nAssuming you have Lean 4 [installed](https://lean-lang.org/install/manual/), you can play\ntic-tac-toe against yourself by running the following command:\n\n```bash\nlake exe tic-tac-toe\n```\n\n### Proofs\n\n_Note: I'm an absolute newbie in Lean 4, so my proofs are probably not the right source to learn\nfrom. You have been warned._\n\nThe [TicTacToe.Basic](./TicTacToe/Basic.lean) module contains a definition of a tic-tac-toe game\nalong with the following proofs:\n\n- Players alternate after each move (see `playersAlternateAfterMove`)\n- A cell gets marked after each move, with the mark of the current player (see\n  `cellMarkedAfterMove`)\n- There is always a correct distribution of cells (e.g. you can't have two `X` marks and zero `O`\n  marks on the board, as that would mean player `X` got two moves and player `O` zero)\n- If the game is in-progress, there are no winning configurations on the board (i.e. no line of\n  three similar marks)\n- If the game has a winner, only that player has a winning board configuration\n- If the game ended in a draw, the board is full and there are no winning configurations on it\n\nNote: the proofs that don't reference a specific theorem are proven by\n`makeMovePreservesWellFormedness`, which ensures a board is always well-formed. See also\n[TicTacToe.Tests](./TicTacToe/Tests.lean) for examples of well-formed and ill-formed game states.\n\n### TODO\n\n- Prove that defensive AI can only lose when two cells are under attack at the same time.\n- Implement unbeatable AI, that looks two steps ahead and never loses. Prove that it can't lose.\n",1780846768221]