This is only a preview of the January 2023 issue of Silicon Chip. You can view 39 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Q Meter":
Items relevant to "Raspberry Pi Pico W BackPack":
Items relevant to "Active Subwoofer, Part 1":
Items relevant to "Noughts & Crosses game using just two modules":
Items relevant to "Noughts & Crosses Machine, Pt1":
Purchase a printed copy of this issue for $11.50. |
CIRCUIT NOTEBOOK
Interesting circuit ideas which we have checked but not built and tested. Contributions will be paid for at
standard rates. All submissions should include full name, address & phone number.
Noughts & Crosses game using just two modules
In the October 2021 issue of Silicon Chip, the Australian entrepreneur
Dick Smith announced a competition
to develop a Noughts and Crosses
machine.
Dick Smith mentions that he built
a machine using electromechanical
components in his announcement. I’d
love to be able to build something like
that, possibly using modern relays. But
I’d need an enormously large number of them and they cost a few dollars each.
I decided that something using an
Arduino or Raspberry Pi would be the
obvious way to do the job in 2021.
More or less randomly, I decided to
follow the Arduino path.
An Arduino Uno and an Adafruit
TFT LCD are an obvious combination;
mine is a ‘plain jane’ implementation. Each of the cells of the Noughts
and Crosses grid becomes a button to
be pressed to indicate the move the
human wants to make. My design
includes an extra rectangular button
at upper left to toggle who plays X to
start each game.
The Adafruit TFT LCD is available
in two versions: V1 and V2. Adafruit
supply and support only V2, but most
clones are V1. If a clone is used, it
is important not to use the Adafruit
support library but a different library:
MCUFRIEND_kbv. The Arduino
Library Manager knows of this library,
76
Silicon Chip
and it is easy to install, but it is necessary to do quite a lot of careful reading
of fine print to persuade it all to work.
I have not debugged my program
for V1 clones, only for V2 TFT LCDs.
I implemented the Newell, Simon
strategy as published. Although I eventually got it to work, the descriptions
of it are not easy to follow. I studied
at least three and became thoroughly
bamboozled by all three of them. There
are eight components of the Newell,
Simon strategy and seven of them are
simple, obvious, and easy to understand. One isn’t.
The problem strategy is described
as “Block Fork”, but it tries to do two
or maybe three jobs at once, and all
descriptions have “unless...” qualifications.
Because I struggled to understand
the Newell, Simon strategy, I tested
my implementation often. I found
mistakes often. I’m reasonably confident that the program submitted never
allows a human to create a fork and
consequently always forces a draw,
unless it wins. An Excel file is available to confirm this.
The Adafruit examples demonstrating the touchscreen don’t mention
debouncing, but it is essential. Each
touch sends a stream of X and Y coordinates of many touches, not just one.
Simple delays don’t flush the redundant points out of the FIFO. I read
Australia's electronics magazine
several examples to discover how to
combine an appropriate delay while
flushing the buffer to avoid unexpected touch events.
Although the Adafruit library
includes several font sizes, they must
be integers, and I found that size 1 is
too small but size 2 is too big. Ideally,
I’d like size √2, but it is unavailable.
For most text, I’ve used size 1 even
though that is a bit small. I’ve used
size 2 for the game’s name at the top
of the screen and size 3 for the Xs and
Os played within the board cells.
A box at the top left advises who
is X and who is O. This box is touch
sensitive. If it is touched at any time,
including during a game, it will toggle
who is X and O, and start a new game,
aborting the game in play if necessary.
If a game is won, it is traditional
to draw a line through the winning
row, column, or diagonal. I don’t do
exactly that; instead, I change the
colour of the text in the winning cells
to white.
Note that the computer doesn’t
attempt to vary its moves. After a few
games, it becomes a bit predictable.
The software sketch (NaughtyCross.
ino) is available for download from
siliconchip.com.au/Shop/6/92, along
with the Excel spreadsheet demonstrating that it will play a perfect game.
Keith Anderson,
Kingston, Tas ($70).
siliconchip.com.au
|