Atari Logik

Type
Game
Category
Mastermind-style number guessing game
Published in
Elektronika, issue 1/88; reprinted on the Czech disk magazine Flop, issue 7
Year
1988
Language
Atari BASIC
Requirements
Any 8-bit Atari with Atari BASIC; keyboard
Text screen with Czech instructions and the column headings ZASAH VEDLE SPATNE POKUS above an input prompt

About the program

This is the classic Bulls and Cows / Mastermind code-breaking game in plain Atari BASIC. The REMs say it comes from the magazine Elektronika, issue 1/88, and that it was typed in ("PRETUKAL") by Ing. J. Vácha of Náměšť nad Oslavou. It was later reissued on the Czech disk magazine Flop 7. The computer thinks of a five-digit number made of the digits 1–9 with no digit repeated. After each guess it tells you how many digits are in the right place, how many are in the number but in the wrong place, and how many aren't in it at all.

Prompts in English

Czech on screen Meaning
MYSLIM SI PETICIFERNE CISLO I'm thinking of a five-digit number
CISLICE 1 AZ 9 SE NESMI OPAKOVAT Digits 1 to 9, none may repeat
HADEJ ! Guess!
ZASAH · VEDLE · SPATNE · POKUS Hit (right place) · Near (wrong place) · Wrong · Attempt no.
SPATNE ZADANE! Entered incorrectly! (not five digits)
CISLA SE NESMI OPAKOVAT! Digits must not repeat!
UHODL JSI, MYSLENE CISLO JE … You got it, the number was …
S TVOU INTELIGENCI TO NENI PRILIS SLAVNE (after 20 tries) "With your intelligence, that's nothing to boast about"
INTELIGENCE PODPRUMERNA (after 50 tries) "Below-average intelligence"
CHCES JESTE HRAT? A/N Play again? A = yes (ano), N = no (ne)

Typing it in

The listing is pure ASCII with no special characters, so it is a good one to type with children. The variable names are Czech too (POKUS = attempt, ZASAH = hit, VEDLE = near, SPATNE = wrong, CISLO = number), and Atari BASIC accepts long names happily. Answer A (ano, yes) to play again.

How to play

Type a five-digit guess such as 12345 and press RETURN. A row of four numbers appears next to your guess: hits, near misses, wrong digits and the attempt count. Line 300 moves the cursor back up so each result sits on the same line as its guess (POKE 84 sets the row, POKE 85 the column). Keep refining until you get five hits.

How it works

Lines 20–70 build the secret number digit by digit, re-rolling any digit already used. The scoring trick is in lines 230–280. Exact hits are counted first, and each matched secret digit is made negative for the moment. That way the following "near" count (every guess digit against every secret digit) can't count them a second time. Line 280 then restores the values with ABS. Your input is read as a number and turned back into a string with STR$, so a leading 0 would be lost. That's presumably why the digits run from 1 to 9.

Variations to try

  • Make it easier with four digits. Change the 5s in lines 30, 130, 150–170, 230–290 and 320.
  • Translate the prompts. They're all in PRINT statements in lines 90–95, 130, 190, 320–340.

Listing

2 REM *** ATARI LOGIK ***
3 REM *** ELEKTRONIKA 1/88 ***
4 REM *******************************
5 REM PRETUKAL ING.J.VACHA,NAMEST N.O.
10 DIM C(5),CI$(5),B$(1),D(5),G$(1)
20 C(1)=INT(RND(0)*9)+1
25 POKUS=0
30 FOR I=2 TO 5
40 LET C(I)=INT(RND(0)*9)+1
50 FOR K=1 TO I-1
60 IF C(I)=C(K) THEN 40
70 NEXT K:NEXT I
80 PRINT CHR$(125):POKE 85,6
90 PRINT "MYSLIM SI PETICIFERNE CISLO"
91 PRINT "CISLICE 1 AZ 9 SE NESMI OPAKOVAT"
95 PRINT " HADEJ !":PRINT:PRINT
100 POKE 85,10:PRINT "ZASAH VEDLE SPATNE POKUS"
110 INPUT CISLO:X=PEEK(84):POKUS=POKUS+1
120 LET XY=LEN(STR$(CISLO))
130 IF XY<>5 THEN PRINT "SPATNE ZADANE!":GOTO 110
140 LET CI$=STR$(CISLO)
150 FOR I=1 TO 5:B$=CI$(I):LET D(I)=VAL(B$):NEXT I
160 FOR J=1 TO 5:LET Z=D(J)
170 FOR I=1 TO 5
180 IF I=J THEN GOTO 200
190 IF Z=D(I) THEN PRINT "CISLA SE NESMI OPAKOVAT!":GOTO 110
200 NEXT I
210 NEXT J
220 ZASAH=0:VEDLE=0:SPATNE=0
230 FOR K=1 TO 5
240 IF C(K)=D(K) THEN ZASAH=ZASAH+1:C(K)=C(K)*(-1)
245 NEXT K
250 FOR I=1 TO 5:FOR J=1 TO 5
260 IF D(I)=C(J) THEN VEDLE=VEDLE+1
270 NEXT J:NEXT I
280 FOR I=1 TO 5:C(I)=ABS(C(I)):NEXT I
290 SPATNE=5-(VEDLE+ZASAH)
300 POKE 84,X-1:POKE 85,12
310 PRINT ZASAH;" ";VEDLE;" ";SPATNE;" ";POKUS
320 IF ZASAH=5 THEN PRINT:PRINT "UHODL JSI, MYSLENE CISLO JE ";CISLO:GOTO 340
325 IF POKUS=20 THEN PRINT "S TVOU INTELIGENCI TO NENI PRILIS SLAVNE"
326 IF POKUS=50 THEN PRINT "INTELIGENCE PODPRUMERNA"
330 GOTO 110
340 PRINT "CHCES JESTE HRAT? A/N":INPUT G$
350 IF G$="A" THEN 20
360 END

Credits