5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8"/>
6 <style type=
"text/css">
15 h1 { font-size:
3em; }
16 h2 { font-size:
2em; }
17 h3 { font-size:
1.6em; }
19 text-decoration: none;
22 -moz-border-radius:
5px;
23 -web-border-radius:
5px;
31 text-shadow:
0 0 20px #
333;
37 text-shadow:
0 0 20px #
333;
51 <textarea id=
"source">
64 .indexlink[[Index](index.html)]
69 A fairly traditional hangman game. The computer chooses a word, the (human) player has to guess it without making too many wrong guesses. You'll need to find a list of words to chose from and develop a simple UI for the game (e.g. text only: display the target word with underscores and letters, lives left, and maybe incorrect guesses).
73 * What do we need to track?
74 * What operations do we need to perform on it?
81 * 'List' of words to choose from
89 <th> </th>
97 * In order in the word
106 * Update discovered letters
108 * Show discovered word
109 * Detect game end, report
110 * Detect game win or loss, report
119 The other side of the game. The human choses a word, the computer has to guess it. Again, go for a very simple UI. Perhaps the human just responds with a list of letter positions for a correct guess, or zero for an incorrect guess.
123 * What do we need to track?
124 * What operations do we need to perform on it?
127 ## Need to think about the algorithm first
129 How will we solve the game?
133 # Guessing strategies
135 Guess words in order of frequency in English
137 What is the frequency of letters in English?
139 Pick a novel, count the letters, list them in frequency order
141 Hint: four lines of code, two of them are
152 * the discovered word
153 * the wrong guesses so far
154 * the order of letters to guess
158 * The most common unguessed letter
165 Put step
1 and step
2 together so the computer can play both sides of hangman on its own. You'll need to fix the interface between the two sides: perhaps define a fixed format for the
"state" of a hangman game. Get them to play several thousand games together and log the results (how many games can they play overnight?). Do a bit of data analysis: how many games were won, how does the word length affect the win rate and the number of guesses needed to get the word, is the number of guesses per target letter constant, and so on.
170 Tidy things up: encapsulate in objects
172 Define a class for a game, a class for a player
174 Run a game by instantiating a game object, passing in a player object
176 Interface: the `player` must respond to a `guess` method
178 Make the `game` generate output only if it's not passed a `player`
181 # Different player strategies
183 Develop different strategies for playing hangman and see which is best. Can you order guesses by letter occurrence frequency (in either normal English or the dictionary)? Does a stochastic or deterministic approach work better?
184 What counts as a
"better" strategy?
186 * Think of some better players
188 * Test their performance
189 * Write records of game to CSV files (look at the standard `csv` library)
192 <script src=
"http://gnab.github.io/remark/downloads/remark-0.6.0.min.js" type=
"text/javascript">
195 <script type=
"text/javascript"
196 src=
"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&delayStartupUntil=configured"></script>
198 <script type=
"text/javascript">
199 var slideshow = remark.create({ ratio:
"16:9" });
204 skipTags: ['script', 'noscript', 'style', 'textarea', 'pre']
207 MathJax.Hub.Queue(function() {
208 $(MathJax.Hub.getAllJax()).map(function(index, elem) {
209 return(elem.SourceElement());
210 }).parent().addClass('has-jax');
212 MathJax.Hub.Configured();