A small Tic-Tac-Toe library written in Kotlin, with an example console-based application.
The core game engine is fully testable and reusable in any Kotlin application.
- UI-Agnostic Core: The
TicTacToeengine has zero dependencies on the UI orprintln. - Immutable State: The
Boardclass is immutable. Moves create a new board state, making state management predictable and safe. - Extensible AI: A simple
PlayerStrategyinterface allows for custom AI. ARandomStrategyis provided as an example. - Fully Tested: The core library logic is validated by a suite of unit tests.
lib/src/main/kotlin/org/jetbrains/kotlinx/tictactoe/TicTacToe.kt: The core game library. It contains all logic for the board, players, and game state.app/src/main/kotlin/org/jetbrains/kotlinx/tictactoe/main.kt: A simple, playable console application that uses theTicTacToelibrary.lib/src/test/kotlin/org/jetbrains/kotlinx/tictactoe/TicTacToeTests.kt: A set of unit tests for theTicTacToelibrary.TicTacToe.ipynb(Kotlin Notebook)- An interactive notebook at the project root that provides a live demo of the
:libmodule and its features.
- An interactive notebook at the project root that provides a live demo of the
Run the main.kt file and follow console prompts.
To use the game engine in your own application, you only need TicTacToe.kt. You can then import it and control the game flow.
Tests are located in TicTacToeTests.kt.