A simple Othello (Reversi) CLI game implementation in different programming languages.
I originally did this in Python many years ago for my university basic programming course assignment, and then a few years later re-implemented it in C++ for learning purposes. Since then, I figured that this could actually be a useful personal project to:
- try out and learn new languages by re-implementing it,
- compare different languages easily with each other, and
- be a practical syntax, formatting, and tooling reference for each language.
I have cleaned up and improved both my old implementations in Python and C++, the two languages I have been using the most. For each language, I try to make the program structure and all the functions match as close as possible, while also trying to follow the best practices and guidelines for each language.
While the program is quite simple, it also covers pretty well most of the functionality and tooling one would commonly use in a programming language. It's big enough to get a good feel for a language, yet small enough that it could be done in a weekend even when starting with a new language. It is also easy to check that the code is working correctly, especially since it is possible to compare side-by-side with the other implementations.
So far, I have added C#, Swift, Rust, Go, and Kotlin implementations. I might still do a few other (modern) languages that interest me and/or have some hype around them, such as Zig, Mojo, and Ruby.
In the meantime, there's probably still room to improve in the current implementations, especially in the languages that I haven't been actively using so much.
All implementations follow this overall architecture:
- main: Command line argument handling and entry point to initialize the game.
- othello: The main gameplay loop.
- board: Game board state and logic.
- player: Player object used for making moves and storing player information.
- utils: Helper classes, enums and functions.
- colorprint: Helper methods for terminal color printing and string formatting (if needed).
Python 3.11+. Uses the colorama package for colored text in the terminal. Formatting follows PEP8 except for the outdated max line length of 79. Uses type hints heavily. Dependencies are handled by Poetry. Formatting with Black and isort, linting with ruff.
- othello.py
- board.py
- player.py
- utils.py
- colorprint.py
C++20. Uses CMake as the build system, and fmt library for sensible string formatting and colored text. Follows the ISO recommended naming style (snake_case), which sadly not that many C++ codebases seem to be using (in my experience). Code formatting is handled by ClangFormat.
- main.cpp
- othello.hpp & othello.cpp
- board.hpp & board.cpp
- player.hpp & player.cpp
- utils.hpp & utils.cpp
- colorprint.hpp
- version.hpp
.NET 8 and C# 11. Uses Pastel for colored text in the terminal. Follows the C# style guide (PascalCase), but with line length limit of 100. Code formatting with CSharpier.
- Othello.cs
- Board.cs
- Player.cs
- Utils.cs
- ColorPrint.cs
- Version.cs
Swift 5. Uses ColorizeSwift for colored text in the terminal. Formatting with swiftformat. Project is handled by the Swift Package Manager, meaning there is no Xcode project.
- main.swift
- othello.swift
- board.swift
- player.swift
- utils.swift
- colorprint.swift
- version.h
Rust 2021 edition. Uses the colored crate for colored text in the terminal.
- main.rs
- othello.rs
- board.rs
- player.rs
- utils.rs
- colorprint.rs
Go 1.21+. Uses Aurora for colored text.
- main.go
- othello/othello.go
- othello/board.go
- othello/player.go
- othello/utils.go
- othello/colorprint.go
- othello/version.go
Kotlin 1.9+ and Gradle.
- Othello.kt
- Board.kt
- Player.kt
- Utils.kt
- ColorPrint.kt
- Write some thoughts on the languages and their differences
- Add unit tests for each language
- Make a NumPy version of Python implementation (not really needed but why not)