begin integer COLOR1,COLOR2,COLOR3,COLOR4, ROW,COL,OLDROW,OLDCOL,MAXCOL; integer array HYP[1:4],BOARD[1:10,1:4],WHITES,BLACKS[1:10]; boolean array OLDMAT,NEWMAT[1:4]; procedure PATERN(ROW); value ROW; integer ROW; begin integer COL; for COL ≔ ,2,3,4 do if BOARD[ROW,COL]=1 then out string(1,“RED ”) else if BOARD[ROW,COL]=2 then out string(1,“BLUE ”) else if BOARD[ROW,COL]=3 then out string(1,“GREEN ”) else if BOARD[ROW,COL]=4 then out string(1,“YELLOW ”) else if BOARD[ROW,COL]=5 then out string(1,“BLACK ”) else if BOARD[ROW,COL]=6 then out string(1,“WHITE ”) else out string(1,“SPACE ”); end PRINT PATTERN; procedure PRINTROW; begin out string(1,“\nMy guess ”); out integer(1,ROW); out string(1,“ is: ”); PATERN(ROW); end PRINT THE CURRENT ROW; START: out string(1,“\n\nMastermind Codebreaker\nVersion 1 or 2 ?”); in integer(0,MAXCOL); if ¬(MAXCOL=1 ∨ MAXCOL=2) then goto START; MAXCOL ≔ AXCOL+5; ROW ≔ ; for COLOR1 ≔ step 1 until MAXCOL do for COLOR2 ≔ step 1 until MAXCOL,1 do for COLOR3 ≔ step 1 until MAXCOL,1,2 do for COLOR4 ≔ step 1 until MAXCOL,1,2,3 do begin integer BLACK,WHITE; HYP[1] ≔ OLOR1; HYP[2] ≔ OLOR2; HYP[3] ≔ OLOR3; HYP[4] ≔ OLOR4; comment SET UP THE HYPOTHESIS ROW. A ROW IS CONSISTENT WITH ALL PREVIOUS ROWS IF IT GIVES RISE TO THE SAME NUMBER OF BLACK AND WHITE INFORMATION PEGS AS THOSE ROWS; for OLDROW ≔ step 1 until ROW-1 do begin BLACK ≔ ; for COL ≔ ,2,3,4 do begin boolean TEMP; TEMP ≔ OLDMAT[COL] ≔ NEWMAT[COL] ≔ HYP[COL]=BOARD[OLDROW,COL]; if TEMP then BLACK ≔ LACK+1; end; if BLACK≠BLACKS[OLDROW] then goto NOT VIABLE; WHITE ≔ ; for COL ≔ ,2,3 do for OLDCOL ≔ OL+1 step 1 until 4 do begin if HYP[COL]=BOARD[OLDROW,OLDCOL] then begin if ¬(NEWMAT[COL] ∨ OLDMAT[OLDCOL]) then begin NEWMAT[COL] ≔ LDMAT[OLDCOL] ≔ ̲rue; WHITE ≔ HITE+1; end end; if HYP[OLDCOL]=BOARD[OLDROW,COL] then begin if ¬(NEWMAT[OLDCOL] ∨ OLDMAT[COL]) then begin NEWMAT[OLDCOL] ≔ LDMAT[COL] ≔ ̲rue; WHITE ≔ HITE+1; end end end; if WHITE≠WHITES[OLDROW] then goto NOT VIABLE; end LOOK AT EACH PREVIOUS ROW; comment AT THIS POINT THE HYPOTHESIS ROW IS VIABLE; for COL ≔ step 1 until 4 do BOARD[ROW,COL] ≔ YP[COL]; PRINTROW; JUNK: out string(1,“\nHow many black pegs ? ”); in integer(0,BLACKS[ROW]); if BLACKS[ROW]=4 then begin out string(1,“Thanks for the game”); goto START; end PROBLEM SOLVED else if BLACKS[ROW]=3 then WHITES[ROW] ≔ else begin if BLACKS[ROW]<0 ∨ BLACKS[ROW]>4 then begin out string(1,“TWIT !!”); goto JUNK; end; out string(1,“How many white pegs ? ”); in integer(0,WHITES[ROW]); if WHITES[ROW]<0 ∨ WHITES[ROW]+BLACKS[ROW]>4 then begin out string(1,“TWIT !!”); goto JUNK; end end; ROW ≔ OW+1; if ROW=10 then begin out string(1,“\nWELL DONE, YOU WIN !!”); goto START; end; NOT VIABLE: end LOOK AT EACH POSSIBLE ROW; out string(1,“\nTwit !!! you made a mistake”); goto START; end OF MASTERMIND CODEBREAKER;