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

Post on 11-Oct-2020

5 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Cat-Mouse-Cheese

37Tuesday, November 19, 13

Cat-Mouse-Cheese

38Tuesday, November 19, 13

Cat-Mouse-Cheese

39Tuesday, November 19, 13

Cat-Mouse-Cheese

40Tuesday, November 19, 13

Cat-Mouse-Cheese

41Tuesday, November 19, 13

Cat-Mouse-Cheese

42Tuesday, November 19, 13

Cat-Mouse-Cheese

43Tuesday, November 19, 13

Cat-Mouse-Cheese

Mouse Wins!

44Tuesday, November 19, 13

Mouse

Wins!45Tuesday, November 19, 13

Cat-Mouse-Cheese

Cat made mistake here.Should have guarded cheese!

46Tuesday, November 19, 13

Cat-Mouse-Cheese

LOLcat: I can has cheez

47Tuesday, November 19, 13

Cat-Mouse-Cheese

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

48Tuesday, November 19, 13

Cat-Mouse-Cheese

49Tuesday, November 19, 13

Cat-Mouse-Cheese

50Tuesday, November 19, 13

Cat-Mouse-Cheese

51Tuesday, November 19, 13

Cat-Mouse-Cheese

52Tuesday, November 19, 13

Cat-Mouse-Cheese

53Tuesday, November 19, 13

Cat-Mouse-Cheese

54Tuesday, November 19, 13

Cat-Mouse-Cheese

55Tuesday, November 19, 13

Cat-Mouse-Cheese

56Tuesday, November 19, 13

Cat-Mouse-Cheese

57Tuesday, November 19, 13

Cat-Mouse-Cheese

58Tuesday, November 19, 13

Cat-Mouse-Cheese

59Tuesday, November 19, 13

Cat-Mouse-Cheese

60Tuesday, November 19, 13

Cat-Mouse-Cheese

61Tuesday, November 19, 13

Cat-Mouse-Cheese

Cat Wins!

62Tuesday, November 19, 13

Cat Wins!

63Tuesday, November 19, 13

Example: Missing Square

64Tuesday, November 19, 13

Example: Missing Square

65Tuesday, November 19, 13

Example: Missing Square

66Tuesday, November 19, 13

Example: Missing Square

67Tuesday, November 19, 13

Example: Missing Square

68Tuesday, November 19, 13

Example: Missing Square

69Tuesday, November 19, 13

Example: Missing Square

70Tuesday, November 19, 13

Example: Missing Square

71Tuesday, November 19, 13

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

top related