Deep Green. System for real-time tracking and playing the board game Reversi. Final Project Submitted by: Nadav Erell

Similar documents
CS 229 Final Project: Using Reinforcement Learning to Play Othello

Learning to Play like an Othello Master CS 229 Project Report. Shir Aharon, Amanda Chang, Kent Koyanagi

Programming an Othello AI Michael An (man4), Evan Liang (liange)

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

Interactive 1 Player Checkers. Harrison Okun December 9, 2015

Artificial Intelligence Search III

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

CS221 Project Final Report Gomoku Game Agent

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

For slightly more detailed instructions on how to play, visit:

Playing Othello Using Monte Carlo

Adversarial Search and Game- Playing C H A P T E R 6 C M P T : S P R I N G H A S S A N K H O S R A V I

Adversary Search. Ref: Chapter 5

AI Approaches to Ultimate Tic-Tac-Toe

Games (adversarial search problems)

Applications of Artificial Intelligence and Machine Learning in Othello TJHSST Computer Systems Lab

Artificial Intelligence. Topic 5. Game playing

Today. Types of Game. Games and Search 1/18/2010. COMP210: Artificial Intelligence. Lecture 10. Game playing

Outline. Game Playing. Game Problems. Game Problems. Types of games Playing a perfect game. Playing an imperfect game

Using Artificial intelligent to solve the game of 2048

Artificial Intelligence. Minimax and alpha-beta pruning

COMP219: COMP219: Artificial Intelligence Artificial Intelligence Dr. Annabel Latham Lecture 12: Game Playing Overview Games and Search

CS 4700: Artificial Intelligence

Five-In-Row with Local Evaluation and Beam Search

2048: An Autonomous Solver

2 person perfect information

Creating a Poker Playing Program Using Evolutionary Computation

Foundations of Artificial Intelligence

Adversarial Search (Game Playing)

Documentation and Discussion

Vishnu Nath. Usage of computer vision and humanoid robotics to create autonomous robots. (Ximea Currera RL04C Camera Kit)

Spring 2005 Group 6 Final Report EZ Park

Google DeepMind s AlphaGo vs. world Go champion Lee Sedol

Evolutionary Neural Network for Othello Game

Foundations of Artificial Intelligence

CS 331: Artificial Intelligence Adversarial Search II. Outline

ARTIFICIAL INTELLIGENCE (CS 370D)

Programming Project 1: Pacman (Due )

A Quoridor-playing Agent

Real Time Word to Picture Translation for Chinese Restaurant Menus

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

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

Intuition Mini-Max 2

CS151 - Assignment 2 Mancala Due: Tuesday March 5 at the beginning of class

Scrabble Board Automatic Detector for Third Party Applications

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

DEMONSTRATION OF AUTOMATIC WHEELCHAIR CONTROL BY TRACKING EYE MOVEMENT AND USING IR SENSORS

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

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

An Evaluation of Automatic License Plate Recognition Vikas Kotagyale, Prof.S.D.Joshi

Adversarial Search and Game Playing. Russell and Norvig: Chapter 5

2/5/17 ADVERSARIAL SEARCH. Today. Introduce adversarial games Minimax as an optimal strategy Alpha-beta pruning Real-time decision making

Pay attention to how flipping of pieces is determined with each move.

CS188 Spring 2014 Section 3: Games

Comp th February Due: 11:59pm, 25th February 2014

Last-Branch and Speculative Pruning Algorithms for Max"

CS 771 Artificial Intelligence. Adversarial Search

COMP219: Artificial Intelligence. Lecture 13: Game Playing

Game playing. Chapter 5, Sections 1 6

An Electronic Eye to Improve Efficiency of Cut Tile Measuring Function

Computer Vision Lesson Plan

Adversarial Search. CS 486/686: Introduction to Artificial Intelligence

Contents. Foundations of Artificial Intelligence. Problems. Why Board Games?

Artificial Intelligence Lecture 3

Foundations of Artificial Intelligence

CMSC 671 Project Report- Google AI Challenge: Planet Wars

ADVERSARIAL SEARCH. Today. Reading. Goals. AIMA Chapter Read , Skim 5.7

