SINCLAIR ANSWERS #2, January/February 1985


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


ASSAULT ON ENEMY POST XIII
by Tony Cotterill


INTO BATTLE

We present 'Assault', our listing for wargamers
who like to mix thinking with fighting.


[Carrying on their tradition of screw-ups from issue #1 ...          ]
[A pity whoever prepared this listing for publication didn't try some]
[thinking beforehand, as it uses numerous UDGs throughout and they   ]
[used a printer which didn't print UDGs, so the listing isn't a lot  ]
[of use. I've typed it in, but I can't be bothered spending hours    ]
[trying to deduce what UDGs are supposed to appear where.        JimG]


March, 1945: a British General struggles across the fields with the
battle-scarred remnants of his penetration force. His mission: to
seize control of enemy HQ. Accompanied by two tank, three light
artillery, and four infantry divisions, he leads into the forest
wherein lies his goal. Standing in his way are the equally battered
enemy defenders, and a river which may only be crossed by one of two
bridges.

This is the scenario for our Assault wargame listing. The aim is to
get your General across the river and through the door of the enemy
HQ; or alternatively, the game may be won by complete destruction of
the opposing forces.

The game is lost if at any time the General is killed or if he has
failed to cross the river before the enemy has blown both the bridges.
Assault has an unlimited number of repeating turns until a conclusion
is reached, each turn consisting of several phases: player move,
player fire, resolution, enemy move, enemy fire, resolution. Let's go
through these in turn.

Player move: The player is given the option to move all, some or none
of his units. This is done by selecting a string of numbers between 1
and 4, and entering them for each piece. The piece will then execute
the moves in order up to a maximum of its movement point allowance,
ignoring any impossible moves, before the prompt passes to the next
piece. The flashing compass which appears on the screen will indicate
which numbers correspond to which directions. Each type of unit has a
different movement maximum and certain terrain features have higher
movement costs to enter:

UNIT:           MOVEMENT PTS:
Infantry             5
Light Artillery      4
Tanks                3
General              3

TERRAIN:        MOVEMENT COST:
Fields               1
Forest               2
Bridge               2
River              No Go
Other piece        No Go

If a unit is not desired to move, no direction numbers should be entered.

Player fire: Any or all of the player's pieces may fire. The target
position should be traced out and entered just as in the movement
phase. If the fire lands in an empty terrain space it will be
immediately resolved; in this way trees may be removed and converted
to fields in order to speed up movement. If the target is a unit, the
resolution comes afterwards so that several pieces may fire at the
same enemy. Each piece has an attack strength and a defence strength
as a measure of their combat abilities. If a units defence is ever
less than starting strength it is wounded and if it drops to 0 the
unit is eliminated. Wounded player pieces turn cyan, enemies turn
black.

Bridges may take a certain amount of damage before they are destroyed
and they will go from blue to red to magenta to green in the process,
to indicate their state of repair. Each unit has a maximum firing
range which is calculated using a pythagorean formula in order to
allow direct straight firing lines. The details of each unit are:

UNIT:             ATTACK:  DEFENCE:   RANGE:
Infantry             1        2        1.5
General              0        2        1.5
Light Artillery      2        3        5.1
Tanks                4        4        3.1
Anti-Tank Post       5        3        6.1

Units in forest squares have an additional defensive advantage for
cover. The General may attack even though his attack is 0, he is just
not very good at it.

Enemy Move/Enemy Fire: The enemy performs the same manoeuvre as the
player and conforms to the same rules. Anti-tank posts do not move.

There are five levels of difficulty to Assault, and different tactics
may be required for each. Be very careful of your General: he is a
weak piece and if ever any enemy gets within range he will be fired
upon. Here's a summary of Unit Types:


UNIT:            MOVEMENT  ATTACK:  DEFENCE:   RANGE:
Infantry             5        1        2        1.5
General              3        0        2        1.5
Light Artillery      4        2        3        5.1
Tanks                3        4        4        3.1
Anti-Tank Post       0        5        3        6.1


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


GRAPHPLOT
by Stephen Fowler


PLOTTING YOUR GRAPHICS

Make your data easier to understand with our graphics utility listing.


Pictures are undoubtedly more fun than numbers; at least, it's
certainly less effort to look at a graph to see what is going on, than
to digest a long sequence of figures.

Our utility program here called Graphplot, will plot a graph on the
screen, or to a printer, from numbers stored in DATA statements on the
Spectrum. It can also cope with simple functions, for example y=sin x.

The program, listed in Fig.1, assumes that you are using a Sinclair
printer. If you are using a different printer you will probably have
to change line 990 of the program to suit it.

The scale of the Y-axis is calculated automatically, and the
increments can vary from thousandths of a unit to millions of them.
The only constraint on the Y-axis is that it contains a zero. The
X-axis can be of any length, and is only limited by the number of DATA
statements that can be held in memory at any one time.

To use Graphplot, first type in the listing given. Save it before
running it, just to he safe. To run the program type RUN 1000. Note
that the numbers in angled brackets after the lines of code are the
checksum numbers. Don't type these in, they are just a checking system
to see all is OK (for the Checksum program, see Sinclair Answers issue
No 1 [except that the 48K version had a big chunk of code missing from
the listing and the buffoons never printed a correction]).

The DATA statements start at line 1030, the number of them is held in
a variable, called PLOTNUMBER, that is set in line number 1008. The
listing includes a short demo of 28 numbers. Run the program with
these first, just to check that everything is working. Check the
output with that in Fig.2; or if you type RUN 2000, should get the
output given in Fig.3.

There are a number of questions that you will be asked when the
program is running: for example, the graph can be printed on a 'blank'
background or with squares to look like graph paper. This is all you
need to do to plot a graph from DATA statements. To generate a graph
from a function, alter line 2024 to the function required. For
example, in the listing it has: LET Y=SIN X. This can easily be
changed, for example: LET Y=2*X, or LET Y=X (K-CX), where K and C
[sic] are constants that you will need to set up with values.

There are a few parameters that need to be set up to get this function
going. XSTART is the first value to be given to the function, it will
usually be zero. PLOTNUMBER holds the total number of points that will
be plotted. 45 points can be plotted on the Spectrum's screen, without
any scrolling. XSCALE holds the number of units that one square on the
graph represents.

Finally, if you wish to plot a graph from data generated by another
program then follow this procedure:
* Add the line DIM B(n) to your program (not Graphplot!), where n is
the number of points to be plotted.
* Alter your program so that all the numbers are stored sequentially
in this array, starting from B(1).
* Run your program.
* Type SAVE "NAME" DATA B(), to save the array to tape with the name
"name". You could verify the correct saving with, VERIFY "NAME" DATA B().
* Load Graphplot.
* Load the array by typing LOAD "name" DATA B().
* Do not now type RUN, instead type GOTO 8, and the graph will be plotted.

All in all, a simple way of getting an interesting picture from a
boring set of numbers!


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


TANK DRIVE (Competition)

"We shall fight on the seas and oceans, we shall fight on the beaches,
 we shall fight on the landing grounds, we shall fight in the fields and
 in the streets, we shall fight in the hills; we shall never surrender."

Those famous words by Sir Winston Churchill suggest that the great man
was unaware that moving about on all this differing terrain can be
quite a problem at times. Any strategist will find themselves very
conscious of landscape features when playing wargames, and you'll have
to judge the best routes for an army to take.

This gave us the inspiration for a great competition, in which
Spectrum owners can win a professional-looking Cheetah 68FX1 add-on
keyboard and brand new Wafadrive system; QL owners can win #100 of
Computer One software, consisting of Pascal, Forth and an Assembler.

Wargaming can be a lot of fun, but computerised war simulations are
also used for more serious matters, such as trying out new battle
tactics or testing the likely effect of new equipment without having
to build it. Automation in battle equipment is already quite high, and
will increase still further over the next few years. So we decided to
take a glimpse into the future, where battle tanks are endowed with
their own minor intelligence.

Study the 26 x 26 square map on the previous page (Fig.1 [see
TANKDRIV.GIF]) and imagine yourself sitting in an amphibious battle
tank, positioned at square Z26. An incoming message informs you that
the enemy headquarters has been sighted at A1. Your mission (should
you choose to accept it) is to travel to and destroy the target as
quickly as possible. So off you go, up hill and down dale, until you
eventually reach your destination. However, each time you move into a
new square on the map, the time it takes to move over that particular
square of terrain (shown in Fig. 2) is added up. This then represents
the total number of hours of travelling time.

Fig.2
TERRAIN:            MOVEMENT (time in hours):
Plain       (P)          1
Path        (P)          1
Bridge      (B)          1
Desert      (D)          2
Forest      (F)          3
Water       (W)          4
Swamp       (S)          5
Mountain    (M)          6

For example, travelling from any square into a mountain location,
followed by a square containing a path would take you seven hours.
That is:
	Hours = Mountain + Path
	      = 6 + 1
	      = 7

Of course, you could take the most direct course towards the target,
but you're probably going to get there quicker if you try to take
advantage of the terrain features. The listing given in Fig.3 will
simulate your journey and try to make intelligent decisions when
choosing the best route to the target. This program has been written
using a 48K Spectrum, but could easily be adapted for use on other
Sinclair computers.

First of all you must type in and run the listing as given. In
deciding each move, the battle tank will look at the terrain features
up to four horizontal or vertical moves ahead (lines 490 to 800). It
then assigns a score to each of the positions which can be reached.
This score is based upon: the distance from the target; and the time
it takes to reach the position (in hours).

These two values are 'weighted' by the variables WEIGHT1 and WEIGHT2
which are initialised in lines 310 and 320 respectively (weighting is
simply a method of assigning an importance to each of the two
calculations). Having calculated the scores for all reachable
positions, the battle tank will move to the first square of the
sequence with the highest score. This continues until the tank reaches
its target. Now consider the following problems given in the box shown
above.

Hopefully you'll find our competition an enjoyable challenge. If you
find it brings out the commander in you, why not try our Assault game
listing in this issue? [... because the printer used didn't print the
numerous UDGs, so the listing wasn't a lot of use! JimG]


Problem One: Having typed in the listing, run it so that the tank
travels from Z26 to A1. The total time in hours for this journey will
be a prime number, the answer to the first problem. If you don't get a
prime number, then you've obviously made a mistake somewhere when
typing in the listing. Check it carefully, being very careful to type
in all the map characters correctly. The answer to Problem One is this
prime number.

[The (double-checked) listing takes 4 hours (!!) to run, and does not]
[produce a prime number at the end (total cost = 98). Yet another    ]
[Sinclair Answers screw-up.                                      JimG]


Problem Two: To start with, you must change the program listing which
you have just typed in, so that the tank will only look ahead three
squares, instead of four. This should have the beneficial effect of
speeding up the time it takes to choose a move by a factor of about
four, so you won't have to wait quite so long. Second, change the
value of WEIGHT2 (in line 320) to eight. For this part of the problem,
the tank must make a circular route, passing through the coordinates
given in Fig.4; in other words, the tank starts at square Z2 and
travels through P13, Q24 and D15 (in this order), to finally end where
it started at Z2. Given that the value of WEIGHT2 is eight, what value
should be given to WEIGHT1 so that the tank makes the complete journey
in the least number of hours? This is not to say that the tank will
take the optimum route, but that no other value for WEIGHT1 will
enable it to find a shorter one.

The answers to this part of the problem are the value given to WEIGHT1
(remember, only one value for the whole route) and the total number of
hours taken with this value.

Fig.4
ROUTE NUMBER: FROM: TO:
      1       Z2    P13
      2       P13   Q24
      3       Q24   D15
      4       D15   Z2

To enter, simply place your answers on the entry form. The competition
is open to all Spectrum and QL users. The first two correct entries,
using Spectrum micros, drawn out of the editor's tin helmet, will each
win a Cheetah 68FX1 keyboard and a Rotronics Wafadrive (both reviewed
in this issue). There will be a similar draw for entries using the QL
computer, the winners receiving #100 worth of Computer One software
(Pascal, Forth and an Assembler).

In the event that there are too few correct entries, the entries with
the nearest answers will be considered. All entries must arrive by
first post on Monday 4th February 1985.


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


TRIANGLE FILLER

COLOURFUL POLY-FILLER

I own both a BBC Micro and a Sinclair Spectrum. I have recently been
writing simple graphics programs on the Spectrum, and found the range
of commands severely limited, especially for filing areas of the
screen, where I normally use the triangle-fill facility available on
the BBC. Are there any packages available which would give me these
facilities on the Spectrum? G Allerton, Brighton


There are a number of packages which allow you to draw pictures
interactively on the screen, such as Melbourne Draw and Screen
Machine; these are, however, designed specifically as drawing
packages, rather than graphics extensions to the Spectrum Basic. It is
nevertheless very easy to implement the graphics facilities available
in other Basics on your Spectrum. As an example of this, the listing
in Fig.1 gives a routine to fill triangles.

To use the routine, all you have to do is set the values (x1,y1),
(x2,y2), (x3,y3) for the three points of the triangle, using Spectrum
graphics coordinates, then GOSUB 1000, to draw and fill the triangle
in the. present INK colour. Since the Spectrum does not have pixel-
definable colours, overlapping triangles of different colours can give
some strange effects (see jagged blob above).

Lines 10 to 70 of the listing give a quick demonstration, plotting
random triangles of different colours.


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


