Fascinating, as Mr. Spock would say. ;-)

I’m not sure where my copy is now, but 101 Basic Computer Games really 
jump-started my programming, and in my opinion the Star Trek game was the best 
game in the book. I ended up adapting it to run on my [okay, my Dad’s LOL] 
TRS-80 (Model 1, Level II, eventually a whopping 32KB of memory), and of course 
it wasn’t big enough so it got expanded, adding more features like persistent 
galaxy state (saved between sessions) and multiplayer capability. (Not 
simultaneously, of course, but the concept of multiple ships of which one was 
actively in use by the current player.)

This abused several interesting features of the TRS-80’s Radio Shack Level II 
BASIC… One (that I’ve never encountered anywhere else) was that you didn’t have 
to put spaces in the code, and eliminating each space saved a byte of memory. 
The following was perfectly legal and readable if your eye was practiced:

100 FORI=1TO10
110 PRINTI
120 NEXTI

Now imagine more complex lines. After all, running them all together eliminates 
unneeded line numbers and saves even more memory:

100 FORI=1TO10:PRINTI:NEXTI

Then you eliminate all of the comments, because they’re pure overhead… When I 
still ran out of room, I started converting some functions into machine code 
(by hand, using a Z80 reference book) and POKEing them into memory…

Luckily, I went to college and encountered a VAX-11/780, at which point I 
recoded the whole mess in VAX-11 BASIC, took advantage of the expansive VT100 
display real estate, and began abusing (as they became available) indexed 
files, shared global sections, and the lock manager to make real multiplayer 
gaming workable.

Despite all of that, the heredity of the game is evident, including the 
coordinate system: (see the compass in the upper right corner!)

[cid:image001.jpg@01D4B4AA.9B972180]

That brings me back around to the point of this note. In VAX BASIC, 
fundamentally unchanged since some point prior to 1985, my course logic looks 
like this:

!
! Return a real course from point (x1,y1) to point (x2,y2)
! using Star Trek course notation.
!
        function single course(long x1,y1,x2,y2)
        declare long x,y
        declare single temp
        on error go back
        x = x2-x1                               ! Calculate offset P1 -> P2
        y = y2-y1                               ! Std. Cartesian system
        if x='0'L then
          if y>'0'L then
            course = 3.0                        ! Straight up
            exit function
          else
            course = 7.0                        ! Straight down
            exit function
          end if
        else
          temp = atn(real(y)/real(x))*57.2958   ! Calculate angle in degrees
          if x<='0'L then
            temp = temp+180.0                   ! Correct for quadrant
          else
            if y<'0'L then
              temp = temp+360.0
            end if
          end if
        end if
        course = temp/45.0+1.0                  ! Convert to proper notation
        end function

My guess is that this algorithm is more or less what you expected to find 
before you started digging into the code. (Originally this used bytes, but as 
memory became cheaper and access more convoluted, I promoted things to improve 
alignment.)

But here’s the punchline: I realized, as I was reading through your excerpt, 
that the algorithm used by the original game is EXACTLY the same that I used in 
my head to “estimate” courses when I was playing my game and I didn’t have the 
time to ask the computer for the course before getting shot myself. I don’t 
remember learning it from the original code, but I’m sure that’s where it came 
from.

If I had to guess – and I am – I’d say the original implementation might not 
have had trig functions available (when did BASIC acquire them?), and this is a 
pretty decent approximation. At least for the limited size and high granularity 
of a 64-sector quadrant. Certainly I could do it rapidly in my head, and I can 
testify that the results pretty much always match the “obvious” calculation, if 
you can aim and shoot fast enough that the target hasn’t moved!

Those were the days,

Scott


From: Simh 
<simh-boun...@trailing-edge.com<mailto:simh-boun...@trailing-edge.com>> On 
Behalf Of Will Senn
Sent: Wednesday, January 23, 2019 10:22 AM
To: Clem Cole <cl...@ccc.com<mailto:cl...@ccc.com>>
Cc: Simh <simh@trailing-edge.com<mailto:simh@trailing-edge.com>>; Bryan Davies 
<bryan.e.dav...@gmail.com<mailto:bryan.e.dav...@gmail.com>>
Subject: Re: [Simh] 101 Basic Games for RSTS/E (was Re: PDP11 on Simh for 
public access)

On 1/21/19 3:55 PM, Clem Cole wrote:
Anyway, the point is that simple computer games in BASIC were being passed 
around between people (as paper tapes), particularly if you had acccess to 
multiple different brands of computers.    You always had the source code, in 
those days so it was really not big deal.  In fact, my memory is that one of 
the new things that you could do on the PDP-10 was >>compile<< your basic 
program, or at least leave it in some form that some one could not see what you 
had done.   But the HP and GE system, you just loaded the program and typed 
'list' - often after turning on the paper tape punch the ASR33.

Clem

Wow

