A command-line Tic-Tac-Toe game built with F# / .NET 10.
You play as O against a random enemy X. Enter a square number (1–9) to place your mark.
- .NET 10 SDK
Verify with:dotnet --version(should show10.x.x)
# Windows
run.bat
# Unix / macOS
chmod +x run.sh
./run.sh
# Or directly
dotnet rundotnet build# Windows x64
dotnet publish -c Release -r win-x64 --self-contained
# Linux x64
dotnet publish -c Release -r linux-x64 --self-containedSquares are numbered 1–9 left-to-right, top-to-bottom:
1 | 2 | 3
---+---+---
4 | 5 | 6
---+---+---
7 | 8 | 9
Empty squares display their number. Placed marks display O or X.
- The current board is printed.
- You are prompted:
Your move (1-9): - Type a number and press Enter.
- If the input is not a number in 1–9, you are asked to try again.
- If the selected square is already occupied, you are asked to try again.
Ois placed on your chosen square.
After your move, the enemy automatically picks a random empty square and places X.
The chosen square number is printed so you can follow along.
| Result | Condition |
|---|---|
| You win | Three Os in a row, column, or diagonal |
| Enemy wins | Three Xs in a row, column, or diagonal |
| Tie | All 9 squares filled with no winner |
After the game ends, you are asked whether to play again.
=== CLI Tic-Tac-Toe ===
You are O. Enemy is X. You go first.
1 | 2 | 3
---+---+---
4 | 5 | 6
---+---+---
7 | 8 | 9
Your move (1-9): 5
Enemy places X on square 3.
1 | 2 | X
---+---+---
4 | O | 6
---+---+---
7 | 8 | 9
Your move (1-9): 1
...
project-example/
├── TicTacToe.fsproj # .NET 10 F# project file
├── run.bat # Windows run script
├── run.sh # Unix run script
├── README.md
├── requirements.md
└── TicTacToe/
├── Board.fs # Cell type, board state, rendering, win detection
├── Game.fs # Game loop, player input validation, enemy AI
└── Program.fs # Entry point, play-again loop
// A cell is either an empty square (showing its number) or a placed mark
type Cell = Empty of int | O | X
// Possible outcomes of a completed game
type GameResult = PlayerWins | EnemyWins | Draw| Module | Responsibility |
|---|---|
Board |
Immutable board operations: create, tryPlace, winner, isFull, render |
Game |
Main game loop, input validation, random enemy move, end-state display |
Program |
Entry point; prints welcome message, drives play-again loop |
- You are always O and always go first.
- The enemy is always X and always moves randomly.
- Selecting an occupied or invalid square re-prompts — the turn does not advance.
- Three marks of the same kind in any row, column, or diagonal wins the game.
- A full board with no winner is a tie.