[Oberon] PO2013 - MasterMind

Tomas Kral thomas.kral at email.cz
Wed Jun 10 15:18:34 CEST 2020


Hi,

Oberon is not exactly a gaming platform, yet I am
recoding `MasterMind' game for PO2013 FPGA system.

In the Score procedure, I use two sets {u,s} to mark pegs already
scored. I was surprised two are needed, possibly one might be enough,
as they do not seem disjoint.

    (*peg is placed in each hole*)
    i := row*8 + peg; s := {}; complete := TRUE;
    FOR j := 0 TO pegs-1 DO
      o := DLogs.ThisId(i); t := o(DShape.Item);
      IF  ~t.fill THEN complete := FALSE END;
      guess[j] := t.col; INC(i)
      (*Out.Int(t.id, 3); Out.Bool(t.fill); Out.Ln*)
    END;

    (*pegs of the right color and correct position*)
    i := row*8 + key; blacks := 0;
    FOR j := 0 TO pegs-1 DO
      IF guess[j] = code[j] THEN
        o := DLogs.ThisId(i); t := o(DShape.Item);
        DShape.Key(t, Black); INC(blacks);
        INC(i); INCL(s, j)
      END
    END;

    (*pegs of the right color and wrong position*)
    u := s; whites := 0;
    FOR j := 0 TO pegs-1 DO
      IF ~(j IN s) THEN
        done := FALSE; k := 0;
        REPEAT
          IF ~(k IN u) & (guess[j] = code[k]) THEN
            o := DLogs.ThisId(i); t := o(DShape.Item);
            DShape.Key(t, White); INC(whites);
            INC(i); INCL(u, k);
            done := TRUE
          END ; INC(k)
        UNTIL done OR (k = pegs)
      END
    END;

-- 
Tomas Kral <thomas.kral at email.cz>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rgb.png
Type: image/png
Size: 28706 bytes
Desc: not available
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20200610/aab5005a/attachment.png>


More information about the Oberon mailing list