20.02.2013 Views

ZX Computings - OpenLibra

ZX Computings - OpenLibra

ZX Computings - OpenLibra

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

After taking your move the<br />

computer will react "My<br />

move" followed by "Search".<br />

The search routine then checks<br />

all 195 possible moves to see if<br />

it can claim any squares. If it<br />

can, it will complete the square<br />

and start again with "My<br />

move". Unfortunately the<br />

search takes approximately 1 2<br />

seconds. This routine may be<br />

altered to a FAST mode by inserting<br />

a new line 153 FAST<br />

followed by a new line at 167<br />

SLOW.<br />

This means that the screen<br />

will blank out for a couple of<br />

seconds during the search,<br />

which in my opinion is not so<br />

good. If the search is unsuccessful<br />

the word "Search" is<br />

followed by an "X" after which<br />

it makes its choice of move.<br />

This is reasonably fast and normally<br />

takes only a second or<br />

two depending on the complexity<br />

of the situation. It does this<br />

by the simple reasoning: if one<br />

of its choices is impractical then<br />

it will not take that move into<br />

account again.<br />

When the grid becomes so<br />

full that it is impossible to move<br />

without giving any squares<br />

away, the program is not able to<br />

take into account how many<br />

squares you can claim from its<br />

move. For this reason the computer<br />

scores two points for<br />

every square it takes.<br />

The ultimate object being<br />

not only to win, but to beat the<br />

computer 88 to 0, which is<br />

almost impossible. If, however,<br />

you beat it by 50 points (which<br />

is very difficult), the coveted<br />

"Congratulations" line prints<br />

up.<br />

The BREAK key will stop the<br />

program at any time. (This can<br />

be useful for sampling the patterns<br />

by simply: BREAK, RUN,<br />

another choice of pattern<br />

number.) Working out where<br />

the computer is going to move<br />

next has been deliberately<br />

made difficult to follow after its<br />

first couple of moves.<br />

The Program<br />

Lines 2-10 set up the instructions.<br />

Note:- Double words, (eg<br />

fora) are separated by the end<br />

of one line and the beginning of<br />

the next.<br />

Line 12 goes to an inkey $ trap.<br />

(Sub 400.) The program will<br />

not continue until a key is pressed.<br />

The value of the key is<br />

recorded in Z $. Not used in this<br />

case.<br />

Lines 16-26 set up the<br />

variables. A:- Keeps a record of<br />

the 195 possible moves.<br />

V:-Records the score. C:-<br />

Defines "whose move". F:-<br />

Starts the computer's turn<br />

position. G:-lndicates if there<br />

are any safe moves left. I:-Is used<br />

to search/ modify the data in<br />

A.<br />

Lines 28-52 set up the display<br />

grid etc.<br />

Lines 54-60 set up D which is<br />

used for the pattern routine.<br />

Lines 62-64 set up "My<br />

score", "Your score". These<br />

look better in inverse characters.<br />

Sub 420 simply blanksout<br />

the line at 1 9, 0; and sets the<br />

next print position again for this<br />

line.<br />

Lines 66-72 sort out whose<br />

move. (The pattern starts at<br />

220. The "My move" starts<br />

at 1 50.)<br />

Lines 74-100 set up all the<br />

variables and traps for "Your<br />

moves" choice. X - Value for<br />

the position acrots the grid.<br />

This can be from 0 to 11. (0 for<br />

A, 1 for B and C, 2 for D and E<br />

etc.) This, together with information<br />

of whether an odd or<br />

even line number down, sorts<br />

out the print position. This arrangement<br />

prevents illegal entries<br />

on the dots or in the middle<br />

of the squares. Y = the up/<br />

down position.<br />

Line 102 goes to the last line of<br />

Sub 470 to get the odd or even<br />

number which is stored in E.<br />

E=0 for even, 1 for odd.<br />

Lines 104-106 again prevents<br />

illegal entries and prevents<br />

entering a move already taken.<br />

Lines 108-110 store and print<br />

a move.<br />

Line 112 Q = The number of<br />

sides to be taken into account in<br />

Sub 440. Sub 430 simply zeros<br />

J, K, L and M in Sub 440 these<br />

variables change to 1 if anytjf<br />

the four directions possible<br />

