/
mastermind: last details mastermind: last details

mastermind: last details - PowerPoint Presentation

phoebe-click
phoebe-click . @phoebe-click
Follow
374 views
Uploaded On 2017-10-11

mastermind: last details - PPT Presentation

David Kauchak CS52 Spring 2017 Admin Assignment 7 Assignment 8 Midterm Course registration Key heuristic guess guess guess all codes not yet guessed The one that minimizes the maximum remaining candidates ID: 594896

tree lose red blue lose tree blue red game green remaining response candidates codemaker guess candidate win code representing

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "mastermind: last details" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

mastermind: last details

David Kauchak

CS52 – Spring 2017Slide2

Admin

Assignment 7

Assignment 8

Midterm

Course registrationSlide3

Key heuristic

guess

guess

guess

all codes not yet guessed

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

max

min

How do we calculate this?Slide4

Key heuristic

guess

guess

guess

all codes not yet guessed

The one that minimizes the maximum remaining candidates

max

min

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 response with largest remaining for that code

max

min

select code with smallest maxSlide5

Game tree

We can

precompute

the entire tree of possibilities

Expensive upfront to compute

Playing

becomes fastSlide6

Game tree

(0,0)

(0,1)

(0,2)

(0,3)

(1,0)

(1,1)

(1,2)

(2,0)

(3,0)

codemaker

response

[

Red

,

Red,

Green

]

(“best” first guess)

1

candidates remaining

4

3

0

6

4

1

6

2Slide7

Game tree

(0,0)

(0,1)

(0,2)

(0,3)

(1,0)

(1,1)

(1,2)

(2,0)

(3,0)

codemaker

response

[

Red

,

Red,

Green

]

(“best” first guess)

1

candidates remaining

4

3

0

6

4

1

6

2

Recurse

!Slide8

Game tree

(0,0)

[

Blue

,

Blue

,

Blue

]

Parent: [Red, Red,

Green]

(26 guesses 1 candidate answer)Slide9

Game tree

(0,0)

[

Blue

,

Blue

,

Blue]

(0,0)

(0,1)

(0,2)

(0,3)

(1,0)

(1,1)

(1,2)

(2,0)

(3,0)

0

0

0

0

0

0

1

0

0

codemaker

response

candidates remaining

What now?

Parent: [

Red

,

Red,

Green

]

(26 guesses

1 candidate answer)Slide10

Game tree

(0,0)

[

Blue

,

Blue

,

Blue]

(0,0)

(0,1)

(0,2)

(0,3)

(1,0)

(1,1)

(1,2)

(2,0)

(3,0)

0

0

0

0

0

0

1

0

0

codemaker

response

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)

Parent: [

Red

,

Red,

Green

]

(26 guesses

1 candidate answer)Slide11

Game tree

(0,0)

(0,1)

(0,2)

(0,3)

(1,0)

(1,1)

(1,2)

(2,0)

(3,0)

codemaker

response

[

Red

,

Red,

Green

]

(“best” first guess)

1

candidates remaining

4

3

0

6

4

1

6

2Slide12

Game tree

(0,1)

(26 guesses

4 candidate answers)

[

Green

,

Blue

,

Blue]

Parent: [Red,

Red, Green] Slide13

Game tree

(0,1)

[

Green

,

Blue

,

Blue

]

Parent: [Red, Red,

Green]

(0,0)

(0,1)

(0,2)

(0,3)(1,0)(1,1)

(1,2)

(2,0)

(3,0)

0

0

0

0

0

1

1

1

1

candidates remaining

What now?

(26 guesses

4 candidate answers)Slide14

Game tree

(0,1)

[

Green

,

Blue

,

Blue

]

Parent: [Red, Red,

Green]

(0,0)

(0,1)

(0,2)

(0,3)(1,0)(1,1)

(1,2)

(2,0)

(3,0)

0

0

0

0

0

1

1

1

1

candidates remaining

Lose

Lose

Lose

Lose

Win

Lose

?

(26 guesses

4 candidate answers)Slide15

Game tree

(0,1)

[

Green

,

Blue

,

Blue

]

Parent: [Red, Red,

Green]

(0,0)

(0,1)

(0,2)

(0,3)(1,0)(1,1)

(1,2)

(2,0)

(3,0)

0

0

0

0

0

1

1

1

1

candidates remaining

Lose

Lose

Lose

Lose

Win

Lose

Recurse

(26 guesses

4 candidate answers)Slide16

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)

listRecurse on responsesSlide17

Representing the game tree

(0,0)

(0,1)

(0,2)

(0,3)

(1,0)

(1,1)

(1,2)

(2,0)

(3,0)

codemaker

response

[

Red

,

Red,

Green

]

How do we store this tree?Slide18

Representing the game tree

(0,0)

(0,1)

(0,2)

(0,3)

(1,0)

(1,1)

(1,2)

(2,0)

(3,0)

codemaker

response

[

Red

,

Red,

Green

]Slide19

Representing the game tree

(0,0)

(0,1)

(0,2)

(0,3)

(1,0)

(1,1)

(1,2)

(2,0)

(3,0)

[

Red

,

Red,

Green

]

knuth_tree

list

codeSlide20

Representing the game tree

(0,0)

(0,1)

(0,2)

(0,3)

(1,0)

(1,1)

(1,2)

(2,0)

(3,0)

[

Red

,

Red,

Green

]

knuth_tree

list

code

The responses aren’t explicitly stored in the tree

There is an

implicit

ordering to the

subtrees

that correspond to theseSlide21

Representing the game tree

[

Blue

,

Blue

,

Blue]

(0,0)

(0,1)

(0,2)

(0,3)

(1,0)

(1,1)

(1,2)

(2,0)

(3,0)

0

0

0

0

0

0

1

0

0

codemaker

response

candidates remaining

Lose

Lose

Lose

Lose

Lose

Lose

Lose

Lose

Win

Write some SML to create this tree.Slide22

Representing the game tree

[

Blue

,

Blue

,

Blue]

(0,0)

(0,1)

(0,2)

(0,3)

(1,0)

(1,1)

(1,2)

(2,0)

(3,0)

0

0

0

0

0

0

1

0

0

codemaker

response

candidates remaining

Lose

Lose

Lose

Lose

Lose

Lose

Lose

Lose

Win

Write some SML to create this tree.Slide23

Representing the game tree

[

Blue

,

Blue

,

Blue]

(0,0)

(0,1)

(0,2)

(0,3)

(1,0)

(1,1)

(1,2)

(2,0)

(3,0)

0

0

0

0

0

0

1

0

0

codemaker

response

candidates remaining

Lose

Lose

Lose

Lose

Lose

Lose

Lose

Lose

Win

Step

([Blue, Blue, Blue], [Lose, Lose, Lose, Lose, Lose, Lose, Lose, Lose, Win])

;Slide24

A simple example

What is the type signature of this function?

What does it do?Slide25

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))Slide26

Midterm

SML

datatypes

(with non-zero constructors, recursive

datatypes

)

mutual recursionhandling exceptions

Binary numberssigned representationadding

shiftingParsing: EBNF grammars

Circuitsgeneral ideas (building circuits, truth tables, etc.)minterm expansion

specific circuits (decoders, multiplexers)Slide27

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.Slide28

Course registration