Tuesday, 18 May 2021

An Iron Curtain Adventure: Miroslav Fídler's P.R.E.S.T.A.V.B.A


In the past I ported a Hungarian game and translated it to English (A Hös Lovag) with the help of Google and a lot of guess work. I recently came across another game from "behind the Iron curtain." It's a Czech game with an anti-Soviet theme, written as a protest when Czechoslovakia was still under the thumb of the USSR. It’s called P.R.E.S.T.A.V.B.A.

I picked up on this fascinating game from Arron Reed’s fascinating writeup. The author, Miroslav Fídler, was one of the few good programmers in Czechoslovakia at the time and knew how to code in assembler, so he intentionally used humble Sinclair Spectrum Basic to program the game in order to disguise his identity.  It was funny to read about how Basic was used as a screen to prevent his identity from being rumbled by the authorities– The people’s language being used to protect him against "the people’s government."  He also apparently, according to Reed, intentionally mangled the code to further disguise his identity.

However, the code was generally pretty clean. I'm not sure if he designed it completely himself, or drew on some standard Basic text adventure engine. There was an error in the room DATA that would have the program read beyond the room description strings available, at least in my Micro Color Basic version. There are only 19 room descriptions, but there is no reference to room 19 (which is the location outside the church), but instead some rooms send you to room 20. In any other machine than the Spectrum, this would cause some kind of error, but due to some quirk in Speccy Basic this discrepancy doesn't seem to cause a problem. I think Fidler might be taking advantage of some features of the Speccy that allows it somehow to ignore anomalous reads so that the data from room 19 is left in place despite there being no room 20 data. So no harm no foul.  But I'm not 100% sure what's going on.

I believe that string DATA items and number DATA items are handled completely separately in a Speccy and you can RESTORE to the beginning of any line number you desire, which is a feature Fídler uses extensively. This means you can read all the strings in order or all the number items in order– the Speccy just doesn’t care. But in other BASICs you have to read all items, string and numeric, in their precise sequence, so I had to do some fixing of how DATA statements were read. The program also has a hidden DATA statement that never gets used. Line 103 reads DATA”DON’T BE AFRAID OF THEM!” Chilling.

The program also contains a weird technique of using the PI function along with the functions NOT, SGN, and INT as replacements for the numbers 0, 1 and 3.  For other numbers, instead of using simple digit, Fídler uses the VAL function and then the number expressed as a string "11."  This might be why Reed suggests that the code was somehow mangled as a further protection against detection by the authorities.  However, this might just be a memory saving trick of Speccy Basic. Instead of multiple bytes being used for each numeric value, 2 bytes, one for each keyword token, is all that is needed. I know in Micro Color Basic floating point numbers require 5 bytes, but it might be more in Speccy Basic. Perhaps then even the VAL plus a string and its 2 quote marks can provide a memory saving.  Again, I can't be sure, and I'm not going to pour over the idiosyncrasies of Sinclair Basic to find out.  Reed might be right that it is some kind of red herring for the authorities.

I also fixed a few quirks and annoyances in the parser and added some responses that are shown by Reed, but were not part of the Speccy version.  I think Reed might have used an Atari port as the basis for his translations and discussion. I was able to draw on Reed's translations to help with my own, especially his English transliteration of the satirical acronym used as the title.

I also added a few tweaks to the descriptions.  I added the date to the slogan about "golden February" since most non-Czechs will be unfamiliar with the year of the February coup that brought in communism.  The downstairs hall now "echoes strangely" to give some clue of where to dig. It now prints a message when you hit your item max, chiding you not to be a "hoarder." And a few others. All the graphics and sound in my version are my additions, including a flashing screen for the pyrotechnics at the end.

Info about playing the game can be found here: http://faculty.cbu.ca/jgerrie/Home/Type-in-Mania.html


The game can be played here under the "Play our 8-bit Text Adventures" link:


Saturday, 1 May 2021

4K Tandy Micro Checkers: Another Bug Found

GWCheckers
GWCheckers

Well I think I uncovered another bug in Micro Checkers for the TRS-80 MC-10.  In my initial post about this program I noted that there was some spottiness regarding the implementation of forced jumping by the A.I.  What prompted this comment was my recollection of a moment when the computer moved a piece from its back row, despite the fact that lower down the board there was an opportunity for it to jump one of my pieces. This struck me as odd for two reasons. First, as noted, it is normal to expect mandatory jumping. Second, it is a normal strategy in checkers to protect your back row, in order to delay or prevent the opponent from kinging their pieces. So I resolved to examine the movement algorithm of the A.I to see if there was some obvious mistake. To help me do this I decided to do a line by line comparison  of the similar code from the GWCheckers program I found online on a French blog site.  I found some differences.  The key one I think is this line in Micro Checkers:

230 IFY=7THENN=N+2

(In my updated and renumbered version, as a memory saving measure, this line became: 23 IFY=7THENN=N+2). The corresponding line from the GWCheckers version was:

960 IF Y = 7 THEN Q = Q-2

