| Re: Star Trek by Krishna Myneni |
|
 |
|
 |
|
 |
|
 |
Group: comp.lang.forth · Group Profile
Author: Krishna MyneniKrishna Myneni Date: Sep 19, 2008 20:34
Doug Hoffman wrote:
> This might be a problem:
>
>
> variable d1 \ damage flag
> ^^^^^^^^^^^
>
> : RepairDamage ( -- )
> 0 d1 !
> w1 f@ d6 f!
> w1 f@ 1e f>= IF 1e d6 f! THEN
>
> 9 1 DO
> d{ I } f@ f0< IF
> d6 f@ d{ I } f@ f+ d{ I } f!
> d{ I } f@ -0.1e f> d{ I } f@ f0< and IF
> -0.1e d{ I } f!
> ELSE
> d{ I } f@ 0e f>= IF
> d1 f@ 1e f<> IF 1e d1 f! THEN
> ^^^^^ ^^^^^
>
> -Doug
Yes, this is a problem! It should be
: RepairDamage ( -- )
0 d1 !
...
d{ I } f@ 0e f>= IF
d1 @ 1 <> IF 1 d1 ! THEN
...
d1 is a flag. However, aside from setting it, it does not appear to be used
anywhere else in the program.
For the sake of demonstrating what I was up against when I translated this code
to Forth, here is the corresponding snippet from the original BASIC source:
...
2700 NEXTI:GOSUB6000:D1=0:D6=W1:IFW1>=1THEND6=1
2770 FORI=1TO8:IFD(I)>=0THEN2880
2790 D(I)=D(I)+D6:IFD(I)>-.1ANDD(I)<0THEND(I)=-.1:GOTO2880
2800 IFD(I)<0THEN2880
2810 IFD1<>1THEND1=1:PRINT"DAMAGE CONTROL REPORT: ";
2840 PRINTTAB(8);:R1=I:GOSUB8790:PRINTG2$;" REPAIR COMPLETED."
2880 NEXTI:IFRND(1)>.2THEN3070
2910 R1=FNR(1):IFRND(1)>=.6THEN3000
2930 D(R1)=D(R1)-(RND(1)*5+1):PRINT"DAMAGE CONTROL REPORT: ";
2960 GOSUB8790:PRINTG2$;" DAMAGED":PRINT:GOTO3070
...
Really! No spaces, and nearly a thousand lines of this with GOTOs everywhere!
Thanks for finding the bug.
Krishna
|