Logica voor Informatica - 12 – Normaalvormen · Vervulbaarequivalenteformules...

80
Games and Strategies Vedran Kasalica

Transcript of Logica voor Informatica - 12 – Normaalvormen · Vervulbaarequivalenteformules...

Games and StrategiesVedran Kasalica

Last time

Proofs by induction

This lecture

Games and Strategies

Modelling Computing Systems

The book is called Modelling Computing Systems - but so far we have studied:

• sets• functions• relations• propositional and predicate logic• induction

... but these are all very static concepts. There's hardly any computation or interaction.

Games

Today we will study how to apply these ideas to model a series of interactions.

Interactions can be:

• computers interacting

• brokers buying/selling shares, etc.

We focus on a more restricted form of interactions, namely games.

Games

Not computer games. Instead focus on well-specified interactions between players.

The players can:

• win the game• lose the game• potentially draw the game

Chance in games

We can distinguish between different kinds of games:

• Games of chance - like roulette - where there is no good strategy for winning.

• Games of no chance - like tic-tac-toe - where it is clear how to win.

These are two extremes: the most fun games have some element of luck (e.g. monopoly).

Games of no chance

We'll study the games without any chance element.

Furthermore, we focus on games of perfect information (e.g. chess).

Finite games - if the game could continue indefinitely call it e.g. “a draw”

Rules according to which the player makes a move on each turn make a strategy.

Strategies

Winning strategy - guarantees a victory regardless the moves of the opponent

Drawing strategy - guarantees that the opponent will not win regardless the moves of the opponent

A position in a game can be:

• winning - there is a winning strategy for the current player• losing - there is a winning strategy for the non-current player• drawing - neither player has a winning strategy

Example: Tic Tac Toe

Drawing position

Example: Tic Tac Toe

Losing position

Strategies

Theorem In a two-player game-of-no-chance of perfect information, either one the two players has a winning strategy, or they both have drawing strategies.

Proof

Case 1: Player X has a winning strategy

Claim: The other one cannot have a winning strategy

If we fix the two strategies only one player will win and only the strategy of that player was the winning one

Proof

Case 2: Neither player has a winning strategy

Claim: Both players have a drawing strategy

First player (X) doesn’t have a winning strategy, so player O can always respond in order to win or draw. Ensuring that player X doesn’t win.

Similarly, player X can ensure that the player O doesn’t win.

Thus, they both have a drawing strategies.

Proof

Case 2: Neither player has a winning strategy

Claim: Both players have a drawing strategy

First player (X) doesn’t have a winning strategy, so player O can always respond in order to win or draw. Ensuring that player X doesn’t win.

Similarly, player X can ensure that the player O doesn’t win.

Thus, they both have a drawing strategies.

Strategies

Theorem In a two-player game-of-no-chance of perfect information, either of the players has a winning strategy or they both have drawing strategies.

Corollary If a game cannot end in a draw, one of the two players has a winning strategy.

Example game

Game: Starting with a pile of 10 coins, 2 players take turns removing either 2 or 3 coins from the pile. The winner is the one that takes the last pile; if one coin remains, then the game is a draw.

Example game

Game: Starting with a pile of 10 coins, 2 players take turns removing either 2 or 3 coins from the pile. The winner is the one that takes the last pile; if one coin remains, then the game is a draw.

Game tree

• each node is a position• circle (W)• square (L)• blank (D)

• edge represents a move

Game tree: Tic Tac ToeW/D/L labels are omitted

...

Nim

Nim

Game:

• Board consists of an arbitrary number of piles, where each has arbitrary number of coins

• 2 players take turns removing each time 1 or more coins from exactly one pile

• Goal is to take the last coin

Nim

Game:

• Board consists of an arbitrary number of piles, where each has arbitrary number of coins

• 2 players take turns removing each time 1 or more coins from exactly one pile

• Goal is to take the last coin

Nim

Game:

• Board consists of an arbitrary number of piles, where each has arbitrary number of coins

• 2 players take turns removing each time 1 or more coins from exactly one pile

• Goal is to take the last coin

Nim

Game:

• Board consists of an arbitrary number of piles, where each has arbitrary number of coins

• 2 players take turns removing each time 1 or more coins from exactly one pile

• Goal is to take the last coin

Nim

Game:

• Board consists of an arbitrary number of piles, where each has arbitrary number of coins

• 2 players take turns removing each time 1 or more coins from exactly one pile

• Goal is to take the last coin

Nim

Game:

• Board consists of an arbitrary number of piles, where each has arbitrary number of coins

• 2 players take turns removing each time 1 or more coins from exactly one pile

• Goal is to take the last coin

Nim

Winning strategies

• 1 pile game

Nim

Winning strategies

• 1 pile game

Nim

Winning strategies

• 1 pile game (W)

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal (L)

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal (L)• piles are not equal

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal (L)• piles are not equal (W)

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal (L)• piles are not equal (W)

• 3 pile game• 2 piles are equal

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal (L)• piles are not equal (W)

• 3 pile game• 2 piles are equal (W)

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal (L)• piles are not equal (W)

• 3 pile game• 2 piles are equal (W)• piles contain 1, 2 and 3 coins

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal (L)• piles are not equal (W)

• 3 pile game• 2 piles are equal (W)• piles contain 1, 2 and 3 coins

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal (L)• piles are not equal (W)

• 3 pile game• 2 piles are equal (W)• piles contain 1, 2 and 3 coins

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal (L)• piles are not equal (W)

