Hardware Reference
In-Depth Information
TIC-TAC-TOE IS BETTER known as noughts and crosses in Europe. So when the 1956
American TV show Tic Tac Dough, which had a theme tune that followed the rhythm of those
words, was transferred to the U.K., they changed the name to Criss Cross Quiz to keep the
same rhythm and because no one in the U.K. knew the game as tic-tac-toe. On U.S. TV the
show was revived in 1978 and in 1980 became one of the irst TV shows to have its graphics
generated by a computer. Each square was controlled by one Apple II computer, with the
whole array being controlled by an Altair 8800 computer system. So it is perhaps itting that
tic-tac-toe should be the subject of this topic's irst software project. In fact, I made a noughts
and crosses automatic playing machine simply out of multipole switches and lashlight bulbs
way back in the mid-60s for a school open day.
I am sure that you know how to play tic-tac-toe, but just in case this topic reaches places
where it is not a familiar game, I'll go over how it is played. he game is played on a 3 X 3 grid
formed by drawing two horizontal lines and two vertical lines. Two players in turn mark an
empty square with a cross or a zero. he irst player to have three of their marks in a line is
the winner. he line can be horizontal, vertical or diagonal.
Tic-tac-toe is an ideal game for learning how to program because it uses so many concepts that
are useful in computer programming, as well as having the virtue that it can be built up gradu-
ally in a step-by-step manner. his is the way that all projects should be developed, one small
step at a time. Nobody writes a large program and then runs it for the irst time, except perhaps
beginners. his is because by writing small and testing, you drastically reduce where any errors
can be. If your irst bit has no errors, when you write the next bit, and suddenly there is an
error, then it is almost certain that your error lies in the code you have just written.
Errors
When you write code you can make two sorts of errors: he irst sort, known as a syntax error, is
when the computer can't make sense of the instructions you have given it. Examples of these
types of errors are spelling variable names incorrectly, not adhering to the same uppercase and
lowercase mix in variables and not getting the format of a command correct, such as forgetting
to add a colon. he second sort, known as a logical error, is much harder to spot. hese errors are
when the computer does exactly what you told it to do, but what you told it to do was not exactly
what you wanted it to do. Logical errors can be the hardest to ind. his often fools beginners
because, when the computer is inished complaining about errors, they expect a program to run
like they thought they wrote it. In this case logical errors are caused by the programmer's think-
ing more like a human and not enough like a computer. he more experienced you get, the better
you will become at avoiding these errors, but it is human nature that you will never be entirely
free of them; you will just get better at spotting them and tracking them down.
It is important to realise that there is no one correct way to write a program, despite what
some programmers might want to think. he forums are full of raging arguments as to the
best style and technique to use, but do not be intimidated by this. Good code is code that
Search WWH ::




Custom Search