So, I dug a bit and found the code is practically everywhere  and when folks 
extended it, they were pretty specific about what they extended. Take the code 
for the library computer's calculator for distance and direction... it's nearly 
untouched in other versions - prolly cuz it's a little convoluted (seems like 
some translation from rectangular to polar coordinates and back again using 
standard trig functions would have worked and been MUCH easier to understand...

In reviewing the SPACWR code, and comparing it to STTR1 which preceded it and 
SUPERTREK which came later, I came across this bit of library computer code for 
calculating direction and distance from one sector in a quadrant to another. It 
seems like basic trig would have been easier, but the author chose another 
route, pun intended. In the code where the direction is calculated, though, it 
looks like there are at least 2 bugs. But, seeing as all of the versions use 
basically the same exact logic, I must be missing something and I am hoping 
y'all know something about the interpreter that makes this magically ok, or can 
read it better than I and tell me that it's actually ok, as is (maybe the bugs 
don't materially effect the outcome) or this was a well known quirk of the 
system that was beloved by all oldtimers :).

I'm running this in RSTSV06C-03, but STTR1 was written for an HP calculator or 
something and SUPERTREK was written for a Data General Nova 800 w/32K of core, 
so I don't think it's a system specific issue, but rather a straight up logic 
problem.

Below is the code and it's pretty self contained.

The 2 bugs are these:

1. Lines 4880, 5250, and 5270 refer to H8. H8 is effectively constant 0, set in 
4880 and again in 5270, the check in 5250 will never evaluate true. It looks 
like it was meant to break out of the loop early, but there aren't any other 
uses of it elsewhere in the code - but it's persistent - appearing in many 
versions of the code, doing nothing.

2. The more pernicious, or at least annoying to me bug is the test in line 
5140, X is always less than zero here. So the path from 5140 to 5190 is never 
executed.

I don't want to fix anything until I'm sure it's broken. I don't particularly 
care for the method used here, but if it works...

Here's what the vector's get translated into (the direction, a real number 
between 1 and 8.999etc that is calculated), for reference:


 4  3  2
  \ ^ /
   \^/
5 ----- 1
   /^\
  / ^ \
 6  7  8

This is the code followed by my annotations for what they're worth (usually I 
put them in column 90, but that wouldn't look good in email, so I just split 
'em):

4880 PRINT:H8=0
4881 REM *** PHOTON TORPEDO DATA CODE BEGINS HERE
4900 FOR I=1TO3
4910 IF K(I,3)<=0 THEN 5260
4920 C1=S1:A=S2:W1=K(I,1):X=K(I,2)
4960 GOTO 5010
4970 PRINT"YOU ARE AT QUADRANT ( "Q1","Q2" )  SECTOR ( "S1","S2" )"
4990 INPUT "SHIP AND TARGET COORDINATES ARE:";C1,A,W1,X
5010 X=X-A:A=C1-W1
5030 IF X<0 THEN 5130
5031 IF A<0 THEN 5190
5050 IF X>0 THEN 5070
5051 IF A=0 THEN 5150
5070 C1=1
5080 IF ABS(A) <= ABS(X) THEN 5110
5085 V5=C1+(((ABS(A)-ABS(X))+ABS(A))/ABS(A))
5090 PRINT "DIRECTION ="V5
5100 GOTO 5240
5110 PRINT "DIRECTION ="C1+(ABS(A)/ABS(X))
5120 GOTO 5240
5130 IF A>0 THEN 5170
5140 IF X=0 THEN 5190
5150 C1=5:GOTO 5080
5170 C1=3:GOTO5200
5190 C1=7
5200 IF ABS(A)>=ABS(X) THEN 5230
5210 PRINT "DIRECTION ="C1+(((ABS(X)-ABS(A))+ABS(X))/ABS(X))
5220 GOTO 5240
5230 PRINT "DIRECTION ="C1+(ABS(X)/ABS(A))
5240 PRINT "DISTANCE ="SQR(X**2+A**2)
5250 IF H8=1 THEN 5320
5260 NEXT I
5270 H8=0
5280 INPUT "DO YOU WANT TO USE THE CALCULATOR";A$
5300 IF A$="YES" THEN 4970
5310 IF A$<>"NO" THEN 5280
5320 GOTO 1270
5321 REM *** END OF LIBRARY COMPUTER CODE

! ---- One Scenario that works to help illustrate (direction is 3)

! SECTOR MAP (SIMPLIFIED)
!
!   | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
!    +---+---+---+---+---+---+---+---+
! 1 |   |   | K1|   |   |   |   |   |
!    +---+---+---+---+---+---+---+---+
! 2 |   |   |   |   |   |   |   |   |
!    +---+---+---+---+---+---+---+---+
! 3 |   |   |   |   |   |   |   |   |
!    +---+---+---+---+---+---+---+---+
! 4 |   |   | E |   |   |   |   |   |
!    +---+---+---+---+---+---+---+---+
! 5 |   |   |   |   |   |   |   |   |
!    +---+---+---+---+---+---+---+---+
! 6 |   |   |   |   |   |   |   |   |
!    +---+---+---+---+---+---+---+---+
! 7 |   |   |   |   |   |   |   |   |
!    +---+---+---+---+---+---+---+---+
! 8 |   |   |   |   |   |   |   |   |
!    +---+---+---+---+---+---+---+---+
!
!  S1 = 4, S2 = 3, K(1,1) = 1, K(1,2) = 3
!  C1 = 4, A = 3, W1 = 1, X = 3

