Share your repls and programming experiences

← Back to all posts
Type-Level Tic-Tac-Toe
bijan2005 (0)

Rust is a language with a very strong type system. In fact, its type system is so strong that it's possible to program only using types, with no values in sight!

This is an implementation of Tic-Tac-Toe (also known as Naughts and Crosses) using only types.

Note: This implementation has no victory detection. Trust me, I tried, I'd rather not have a 3,000-line repl.

How to Play

Unfortunately, due to all computations being compile-time, it's impossible to use any I/O systems, meaning you'll need to edit the code to play the game.

  • To get the current game state, run the file and scroll down to the bottom.
  • To make a move, scroll down the file to the fn main and copy+paste the following code to the end of it:
type Step_N = <Step_N-1 as Move<Pos_Y, Pos_X>>::NewState;
println!("{}", Step_N::show());
  • Replace _N with the number of the current turn (it doesn't have to be numbers, really, but they're easy), _N-1 with the previous turn, and _X _Y with the x- and y- position of the move you want to make (If you make an incorrect placement, there will be an error, so be warned).
  • Run the code again to see your move!
Commentshotnewtop
CaptainAnon (139)

Rust does allow you to read in code from the command line using stdin.

bijan2005 (0)

@CaptainAnon Yes, but it doesn't allow you to do it at compile-time, which is when type constraint calculations take place.

I could be wrong about that, but I couldn't find a good way to do it.

CaptainAnon (139)

@bijan2005 I think you can use match with the Result enum to try and parse the data onto the board and fail if the data cannot be parsed.