new cat-mouse-cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · cat can’t catch mouse:...

57
Cat-Mouse-Cheese 37 Tuesday, November 19, 13

Upload: others

Post on 11-Oct-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

37Tuesday, November 19, 13

Page 2: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

38Tuesday, November 19, 13

Page 3: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

39Tuesday, November 19, 13

Page 4: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

40Tuesday, November 19, 13

Page 5: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

41Tuesday, November 19, 13

Page 6: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

42Tuesday, November 19, 13

Page 7: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

43Tuesday, November 19, 13

Page 8: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

Mouse Wins!

44Tuesday, November 19, 13

Page 9: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Mouse

Wins!45Tuesday, November 19, 13

Page 10: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

Cat made mistake here.Should have guarded cheese!

46Tuesday, November 19, 13

Page 11: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

LOLcat: I can has cheez

47Tuesday, November 19, 13

Page 12: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

LOLcat: I can has cheezMouse: Oh $#!%

48Tuesday, November 19, 13

Page 13: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

49Tuesday, November 19, 13

Page 14: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

50Tuesday, November 19, 13

Page 15: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

51Tuesday, November 19, 13

Page 16: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

52Tuesday, November 19, 13

Page 17: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

53Tuesday, November 19, 13

Page 18: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

54Tuesday, November 19, 13

Page 19: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

55Tuesday, November 19, 13

Page 20: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

56Tuesday, November 19, 13

Page 21: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

57Tuesday, November 19, 13

Page 22: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

58Tuesday, November 19, 13

Page 23: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

59Tuesday, November 19, 13

Page 24: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

60Tuesday, November 19, 13

Page 25: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

61Tuesday, November 19, 13

Page 26: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat-Mouse-Cheese

Cat Wins!

62Tuesday, November 19, 13

Page 27: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Cat Wins!

63Tuesday, November 19, 13

Page 28: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Example: Missing Square

64Tuesday, November 19, 13

Page 29: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Example: Missing Square

65Tuesday, November 19, 13

Page 30: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Example: Missing Square

66Tuesday, November 19, 13

Page 31: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Example: Missing Square

67Tuesday, November 19, 13

Page 32: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Example: Missing Square

68Tuesday, November 19, 13

Page 33: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Example: Missing Square

69Tuesday, November 19, 13

Page 34: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Example: Missing Square

70Tuesday, November 19, 13

Page 35: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Example: Missing Square

71Tuesday, November 19, 13

Page 36: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Example: Missing SquareThis position (mouse moves next) is a draw.

Cat can’t catch mouse: mouse can keep the hole between them.

Mouse can’t get cheese, because cat can get there first.

Both sides can play forever, but eventually positions will repeat.

72Tuesday, November 19, 13

Page 37: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Game as GraphHow can we represent this game as a graph?Think back to the robot scheduling example (solved exercise 2, chap 3). Configuration graph: each vertex was a pair of locations--one for each robot.For our graph: each vertex will be vector: (mouseLoc, catLoc, mover, cheeseLeft)

73Tuesday, November 19, 13

Page 38: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Solving: SetUp

Idea: Classify each node as one of: MWin, CWin, Draw

Initial Set-up:1: Build the whole graph.2: If catLoc==mouseLoc, node is CWin, active3: Else if mouseLoc==cheeseLoc, node is MWin, active4: Mark rest: unknown (for now).

74Tuesday, November 19, 13

Page 39: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Solving: “Search step”Let v be any active node. We know v is CWin or MWin. Suppose it’s a CWin.For all w such that (w,v) is a valid move for Cat: Mark w as a CWin, active.For all w such that (w,v) is a valid move for Mouse:

If, from w, EVERY valid move leads to a CWin, mark w as a CWin, and make active.

Mark v as inactive.

75Tuesday, November 19, 13

Page 40: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Solving: “Search step”Let v be any active node. We know v is CWin or MWin. Suppose it’s a MWin.For all w such that (w,v) is a valid move for Mouse: Mark w as a MWin, active.For all w such that (w,v) is a valid move for Cat:

If, from w, EVERY valid move leads to a MWin, mark w as MWin, and make active.

Mark v as inactive.

76Tuesday, November 19, 13

Page 41: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Solving: Wrap-upSuppose we are out of active nodes.Then loop through all nodes, and change the “unknown” ones to Draw.We are now done classifying all positions.To actually play the game, build a “play forest” as follows: whenever we activate a node w, from an already active node v, mark preferredMove[w] = v.“Retrograde Analysis”

77Tuesday, November 19, 13

Page 42: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Running TimeClaim: This algorithm runs in linear time, if we consider the configuration graph as the input.(This is quadratic time in terms of the original game board size, or quartic time in terms of n, for an nxn board.)Proof of Claim: We make 2 passes through the nodes (initial and final), and for each active node v, we explore degree(v) edges in search step. Sum of degrees = 2 #edges.

