« Back to projects

Arbitrarily-Sized Tic Tac Toe

Languages: Scala
Summary: An exercise-turned-project, this is a command-line version of Tic Tac Toe that allows arbitrarily sized square boards. At size 15 it becomes Gomoku and at size 19 it becomes Connect6.
Source code: github [.tar.gz / .zip]

Details

This is a command-line version of Tic Tac Toe that can be played at any (square) size you want. For a command-line game it has a friendly interface: both axes are labeled and the columns are letters instead of numbers. And just like Excel, once you get past 26 letters it starts using two (AA, AB, AC, etc).

Originally this started out as an exercise I did as part of my Seven Languages In Seven Weeks project to help me learn Scala. I ended up putting enough time into making it solid and usable that I decided it deserved its own project page.

Anyway, here’s what it looks like:


Player X's turn.
Enter square: (e.g. A0): a2

     A   B   C   
   ┌───┬───┬───┐
0  │ X │ X │ O │
   │───│───│───│
1  │   │ O │   │
   │───│───│───│
2  │ X │   │   │
   └───┴───┴───┘

What, you want bigger? Okay!


Enter board size: 27

6 in a row to win (27x27 board)

     A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z   AA  
   ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
0  │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
1  │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
2  │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
3  │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
4  │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
5  │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
6  │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
7  │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
8  │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
9  │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
10 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
11 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
12 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
13 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
14 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
15 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
16 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
17 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
18 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
19 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
20 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
21 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
22 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
23 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
24 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
25 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   │───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│───│
26 │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │   │
   └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘


Player X's turn.
Enter square: (e.g. A0): 

Want to see how big it can get? Go download it now and try it out! I haven’t enforced any kind of sensible limit, so you can fill your terminal with characters or get OutOfMemory errors to your heart’s content.

Content by Nick Knowlson: Google+
rsstwitter