Introduction Solvability Rules Computer Solution Implementation. Connect Four. March 9, Connect Four 1

Similar documents
The game of Reversi was invented around 1880 by two. Englishmen, Lewis Waterman and John W. Mollett. It later became

Adversary Search. Ref: Chapter 5

Real-Time Connect 4 Game Using Artificial Intelligence

CMPUT 396 Tic-Tac-Toe Game

Intro to Java Programming Project

EXPLORING TIC-TAC-TOE VARIANTS

Introduction to AI Techniques

Universiteit Leiden Opleiding Informatica

Surreal Numbers and Games. February 2010

The Mathematics of Playing Tic Tac Toe

Module 3. Problem Solving using Search- (Two agent) Version 2 CSE IIT, Kharagpur

2 person perfect information

A Quoridor-playing Agent

Unit 12: Artificial Intelligence CS 101, Fall 2018

ARTIFICIAL INTELLIGENCE (CS 370D)

Foundations of AI. 5. Board Games. Search Strategies for Games, Games with Chance, State of the Art. Wolfram Burgard and Luc De Raedt SA-1

UNIT 13A AI: Games & Search Strategies. Announcements

CSC 380 Final Presentation. Connect 4 David Alligood, Scott Swiger, Jo Van Voorhis

COMP9414: Artificial Intelligence Problem Solving and Search

Advanced Automata Theory 4 Games

mywbut.com Two agent games : alpha beta pruning

Five-In-Row with Local Evaluation and Beam Search

Easy Games and Hard Games

a b c d e f g h 1 a b c d e f g h C A B B A C C X X C C X X C C A B B A C Diagram 1-2 Square names

Foundations of AI. 6. Adversarial Search. Search Strategies for Games, Games with Chance, State of the Art. Wolfram Burgard & Bernhard Nebel

Second Annual University of Oregon Programming Contest, 1998

Heuristic Search with Pre-Computed Databases

Conversion Masters in IT (MIT) AI as Representation and Search. (Representation and Search Strategies) Lecture 002. Sandro Spina

PROBLEMS & INVESTIGATIONS. Introducing Add to 15 & 15-Tac-Toe

3. Bishops b. The main objective of this lesson is to teach the rules of movement for the bishops.

Final Practice Problems: Dynamic Programming and Max Flow Problems (I) Dynamic Programming Practice Problems

CSE548, AMS542: Analysis of Algorithms, Fall 2016 Date: Sep 25. Homework #1. ( Due: Oct 10 ) Figure 1: The laser game.

CHECKMATE! A Brief Introduction to Game Theory. Dan Garcia UC Berkeley. The World. Kasparov

UNIT 13A AI: Games & Search Strategies

AI Approaches to Ultimate Tic-Tac-Toe

Background. Game Theory and Nim. The Game of Nim. Game is Finite 1/27/2011

On Drawn K-In-A-Row Games

Artificial Intelligence Lecture 3

Tic-tac-toe. Lars-Henrik Eriksson. Functional Programming 1. Original presentation by Tjark Weber. Lars-Henrik Eriksson (UU) Tic-tac-toe 1 / 23

BMT 2018 Combinatorics Test Solutions March 18, 2018

CSE 573 Problem Set 1. Answers on 10/17/08

CSC 110 Lab 4 Algorithms using Functions. Names:

Games of Skill Lesson 1 of 9, work in pairs

1, 2,, 10. Example game. Pieces and Board: This game is played on a 1 by 10 board. The initial position is an empty board.

CS 440 / ECE 448 Introduction to Artificial Intelligence Spring 2010 Lecture #5

Introduction to Spring 2009 Artificial Intelligence Final Exam

Adverserial Search Chapter 5 minmax algorithm alpha-beta pruning TDDC17. Problems. Why Board Games?

Game, Set, and Match Carl W. Lee September 2016

Problem Set 4 Due: Wednesday, November 12th, 2014

Adversarial Search (Game Playing)

2359 (i.e. 11:59:00 pm) on 4/16/18 via Blackboard

Game Tree Search. CSC384: Introduction to Artificial Intelligence. Generalizing Search Problem. General Games. What makes something a game?

22c:145 Artificial Intelligence

Search Depth. 8. Search Depth. Investing. Investing in Search. Jonathan Schaeffer

CS 1571 Introduction to AI Lecture 12. Adversarial search. CS 1571 Intro to AI. Announcements

Investigation of Algorithmic Solutions of Sudoku Puzzles

Coin Cappers. Tic Tac Toe

CS188 Spring 2010 Section 3: Game Trees

CS 2710 Foundations of AI. Lecture 9. Adversarial search. CS 2710 Foundations of AI. Game search

Computer Science and Software Engineering University of Wisconsin - Platteville. 4. Game Play. CS 3030 Lecture Notes Yan Shi UW-Platteville

Contents. MA 327/ECO 327 Introduction to Game Theory Fall 2017 Notes. 1 Wednesday, August Friday, August Monday, August 28 6

Announcements. CS 188: Artificial Intelligence Spring Game Playing State-of-the-Art. Overview. Game Playing. GamesCrafters

Lecture 2: Problem Formulation

CS 4700: Foundations of Artificial Intelligence

Documentation and Discussion

1 Introduction. 1.1 Game play. CSC 261 Lab 4: Adversarial Search Fall Assigned: Tuesday 24 September 2013

Games (adversarial search problems)

16.410/413 Principles of Autonomy and Decision Making

1 Modified Othello. Assignment 2. Total marks: 100. Out: February 10 Due: March 5 at 14:30

CS 771 Artificial Intelligence. Adversarial Search

CS188 Spring 2010 Section 3: Game Trees

This game can be played in a 3x3 grid (shown in the figure 2.1).The game can be played by two players. There are two options for players:

Using a genetic algorithm for mining patterns from Endgame Databases

CS 229 Final Project: Using Reinforcement Learning to Play Othello

Advanced Automata Theory 5 Infinite Games

STAJSIC, DAVORIN, M.A. Combinatorial Game Theory (2010) Directed by Dr. Clifford Smyth. pp.40

game tree complete all possible moves

A Level Computer Science H446/02 Algorithms and programming. Practice paper - Set 1. Time allowed: 2 hours 30 minutes

Game-Playing & Adversarial Search

Computer Game Programming Board Games

CPS331 Lecture: Search in Games last revised 2/16/10

Game Engineering CS F-24 Board / Strategy Games

UMBC 671 Midterm Exam 19 October 2009

Artificial Intelligence Adversarial Search

(Provisional) Lecture 31: Games, Round 2

Last update: March 9, Game playing. CMSC 421, Chapter 6. CMSC 421, Chapter 6 1

CS 188: Artificial Intelligence Spring Announcements

Set 4: Game-Playing. ICS 271 Fall 2017 Kalev Kask

Computational aspects of two-player zero-sum games Course notes for Computational Game Theory Section 3 Fall 2010

Announcements. Homework 1 solutions posted. Test in 2 weeks (27 th ) -Covers up to and including HW2 (informed search)

Artificial Intelligence. Minimax and alpha-beta pruning

Grade 7 & 8 Math Circles. Mathematical Games

Eleventh Annual Ohio Wesleyan University Programming Contest April 1, 2017 Rules: 1. There are six questions to be completed in four hours. 2.

CS188: Section Handout 1, Uninformed Search SOLUTIONS

CS510 \ Lecture Ariel Stolerman

How hard are computer games? Graham Cormode, DIMACS

Introduction to Artificial Intelligence CS 151 Programming Assignment 2 Mancala!! Due (in dropbox) Tuesday, September 23, 9:34am

Algorithms for Data Structures: Search for Games. Phillip Smith 27/11/13

Positive Triangle Game

CSE 473: Artificial Intelligence Fall Outline. Types of Games. Deterministic Games. Previously: Single-Agent Trees. Previously: Value of a State

Transcription:

Connect Four March 9, 2010 Connect Four 1

Connect Four is a tic-tac-toe like game in which two players drop discs into a 7x6 board. The first player to get four in a row (either vertically, horizontally, or diagonally) wins. Connect Four 2

The game was first known as The Captain s Mistress, but was released in its current form by Milton Bradley in 1974. In 1988 Victor Allis solved the game, showing that with perfect play by both players, the first player can always win if he plays the middle column first, and if he chooses another column first the second player can always force a draw. Connect Four 3

Today we will explore the different strategies involved in playing connect four, how a computer could emulate these strategies, and how these techniques relate to other artificial intelligence topics involved in solving games with large search spaces. Connect Four 4

For convenience, we will call the first player white (W) and the second player black (B). Connect Four 5

Recall: a strong solution to a game means knowing the outcome of the game from any given board position. One strategy to try would be storing all possible game positions in a database, exploring the tree of game play from each position, and determining the winner in each case. We will see that this strategy, at least at this time, is not really feasible for Connect Four (and even much less so for more complex games like GO and chess). Connect Four 6

First we look for an upper bound on the number of possible Connect Four board positions. Each grid square can be in one of 3 states: black, white, or empty. Since there are 7x6 = 42 squares, this gives a very crude upper bound of 3 42 10 20. A not so much closer look reveals that we can get a much tighter upper bound by noticing that many positions we counted before were illegal. For instance, if one square is empty in a column, then all the squares above it must also be empty. So we throw these possible positions out. Removing these configurations gives a better upper bound of 7.1 10 13 possible positions. Connect Four 7

There are other types of illegal positions that are harder to detect. For instance, if we are assuming that white moves first, then some game configurations, such as a stack in one column from bottom up of BWBWBW is impossible, since black would have had to move first. It turns out that no one has been able to weed out all of these positions from databases The best lower bound on the number of possible positions has been calculated by a computer program to be around 1.6 10 13. So we would need at least that many positions stored to do a brute force search of the game. Connect Four 8

Instead of a brute force search, we can try a knowledge-based approach. Instead of searching the entire game space, we can formulate general rules that tell which player will win in which situations. We saw this approach fail last week for a computer playing tic-tac-toe. Connect Four 9

1. If there is a winning move, take it. 2. If your opponent has a winning move, take the move so he can t take it. 3. Take the center square over edges and corners. 4. Take corner squares over edges. 5. Take edges if they are the only thing available. Connect Four 10

Apparently this strategy won t always work. In general, we must classify these sorts of rules into two classes: that guarantee a certain results (and require proof that they do so) Heuristic rules that are generally advantageous but are not without downfall (like the strategy given above) Connect Four 11

We ll explore possible strategies to follow for Connect Four below. First we ll learn some terminology associated with describing the strategy. Connect Four 12

We will number the 7 x 6 board with columns a to g left to right and numbers 1 to 6 from bottom to top. So the coveted middle bottom square is d1. Courtesy of Victor Allis. Used with permission. Figure 3.9 in "A Knowledge-based Approach of Connect-Four. The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 22. Connect Four 13

Threat: A threat is a square that if taken by opponent forms a game-winning group of four. For example, in the game below White has threats at b1 and f1: Courtesy of Victor Allis. Used with permission. Figure 3.9 in "A Knowledge-based Approach of Connect-Four. The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 22. Connect Four 14

Useless Threat: A useless threat is a threat that will never be able to be carried out by the opponent. Connect Four 15

The picture below illustrates the concept of a useless threat. Courtesy of Victor Allis. Used with permission. Figure 3.1 in "A Knowledge-based Approach of Connect-Four. The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 16. 16

It is clear that a threat can only be carried out if the opponent is forced to play the square below (or he allows you to play below the threat). In analyzing threats, certain patterns show up in how the squares are divided among players. Connect Four 17

Odd and Even Threats The odd/evenness of a threat is determined by the row number. So d1 is an odd threat, etc. In normal game play, white is most likely to get odd squares, while black is most likely to get even squares. Why? Connect Four 18

In general, we see the following patterns: White has an odd threat, Black even: White wins White and Black both have even threats: there is no column where an odd number of squares can be played, so both players will get their normal squares (as defined above), and Black will be able to refute Whites threat and win. White has an even threat, Black an odd threat: draw. White and Black both have odd threats: usually neither of these threats end up working and depend on other threats. In a careful analysis of threats it is important to make sure that taking care of one threat does not allow another threat to be created. Connect Four 19

Zugzwang: The formal definition of this strange German word: a situation where a player is forced to make a move when he would rather make no move at all. In connect four, a player is able to control the zugzwang if the player is able to guide the way odd and even squares are divided up among players. As an example, we look at the following game situation (Allis 26), where White is about to move: Connect Four 20

Courtesy of Victor Allis. Used with permission. Figure 4.2 in "A Knowledge-based Approach of Connect-Four. The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 25. Connect Four 21

Note that all columns contain an even number of pieces, so White will never fill up a column since it must take only odd squares. So Black can just play follow-up and mimic Whites every move. This will result in the following position: Connect Four 22

Courtesy of Victor Allis. Used with permission. Figure 4.3 in "A Knowledge-based Approach of Connect-Four. The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 26. Connect Four 23

Now White must play either b1 or f1, which Black will follow, and win the game with a group of four on the second row. Connect Four 24

So in conclusion, Zugzwang involves being able to divide up how even and odd squares are distributed to the two players. Black wanted only even squares because eventually it would be able to fulfill its threat at either b2 or f2. But if it had wanted odd squares, it could have just stopped playing follow up and played in a different column. Connect Four 25

As an example of using a knowledge based approach to teach a computer to play a game, the following rules were used in programming VICTOR to win connect four. Each rule classifies threats and gives solutions to some of them. Each rule is valid for the player that controls the Zugzwang, which is assumed to be black in the following examples. Each of these rules is a possible winning connection for the player. Connect Four 26

Claimeven: Controller of zugzwang can get all empty even squares which are not directly playable by letting the opponent play all emtpy odd squares. Required: Two squares, directly above each other. Both squares are empty, the upper square must be even. Solutions: All groups which contain the upper square. Connect Four 27

Courtesy of Victor Allis. Used with permission. Figure 6.1 in "A Knowledge-based Approach of Connect-Four. The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 36. 28

Baseinverse: Based on the fact that a player cannot play two directly playable squares in one turn. Required: Two directly playable squares Solutions: All groups which contain both squares. Connect Four 29

Courtesy of Victor Allis. Used with permission. Figure 6.2 in "A Knowledge-based Approach of Connect-Four. The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 37. Connect Four 30

Vertical: Based on the face that a player cannot play two men in the same column in one turn, while by playing one man in the column, the square directly above becomes immediately playable. Required: two squares directly above each other. Both squares empty, upper square must be odd. Solutions: all groups which contain both squares Connect Four 31

Courtesy of Victor Allis. Used with permission. Figure 6.3 in "A Knowledge-based Approach of Connect-Four. The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 38. 32

Aftereven: Side-effect of one or more claimevens. If a player in control of zugzwang can complete a group using squares from claimeven, he will eventually be able to finish the group. Required: a group which can be completed by the controller of the zugzwang, using only squares of a set of claimevens. Solutions: all groups which have at least one square in all aftereven columns above the empty aftereven group in that column. Also, all groups which are solved by the claimevens. Connect Four 33

Courtesy of Victor Allis. Used with permission. Figure 6.4 in "A Knowledge-based Approach of Connect-Four. The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 39. Connect Four 34

Lowinverse: Based on the fact that the sum of two odd numbers is even. Required: two different columns, each with 2 squares lying directly above each other. All must be empty and the upper square must be odd. Solution: All groups which contain both upper squares, all groups which are solved by verticals. Connect Four 35

Courtesy of Victor Allis. Used with permission. Figure 6.6 in "A Knowledge-based Approach of Connect-Four. The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 41. 36

Highinverse: Based on the same principle as lowinverse: Required: Two columns with 3 empty squares each, upper square is even. Connect Four 37

Solutions: all groups which contain the two upper squares, groups which contain the two middle squares, all vertical groups which contain the two highest squares of one of the highinverse columns If the lower square of the first columns i directly playable: all groups which contain both the lower square of the first column and the upper square of the second. If the lower square of the second column is directly playable: all groups which contain both the lower square of the second column and the upper square of the first column. Connect Four 38

Baseclaim: Combination of two baseinverses and a claimeven. Required: Three directly playable squares and the square above the second playable square. The non-playable square must be even. Solutions: All groups which contain the first playable square and the square above the second playable square. All groups which contain the second and third playable square. Connect Four 39

Courtesy of Victor Allis. Used with permission. Figure 6.7 in "A Knowledge-based Approach of Connect-Four.The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 42. Connect Four 40

Before: Based on a combination of claimevens and verticals Required: A group without men of the opponent, which is called the Before group. All empty squares of the Before group should not lie in the upper row of the board. Solutions: All groups which contain all squares which are successors of empty squares in the Before group. All groups which are solved by the Verticals which are part of the Before. All groups which are solved by the Claimevens which are part of the Before Connect Four 41

Courtesy of Victor Allis. Used with permission. Figure 6.8 in "A Knowledge-based Approach of Connect-Four. The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 43. Connect Four 42

Specialbefore: A version of the before Required: A group without men of the opponent, which is called the Specialbefore group. A directly playable square in another column. All empty squares of the Specialbefore group should not lie in the upper row of the board. One empty square of the Before group must be playable. Solutions: All groups which contain all successors of empty squares of the Specialbefore group and the extra playable square. All groups which contain the two playable squares. All groups which are solved by one of the Claimevens. All groups which are solved by one of the Verticals. Connect Four 43

Courtesy of Victor Allis. Used with permission. Figure 6.10 in "A Knowledge-based Approach of Connect-Four. The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 45. Connect Four 44

Victor Allis s program VICTOR developed a method of finding an optimal strategy based on the 9 rules given above. The position evaluator (white or black) is given a description of the board and comes up with an optimal next move. Connect Four 45

First all possible instances of the nine rules above are found and checked against all 69 possibilities to connect winning groups. The rule applications that solve at least one problem are stored in a list of solutions with a list of the groups solved by the solution and a list of other solutions that can be used to solve the problem. Connect Four 46

The next step is finding which solutions can work together. First all solutions are assembled as nodes into an undirected graph, where two nodes are connected if and only if they can t be used simultaneously. These connections are stored in an adjacency matrix. Then, the problems (threats) are added as nodes, and solutions are connected with problems if they solve the problem (no problems are connected). Connect Four 47

Note that two rules might not necessarily be able to be used at the same time. The following table describes the relationships between rules (taken from Allis, section 7.4): Connect Four 48

Courtesy of Victor Allis. Used with permission. In "A Knowledge-based Approach of Connect-Four. The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 50. Connect Four 49

Then we solve the following problem: Given: Two sets of nodes, S(olutions) and P(roblems). Try to find an independent subset C of S with the property that P is contained in the set of all neighbors of C, B(C ). (Note this is a potentially NP-complete problem) Connect Four 50

The following recursive algorithm was used by Allis: FindChosenSet(P, S) { if (P == EmptySet) { Eureka() /* We have found a subset C meets all constraints. */ } else { MostDifficultNode = NodeWithLeastNumberOfNeighbours(P); for (all neighbours of MostDifficultNode) { FindChosenSet(P - { MostDifficultNode }, S - AllNeighboursOf(ChosenNeighbour)); } } } Courtesy of Victor Allis. Used with permission. In "A Knowledge-based Approach of Connect-Four. The Game is Solved: White Wins." Master's Thesis, Vrije University, 1988, pp. 59. Connect Four 51

One method used to solve game trees is conspiracy-number search. In the instance of connect four, consider three types of nodes: -1 black can at least draw the game, 1 the game is a win for white, or 0 the game is as yet undecided. Now any node that has as a child a node with a value of 1 can be colored 1. Any node that has all nodes colored -1 can be colored -1. Note it is much easier to change a node to a 1 than a -1. Connect Four 52

The conspiracy number of a node is a tuple of counts for the number of children needed to conspire to change the value of the node to each of the possible values. Let (x, y) be the conspiracy number of a node, with x the number of nodes that need to conspire to change the value to 1, and y to -1. We know x will always be 1, since we only need one childe of value 1 to change our value to 1. But y is the number of ons of the node yet to be evaluated if all those evaluated so far have been -1. If sons have already been evaluated to 1, then y is. Connect Four 53

The purpose of conpsiracy number search is to evaluated as few nodes as possible to find the result of the game tree. Therefore, we try to avoid evaluating nodes with large conspiracy numbers. If we want to evaluate a node at the top of the tree, we choose the neighbors with the lowest conspiracy numbers to evaluate until we are sure of their value. We move up the tree in this way, whenever possible avoiding evalutating nodes with large conspiracy numbers. Connect Four 54

Connect Four tournament! Connect Four 55

MIT OpenCourseWare http://ocw.mit.edu ES.268 The Mathematics in Toys and Games Spring 2010 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.