CSE 40171: Artificial Intelligence. Adversarial Search: Game Trees, Alpha-Beta Pruning; Imperfect Decisions

Alpha-Beta search in Pentalath

Adversarial search (game playing)

Lecture 14. Questions? Friday, February 10 CS 430 Artificial Intelligence - Lecture 14 1

Final Project: Reversi

CS 188: Artificial Intelligence

EE368 Digital Image Processing Project - Automatic Face Detection Using Color Based Segmentation and Template/Energy Thresholding

Real-Time Connect 4 Game Using Artificial Intelligence

Foundations of AI. 6. Board Games. Search Strategies for Games, Games with Chance, State of the Art

Artificial Intelligence 1: game playing

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

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

Lane Detection in Automotive

Checkerboard Tracker for Camera Calibration. Andrew DeKelaita EE368

Evolutionary Computation for Creativity and Intelligence. By Darwin Johnson, Alice Quintanilla, and Isabel Tweraser

Problem 1. (15 points) Consider the so-called Cryptarithmetic problem shown below.

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

Adversarial Search and Game Playing

Generalized Game Trees

Game Playing: Adversarial Search. Chapter 5

Game-playing: DeepBlue and AlphaGo

ME 6406 MACHINE VISION. Georgia Institute of Technology

Biometrics Final Project Report

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

Adversarial Search. Soleymani. Artificial Intelligence: A Modern Approach, 3 rd Edition, Chapter 5

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

FPGA based Real-time Automatic Number Plate Recognition System for Modern License Plates in Sri Lanka

Blur Detection for Historical Document Images

Game-playing AIs: Games and Adversarial Search I AIMA

Game Playing AI Class 8 Ch , 5.4.1, 5.5

ADVERSARIAL SEARCH. Today. Reading. Goals. AIMA Chapter , 5.7,5.8

Adversarial Search. CS 486/686: Introduction to Artificial Intelligence

Transcription:

Deep Green System for real-time tracking and playing the board game Reversi Final Project Submitted by: Nadav Erell Introduction to Computational and Biological Vision Department of Computer Science, Ben-Gurion University 22 March, 2013 Abstract This project presents a computer vision and artificial intelligence system for playing a game of Reversi. The system is capable of tracking the progress of a real-world Reversi board game using a regular webcam, and may also suggest moves for each player computed using methods of artificial intelligence. 1

Contents 1 Introduction and Problem Description 3 2 The solution 4 2.1 System setup................................... 4 2.2 Detecting the game board............................ 5 2.2.1 Segmentation.............................. 5 2.2.2 Homography............................... 6 2.3 Analyzing the board and acquiring the pieces.................. 7 2.4 Artificial Intelligence for Reversi......................... 7 3 Experiments and Performance 9 4 Conclusions and Further Work 9 References 11 2

1 Introduction and Problem Description Reversi, with variants also known as Othello, is a relatively simple strategy board game originating in England near the end of the 19th century. The game quickly gained popularity and spread to other countries, and has in the past few decades also been warmly embraced by computer scientists around the world. The game is played on a board containing 8 8 squares, and uses 64 identical pieces (discs) which fill up the board as the game progresses. The discs are colored with a light color on one side and a darker color on the other (often black and white, but occasionally other colors are used). The most common modern version of the game begins with 2 black discs (i.e. the black side faces up) and 2 white discs placed in the middle 4 squares in diagonals. The game is played in turns, with each player allowed to place a disc of his color only is such a manner that he captures at least one of the opponent s discs. A disc is captured if due to the new disc placed, it is now trapped between two of the opponent s discs. The winner is the player who has the most discs at the end of the game (usually when the board fills up completely, but occasionally in other circumstances). For a more detailed description of the game and some playing strategies, see [3]. In the context of computer science, the game is usually referred to as Othello, and has been thoroughly analyzed in terms of complexity and game strategies. The estimated game-tree complexity of Othello is 10 58, thus ensuring that any naive implementation will not be able to search to any significant depth. This project focuses less on the AI implementation (detailed later on), but rather on the acquisition and analysis of a physical game board from a regular camera input. The problem requires detecting the board area in an image, detecting the discs and their exact location in the grid, and feeding this data to the game AI, all while maintaining sufficient performance for an acceptable real-time user experience. The system has been tuned to a specific version of the Reversi board, with a square green board, no line marks, and white and orange discs. Due to the system s reliance on colors, standard lighting conditions as present in most work locations are assumed. The system does not require any special hardware for its operation, and performs well enough on an average 3 year old laptop with a standard USB webcam attached. 3