• 3 pile game• 2 piles are equal (W)• piles contain 1, 2 and 3 coins

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal (L)• piles are not equal (W)

• 3 pile game• 2 piles are equal (W)• piles contain 1, 2 and 3 coins

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal (L)• piles are not equal (W)

• 3 pile game• 2 piles are equal (W)• piles contain 1, 2 and 3 coins

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal (L)• piles are not equal (W)

• 3 pile game• 2 piles are equal (W)• piles contain 1, 2 and 3 coins (L)

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal (L)• piles are not equal (W)

• 3 pile game• 2 piles are equal (W)• piles contain 1, 2 and 3 coins (L)• arbitrary number of coins (?)

Nim

Winning strategies

• 1 pile game (W)• 2 pile game

• piles are equal (L)• piles are not equal (W)

• 3 pile game• 2 piles are equal (W)• piles contain 1, 2 and 3 coins (L)• arbitrary number of coins (?)

Nim

Universal winning strategy:

1) Write out number of coins in piles in binary representation

Nim

Universal winning strategy:

2) Add up the columns module 2

Nim

Universal winning strategy:

If all of the columns have even parity, the position is balanced, otherwise it’s unbalanced

Nim

Observation:

1. If the position is balanced, then every move will lead to an unbalanced position

2. If the position is unbalanced, then there exists a move that will lead to a balanced position

3. Empty board is a balanced position

Nim

Universal winning strategy:

3) If the position is unbalanced (W), player should make a move to make it balanced each time and he is insured to win

Nim

Universal winning strategy:

4) If the position is balanced (L), the opponent has a chance to use the same strategy to win

Chomp

Chomp

Game:

• we have a n x m bar where leftmost-topmost square is poisonous• two players take turns to bite of the bar, where each player has to

choose a remaining square and eat all the squares below it and to the right from it

• the player that eats the poisonous square lost the game

Chomp

Game:

• we have a n x m bar where leftmost-topmost square is poisonous• two players take turns to bite of the bar, where each player has to

choose a remaining square and eat all the squares below it and to the right from it

• the player that eats the poisonous square lost the game

Chomp

Strategies:

• 1 x 1

Chomp

Strategies:

• 1 x 1 (L)

Chomp

Strategies:

• 1 x 1 (L)• 1 x n

Chomp

Strategies:

• 1 x 1 (L)• 1 x n (W) - take all the squares apart from the poisonous one

Chomp

Strategies:

• 1 x 1 (L)• 1 x n (W) - take all the squares apart from the poisonous one• 2 x n

Chomp

Strategies:

• 1 x 1 (L)• 1 x n (W) - take all the squares apart from the poisonous one• 2 x n (W) - take the bottom-right square (and keep that structure)

Chomp

Strategies:

• 1 x 1 (L)• 1 x n (W) - take all the squares apart from the poisonous one• 2 x n (W) - take the bottom-right square (and keep that structure)• n x n

Chomp

Strategies:

• 1 x 1 (L)• 1 x n (W) - take all the squares apart from the poisonous one• 2 x n (W) - take the bottom-right square (and keep that structure)• n x n (W) - remove (n-1) x (n-1) squares and mimic the payer

response in the following moves

Chomp

Strategies:

• 1 x 1 (L)• 1 x n (W) - take all the squares apart from the poisonous one• 2 x n (W) - take the bottom-right square (and keep that structure)• n x n (W) - remove (n-1) x (n-1) squares and mimic the payer

response in the following moves• n x m (?)

Chomp

Strategies:

• 3 x 4

Chomp

Theorem: Except for the 1 x 1 case, the first player always has a winning strategy.

Chomp

Theorem: Except for the 1 x 1 case, the first player always has a winning strategy.

Proof:

Suppose that the second player has a winning strategy.

Draw a contradiction.

Hex

Hex

Game:

• played on a board consisting of n x n hexagons• territories in NE and SW belong to player 1• territories in SE and NW belong to player 2• players take turns marking empty cells with their respective

symbol• the winner is the player that connects the two disconnected

territories first with an unbroken chain of their symbols

Hex

Game:

• played on a board consisting of n x n hexagons• territories in NE and SW belong to player 1• territories in SE and NW belong to player 2• players take turns marking empty cells with their respective

symbol• the winner is the player that connects the two disconnected

territories first with an unbroken chain of their symbols

Hex

Theorem: The game of Hex can never end in a draw.

Hex

Theorem: The first player always has a winning strategy in Hex.

Bridg-it

Bridg-it

Game:

• played on a staggered n x n board• a pair of opposing borders belongs to each player (S&N and W&E)• players take turns connecting neighbouring dots of their respective

color, horizontally or vertically• the winner is the player that connects their the

two opposite borders• 2 lines are not allowed to cross

Bridg-it

Theorem: The game of Bridg-it can never end in a draw.

Bridg-it

Theorem: The game of Bridg-it can never end in a draw.

Bridg-it

Theorem: The first player always has a winning strategy in Bridg-it.

Bridg-it

Winning strategy:

Conclusion

We have learned:

• How to model player interactions• How to formalise a game• How to evaluate the quality of a position• How mathematical theory can be used to make a winning strategy

These concepts are quite useful in Game theory - application of agent interactions in economics, social sciences, computer science, etc. (e.g. auction, bargaining)

Agents might have different goals and potentially cooperate

Material

Modelling Computing Systems Chapter 10