### The Project

My new project is to implement a game in as many different programming languages as possible. This gives me an opportunity to explore new languages and investigate different language features. Since Python is the language I am most familiar with these days, I’m going to do the initial implementation in Python. I’ll go through the initial Python coding in this blog. Also, the initial implementation is going to be for the command line, but I may implement a GUI interface later on.

Code for the project will be posted to this GitHub repository: https://github.com/bacovcin/multidim-tic-tac-toe

### The Game – Multidimensional Tic-Tac-Toe

I wanted to use a game that is complicated enough to be interesting without requiring thousands of lines of code. I’ve selected to do Multi-Dimensional Tic-Tac-Toe. Standard 2-dimensional Tic-Tac-Toe is a classic introduction to game coding, and the multi-dimensional extension makes the project slightly more interesting.

Since standard 2-dimensional Tic-Tac-Toe is simply an instantiation of multi-dimensional Tic-Tac-Toe, most of the rules of multi-dimensional Tic-Tac-Toe can be seen in that game. Two players compete against each other to create “3 in a row” on a 3 by 3 grid. See below for a completed 2-dimensional game where the X player is a winner (since X got 3 in a row on the top line):

X|X|X

=.=.=

O|O|.

=.=.=

O|.|.

The essence of the game is a 2-dimensional grid, where each dimension has 3 levels (i.e., a 3×3 grid). The dimensionality of the game can be increased by adding another 3 levels (e.g., a 3x3x3 grid). This can be represented by duplicating the previous play board twice. Here is a picture of a 3-dimensional board before the game has begun:

.|.|. | .|.|. | .|.|.

=.=.= | =.=.= | =.=.=

.|.|. | .|.|. | .|.|.

=.=.= | =.=.= | =.=.=

.|.|. | .|.|. | .|.|.

The object of the game in higher dimensions is still the same: get 3 in a row. However, in higher dimensions, getting a single 3 in a row becomes quite easy. Instead, you must get 1 less than the number of dimensions in a row **without reusing any cells**.

X-wins (2 lines, no reuse)

X|X|X | .|.|. | .|.|.

=.=.= | =.=.= | =.=.=

X|.|. | .|X|. | .|.|X

=.=.= | =.=.= | =.=.=

.|.|. | .|.|. | .|.|.

X hasn’t won (2 lines, but reuses the upper left corner)

X|X|X | .|.|. | .|.|.

=.=.= | =.=.= | =.=.=

.|.|. | .|X|. | .|.|.

=.=.= | =.=.= | =.=.=

.|.|. | .|.|. | .|.|X

The game needs to be implemented in a general way, so that the only limit on dimensions is how much screen real-estate the board uses.

## List of Posts

I’m going to include here a link to a list of posts in this series: https://www.hakivabacovcin.com/category/programming/multi-dimensional-tic-tac-toe/

## 1 Comment

## homescapes game · 24 November 2017 at 8:33 am

I expect you will enhance and upgrade the game.