2 The solution As previously explained, the system can be roughly separated to a computer vision element, which accounted for the majority of the work, and and a separate AI module for suggesting moves. A very high-level description of a single iteration of the system is described in the following chart: Figure 1: Top-level flowchart for the system When in continuous tracking mode (selectable in GUI), the system will loop this process every few seconds. 2.1 System setup In order to provide a compelling user experience for the system, it has been developed in such a way that almost no setup is required. A GUI is used to control the attached webcam and to pause and resume the processing of the input data. The camera does not need to be located directly above the game board, and in good lighting conditions may even be placed at a considerable angle and varying distance from the board. If the camera is moved around, or for whatever reason the system is unable to correctly acquire the game board, it will ignore the current frame and continue processing the next, thus providing flexibility in setup and during gameplay. Figure 2: Deep Green system GUI: at launch, and after starting the camera. 4

2.2 2.2.1 Detecting the game board Segmentation The relaxing assumption of having a green board under relatively decent lighting conditions is used to simplify the process of closely detecting the board area. A binary threshold is applied to each channel of the RGB color image, requiring at least a certain level of green, and at most certain levels of red and blue, which have been determined empirically. These masks, along with an additional grayscale threshold, are combined to produce a final binary mask. Assuming the board takes up a considerable part of the image, it should become the dominant connected component of the combined mask. To further ensure the correct segmentation of the board from the rest of the image, binary operations of dilation and erosion are applied, after which the largest connected component is selected. Figure 3: Input image - original and grayscale. Red mask Green mask Blue mask Figure 4: Segmentation via binary thresholding on each RGB channel. 5

Figure 5: Combined binary mask (left), final mask after dilation and erosion (right). 2.2.2 Homography In order to enable the flexibility in camera angle and distance, the concept of homography1 is used to transform the image. Intuitively, this method allows us to obtain an image that looks as if the camera been located directly above the board, with the image axes parallel to the board axes. The homography is calculated using 4 points from the image (chosen as the 4 corners of the board), and the corresponding 4 points in the second image (which are simply chosen as a perfect square of size 400 400 pixels). For a fully automatic process, a relatively simple method has been developed to automatically mark the corners of the board by finding the pixels in the board mask from the previous module which are nearest to the full image corners. Input image Image after homography Cropped board area Figure 6: Homography and tight cropping of board area. 1 From Wikipedia (Homography): A homography is an invertible transformation from a projective space to itself that maps straight lines to straight lines....in the field of computer vision, any two images of the same planar surface in space are related by a homography. This has many practical applications, such as image rectification. 6

