mastermind: last details

Slides:



Advertisements
Similar presentations
Adversarial Search We have experience in search where we assume that we are the only intelligent being and we have explicit control over the “world”. Lets.
Advertisements

CS 206 Introduction to Computer Science II 12 / 01 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 02 / 11 / 2009 Instructor: Michael Eckmann.
Alpha-Beta Search. 2 Two-player games The object of a search is to find a path from the starting position to a goal position In a puzzle-type problem,
Game Trees: MiniMax strategy, Tree Evaluation, Pruning, Utility evaluation Adapted from slides of Yoonsuck Choe.
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 2 Adapted from slides of Yoonsuck.
CISC 235: Topic 6 Game Trees.
Computer Science 101 Fast Searching and Sorting. Improving Efficiency We got a better best case by tweaking the selection sort and the bubble sort We.
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
DIGITAL CIRCUITS David Kauchak CS52 – Fall 2015.
ENCRYPTION TAKE 2: PRACTICAL DETAILS David Kauchak CS52 – Spring 2015.
David Stotts Computer Science Department UNC Chapel Hill.
Outline Binary Addition 2’s complement Binary Subtraction Half Adder
Mergeable Heaps David Kauchak cs302 Spring Admin Homework 7?
Greedy algorithms David Kauchak cs302 Spring 2012.
Amortized Analysis and Heaps Intro David Kauchak cs302 Spring 2013.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Search: Games & Adversarial Search Artificial Intelligence CMSC January 28, 2003.
CSE332: Data Abstractions Lecture 7: AVL Trees
David Kauchak CS 52 – Spring 2017
CSE373: Data Structures & Algorithms Priority Queues
Computer Architecture & Operations I
Topic 2: binary Trees COMP2003J: Data Structures and Algorithms 2
Some more Decrease-and-conquer Algorithms
CSC317 Selection problem q p r Randomized‐Select(A,p,r,i)
CSE373: Data Structures & Algorithms
Andreas Klappenecker [partially based on the slides of Prof. Welch]
CS 332: Algorithms Hash Tables David Luebke /19/2018.
Week 6 - Wednesday CS221.
Multiway search trees and the (2,4)-tree
David Kauchak CS 52 – Spring 2016
Best-fit bin packing in O(n log n) time
David Kauchak CS52 – Spring 2016
C ODEBREAKER Class discussion.
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
CMSC 341 Lecture 13 Leftist Heaps
ITEC 2620M Introduction to Data Structures
CSCI 5582 Artificial Intelligence
Games with Chance Other Search Algorithms
Interval Heaps Complete binary tree.
7/23/2009 Many thanks to David Sun for some of the included slides!
Data Structures: Segment Trees, Fenwick Trees
CSE 373 AVL trees read: Weiss Ch. 4, section
Visualizing Prim’s MST Algorithm Used to Trace the Algorithm in Class
Alpha-Beta Search.
Parsing and More Parsing
8/04/2009 Many thanks to David Sun for some of the included slides!
B-Tree.
CSE373: Data Structures & Algorithms Lecture 5: AVL Trees
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
Alpha-Beta Search.
CSE 332: Data Abstractions AVL Trees
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
Alpha-Beta Search.
Binary Search Trees 7/16/2009.
Advanced Implementation of Tables
CSE 12 – Basic Data Structures
CS 261 – Data Structures Trees.
Collaboration of Parafrase-2 and NaraView
Alpha-Beta Search.
Amortized Analysis and Heaps Intro
Basic circuit analysis and design
The Selection Problem.
B-Trees.
CSE 332: Sorting II Spring 2016.
Data Structures and Algorithms
Alpha-Beta Search.
CS51A David Kauchak Spring 2019
CS51A David Kauchak Spring 2019
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning
Presentation transcript:

mastermind: last details David Kauchak CS52 – Spring 2017

Admin Assignment 7 Assignment 8 Midterm Course registration

Key heuristic all codes not yet guessed … guess min guess guess 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?

Key heuristic all codes not yet guessed … guess min guess guess 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

Game tree We can precompute the entire tree of possibilities Expensive upfront to compute Playing becomes fast

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

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

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

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

Game tree (0,0) [Blue, Blue, Blue] (0,0) (0,1) (0,2) (0,3) (1,0) (1,1) (26 guesses 1 candidate answer) Parent: [Red, Red, Green] (0,0) [Blue, Blue, Blue] codemaker response (0,0) (0,1) (0,2) (0,3) (1,0) (1,1) (1,2) (2,0) (3,0) 1 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)

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

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

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

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

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

Building the game tree Recurse on responses 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 Recurse on responses

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

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

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

Representing the game tree [Red, Red, Green] code knuth_tree list (0,0) (0,1) (0,2) (0,3) (1,0) (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

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

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

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

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

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

Midterm SML Binary numbers Parsing: EBNF grammars Circuits 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.) minterm expansion specific circuits (decoders, multiplexers)

Midterm Encryption Resources: encryption/decryption modular arithmetic 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.

Course registration