+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Hangman (again)</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <style type="text/css">
+ /* Slideshow styles */
+ body {
+ font-size: 20px;
+ }
+ h1, h2, h3 {
+ font-weight: 400;
+ margin-bottom: 0;
+ }
+ h1 { font-size: 3em; }
+ h2 { font-size: 2em; }
+ h3 { font-size: 1.6em; }
+ a, a > code {
+ text-decoration: none;
+ }
+ code {
+ -moz-border-radius: 5px;
+ -web-border-radius: 5px;
+ background: #e7e8e2;
+ border-radius: 5px;
+ font-size: 16px;
+ }
+ .plaintext {
+ background: #272822;
+ color: #80ff80;
+ text-shadow: 0 0 20px #333;
+ padding: 2px 5px;
+ }
+ .ciphertext {
+ background: #272822;
+ color: #ff6666;
+ text-shadow: 0 0 20px #333;
+ padding: 2px 5px;
+ }
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
+ }
+ .float-right {
+ float: right;
+ }
+ </style>
+ </head>
+ <body>
+ <textarea id="source">
+
+# Hangman
+
+1. **Set a puzzle** <== here
+2. Guess a word
+3. Automatic player
+4. Better strategies
+
+---
+
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+# Data for Hangman
+
+## Creating a game
+* 'List' of words to choose from
+ * Pick one at random
+
+## Game state
+
+<table>
+<tr valign="top">
+<th>Data</th>
+<th> </th>
+<th>Operations</th>
+</tr>
+<tr valign="top">
+<td>
+
+* Target word
+* Discovered letters
+ * In order in the word
+* Lives left
+* Wrong letters?
+
+</td>
+<td></td>
+<td>
+
+* Get a guess
+* Update discovered letters
+* Update lives
+* Show discovered word
+* Detect game end, report
+* Detect game win or loss, report
+
+</td>
+</tr>
+</table>
+
+---
+
+# Next steps
+
+We've got a list of valid words.
+
+* How to pick one?
+ * look in the `random` module
+
+* Once we have a word, how to represent what's been guessed?
+
+---
+
+# Representing the game state
+
+Three data items:
+
+* `target`, the target word: a `string`
+* `discovered`, what's been found so far: a `list` of letters (each a length-one `string`)
+ * unguessed letters are `_`
+* `guess`, the letter that's just been guessed: a length-one `string`
+* `lives`, the lives remaining: an `int`
+* `wrong_letters`, the incorrect guesses: a `list` (optional)
+ * (but it makes the automated players easier if they don't have to track wrong guesses and therefore be made stateless)
+
+---
+
+# Challenges
+
+1. Print a `discovered` word
+2. Read a letter
+3. Check if the `guess`ed letter is in the `target`
+4. Update `discovered` word with the newly-`guess`ed letter
+5. Update `lives` and `wrong_letters` if the guess is wrong
+
+## Hints
+
+1. Remember `<string>.join(<list>)` ?
+2. `input('prompt')` (or `input('prompt').strip().lower()[0]` )
+3. Walk over `target`, looking for `guess`. Explicit iteration (`for letter in target:`) or with a comprehension (`enumerate(target)`)
+4. `target[n] = guess`. Note that you need the numerical position, and you need all the positions for repeated words.
+5. How do you know the guess is wrong?
+
+
+ </textarea>
+ <script src="http://gnab.github.io/remark/downloads/remark-0.6.0.min.js" type="text/javascript">
+ </script>
+
+ <script type="text/javascript"
+ src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&delayStartupUntil=configured"></script>
+
+ <script type="text/javascript">
+ var slideshow = remark.create({ ratio: "16:9" });
+
+ // Setup MathJax
+ MathJax.Hub.Config({
+ tex2jax: {
+ skipTags: ['script', 'noscript', 'style', 'textarea', 'pre']
+ }
+ });
+ MathJax.Hub.Queue(function() {
+ $(MathJax.Hub.getAllJax()).map(function(index, elem) {
+ return(elem.SourceElement());
+ }).parent().addClass('has-jax');
+ });
+ MathJax.Hub.Configured();
+ </script>
+ </body>
+</html>