2.3 Analyzing the board and acquiring the pieces Once the homography has been applied and the image cropped to retain approximately only the board area, aligned to the image axes, we can more easily begin acquiring the white and orange discs. Since the board is green, and the discs white or orange, the red color channel provides an excellent opprtunity for segmentation of the discs from the board 2. In some cases, other areas of the image make it through the initial thresholding. However, areas which are not actually discs can be identified and removed fairly easily. This is achieved by first performing dilation and erosion, and then by filtering connected components which are either far too big or far too small in area, or those that are very eccentric in shape (as opposed to the discs which are nearly perfect circles). This method proved very robust and much simpler to implement than the Hough Transform for circles, which was attempted initially. At this point, we are left with a set of discs, which must now be aligned to the game grid in order to be encoded and sent to the game AI. Due to the homography process, the board should at this point be aligned to the image axes. Therefore, we can simply divide the image into 8 8 cells, and assign each disc to the nearest cell (differentiating between white and orange discs). 2.4 Artificial Intelligence for Reversi In light of the focus of this project on the Computer Vision aspect, a relatively simple algorithm using Minimax with alpha-beta pruning has been chosen for the implementation of the AI element. It has been tuned in such a manner that it can beat a novice player using 5-ply cutoff with a delay of no more than a couple of seconds for calculations in each turn. In layman s terms, this means that the computer simulates various possible scenarios for the game to a maximum depth of 5 moves (combined for both players), and chooses the move which it expects will be most advantageous. Since the number of possible game states grows exponentially with the depth of the search, a standard but often effective technique (alpha-beta pruning) is used to reduce the number of game states evaluated. This is achieved by ignoring search paths which can be guaranteed to find a suboptimal result for the heuristic evaluation function used. It should be noted that the heuristic function used to evaluate the value of each game state is extremely simple, but sufficient for a project mainly concerned with computer vision. That said, the program is designed in a flexible and extensible manner, such that improvements to the heuristic function can be incorporated with minimal effort if required. 2 An earlier effort was made to address black and white pieces with high and low grayscale thresholding. This effort proved effective on several static images, but isn t currently used in the system due to the lack of availability of a physical game set with black discs. 7

The code provided with this report includes a standalone version of Reversi coded entirely in Python, as well a version of the script intended to be used in conjunction with the MATLAB code in order to provide suggestions for a single move at a time. The code is very readable and contains some documentation, and a readme file with usage instructions is supplied as well. Figure 7: Suggested moves by the game AI. 8

3 Experiments and Performance The system was tested on a Windows 8 laptop with a relatively old Intel Core 2 Duo processor @ 2.53 GHz, running the 2010 version of MATLAB and the latest version of Python (3.3). The webcam used was a simple one with a resolution of 640 480. Under these conditions, the full processing for each image frame (board detection, pieces detection, AI game calculations) required between 2-5 seconds, thus limiting somewhat the real-time feel of the UI. That said, the current performance is quite sufficient for playing an actual game, and the delay is relatively insignificant for the game flow. Apart from the step-by-step example shown in section 2, the system was tested at various conditions. The system is capable of handling moderate variations in camera angle, camera distance and even lighting conditions. Gradually, as conditions deteriorate, the homography becomes less accurate, the board area may not be recognized perfectly, and thus the final detection of the discs may fail. In particular, the system fails completely under poor lighting conditions (either too dark, or non-white artificial lighting which renders the color masks ineffective). To highlight the robustness of the process, Figure 8 provides an additional example, this time with the camera located at a considerable angle from the board. Input image Image after homography Final Detection Figure 8: Perfect board detection despite difficult camera angle. 4 Conclusions and Further Work This project has been an excellent experience in implementing a system from start to finish, while tackling various problems along the way, and putting to practice some of the methods taught in class. Perhaps the most critical lesson learned is the importance of selecting the right tool for the job; Several hours were spent attempting to use circular Hough transforms for disc 9

detection, and clever calculations for the point set used to determine the Homography, when much simpler methods eventually proved more effective. The final system is easy to set up, fairly robust, and is capable of handling considerable variations in camera angle and distance. It is also designed to be modular and extensible, making it much easier to improve upon in the future if desired, or perhaps even simply to improve its performance on faster hardware. That said, the system is not without its limitations. For one, poor lighting conditions were avoided on purpose to reduce the additional complexities it would introduce. Apart from that, the system was tuned to a specific version of the Reversi board game, and would likely need to be slightly adjusted to perform well on different boards (with different colors). Finally, the game AI is fairly simple, and could definitely be improved as well, even if that was not the main focus of this project. 10

References [1] Ohad Ben-Shahar. Introduction to computational and biological vision. Lectures Notes, 2013. [2] Rami Hagege. Introduction to digital image processing. Lecture Notes, 2013. [3] Emmanuel Lazard. Strategy guide. http://radagast.se/othello/help/strategy. html, 1993. [Online; accessed 21-March-2013]. [4] S.J. Russell and P. Norvig. Artificial Intelligence: A Modern Approach. Prentice Hall Series in Artificial Intelligence. Prentice Hall, 2010. 11