Since in Micro Checkers the top line is line 7 (computer's side), I had the suspicion that the function of this line was to "demote" moves from the computer's back row in terms of priority.  The N variable in Micro Checkers and the Q variable in GWCheckers seem to be a count for prioritizing moves. The higher the value, the more attractive the move. In other words, the move option that gets the highest N/Q value is the one that gets selected. I think it is possible that the aberrant behaviour I witnessed might have been a result of this + sign instead of a - sign in line 230.  Why else would a back row move be prioritized over a possible jump?

However, I also found an additional check as part of the Micro Checkers code:

100 FORX=7TO0STEP-1:FORY=7TO0STEP-1:IFS(X,Y)>-1ORS(X,Y)=-3THEN130

Whereas, the corresponding line from the GWCheckers version was:

230 FOR X = 0 TO 7: FOR Y = 0 TO 7: IF S (X, Y)> - 1 THEN 350

Also, you will note the Micro Checkers searches from the top row (7) down (0-- the player's side), whereas GWCheckers searches from the bottom row up.  I don't know what the significance of that change is.  I did try simply removing the red highlighted check for S(X,Y)=3, but the resulting game play was terrible, with the A.I moving into positions in which it could be jumped.  So I obviously didn't make that change permanent.  However, I wondered whether I should adopt the bottom up direction of  search.  I suspect that the algorithm simply selects any move with a higher N/Q value as it does its search.  So if it searches from bottom of the board (the human player's side) up, as in the GWCheckers, then a certain priority is given to offensive moves, since they could then be prioritized over any equal weighted top of board (computer side) moves.  I want the program to be more aggressive, especially early in the game, so I made the change to the GWCheckers search order.

Here is the line in Micro Checkers where the move is selected:

290 NEXTC:IFN>R(0)THENR(0)=N:R(1)=X:R(2)=Y:R(3)=J:R(4)=K

GWCheckers:

1080 NEXT C: IF Q> R (0) THEN R (0) = Q: R ( 1) = X: R (2) = Y: R (3) = U: R (4) = V

Because the check is for if a move (N/Q) is greater than any prior highest move, if a move further down the board (towards the human player) has the highest number, no equally high numbered move further back will be able to supplant it. Whereas in the original Micro Checkers, any back row move that gets established as highest (such as the aberrant back row move I noted above) can never be supplanted by any equally high move closer to the human side of the board (i.e more "offensive" plays). I'm not 100% sure the GW Strategy will result in better play and I am starting to lose my taste for playing these games of Checkers against a fairly simple A.I.  But I will continue testing and let you know if I think it needs to be changed back.

Another change that I made is that I noticed that the initial move was always the same from a fresh boot of the computer. The game had no way of randomly seeding the random number process.  However with a little change this could be easily accomplished via the initial INKEY$ input routine for asking whether one wanted to move first.  By relocating the RND assignment to variable T, within that key press routine, the operator's initial key press would randomly seed the random number sequence. So I changed:

50 PRINT@20,"CHECKERS";:SOUND150,5:PRINT@51,"MOVE FIRST?";
60 A$=INKEY$:IFA$=""THEN60
70 IFA$="Y"THEN450
80 R(1)=(RND(4)*2)-1:R(2)=5:T=RND(2):T=T-1:IFT=0THENT=T-1

To:

4 PRINT@20,"CHECKERS";:PRINT@51,"MOVE FIRST?";:T=RND(2):A$=INKEY$:ON-(A$="")GOTO4:IFA$="Y"THEN43
7 R(1)=RND(4)*2-1:R(2)=5:T=T-1:T=T+(T=0):R(3)=R(1)+T:R(4)=4:ON-(R(3)>7)GOTO7:GOTO32

I also found some more memory savings by consolidating a lot of additions and subtractions to N by way of simply adding and subtracting appropriately multiplied results from logical comparisons, rather than having separate lines using IF statements.  This allowed me to fix up the prompt clearing function.  Now when you change your mind about a move, and hit <ENTER> on an inappropriate square, the cancellation and return to the FROM prompt is signaled by the CLEARING of the TO prompt.

The Game MCCHKRS can  be played >>>here<<<. Select the "Play Game" button, then select the "Play Our Other 8-Bit Basic Game Ports" link, and then choose the filename from the Cassette list and type RUN.

Below is an image of me being trounced by the latest version of the game.  If you make a critical error in the early game, the computer can get and stay ahead of you.

Me getting trounced by the latest A.I.

Addendum: I put 100 FORX=7TO0STEP-1:FORY=7TO0STEP-1 back in place. It seemed that there was some suicidal behaviour of kinged pieces that might resulted from the change to a search order as in:
230 FOR X = 0 TO 7: FOR Y = 0 TO 7

I find this game interesting because clearly Tandy used an existing version of the program to create its 4K Checkers for the MC-10.  Either that, or someone took their version and debugged it and added graphics to create the PC version. It would be interesting to track down and verify the original author of the program. It doesn't appear that Tandy acknowledged the author of the program their documentation in any way: https://colorcomputerarchive.com/repo/MC-10/Documents/Manuals/Games/MicroCheckers/Micro_Checkers.htm
So despite all the "copyright stuff" in their manual, it is not entirely clear to me that they respected copyright in the creation of the program.  They might have simply paid someone to condense some original BASIC program, without proper consent.