1 / 28

mastermind: last details

Understand the key heuristic to minimize maximum remaining candidates in the Mastermind game. Learn how to build and represent the game tree efficiently for a winning strategy.

tsang
Download Presentation

mastermind: last details

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. mastermind: last details David Kauchak CS52 – Spring 2017

  2. Admin Assignment 7 Assignment 8 Midterm Course registration

  3. Key heuristic all codes not yet guessed … guess guess guess min max The one that minimizes the maximum remaining candidates Max (codemaker response): assume we get the response with the largest remaining candidate set Min (our guess): pick the one that, worst case, results in the smallest candidate set How do we calculate this?

  4. Key heuristic all codes not yet guessed … guess guess guess min max The one that minimizes the maximum remaining candidates For all codes not yet guessed: Consider all possible responses: Calculate the size of the remaining candidates if we guessed that code and got that response select code with smallest max select response with largest remaining for that code min max

  5. Game tree We can precompute the entire tree of possibilities Expensive upfront to compute Playingbecomes fast

  6. Game tree [Red, Red,Green] (“best” first guess) codemaker response (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0) candidates remaining 6 1 1 4 3 0 4 2 6

  7. Game tree [Red, Red,Green] (“best” first guess) codemaker response (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0) candidates remaining 6 1 1 4 3 0 4 2 6 Recurse!

  8. Game tree (26 guesses 1 candidate answer) Parent: [Red, Red,Green] (0,0) [Blue, Blue, Blue]

  9. Game tree (26 guesses 1 candidate answer) Parent: [Red, Red,Green] (0,0) [Blue, Blue,Blue] codemaker response (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0) 0 1 0 0 0 0 0 0 0 candidates remaining What now?

  10. Game tree (26 guesses 1 candidate answer) Parent: [Red, Red,Green] (0,0) [Blue, Blue,Blue] codemaker response (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0) 0 1 0 0 0 0 0 0 0 candidates remaining Lose Lose Lose Lose Lose Lose Lose Lose Win Use lose to indicate we don’t have any options left (this shouldn’t happen if we use a reasonable strategy)

  11. Game tree [Red, Red,Green] (“best” first guess) codemaker response (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0) candidates remaining 6 1 1 4 3 0 4 2 6

  12. Game tree (26 guesses 4 candidate answers) Parent: [Red, Red,Green] (0,1) [Green, Blue, Blue]

  13. Game tree (26 guesses 4 candidate answers) Parent: [Red, Red,Green] (0,1) [Green, Blue, Blue] (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0) 1 1 0 0 0 0 1 1 0 candidates remaining What now?

  14. Game tree (26 guesses 4 candidate answers) Parent: [Red, Red,Green] (0,1) [Green, Blue, Blue] (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0) 1 1 0 0 0 0 1 1 0 candidates remaining Lose Lose Lose Lose Lose Win ?

  15. Game tree (26 guesses 4 candidate answers) Parent: [Red, Red,Green] (0,1) [Green, Blue, Blue] (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0) 1 1 0 0 0 0 1 1 0 candidates remaining Lose Lose Lose Lose Lose Win Recurse

  16. Building the game tree If 0 options then Lose If 1 option and the response was (num_pegs, 0) then Win Otherwise, build another Tree: • Guess = one that minimizes the maximum remaining candidates over all responses • Break ties by 1) those that are still valid codes and 2) found first in candidate (valid)list • Recurseon responses

  17. Representing the game tree [Red, Red,Green] codemaker response (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0) How do we store this tree?

  18. Representing the game tree [Red, Red,Green] codemaker response (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0)

  19. Representing the game tree [Red, Red,Green] code knuth_tree list (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0)

  20. Representing the game tree [Red, Red,Green] code knuth_tree list (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0) The responses aren’t explicitly stored in the tree There is an implicit ordering to the subtrees that correspond to these

  21. Representing the game tree [Blue, Blue,Blue] codemaker response (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0) 0 1 0 0 0 0 0 0 0 candidates remaining Lose Lose Lose Lose Lose Lose Lose Lose Win Write some SML to create this tree.

  22. Representing the game tree [Blue, Blue,Blue] codemaker response (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0) 0 1 0 0 0 0 0 0 0 candidates remaining Lose Lose Lose Lose Lose Lose Lose Lose Win Write some SML to create this tree.

  23. Representing the game tree [Blue, Blue,Blue] codemaker response (0,1) (0,3) (1,0) (0,0) (0,2) (1,1) (1,2) (2,0) (3,0) 0 1 0 0 0 0 0 0 0 candidates remaining Lose Lose Lose Lose Lose Lose Lose Lose Win Step ([Blue, Blue, Blue], [Lose, Lose, Lose, Lose, Lose, Lose, Lose, Lose, Win]);

  24. A simple example What is the type signature of this function? What does it do?

  25. A simple example knuth_tree -> (code * knuth_tree) Returns the next code and then always chooses the first element in the knuth tree (i.e. associated with response (0,0))

  26. Midterm SML • datatypes(with non-zero constructors, recursive datatypes) • mutual recursion • handling exceptions Binary numbers • signed representation • adding • shifting Parsing: EBNF grammars Circuits • general ideas (building circuits, truth tables, etc.) • mintermexpansion • specific circuits (decoders, multiplexers)

  27. Midterm Encryption • encryption/decryption • modular arithmetic Resources: • We will provide you with the graphical pictures for the gates. • Like the previous midterms, you may bring one single-sided, 8.5" x 11" piece of paper with notes.

  28. Course registration

More Related