--- title: "Mastermind" id: 72389 type: "computer_media" slug: "mastermind-2" url: "http://localhost/computer_media/mastermind-2/" markdown_url: "http://localhost/computer_media/mastermind-2.md" published_at: "2026-10-23T07:47:10+00:00" modified_at: "2026-10-23T07:47:10+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2026/10/mastermind-2.png" excerpt: "Crack a hidden four-colour code from red, orange, yellow, green, blue and white, with block and checkerboard pegs scoring each guess." post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" genre: - name: "Game" slug: "game" taxonomy: "genre" url: "http://localhost/type/game/" media_type: "Program" download_url: "https://archive.org/download/timex-sinclair-software-archive/Mastermind%20-%20Colors%20%28198x%29%28-%29%28TS2068%29%28US%29%28Program%29.zip" tsrun_member: "Mastermind - Colors (198x)(-)(TS2068)(US)(Program)/Mastermind - Colors (198x)(-)(TS2068)(US)(Program).tap" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2026/10/mastermind-2.png" related_content: - id: 72713 title: "SNUG-ISTUG Public Domain Library" type: "computer_media" url: "http://localhost/computer_media/snug-istug-public-domain-library/" media_type_tags: "Game" license: false --- # Mastermind A colour version of Mastermind. The computer hides a four-letter code made from `R O Y G B W`, and colours can repeat. You type a four-letter guess and it is printed up the screen from the bottom, with a peg for each hit beside it. A solid block means the right colour in the right place, and a checkerboard UDG means the right colour in the wrong place. You get nine guesses. The program then shows the code, or the number of tries you took. No author is named. The listing is heavily compacted. ## Program Analysis ### Scoring Each guess is first compared position by position (lines 150–210). Exact matches are marked out in working copies of the code and the guess, so they can’t be counted again. Lines 230–310 then look for colour matches among what is left. The variable `b` is the screen column for the next peg, and it is also the win test: four exact hits leave `b=8`. ## Notable Techniques - Number-free constants: `SGN a` for 1, `NOT a` for 0, `INT PI` for 3 and `a+a` for 8. - `POKE 23658,8` turns on caps lock so guesses come in as capitals. - UDG a is a checkerboard made from alternating 85 and 170 bytes. - Line 330 prints “WRONG” with a string-AND: `"WRONG" AND d=SGN d`. ## Potential Issues - The code letter is chosen with `"ROYGBW"(VAL "RND*5+1")`. The index is rounded, so R and W come up half as often as the other colours. - There is no `CLS` at the start, so the loader’s “Program:” line stays on screen. - Guesses are not checked for length or letters. This program came from an Oliger (JLO SAFE) disk, a copy of the SNUG library disk 13/14, and was converted to load from tape. No changes were needed. It was tested in ZEsarUX with several guesses. ## Source Code ``` 10 FOR z=0 TO 6 STEP 2: POKE USR "a"+z,85: POKE USR "a"+Z+1,170: NEXT z 20 POKE 23658,8 30 LET a=4 40 DIM a$(a) 50 DIM b$(a) 60 FOR d=SGN a TO a 70 LET a$(d)="ROYGBW"(VAL "RND*5+1") 80 NEXT d 90 PRINT "ROYGBW ::::::::::::::::" 100 FOR d=19 TO INT PI STEP -2 110 LET b=NOT a 120 INPUT LINE b$ 130 PRINT AT d,9;b$ 140 LET c$=a$ 150 FOR e=SGN a TO a 160 IF b$(e)<>c$(e) THEN GO TO 210 170 PRINT AT d,b;"::" 180 LET b=b+2 190 LET b$(e)="a" 200 LET c$(e)="::" 210 NEXT e 220 IF b=a+a THEN GO TO 330 230 FOR e=SGN a TO a 240 FOR f=SGN a TO a 250 IF c$(e)<>b$(f) THEN GO TO 300 260 PRINT AT d,b;"a" 270 LET b=b+2 280 LET b$(f)="a" 290 GO TO 310 300 NEXT f 310 NEXT e 320 NEXT d 330 PRINT AT NOT a,NOT a;"WRONG" AND d=SGN d;TAB a+a;" ";a$, 340 IF d<>SGN d THEN PRINT INT VAL "11-d/2";" TRIES" ```