
SHEEPDOG TRIAL
by Guy Morgan
from ZX Computing Apr/May.1983

Round up your sheep with this program for your
16K ZX81 from Guy Morgan of mid-Glamorgan.


The object of this game is to round up a number of sheep in
the shortest possible time. You are given the choice of how
many sheep (between one and six) you would like to round up;
one sheep is fairly easy, but if you choose to round up six
sheep you will find it very time consuming as they keep
wandering out of the pen as others are being rounded up.

You move the sheep by placing the dog near to the sheep
using the cursor keys, so that it will move directly away
from the dog. However, if you move too close to the sheep,
you may find that the sheep will panic and are liable to
move in an unpredictable direction.

The dog is allowed three moves between sheep moves; this can
be increased if required by changing line 710. The game ends
when the dog has rounded up the sheep and is standing guard
at the gate of the pen and the dog's three moves have been
completed. At any stage of the game, neither the dog or
sheep are allowed to jump the fence or wall of the pen.


It's a dog's life

The dog and sheep are POKEd onto the screen and the previous
positions of the characters are blanked by POKEing with
zero. The POKE numbers are calculated as offsets using the
number held in the system variable D-FILE as a base point.

The checks on the relationship between sheep and dog are
made in terms of x and y co-ordinates, so routines to
convert to these are included; they are located at the
beginning of the program to speed up the operation. The
routine to generate random sheep moves is also placed at the
beginning of the program for the same reason. The positions
of the sheep in terms of the POKE offsets are held in the
array, S(NS).

The timer, which is initialised in lines 707 to 709 and
updated by the subroutine at line 2010, makes use of the
FRAMES system variable. Lines 9000 and 9010 are the usual
ZX81 self-RUN routine.


= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

[Letter from ZX Computing Oct/Nov.1983.                           ]
[I haven't included the suggested change in the accompanying file,]
[so I haven't tested it out.                                 JimG.]


ADDING ON

Dear ZX Computing,

After typing in the Sheepdog Trial program in the April/May edition
of ZX Computing, I wrote an addition to include a gate at the 
entrance to the pen. After three attempts, the routine was working
sufficiently well to send it to you. The additional lines are as follows:

 765 IF INKEY$="W" THEN GOTO 3000
3000 REM **GATE**
3010 IF PEEK(w+313)=8 OR PEEK(w+313)=20 THEN GOTO 720
3020 IF PEEK(w+313)=0 THEN GOTO 3060
3030 POKE w+313,0
3040 PAUSE 15
3050 GOTO 720
3060 POKE w+313,22
3070 PAUSE 15
3080 GOTO 720

The explanations are as follows:

765   Checks to see if "W" was pressed (this can easily be altered).
3010  Checks to see if the gate square is occupied.
3020  Checks if the gate is there. If it is in place, it is removed
      by line 3030; if it is not there, it is put into position by line 3060.
3040/ Are in place to allow time to remove the finger from the key
3070  (otherwise the gate is continually removed and replaced).

The routine was written without a GOSUB command in order to
make it easier to go back to the INKEY$ in line 720 so that a
move is not used up.

Yours faithfully,

Kevin Lownsborough, Humberside


--
Another Fine Product transcribed by:
Jim Grimwood (jimg@globalnet.co.uk), Weardale, England
--
