Answered step by step
Verified Expert Solution
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 IO based programming. A Perspective Shift In Part 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 precomputed. We have a finite set of inputs both the guess and the answer have only 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 theres 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 T T T 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 D list of bools listlistbool 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 commaseparated characters in no particular order, and returns a list of the indices corresponding to those characters: eg abc would return It should not matter what order the characters are in They should work with both upper and lower case letters ie aBc would return the same as abc 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 rowcolumn lookup pair to be checked in the verifier, in the form xyie pf type, tupleint int You will need to read the specific values from the file verifierAddress.in It is in the format guess,xy on each line. eg an input guess of returns 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 criteria A The Triangle Compared to T T T B The number of s in the code xxxx C Which number is smaller than either of the others TC&S ST&C CS&T D Number of Even numbers compared to Odd EvenOdd, Even
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 IO based programming.
A Perspective Shift
In Part 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 precomputed. We have a finite set of inputs both the guess and the answer have only 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 theres 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 T T T
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 D list of bools listlistbool 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 commaseparated characters in no particular order, and returns a list of the indices corresponding to those characters:
eg abc would return
It should not matter what order the characters are in
They should work with both upper and lower case letters ie aBc would return the same as abc
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 rowcolumn lookup pair to be checked in the verifier, in the form xyie pf type, tupleint int
You will need to read the specific values from the file verifierAddress.in It is in the format guess,xy on each line.
eg an input guess of returns
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 criteria
A The Triangle Compared to T T T
B The number of s in the code xxxx
C Which number is smaller than either of the others TC&S ST&C CS&T
D Number of Even numbers compared to Odd EvenOdd, Even
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started