Assignment 0
Deadline: Nov, 4 2023 14:00 CET
This assignment aims to help you get acquainted with the course set-up, the assignment workflow and, if need be, (re-)introduce you to Python.
Exercise
The task is to create a function that will make the most likely guess for a game of hangman. This guess will be informed by the letters that have already been tried and the most common letters appearing at positions where letters have not been guessed.
All code should be implemented in the provided template. The main method is already provided, as well as a sample lexicon that will be used for testing.
0.1 Implement guess_hangman()
Guess a letter, given the template, lexicon and guesses so far.
Note that this function is ‘stateless’. That is, it does not store any information internally. The template, the lexicon, and the letters guessed so far are provided as arguments to the function (not the best software design practice, but we are not in a software engineering course). We assume that caller is not cheating: the lexicon stays fixed during a particular turn, and the caller always provides the letters guessed so far correctly.
We try to implement a simple, heuristic-based hangman guesser. The idea is to match the most likely word in the lexicon, and in case the word is not in the lexicon, guess the most frequent letter in the lexicon that we did not guess so far.
You can (and probably you should) delegate well-defined parts
to other functions.
However, you are not allowed to make use of any additional libraries
(including Counter
from the collections
library).
A sample lexicon is provided as lexicon.txt. This lexicon is also used for testing, please do not modify it.
Grading
You are provided with pytest tests
in test_a0.py that will run every time
your code is pushed to GitHub.
You can see their results on GitHub and observe what is failing.
You can also run these tests locally through (IDE) terminal by calling pytest
.
Tests can also be run individually
by calling pytest <test_file_name>::<test_name>
Food for Thought
The assignments will try to encourage you to solve a problem (often in an efficient way). In some assignments, we will also include a few additional questions that you are not required to answer in any way, but recommended to think about them. Here are a few examples:
- What is the effect of word length, the size of the lexicon and the number of characters on the efficiency of your algorithm in finding the word in least number of tries?
- Are there more efficient methods than guessing the most frequent character once we know that the word is not in the lexicon?
- Think about (or write a function that implements) an adversarial word selector that would result in the algorithm you implemented to perform badly.
Wrapping up
Do not forget to
- indicate your name(s) in the file header
- commit all your changes
- push it to your GitHub repository