WolframAlpha.com
WolframCloud.com
All Sites & Public Resources...
Products & Services
Wolfram|One
Mathematica
Wolfram|Alpha Notebook Edition
Programming Lab
Finance Platform
SystemModeler
Wolfram Player
Wolfram Engine
WolframScript
Enterprise Private Cloud
Enterprise Mathematica
Wolfram|Alpha Appliance
Enterprise Solutions
Corporate Consulting
Technical Consulting
Wolfram|Alpha Business Solutions
Resource System
Data Repository
Neural Net Repository
Function Repository
Wolfram|Alpha
Wolfram|Alpha Pro
Problem Generator
API
Data Drop
Products for Education
Mobile Apps
Wolfram Player
Wolfram Cloud App
Wolfram|Alpha for Mobile
Wolfram|Alpha-Powered Apps
Services
Paid Project Support
Wolfram U
Summer Programs
All Products & Services »
Technologies
Wolfram Language
Revolutionary knowledge-based programming language.
Wolfram Cloud
Central infrastructure for Wolfram's cloud products & services.
Wolfram Science
Technology-enabling science of the computational universe.
Wolfram Notebooks
The preeminent environment for any technical workflows.
Wolfram Engine
Software engine implementing the Wolfram Language.
Wolfram Natural Language Understanding System
Knowledge-based broadly deployed natural language.
Wolfram Data Framework
Semantic framework for real-world data.
Wolfram Universal Deployment System
Instant deployment across cloud, desktop, mobile, and more.
Wolfram Knowledgebase
Curated computable knowledge powering Wolfram|Alpha.
All Technologies »
Solutions
Engineering, R&D
Aerospace & Defense
Chemical Engineering
Control Systems
Electrical Engineering
Image Processing
Industrial Engineering
Mechanical Engineering
Operations Research
More...
Finance, Statistics & Business Analysis
Actuarial Sciences
Bioinformatics
Data Science
Econometrics
Financial Risk Management
Statistics
More...
Education
All Solutions for Education
Trends
Machine Learning
Multiparadigm Data Science
Internet of Things
High-Performance Computing
Hackathons
Software & Web
Software Development
Authoring & Publishing
Interface Development
Web Development
Sciences
Astronomy
Biology
Chemistry
More...
All Solutions »
Learning & Support
Learning
Wolfram Language Documentation
Fast Introduction for Programmers
Wolfram U
Videos & Screencasts
Wolfram Language Introductory Book
Webinars & Training
Summer Programs
Books
Need Help?
Support FAQ
Wolfram Community
Contact Support
Premium Support
Premier Service
Technical Consulting
All Learning & Support »
Company
About
Company Background
Wolfram Blog
Events
Contact Us
Work with Us
Careers at Wolfram
Internships
Other Wolfram Language Jobs
Initiatives
Wolfram Foundation
MathWorld
Computer-Based Math
A New Kind of Science
Wolfram Technology for Hackathons
Student Ambassador Program
Wolfram for Startups
Demonstrations Project
Wolfram Innovator Awards
Wolfram + Raspberry Pi
Summer Programs
More...
All Company »
Search
Join
Sign In
Dashboard
Groups
People
Message Boards
Answer
(
Unmark
)
Mark as an Answer
GROUPS:
Staff Picks
Computer Science
Game Development
Mathematics
Recreation
Algebra
Discrete Mathematics
Dynamic Interactivity
Wolfram Language
6
Rauan Kaldybaev
Naughts and crosses on a tesseract, or the four-dimensional tic-tac-toe
Rauan Kaldybaev
Posted
3 months ago
1170 Views
|
2 Replies
|
6 Total Likes
Follow this post
|
Four-dimensional naughts and crosses: what is it and how to play it
This is already the twentieth draw in a row - Marat said tiredly. That was true, every game we played went by the same scenario, as if everything was planned in advance. I paused for a second. Well, I said...
X
X
O
X
O
O
X
X
·
·
·
·
·
O
·
·
·
·
·
O
X
O
X
X
X
X
O
O
O
X
O
X
O
·
X
O
O
·
X
O
O
X
X
O
X
·
·
X
·
O
O
O
·
·
·
·
X
·
O
·
X
·
·
·
·
·
X
·
·
·
·
·
·
O
X
O
O
O
X
X
O
u
t
[
]
=
Introduction
What is the difference between 2D and 4D?
The game is practically the same in four dimensions: the players still need to construct rows of three tiles to win. The main difference is that the game happens not on a two-dimensional square but on a four-dimensional generalization of cube called tesseract. It isn’t that scary as it sounds, though - rows are still counted in much the same way. Because the 4D game gives more opportunities for constructing tiles, in order to win one must construct not just one row but nine - that’s the second difference. Lastly, since the central tile gives the player who takes it too much of a lead, I decided to disable it to make the game more balanced.
Why is 4D better?
It is cooler - I mean, when was the last time you played in four dimensions?
◼
It is harder to find the optimal strategy. While in 2D naughts and crosses it doesn’t take long to figure out the undefeatable tactic, in the four-dimensional case there are too many possible scenarios to do this.
◼
It requires more thinking. While in the 2D tic-tac-toe there are 8 possible rows, in 4D there are 232. What this means is that the players need to think several turns in advance to choose the tile that’s going to let them construct more rows.
◼
It gives an intuition for four-dimensional space.
◼
Because there is more space in the game, the 4D version can accommodate more players.
◼
The chance of draw is smaller in the four-dimensional version.
◼
How do you construct the rules?
It might not be immediately clear how we can extend the aughts and crosses game if no human (excluding mental asylum patients) has ever experienced 4D space and thus can’t tell us what it is like. However, it turns out that this is not a problem, as we have math at our disposal. If we first develop a mathematical formalism for the
2D tic-tac-toe
, it is very easy to generalize to any higher number of dimensions.
Formalizing the “normal” 2-dimensional naughts and crosses
Playing grid
We can view the playing grid as an array, which is basically a table that stores the information about each tile; let’s call it
g
. We denote the value of the
n
’th tile in the
m
’th row as
g
m
n
, and
m
and
n
are called the indexes of
g
. Here is a picture showing which entries of
g
correspond to which tiles:
G
r
i
d
[
T
a
b
l
e
[
S
u
b
s
c
r
i
p
t
[
"
g
"
,
S
t
r
i
n
g
J
o
i
n
[
T
o
S
t
r
i
n
g
/
@
{
i
,
j
}
]
]
,
{
i
,
3
}
,
{
j
,
3
}
]
,
F
r
a
m
e
A
l
l
,
S
p
a
c
i
n
g
s
{
1
,
1
}
]
I
n
[
]
:
=
g
1
1
g
1
2
g
1
3
g
2
1
g
2
2
g
2
3
g
3
1
g
3
2
g
3
3
O
u
t
[
]
=
If, for example, the playing grid looks like this:
e
x
a
m
p
l
e
2
D
g
r
i
d
=
A
r
r
a
y
[
R
a
n
d
o
m
C
h
o
i
c
e
[
{
"
·
"
,
"
X
"
,
"
O
"
}
]
&
,
{
3
,
3
}
]
;
I
n
[
]
:
=
G
r
i
d
[
e
x
a
m
p
l
e
2
D
g
r
i
d
,
F
r
a
m
e
A
l
l
,
S
p
a
c
i
n
g
s
{
1
,
1
}
]
I
n
[
]
:
=
O
·
X
X
·
·
X
·
·
O
u
t
[
]
=
Then this is what the entries of
g
are:
C
o
l
u
m
n
@
F
l
a
t
t
e
n
@
T
a
b
l
e
[
R
o
w
[
{
S
u
b
s
c
r
i
p
t
[
"
g
"
,
S
t
r
i
n
g
J
o
i
n
[
T
o
S
t
r
i
n
g
/
@
{
i
,
j
}
]
]
,
"
=
"
,
T
o
S
t
r
i
n
g
@
e
x
a
m
p
l
e
2
D
g
r
i
d
[
[
i
,
j
]
]
}
]
,
{
i
,
3
}
,
{
j
,
3
}
]
I
n
[
]
:
=
g
1
1
=
O
g
1
2
=
·
g
1
3
=
X
g
2
1
=
X
g
2
2
=
·
g
2
3
=
·
g
3
1
=
X
g
3
2
=
·
g
3
3
=
·
O
u
t
[
]
=
Representing grid entries with numbers
This idea is rather straightforward. Instead of using
“
·
”
to represent empty spaces, we can store the number 0 in the playing grid. Also, instead of representing player 1’s marks as
“X”
, we can use the number 1. When displaying the grid, we can substitute the proper icons for the numbers, so that the user sees the familiar picture.
This would allow us to change the users’ icons during the game, and this would also let two users playing on different computers with different icon settings to compare their playing grids.
The notion of a line
The key feature of the tic-tac-toe game is that a player needs to place three marks in a line to win. For instance, if
g
1
2
=
g
2
2
=
g
3
2
=
1
, then these three entries form a line. Let’s try to formalize this notion.
If three marks are placed in a line, there is such mark that lies exactly in-between the other two. We can formalize this statement with the help of vectors. We can view the indexes of
g
not only as indexes but also as coordinates on a two-dimensional plane if we imagine an actual physical tic-tac-toe playing grid. Then, the statement that a point
P
2
lies in-between the points
P
1
and
P
3
can be written as
P
2
x
=
P
1
x
+
P
3
x
2
P
2
y
=
P
1
y
+
P
3
y
2
w
h
e
r
e
P
1
x
i
s
t
h
e
x
-
c
o
o
r
d
i
n
a
t
e
o
f
p
o
i
n
t
1
.
T
h
i
s
c
a
n
a
l
s
o
b
e
w
r
i
t
t
e
n
i
n
v
e
c
t
o
r
n
o
t
a
t
i
o
n
a
s
P
2
=
P
1
+
P
3
2
,
w
h
e
r
e
P
1
i
s
t
h
e
p
o
s
i
t
i
o
n
v
e
c
t
o
r
o
f
t
h
e
f
i
r
s
t
p
o
i
n
t
.
We can re-write these equations as
P
3
-
P
2
=
P
2
-
P
1
=
v
Where
v
is some vector. There are some limitations for
v
. First of all, it cannot be zero, because that would mean that the three tiles are actually one same tile, which does not make a lot of sense. Second, since the tiles must be adjacent to each other, the components of
v
must be either 0, -1, or 1. Think of this like this: if you are standing on a tile and you jump to a neighboring one, then you are only going to move by either -1, 0, or 1 length units along each direction of space.
Counting rows
This is not essential for playing but just quite curious. If you just want to play, you can safely skip this part.
Let’s try to find an algorithm for counting rows. To do that, we just have to iterate over all possible lines and count those that match the criterion.
We can characterize a line by giving its starting point (e.g. the tile that is on one of the line’s ends) and the vector
v
. The other two points can be found by simply moving by the displacement
v
from the starting point.
We can first find all possible vectors v for the two - dimensional grid by enumeration and selection :
p
o
s
s
i
b
l
e
2
D
v
=
S
e
l
e
c
t
[
F
l
a
t
t
e
n
[
T
a
b
l
e
[
{
v
x
,
v
y
}
,
{
v
x
,
{
-
1
,
0
,
1
}
}
,
{
v
y
,
{
-
1
,
0
,
1
}
}
]
,
1
]
,
#
≠
{
0
,
0
}
&
]
;
I
n
[
]
:
=
Here is what we get:
C
o
l
u
m
n
@
p
o
s
s
i
b
l
e
2
D
v
I
n
[
]
:
=
{
-
1
,
-
1
}
{
-
1
,
0
}
{
-
1
,
1
}
{
0
,
-
1
}
{
0
,
1
}
{
1
,
-
1
}
{
1
,
0
}
{
1
,
1
}
O
u
t
[
]
=
Basically, if we draw all the possible vectors, we get a hedgehog:
G
r
a
p
h
i
c
s
[
A
r
r
o
w
[
{
{
0
,
0
}
,
#
}
]
&
/
@
p
o
s
s
i
b
l
e
2
D
v
]
I
n
[
]
:
=
O
u
t
[
]
=
K
n
o
w
i
n
g
v
,
w
e
c
a
n
c
o
m
p
u
t
e
t
h
e
s
e
t
o
f
p
o
s
s
i
b
l
e
s
t
a
r
t
i
n
g
p
o
i
n
t
s
f
o
r
i
t
.
T
h
e
o
n
l
y
c
r
i
t
e
r
i
o
n
t
h
a
t
w
e
h
a
v
e
t
o
s
a
t
i
s
f
y
i
s
t
h
a
t
a
l
l
t
i
l
e
s
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e
s
o
f
s
i
:
s
i
∈
{
3
}
v
i
=
-
1
s
i
∈
{
1
,
2
,
3
}
v
i
=
0
s
i
∈
{
1
}
v
i
=
1
Given
v
, we can calculate the set of possible values for each of the
s
i
. We can then iterate through all possible combinations of
s
i
, and this will give us the set of possible values of
s
. For instance, if
v
=
<
-
1
,
0
>
, then
s
1
∈
{
3
}
and
s
2
∈
{
1
,
2
,
3
}
, then this basically means that the first component of
s
is 3 and the second component is either 1, 2, or 3. Then,
s
can be either
{
3
,
1
}
,
{
3
,
2
}
, or
{
3
,
3
}
. We can automatize this process using Wolfram Language.
g
e
t
2
D
s
t
a
r
t
i
n
g
P
o
i
n
t
s
[
v
_
]
:
=
T
u
p
l
e
s
[
T
a
b
l
e
[
W
h
i
c
h
[
q
-
1
,
{
3
}
,
q
0
,
{
1
,
2
,
3
}
,
q
1
,
{
1
}
]
,
{
q
,
v
}
]
]
;
I
n
[
]
:
=
g
e
t
2
D
s
t
a
r
t
i
n
g
P
o
i
n
t
s
[
{
-
1
,
0
}
]
I
n
[
]
:
=
{
{
3
,
1
}
,
{
3
,
2
}
,
{
3
,
3
}
}
O
u
t
[
]
=
Now, you would think (at least I thought) that, to find the number of lines a particular player has scored, we simply have to iterate through all possible
v
’s and their corresponding sets of possible starting points, and then count the number of lines using the algorithm given above. However, if you actually did that, you would get twice the actual number of lines, because each line would be counted twice, as there are two combinations of
s
and
v
that yield the same starting point. Mathematically, if we construct a line
{
s
,
s
+
v
,
s
+
2
v
}
, we can also construct a line
{
s
'
,
s
'
+
v
'
,
s
'
+
2
v
'
}
, where
v
=
-
v
'
,
s
'
=
s
-
2
v
. If we substitute the definitions of
v’
and
s’
, we would get the line
{
s
+
2
v
,
s
+
v
,
s
}
, which is basically the old one written in reverse.
To prevent this situation from happening, we can remove half of the
v
’s, such that there was no
v
and -
v
pairs. For that, let us draw a plane B, such that it passes through the origin and none of the possible vectors
v
lies inside this plain. You can prove that if we only leave such
v
’s that lie on one side of the plane, there will be no
v
and -
v
pairs. This is the solution to the problem.
We can characterize the plane B by a normal vector
N
. If
v
·
N
>
0
, the lector lies on one side of the plain, and if
v
·
N
is negative, then the vector lies on the other side. We can use this property to remove the “extra” vectors
v
. Now, the choice of
N
is arbitrary, we just have to make sure that no vector
v
lies in the plane, e.g.
v
·
N
≠
0. One of the ways in which it can be done is when
N
i
=
i
-
1
2
, so that none of the
N
’s components can be obtained by adding or subtracting the other ones. Because the components of
v
are either -1, 0, or 1, the dot product of
v
and
N
will have the form
-
N
1
+
N
2
+
.
.
.
, so it cannot be zero.
This is how the normal vector
N
looks like in two dimensions:
n
o
r
m
a
l
V
e
c
t
o
r
2
D
=
A
r
r
a
y
[
2
^
(
#
-
1
)
&
,
2
]
I
n
[
]
:
=
{
1
,
2
}
O
u
t
[
]
=
This is how we filter the set of possible
v
’s (the “hedgehog”).
v
T
o
C
o
n
s
i
d
e
r
=
S
e
l
e
c
t
[
p
o
s
s
i
b
l
e
2
D
v
,
T
o
t
a
l
[
#
*
n
o
r
m
a
l
V
e
c
t
o
r
2
D
]
>
0
&
]
I
n
[
]
:
=
{
{
-
1
,
1
}
,
{
0
,
1
}
,
{
1
,
0
}
,
{
1
,
1
}
}
O
u
t
[
]
=
We are left with half of the original hedgehog.
G
r
a
p
h
i
c
s
[
A
r
r
o
w
[
{
{
0
,
0
}
,
#
}
]
&
/
@
v
T
o
C
o
n
s
i
d
e
r
]
I
n
[
]
:
=
O
u
t
[
]
=
So finally, we have the algorithm for counting rows:
c
o
u
n
t
R
o
w
s
2
D
[
g
_
,
p
l
a
y
e
r
I
d
_
]
:
=
B
l
o
c
k
[
{
s
c
o
r
e
=
0
}
,
T
a
b
l
e
[
T
a
b
l
e
[
I
f
[
A
l
l
T
r
u
e
[
g
[
[
#
[
[
1
]
]
,
#
[
[
2
]
]
]
]
&
/
@
{
s
,
s
+
v
,
s
+
2
v
}
,
#
p
l
a
y
e
r
I
d
&
]
,
s
c
o
r
e
+
+
]
,
{
s
,
g
e
t
2
D
s
t
a
r
t
i
n
g
P
o
i
n
t
s
[
v
]
}
]
,
{
v
,
v
T
o
C
o
n
s
i
d
e
r
}
]
;
s
c
o
r
e
]
;
I
n
[
]
:
=
Generalizing to four dimensions
In four dimensions, everything is basically the same as in the two-dimensional case. As before, we can represent the playing grid as an array, except that now it has not two but four indexes. It can be drawn as a 3
3 grid of 3
3 grids, like this:
·
O
·
·
O
·
·
O
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
X
·
·
·
·
·
X
·
X
·
·
O
Y
·
·
Y
Y
X
Y
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
O
u
t
[
]
=
Here is a picture showing which entries of g correspond to which tiles:
g
1
1
1
1
g
1
2
1
1
g
1
3
1
1
g
2
1
1
1
g
2
2
1
1
g
2
3
1
1
g
3
1
1
1
g
3
2
1
1
g
3
3
1
1
g
1
1
1
2
g
1
2
1
2
g
1
3
1
2
g
2
1
1
2
g
2
2
1
2
g
2
3
1
2
g
3
1
1
2
g
3
2
1
2
g
3
3
1
2
g
1
1
1
3
g
1
2
1
3
g
1
3
1
3
g
2
1
1
3
g
2
2
1
3
g
2
3
1
3
g
3
1
1
3
g
3
2
1
3
g
3
3
1
3
g
1
1
2
1
g
1
2
2
1
g
1
3
2
1
g
2
1
2
1
g
2
2
2
1
g
2
3
2
1
g
3
1
2
1
g
3
2
2
1
g
3
3
2
1
g
1
1
2
2
g
1
2
2
2
g
1
3
2
2
g
2
1
2
2
g
2
3
2
2
g
3
1
2
2
g
3
2
2
2
g
3
3
2
2
g
1
1
2
3
g
1
2
2
3
g
1
3
2
3
g
2
1
2
3
g
2
2
2
3
g
2
3
2
3
g
3
1
2
3
g
3
2
2
3
g
3
3
2
3
g
1
1
3
1
g
1
2
3
1
g
1
3
3
1
g
2
1
3
1
g
2
2
3
1
g
2
3
3
1
g
3
1
3
1
g
3
2
3
1
g
3
3
3
1
g
1
1
3
2
g
1
2
3
2
g
1
3
3
2
g
2
1
3
2
g
2
2
3
2
g
2
3
3
2
g
3
1
3
2
g
3
2
3
2
g
3
3
3
2
g
1
1
3
3
g
1
2
3
3
g
1
3
3
3
g
2
1
3
3
g
2
2
3
3
g
2
3
3
3
g
3
1
3
3
g
3
2
3
3
g
3
3
3
3
O
u
t
[
]
=
Here is an example of a row:
X
·
·
·
·
·
·
·
·
·
X
·
·
·
·
·
·
·
·
·
X
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
O
u
t
[
]
=
I
n
t
h
i
s
c
a
s
e
,
g
1
1
1
1
,
g
1
2
1
2
,
g
1
3
1
3
f
o
r
m
a
l
i
n
e
i
n
w
h
i
c
h
e
v
e
r
y
t
i
l
e
i
s
t
a
k
e
n
b
y
t
h
e
p
l
a
y
e
r
1
a
n
d
m
a
r
k
e
d
a
s
X
.
In the four-dimensional case, it’s far easier to make a line, so I decided to set the winning threshold to 9. In other words, one needs to score nine lines in order to win.
How to play
Below is how you play the game using the WL functions presented in this essay. You can still play the game even if you don’t have access to Wolfram Language, though, if you understand how the game works - you just need a piece of paper and a pen. There is nothing you can’t do that the computer can (at least in this case). The algorithm for counting rows is described
here
.
0. Start a new game
Here is how you create a new game:
N
C
4
n
e
w
G
a
m
e
[
N
P
l
a
y
e
r
s
3
]
I
n
[
]
:
=
There are the options for this function:
"NPlayers"
is the number of players in the game. By default, it’s set to 2.
◼
“PlayerIcons”
is the list of the characters that represent players on the grid. by default it’s set to
{0
→
“
·
“, 1
→
“X”, 2
→
“O”, 3
→
“Y”, 4
→
“Z”}
. What it means that blank spaces (0) will be represented as
“
·
“
, player 1 will be represented by
“X”
, player 2 - by
“O”
, and so on. There must be at least as many icons as there are players.
◼
“Threshold”
is the score that a player needs to get to win. By default it’s set to 9.
◼
1. Launch the game
N
C
4
p
l
a
y
[
]
I
n
[
]
:
=
(You have to run this line on your computer, as Cloud does not display the results properly) Players’ lines are shown in blue. The “Turn” part of the panel indicates whose turn it is, and “Scores” shows what scores the players have. “History” shows the three latest changes that happened in the game in the form
tileId
→
player
,
player
is the player who was the last to act, and
tileId
is the id of the tile that they chose. The “Back” button cancels the latest change that happened; use it when you accidentally pressed at a wrong place in the grid.
Here is what the playing grid may look like:
·
O
·
·
O
·
·
O
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
X
·
·
·
·
·
X
·
X
·
·
O
Y
·
·
Y
Y
X
Y
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
O
u
t
[
]
=
2. Tap at some place on the grid
If you and your opponent(s) are in the same room
This will put your mark at that place. Press “Back” if you accidentally pressed a wrong tile.
If you are playing online
T
h
i
s
w
i
l
l
p
u
t
y
o
u
r
m
a
r
k
a
t
t
h
a
t
p
l
a
c
e
.
N
o
w
,
t
o
l
e
t
y
o
u
r
o
p
p
o
n
e
n
t
(
s
)
k
n
o
w
w
h
e
r
e
y
o
u
c
h
o
s
e
t
o
p
l
a
c
e
y
o
u
r
m
a
r
k
,
c
o
p
y
t
h
e
t
i
l
e
i
d
f
r
o
m
t
h
e
“
H
i
s
t
o
r
y
”
p
a
r
t
o
f
t
h
e
p
a
n
e
l
.
T
h
e
s
e
c
t
i
o
n
w
i
l
l
h
a
v
e
t
h
e
f
o
l
l
o
w
i
n
g
f
o
r
m
:
H
i
s
t
o
r
y
:
2
3
→
X
4
5
→
O
9
→
X
T
h
e
b
o
t
t
o
m
p
a
i
r
s
h
o
w
s
t
h
e
l
a
s
t
t
u
r
n
t
h
a
t
w
a
s
m
a
d
e
.
T
h
e
g
e
n
e
r
a
l
“
f
o
r
m
u
l
a
”
i
s
t
i
l
e
I
d
→
i
c
o
n
.
A
n
y
w
a
y
,
y
o
u
s
h
o
u
l
d
c
o
p
y
t
h
e
l
e
f
t
p
a
r
t
o
f
t
h
e
b
o
t
t
o
m
p
a
i
r
(
i
n
t
h
i
s
c
a
s
e
,
i
t
w
o
u
l
d
b
e
9
)
.
N
o
w
,
s
e
n
d
i
t
t
o
y
o
u
r
o
p
p
o
n
e
n
t
(
s
)
v
i
a
,
f
o
r
e
x
a
m
p
l
e
,
a
T
e
l
e
g
r
a
m
c
h
a
t
.
U
p
o
n
r
e
c
e
i
v
i
n
g
t
h
i
s
i
n
f
o
r
m
a
t
i
o
n
,
y
o
u
r
o
p
p
o
n
e
n
t
s
s
h
o
u
l
d
p
r
o
c
e
e
d
t
o
s
t
e
p
3
.
Bonus: see where the scores came from
It can often be quite difficult to see where the players’ scores came from. In this case, you can use the
NC4showLines
function, that gives an animation that illustrates it. Below, you can see the result of
NC4howLines[1]
, which shows player 1’s lines.
·
·
·
·
·
·
·
·
·
·
·
·
·
O
·
·
·
·
O
O
O
·
X
·
X
X
X
·
X
·
·
·
·
·
·
·
·
X
·
·
·
·
X
·
·
X
·
O
O
O
·
O
·
·
·
X
·
X
·
X
X
O
·
·
·
·
O
·
·
·
·
·
·
·
·
O
·
·
·
·
O
u
t
[
]
=
Similarly, of you want to see a similar visual for the second player (O), use
NC4showLines[2]
.
3. Enter the opponent’s turn
If you and your opponents are in the same room
Simply get your opponents to the computer and get them to repeat point 2.
If you are playing online
At this step, your opponent should have sent you the id of the tile that they chose to place their mark at.
Enter the tile id that you received into the text input field on top of the panel. Then place the “Go” button; if everything went correctly, one of the tiles in the playing grid will be marked, and the turn will go to the next person. If the number you entered was invalid for some reason, nothing will happen.
4. If any of the players won, proceed to step 5. Otherwise, return to step 3
Basically, keep playing until someone wins.
5. Rejoice your victory (maybe)
O
u
t
[
]
=
6. Return to step 0 or quit playing
Export / load game
You can export the game in the form of a string:
N
C
4
e
x
p
o
r
t
G
a
m
e
[
]
I
n
[
]
:
=
{
3
,
{
0
-
>
"
·
"
,
1
-
>
"
X
"
,
2
-
>
"
O
"
,
3
-
>
"
Y
"
,
4
-
>
"
Z
"
}
,
9
,
"
M
A
w
G
G
F
I
a
A
j
m
Z
1
E
9
s
y
7
A
D
B
3
u
v
c
4
z
h
X
O
D
R
Y
E
B
g
K
u
H
v
v
7
M
3
r
H
Y
2
P
R
j
"
}
O
u
t
[
]
=
The string contains all information about the game: the number of players, the game’s history (e.g. the record of what turns were made by each player), the winning threshold, and even the players’ icons are included.
You can store this string in a .txt (or your favorite file format) file and later upload them using
NC4loadGame
:
N
C
4
l
o
a
d
G
a
m
e
[
"
{
3
,
{
0
-
>
\
"
·
\
"
,
1
-
>
\
"
X
\
"
,
2
-
>
\
"
O
\
"
,
3
-
>
\
"
Y
\
"
,
4
-
>
\
"
Z
\
"
}
,
9
,
\
"
M
A
w
G
G
F
I
a
A
j
m
Z
1
E
9
s
y
7
A
D
B
3
u
v
c
4
z
h
X
O
D
R
Y
E
B
g
K
u
H
v
v
7
M
3
r
H
Y
2
P
R
j
\
"
}
"
]
I
n
[
]
:
=
You can also use this function to compare two games. If you and your friend are playing remotely and you want to make sure that you are playing the same game, you can compare the last part of the strings (the “rubbish” part). This is where the game’s history is stored; the computer also uses this data to determine what the playing grid looks like.
Code
Setup
C
l
e
a
r
A
l
l
[
N
C
4
n
e
w
G
a
m
e
,
N
C
4
p
l
a
y
,
N
C
4
s
h
o
w
L
i
n
e
s
,
N
C
4
s
h
o
w
G
r
i
d
,
N
C
4
e
x
p
o
r
t
G
a
m
e
,
N
C
4
e
x
p
o
r
t
G
r
i
d
,
N
C
4
l
o
a
d
G
a
m
e
,
N
C
4
g
r
i
d
W
r
i
t
e
,
N
C
4
g
e
t
G
r
i
d
C
o
o
r
d
s
,
N
C
4
g
e
t
T
i
l
e
I
d
,
N
C
4
g
e
t
T
i
l
e
,
N
C
4
c
o
u
n
t
L
i
n
e
s
,
N
C
4
g
r
i
d
W
r
i
t
e
,
N
C
4
s
h
o
w
C
o
n
g
r
a
t
u
l
a
t
i
o
n
s
,
N
C
4
g
r
i
d
F
u
l
l
Q
,
N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