PatchbyThe file ".log" contains information to be transmitted to the other player regarding referee calls. Since it is necessary to tell the other player which piece was taken, the log was written like this: Piece gone| 6 5 4 Meaning the piece at 65(f5) which was a Knight has been taken. Well, player White, who has just taken the piece already knows it was taken from f5, but doesn't know which piece. To White, the announcement is just "Piece gone". However, when player Black logs on, the player needs to know what piece was taken. Hence the "4" is transmitted. What happens is that the referee calls are stored in file xxx.log, where xxx is the name of the game. When White is finished, White is to transmit xxx.log to Black where the announcement will be expanded to Piece gone at f5, namely a Bishop. All that is good except that White could merely look at xxx.log before transmitting and thus know what piece was taken - A violation of Kriegspiel rules. To avoid this, it is necessary to encrypt the last digit (in this case "4"). Well, that is a patch to a previously certified module, and adds new cases to be tested. To avoid a lot of redo, the "RefereeSpeaks" sub will be tested as a separate entity. Below is the driver/new version. It has been tested with the following data: Try King 1| 3 2 1 Try Queen 2| 4 3 2 Try Bishop 3| 5 4 3 Try Knight 4| 6 5 4 Try Rook 5| 7 6 5 Try king 7| 8 7 7 Try rook 8| 1 8 8 Pawn gone| 2 1 9 Pawn gone| 5 5 6 Recall That covers all cases and thus no bug will be introduced. After replacing the current RefereeSpeaks with the following, the applicable module, DM4BAA-Logic, was retested with the certification plan. Mac DECLARE SUB RefereeSpeaks (Msg$) CLS DIM SHARED RefLogOld AS INTEGER: RefLogOld = -1 CONST GameName = "ref" CONST SecretKey = 57821 DO LINE INPUT "Command: "; c$ IF c$ = "" THEN SYSTEM CALL RefereeSpeaks(c$) LOOP SUB RefereeSpeaks (Msg$) DIM RefLog AS STRING: RefLog = GameName + ".log" DIM c AS INTEGER, y AS INTEGER IF Msg$ = "Recall" THEN OPEN RefLog FOR APPEND AS #1: CLOSE OPEN RefLog FOR INPUT AS #1 IF EOF(1) THEN CLOSE : EXIT SUB CLS : PRINT "Referee Calls Overheard:": PRINT DO WHILE NOT EOF(1) LINE INPUT #1, l$ IF INSTR(l$, "|") > 0 THEN if Left$(l$,4)<>"Pawn" then gosub PieceGone gosub PrintPiece endif PRINT SPACE$(4) + l$ c = c + 1: 'Count lines except following cases IF l$ = "White to move" THEN c = c - 1 IF l$ = "Black to move" THEN c = c - 1 IF l$ = "Legal Move" THEN c = c - 1 LOOP CLOSE IF c = 0 THEN SLEEP 2 FOR c = 1 TO 1000 k$ = INKEY$: IF k$ <> "" THEN EXIT FOR NEXT c CLS : EXIT SUB END IF PRINT SPACE$(4) + "(Press Enter to acknowledge)" DO: LINE INPUT ""; e$: LOOP WHILE e$ <> "" CLS ELSE IF RefLogOld THEN OPEN RefLog FOR APPEND AS #1 ELSE OPEN RefLog FOR OUTPUT AS #1 RefLogOld = -1 END IF IF INSTR(Msg$, "|") > 0 THEN if left$(Msg$,4)<>"Pawn" then GOSUB Encrypt1 endif PRINT #1, Msg$ CLOSE y = INSTR(Msg$, "|") IF y > 0 THEN PRINT LEFT$(Msg$, y - 1) ELSE PRINT Msg$ END IF EXIT SUB PieceGone: '========== Get hold of 7-digit number Suffix$ = RIGHT$(l$, 7) '========== Decrypt 6-digit message key plus encrypted Piece Tmp# = RND(-SecretKey) FOR i = 1 TO 7 v% = VAL(MID$(Suffix$, i, 1)) v% = v% - INT(RND * 10) IF v% < 0 THEN v% = v% + 10 MID$(Suffix$, i, 1) = RIGHT$(STR$(v%), 1) NEXT i '========== Using 6-digit message key, decrypt piece x# = RND(-VAL(LEFT$(Suffix$, 6))) v% = VAL(RIGHT$(Suffix$, 1)) v% = v% - INT(RND * 9) IF v% < 1 THEN v% = v% + 9 '========== Now replace 7-digit number with original piece l$ = LEFT$(l$, LEN(l$) - 7) + RIGHT$(STR$(v%), 1) RETURN PrintPiece: y = INSTR(l$, "|") q$ = RIGHT$(l$, LEN(l$) - y) l$ = LEFT$(l$, y - 1) l$ = l$ + ": " + MID$("KQBNRPKRP", VAL(RIGHT$(q$, 1)), 1) l$ = l$ + " at " + MID$("abcdefgh", VAL(LEFT$(q$, 2)), 1) l$=l$+ MID$(q$, 4, 1) return Encrypt1: '=========== Generate New 6-digit message key RANDOMIZE TIMER DO k# = 1717177427 * RND k$ = LTRIM$(STR$(k#)) LOOP WHILE LEN(k$) < 12 y = INSTR(k$, ".") IF y > 0 THEN MID$(k$, y, 1) = RIGHT$(STR$(RND * 7793412), 1) k$ = MID$(k$, 3, 6) '=========== Using 6-digit message key, encrypt Piece x# = RND(-VAL(k$)) v% = VAL(RIGHT$(Msg$, 1)) v% = v% + INT(RND * 9) IF v% > 9 THEN v% = v% - 9 '=========== Now encrypt 6-digit message key + encrypted piece Suffix$ = k$ + RIGHT$(STR$(v%), 1) k# = RND(-SecretKey) FOR i = 1 TO 7 v% = VAL(MID$(Suffix$, i, 1)) v% = v% + INT(RND * 10) IF v% > 9 THEN v% = v% - 10 MID$(Suffix$, i, 1) = RIGHT$(STR$(v%), 1) NEXT i '=========== And replace original piece with 7-digit number Msg$ = LEFT$(Msg$, LEN(Msg$) - 1) + Suffix$ RETURN END SUB from IP address 68.98.164.60 |