Skip to content

A calculator’s way of playing tic-tac-toe

How hard can it be? You sit down and figure out what to do in every possible tic-tac-toe situation, and you program the calculator to carry out those moves. Surely it can’t be that tricky — can it?

Well, the program extension on my graphic calculator was a bit trickier than I thought it would be. To program the calculator to play against a human (an extension of the original program, which just hosted a two-player, human vs. human game) took me probably around fifteen hours accumulated. It involved an extra 190 lines of code (the two-player version was 58 lines long) and the use of fifteen more variables. The extra code was almost 1,945 bytes, bringing the total program size to 2,809 bytes — the longest program for a calculator I’ve written yet.

And it’s quite boring code, really. It’s just, check if this is the situation, then if it is do this, if it’s not try the next one, and so on, and so on. But then, even after I had figured out the calculator’s tactical manual, the calculator still had to be trained to recognise rotations and reflections of the same situation. So sometimes I would be caught out for a few minutes trying to figure out how to test for some generic condition.

But I got there in the end. It’s perhaps not the most interesting game to play against a calculator, and most people who I’ve asked to test the program seem to be put off by the fact that the calculator is programmed to try and win the game (really, people, it’s not that stupid), but now I have a calculator with 2 kilobytes less memory and the ability to play tic-tac-toe — not your everyday calculator.

One Comment Post a comment
  1. alice #

    omg how do u even know how to program stuff onto a calculator…

    27 October 2005

Leave a comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: