Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Bletchly Basics Now that we have some idea how the game works and what the logical structures are, we're going to take the next step

Bletchly Basics
Now that we have some idea how the game works and what the logical structures are, we're going to take the next step in making the game playable, and also mess with everyone's head by introducing a different way to think about the verifiers that's more amenable to I/O based programming.
A Perspective Shift
In Part 3, we approached verifiers as programmatic structures - they compute some property of the input and return the result. It can be observed, however, that with a finite set of inputs, the results of any verifier can be pre-computed. We have a finite set of inputs - both the guess and the answer have only 125 possibilities each. Thus with a finite amount of space, we can simply just list all the possibilities, and use the guess and the answer to index them in some clever way - then it just becomes a lookup table.
In this Part, we will use this approach to verifiers, though we will elide how they're computed and which exact situation they correspond to.
Input Data
There are two main data inputs, stored in files, the verifierAddress.in file and the game card files.
The verifierAddress.in gives the indexing scheme for which row and column to look in for a particular guess.
The game cards have one string on the top line (the criterion). The rest of the file makes up the verifier (there's some magic in how this data is computed so that the lookup works, and in the board game these come as two separate pieces, allowing the lookup to change dependent on the secret answer). You have been given four example verifier files, however the tests will use more than these, so you can't simply hard code these ones.
The contents of the verifier files has the format (with different data in each of course):
The Triangle Compared to 3(T<3, T=3, T>3)
0,0,0,1,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,1,1,0,1,0
0,0,0,1,0,0,0,0,0,0,0,0
0,0,0,1,0,0,0,1,0,0,0,1
0,1,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,1,1,0,0,0,1,1
0,0,0,0,0,0,0,0,1,0,0,0
0,0,0,1,0,0,1,0,0,0,0,0
0,1,0,1,0,0,0,0,1,0,0,1
0,1,0,0,0,0,1,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,1,0,0,0,1,1,0,0,0
Some definitions
You don't have to have variables with these names, but to simplify the documentation, here is what these key conceptual components have been called
the criterion is a str describing the logic of checks made in the associated verifier.
verifier is a 2D list of bools (list[list[bool]]) that checks the condition as described in the criterion.
gameCard is a tuple of the above (criterion, verifier).
Functions
For the actual task, you will implement a series of functions (no objects or classes here!) in the machine.py file. You start with an empty __main__ section. This is not part of the tests, and you may use it for your personal testing. All your functions should be defined in this file. The function details are as follows:
inputCard takes a filename as a str and returns a gameCard corresponding to the data in that file (as described above).
getVerifierInput takes a str of 3 comma-separated characters in no particular order, and returns a list of the indices corresponding to those characters:
e.g., a,b,c would return [0,1,2].
It should not matter what order the characters are in.
They should work with both upper and lower case letters (i.e., a,B,c would return the same as a,b,c).
You do not have to check to ensure valid input.
The output list of ints should be sorted.
guessToIndex takes a guess (int) and returns the row-column lookup pair to be checked in the verifier, in the form (x,y)(i.e. pf type, tuple[int, int]).
You will need to read the specific values from the file verifierAddress.in. It is in the format guess,x,y on each line.
e.g., an input guess of 111 returns (2,5)
checkVerifier takes a gameCard and a guess as an int, and returns a bool stating if the guess is true or false by obtaining the lookup pair, then looking in that location on the verifier given by the gameCard.
listCriteria takes a list of gameCards and returns a str listing the number of criteria, then each condition indented by four spaces, and enumerated with an uppercase letter followed by a close parenthesis, and then the criterion. An example of this format is:
You have 4 criteria
A) The Triangle Compared to 3(T<3, T=3, T>3)
B) The number of 4s in the code (0x4,1x4,2x4,3x4)
C) Which number is smaller than either of the others (T<(C&S), S<(T&C), C<(S&T))
D) Number of Even numbers compared to Odd (Even>Odd, Even

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions