Coronavirus (Covid-19): Latest updates and information
Skip to main content Skip to navigation

Skeleton definitions for the WordGame model

The Wordgame model illustrates some of the basic functionalities of %dasm and %eden.

It sets up an environment to support interaction somewhat like that represented in the two player game Mastermind.

The essential principle is that one player chooses a four letter word (the 'target'), and the other player guesses the word (the 'guess').

In response to each guess, the first player gives feedback in the form of a display which comprises up to four black or red coloured panels:

  • A black panel is included for every letter in the guess that is the same as the letter in the corresponding location of the target.
  • A red panel is included for every letter in the guess that matches a letter not in the same location in the target.

The panel display is ordered linearly in such a way that black panels appear to the left of red panels.

The following 16 definitions set up observables that record the result of comparing each letter of the target with each letter of the guess:

@wordgame match = (new);

@wordgame match 11 is {@wordgame target 0 == (@wordgame guess 0)};

The following 16 definitions convert boolean observables in @wordgame .match to 0s and 1s

a11 is {if (.match 11) {1} else {0}}

The number of letters that appear in the correct position is given by the observable:

@wordgame numsame is {.a11 + (.a22) + (.a33) + (.a44)};

The number of instances of a letter matching the same letter in another position is given by the observable:

@wordgame numcomm is {.a12+(.a13)+(.a14)+(.a21)+(.a23)+(.a24)+(.a31)+(.a32)+(.a34)+(.a41)+(.a42)+(.a43)};

and the total number of matches is given by:

@wordgame nummatch is {.numsame + (.numcomm)};

The panel display, as determined by the target and the guess, can be laid out as an array of four Scout windows, as follows:

display dispsignal;

screen = dispsignal;

window signal;

signal = {
type: DONALD
box: [{10,10}, {110, 35}]
pict: "sigpict"
bgcolor: "white"

window sign1, sign2, sign3, sign4;
string col1, col2, col3, col4;

sign1 = {
type: DONALD
box: [{10,10}, {33, 35}]
pict: "sigpict"
bgcolor: col1
bdcolor: "white"


dispsignal = <sign1 / sign2 / sign3 / sign4 / signal>;

To test the panel display mechanism, you can supply colours for the panels:

col1 = "red";
col2 = "blue";
col3 = "green";
col4 = "black";

(Identical definitions will also work if made in Eden.)

The colours of the panels can be deduced from the values of the observables a11, a12, ..., a44 as follows:


@wordgame colsig = (new);

@wordgame colsig
col1 is {if (1 == (@wordgame numsame) or (1 < (@wordgame numsame))) {
} else {
if (1 == (@wordgame nummatch) or (1 < (@wordgame nummatch))) {"red"} else {"white"}