4880 ! NO TELLING WHAT H8 IS SUPPOSED TO BE, BUT PRESENT IN STTR1 AND SUPER TREK
4881 REM
4900 ! LOOP THROUGH KLINGONS
4910 ! SKIP ANY THAT ARE DESTROYED
4920 ! SAVE SECTOR INFORMATION FOR THE ENTERPRISE (4,3) AND KLINGON (1,3)
4960 ! SKIP THE NEXT TWO LINES
4970 ! DISPLAY THE LOCATION OF THE ENTERPRISE
4990 ! DISPLAY THE LOCATION OF THE KLINGON
5010 ! DETERMINE DISTANCES FROM ENTERPRISE TO KLINGON  (X=0, A=3)
5030 ! X IS THE I DISTANCE, A IS THE J DISTANCE, X NEGATIVE? (NO)
5031 ! X IS NON-NEGATIVE, A NEGATIVE? (NO)
5050 ! A IS NON-NEGATIVE, X > 0? (NO)
5051 ! X IS ZERO, A ZERO? (NO)
5070 ! X IS ZERO AND A > 0, SET DIRECTION TO 1 (C1=1)

! CORRECT AND PRINT DIRECTION 1 AND 5
5080 ! J DISTANCE SMALLER THAN OR EQUAL TO THE THE I DISTANCE? JUMP TO 5110 (NO)
5085 ! V5 = (1 + (((J DISTANCE - I DISTANCE) + J DISTANCE)) / J DISTANCE) | 
(1+(((3-0)+3))/3) | (3)
5090 ! DISPLAY THE DIRECTION TO THE USER
5100 ! GOTO DISPLAY THE DISTANCE
5110 ! THE J DISTANCE IS SMALLER THAN OR EQUAL TO THE I DISTANCE, DISPLAY (1 + 
(J DISTANCE/I DISTANCE))
5120 ! GOTO DISPLAY THE DISTANCE

5130 ! X IS NEGATIVE, A > 0?
5140 ! X IS NEGATIVE, CAN'T BE ZERO..., GONNA FALL THROUGH
5150 ! X AND A ARE 0 (OR X IS NEGATIVE), SET DIRECTION TO 5, GOTO CORRECT AND 
PRINT DIRECTION 1 AND 5
5170 ! X IS NEGATIVE, A > 0, SET DIRECTION TO 3 GOTO PRINT DIRECTION 3
5190 ! DIRECTION IS 7 ; NOT GONNA HAPPEN

! CORRECT AND PRINT DIRECTION 3 AND 7
5200 ! J DISTANCE GREATER THAN OR EQUAL TO THE I DISTANCE? JUMP TO 5230
5210 ! DISPLAY THE CORRECTED DIRECTION
5220 ! GOTO DISPLAY THE DISTANCE
5230 ! DISPLAY THE UNCORRECTED DIRECTION

5240 ! DISPLAY THE DISTANCE
5250 ! NEVER GONNA HAPPEN
5260 ! NEXT KLINGON
5270 ! WHO CARES

5280 ! DISPLAY CALCULATOR PROMPT
5300 ! REDISPLAY YOU ARE AT QUADRANT...
5310 ! REDISPLAY DO YOU WANT TO USE...
5320 ! GOTO TOP OF LOOP
5321 REM



--

GPG Fingerprint: 68F4 B3BD 1730 555A 4462  7D45 3EAA 5B6D A982 BAAF

DXC Technology Company - Headquarters: 1775 Tysons Boulevard, Tysons, Virginia 
22102, USA.
DXC Technology Company -- This message is transmitted to you by or on behalf of 
DXC Technology Company or one of its affiliates. It is intended exclusively for 
the addressee. The substance of this message, along with any attachments, may 
contain proprietary, confidential or privileged information or information that 
is otherwise legally exempt from disclosure. Any unauthorized review, use, 
disclosure or distribution is prohibited. If you are not the intended recipient 
of this message, you are not authorized to read, print, retain, copy or 
disseminate any part of this message. If you have received this message in 
error, please destroy and delete all copies and notify the sender by return 
e-mail. Regardless of content, this e-mail shall not operate to bind DXC 
Technology Company or any of its affiliates to any order or other contract 
unless pursuant to explicit written agreement or government initiative 
expressly permitting the use of e-mail for such purpose. --.
_______________________________________________
Simh mailing list
Simh@trailing-edge.com
http://mailman.trailing-edge.com/mailman/listinfo/simh

Reply via email to