78Tuesday, November 19, 13

Page 43: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Correctness of the Alg.

Nodes marked as Win are clearly correct.Nodes marked as Draw can move to other Draw nodes. Always safe, as any node from which the other player could move to a Winning node would have been marked as a win for that player. So they really do lead to a Draw.

79Tuesday, November 19, 13

Page 44: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Configuration Graphnode=state of game mover: M or C

Summary: Retrograde A

C

M

C

C C

C

M

M

M

M

C

...

done

80Tuesday, November 19, 13

Page 45: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Configuration Graphnode=state of game mover: M or C

Start with won positions, say for Cat.

Summary: Retrograde A

C

CWin

M

C

C C

C

M

M

M

M

C

...

done

81Tuesday, November 19, 13

Page 46: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Configuration Graphnode=state of game mover: M or C

Start with won positions, say for Cat.Augmentation rules:

(1) Cat can move there

Summary: Retrograde A

C

CWin

M

C

C C

C

M

M

M

M

C

...

done

82Tuesday, November 19, 13

Page 47: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Configuration Graphnode=state of game mover: M or C

Start with won positions, say for Cat.Augmentation rules:

(1) Cat can move there

Summary: Retrograde A

C

CWin

M

C

C C

C

M

M

M

M

C

...

done

83Tuesday, November 19, 13

Page 48: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Configuration Graphnode=state of game mover: M or C

Start with won positions, say for Cat.Augmentation rules:

(1) Cat can move there

Summary: Retrograde A

C

CWin

M

C

C C

C

M

M

M

M

C

...

done

84Tuesday, November 19, 13

Page 49: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Configuration Graphnode=state of game mover: M or C

Start with won positions, say for Cat.Augmentation rules:

(1) Cat can move there(2) Mouse has no option

Summary: Retrograde A

C

CWin

M

C

C C

C

M

M

M

M

C

...

done

85Tuesday, November 19, 13

Page 50: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Configuration Graphnode=state of game mover: M or C

Start with won positions, say for Cat.Augmentation rules:

(1) Cat can move there(2) Mouse has no option

Summary: Retrograde A

C

CWin

M

C

C C

C

M

M

M

M

C

...

done

86Tuesday, November 19, 13

Page 51: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Configuration Graphnode=state of game mover: M or C

Start with won positions, say for Cat.Augmentation rules:

(1) Cat can move there(2) Mouse has no option

Summary: Retrograde A

C

CWin

M

C

C C

C

M

M

M

M

C

...

done

Apply Inductively!Finds all CWins

87Tuesday, November 19, 13

Page 52: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Configuration Graphnode=state of game mover: M or C

Start with won positions, say for Cat.Augmentation rules:

(1) Cat can move there(2) Mouse has no option

Summary: Retrograde A

C

CWin

M

C

C C

C

M

M

M

M

C

...

done

Apply Inductively!Finds all CWins

88Tuesday, November 19, 13

Page 53: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Configuration Graphnode=state of game mover: M or C

Start with won positions, say for Cat.Augmentation rules:

(1) Cat can move there(2) Mouse has no option

Summary: Retrograde A

C

CWin

M

C

C C

C

M

M

M

M

C

...

done

Apply Inductively!Finds all CWins

89Tuesday, November 19, 13

Page 54: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Configuration Graphnode=state of game mover: M or C

Start with won positions, say for Cat.Augmentation rules:

(1) Cat can move there(2) Mouse has no option

Summary: Retrograde A

C

CWin

M

C

C C

C

M

M

M

M

C

...

done

Apply Inductively!Finds all CWins

90Tuesday, November 19, 13

Page 55: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Retrograde AnalysisStart with positions where cat has won.Recursively apply rules to find all CWins.Do same for MWins.All other nodes must be Draws.

Goal: # operations done per edge is O(1).Implies: Linear Time in size of configuration graph.

91Tuesday, November 19, 13

Page 56: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Retrograde AnalysisDetail: When applying rule 2 (when all moves for mouse lead to CWin, then that node is also a CWin): potentially doing degree2 operations.Fix: use memory. For each mouse node, keep a count of how many of its neighbors are CWins. May have to update this count degree times, but then can reuse it for each neighbor. (see whiteboard)

92Tuesday, November 19, 13

Page 57: New Cat-Mouse-Cheesehayes/teaching/cs361-fall13/... · 2013. 11. 20. · Cat can’t catch mouse: mouse can keep the hole between them. Mouse can’t get cheese, because cat can get

Retrograde AnalysisR.A. has been used for many famous examples.

Recent proof that Rubik’s cube can be solved in 20 moves or fewer.Solution of Oware game in 2002 (900 billion positions considered).Solution of Checkers in 2007.Some chess endgames, e.g. KQR vs QR.

93Tuesday, November 19, 13