UNCLE BERNIE'S CODEBREAKER GAME

**UPDATE**

The CODEBREAKER app is now live on GitHub.

Link: https://github.com/Rob42101/CODEBREAKER

I may release a support app; the working title is simply "solver". It's fundamentally the base code that I used in the development of the AI side of codebrk.py and comes in very handy. Without it, one could spend hours writing out, with pen & paper, the valid codes, based on the AI feedback, and I very much doubt that users would do that in this day and age, given that we have now have computers that could not even be imagined, back in the day.

This kind of computer game was radical back then, and people were prepared to spend as long as it took, to crack a code, with a real sense of achievement, in doing so.

It will need cleaning up, because as is, the operation makes perfect sense to me, but I doubt if the same would apply to anyone else. I'd also need some encouragement, to put in the time and effort needed to make it fit for general release. On the other hand, the coders among us, could either reverse engineer my code, or better still, write some original code, to see if you can have your AI beat my AI, which is what it would amount to.

Enjoy and your feedback is welcomed.

----

### Overview

This Python implementation of the game known as UNCLE BERNIE'S CODEBREAKER GAME
was written to emulate the original game as closely as possible.

The algorithms that I have created were inspired by Bernie and his explanation
of how the original game was coded, for which Bernie has my deepest thanks.

Visit https://www.applefritter.com/content/uncle-bernies-codebreaker-game-apple-1
to read a very detailed account of the original game, by the game author, as well
as hints and tips about how to play the game and some screen shots of the game in
progress.

There, you will also be able to d/load the Codebreaker game manual (PDF format) as
well as source code files that should run on the the Apple-1 and Apple II computers,
should you wish to do so.

I have written this Python implementation for those that simply want to play the
game without having to run the original binary.

Python dependencies have been kept to a minimum, but in order to have a more authentic
experience, I have used the Terminal class object from the `blessed` library.

For more information on that, please see these links:

https://pypi.org/project/blessed/

https://blessed.readthedocs.io/en/latest/terminal.html

### Running the game

In order to run this game, you will need to either grant the `codebrk.py` file
executable permission or load the script through your Python3 interpreter.

The game should be run from a terminal window set to apx 50x25. Although the window
size is not important to the game operation, if you resize the terminal window after
the game has been started, you may experience some issues with the display until a few
lines have been written. This because the framework that I have used, needs to figure
out where the insertion point is, in relation to the terminal window size.

You **should not use the enter or return keys**: once you have typed four letters or
four feedback symbols, the app will recognise that and move on, without any further
keyboard action. If you make a mistake, you can clear your input by pressing the `Esc`
key, before you type the forth letter/symbol, after which, you are committed to your
input, so you'll need to be mindful of that.

This is what the entry screen should look like, once you have the game up and running.

```
*** UNCLE BERNIE'S CODEBREAKER GAME ***

0 ROOKIE
1 MASTER
2 GENIUS
H HELP

ENTER YOUR CHOICE:
```

To exit the game, press the `Esc` key at this point. At no other point in the game can a
graceful exit be called.

The code has been thoroughly tested (10,000+ simulated games) and contains no known bugs.
As such, if you are accused of "cheating", I am as sure as I can be that you will have made
some error in your feedback to the AI guess of your secret code.

So far (as of the date of this document) this game has only been run on a Linux based OS and
as such, I can't say for sure if it will work correctly on a MS Windows system.

### Extras

Because this is a challenging game, at first, you may find it hard to concentrate on both
working out what your next best guess should be, as well as working out what your correct
response should be to the AI best guess. Getting this wrong, will result in you being accused
of cheating, at which point you will forfeit the game. As this can be a source of frustration,
I have provided a 'helper' app (`helper.py`), that will provide the correct response for any
given secret code/guess combination, at any level of game play.

### About the feedback

My understanding is that with the original game, the order in which the feedback symbols
are entered, is unimportant (so, `++*-` is as good as `*++-`). This has been retained in
my implementation of the game, but a purest will tell you that the order should always be
entered as `*` `+` `-` as the priority order.

### Game play hints and tips

If you wait for the AI first best guess, before you decide on what your secret code will be,
you can gain a slight advantage by basing your code on the AI first best guess.

As an example, if the AI first best guess happens to be `ECEC`, then make sure that you
choose a secret code that contains one of those letters, in the correct position, because,
if it does not, your response will have to be `----`, in which case the AI can completely
rule out both the `C` and the `E` from its search space and with only six letters
(at the ROOKIE level), this means that the AI will only have to include the remaining four
letters in any subsequent best guess, making it much easier to find your secret code.

Likewise, if you have to respond with `+---` (one correct letter, in the wrong place), then
the AI knows that there can't be a `E` at positions one or three, and there can't be a `C`
at positions two or four, but there is definitely a `C` at either p1 or p3, or there is
definitely a `E` at p2 or p4.

A response of `*---`, on the other hand (one correct letter, in the correct position) would
give away as little information as possible, because all that the AI would know is that
there is one correct letter, but (at this stage) it will have no clear idea about which
letter is correct or at which position said letter will be.

### In closing

So far as I can tell, when the original game was run and a level of play had been chosen,
the player was then committed to that level (playing as many games as desired) until a machine
`RESET` signal was sent, at which point you would again see the game menu.

This is where my implementation diverges, in so much as; once a game has been concluded, you
will see the game menu displayed right away, rather than simply starting a new game, at the
same level. From there, you can choose whatever level of play you wish and the game scores will
continue to accumulate.

Please enjoy. If you have any comments or feedback, please use this channel, or you can PM me
(rob101) at the [Applefritter.com](https://www.applefritter.com/) website.

Tags: 
Content Type: 

Comments

MacFly's picture

Did you forget a link to the actual Python file (codebrk.py) - or am I somehow not seeing this link?

Thank you for your feedback.

 

This is a preview document. The python files will be hosted on GitHub, just as soon as I have them finalized, which should be within the next few days, any unforeseen issues aside, that is.

 

The reason for posting here first, is so that, if anyone spots anything that needs to be amended or added, then it will be done, before going live on GitHub, is all.

 

For example, I've linked back to this website, so (IMHO) it's a matter of common courtesy to make this known before the fact, rather than after it, so that any potential objections can be addressed.

 

I will link-up the GitHub repository, as and when.

 

 

MacFly's picture

Would you post back with your Computer OS and Python version for me please, as I'll like to keep a record of which systems this has been run on.

 

With thanks.

MacFly's picture

rob101 wrote:

Would you post back with your Computer OS and Python version for me please, as I'll like to keep a record of which systems this has been run on.

Successfully ran on Python 3.6.15 on openSUSE Linux (Kernel  5.14.21)... :)

MacFly wrote:
rob101 wrote:

Would you post back with your Computer OS and Python version for me please, as I'll like to keep a record of which systems this has been run on.

Successfully ran on Python 3.6.15 on openSUSE Linux (Kernel  5.14.21)... :)

 

Thank you. That's useful to know.