from a position has Q number of<br />

16K Programs.<br />

sides altogether (eg in this case<br />

Q = 4 thus any four sides in any<br />

four directions will let J, K, L or<br />

M at least equal 1).<br />

Lines 118-126 If the four sides<br />

of a square are present, then<br />

the program will go to various<br />

parts of subroutine 480. This<br />

routine works out by J, K, L or<br />

M, the direction of the print<br />

statement, which will 'black'<br />

the squares and insert an "*" a<br />

" -" or a "/" depending upon<br />

whose move claimed the<br />

square.<br />

This simply takes the value<br />

of whose turn (in C) adds 22<br />

and prints the CHR $. U is simply<br />

used to help simplify the print<br />

statements.<br />

Line 128 If there is no pattern or<br />

winning move then let C = ABS<br />

(C-1). This changes the<br />

player's turns. If C=1 it<br />

becomes Q and vice versa.<br />

Lines 130-134 sort out the<br />

score. If all 88 squares are<br />

taken then the game finishes at<br />

line 144 where pressing any<br />

key starts another game.<br />

Otherwise line 1 36 starts the<br />

next turn by jumping back to<br />

line 64.<br />

Lines 150-166 Starts the<br />

search routine during "My<br />

turn" using part of Sub 440,<br />

only this time Q = 3. If L or<br />

M = 1 then its found a threesided<br />

square. In this case line<br />

200-210 loop around until the<br />

missing side position is found.<br />

Since "My turn" looks directly<br />

at a position (I) and doesn't<br />

choose X, Y co-ordinates then<br />

sub routine 470 supplies X, Y,<br />

and E. it then jumps back into<br />

the original program at Line<br />

106 having worked out its<br />

move.<br />

Lines 168-196 constitute the<br />

computer's turn if the search<br />

for three sides is unsuccessful.<br />

This will choose any untaken<br />

position other than one which<br />

will make up more than two<br />

sides in any square. (Q = 2 this<br />

time.) It starts at position two<br />

(I) and jumps in steps of 60, to<br />

find a suitable position. If<br />

l> 1 95 then let 1-1-193<br />

keeps this within the "A"<br />

boundary. This tests each<br />

number from 2 to 195 without<br />

repeating, looking reasonably<br />

at random.<br />

Once 1 95 is reached G = 1<br />

and Q = 4 allowing the next<br />

available position to be taken.<br />

This time at line 196 we return<br />

to the main program 104, to<br />

allow a little longer to display<br />

the "My moves" choice (line<br />

194). (X * 2 + 37 + E) works<br />

out the relevant letter.<br />

Note: If you wish to set up<br />

the pattern fast then insert Line<br />

221 FAST and line 69 SLOW.<br />

2 CLS<br />

4 PRINT "SQUAREOLOGY",„"BY J. ENNESS"<br />

6 PRINT AT 3,3;"THE OBJECT OF THIS GAME IS TOJOIN<br />

THE DOTS AND COMPLETE AS","MANY SQUARES AS<br />

POSSIBLE. THE"," COMPUTER ALSO TRYS THIS: AFTER<br />

"," MAKING THE FOURTH MOVE ON ANY'V'THIRD<br />

SIDE."<br />

8 PRINT " [ ] ( ] [ ] THE COMPLETION OF A SQUARE<br />

"/'WILL BLACKEN THE GREY LINES AND","PUT AN<br />

.»OR""-"" IN ITS CENTRE"," NOTE:-THE<br />

COMPUTER SCORES TWO'Y'POINTS PER SQUARE YOU<br />

LOSE."<br />

10 PRINT "[ ] [ l t ] TO START SELECT A PATTERN<br />

1-90R " "0" " FOR NO PATTERN OR A-Z FORA<br />

MYSTERY START. TO ENTER A MOVEPRESS THE<br />

LETTER THEN NUMBER/S'V'OF THE REQUIRED<br />

POSITION. THE","WINNER OF A SQUARE HAS A<br />

SECOND MOVE.",," [ ] [ 1 [ ] ( ] PRESS ANY KEY<br />

TO START"<br />

12 GOSUB 400<br />

14 CLS<br />

<strong>ZX</strong> COMPUTING SUMMER 1982 125

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!