CHAPTER 10 FUN AND GAMES Group 1: Xiangling Liu.

Slides:



Advertisements
Similar presentations
Adversarial Search We have experience in search where we assume that we are the only intelligent being and we have explicit control over the “world”. Lets.
Advertisements

Computers playing games. One-player games Puzzle: Place 8 queens on a chess board so that no two queens attack each other (i.e. on the same row, same.
Lecture 12: Revision Lecture Dr John Levine Algorithms and Complexity March 27th 2006.
Chapter 10 Introduction to Arrays
Artificial Intelligence Adversarial search Fall 2008 professor: Luigi Ceccaroni.
Adversarial Search Chapter 6 Section 1 – 4.
Tic Tac Toe Architecture CSE 5290 – Artificial Intelligence 06/13/2011 Christopher Hepler.
Tutorial 6 of CSCI2110 Bipartite Matching Tutor: Zhou Hong ( 周宏 )
Arrays. INTRODUCTION TO ARRAYS Just as with loops and conditions, arrays are a common programming construct and an important concept Arrays can be found.
J AVA A SSIGNMENT 1. O VERVIEW Tic Tac Toe How it should work Using the supplied methods What you need to do How we will test your code.
Lecture 12 Last time: CSPs, backtracking, forward checking Today: Game Playing.
Search Strategies.  Tries – for word searchers, spell checking, spelling corrections  Digital Search Trees – for searching for frequent keys (in text,
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
CS 61B Data Structures and Programming Methodology July 31, 2008 David Sun.
Representing a Game Board In a game, we represent the action taking place using an array – In a very simple game, we use individual variables to represent.
Game Playing CSC361 AI CSC361: Game Playing.
November 10, 2009Introduction to Cognitive Science Lecture 17: Game-Playing Algorithms 1 Decision Trees Many classes of problems can be formalized as search.
1 search CS 331/531 Dr M M Awais A* Examples:. 2 search CS 331/531 Dr M M Awais 8-Puzzle f(N) = g(N) + h(N)
Sets and Maps Chapter 9. Chapter 9: Sets and Maps2 Chapter Objectives To understand the Java Map and Set interfaces and how to use them To learn about.
Adversarial Search and Game Playing Examples. Game Tree MAX’s play  MIN’s play  Terminal state (win for MAX)  Here, symmetries have been used to reduce.
Adversarial Search: Game Playing Reading: Chess paper.
THE RENJU GAME BY ABHISHEK JAIN, PRANSHU GUPTA & RHYTHM DAS PCLUB SUMMER PROJECT PRESENTATION JUNE, L7 IIT KANPUR MENTOR – SANIL JAIN.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Chapter 2 Recursion: The Mirrors. © 2005 Pearson Addison-Wesley. All rights reserved2-2 Recursive Solutions Recursion is an extremely powerful problem-
Game Playing: Adversarial Search Chapter 6. Why study games Fun Clear criteria for success Interesting, hard problems which require minimal “initial structure”
1 Adversary Search Ref: Chapter 5. 2 Games & A.I. Easy to measure success Easy to represent states Small number of operators Comparison against humans.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Data Structures Using C++ 2E Chapter 6 Recursion.
CISC 235: Topic 6 Game Trees.
Lecture 5 Note: Some slides and/or pictures are adapted from Lecture slides / Books of Dr Zafar Alvi. Text Book - Aritificial Intelligence Illuminated.
Minimax.
Data Structures Using C++ 2E Chapter 6 Recursion.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
Recursion Chapter 7. Chapter Objectives  To understand how to think recursively  To learn how to trace a recursive method  To learn how to write recursive.
October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 1 Iterative Deepening A* Algorithm A* has memory demands that increase.
Chapter 2 Recursion: The Mirrors. © 2005 Pearson Addison-Wesley. All rights reserved2-2 Recursive Solutions Recursion is an extremely powerful problem-
Mark Dunlop, Computer and Information Sciences, Strathclyde University 1 Algorithms & Complexity 5 Games Mark D Dunlop.
Computer Programming for Engineers. Outline Tic-Tac-Toe (O-X Game) Drawing 3x3 grid Receiving the inputs Checking for a winner Taking turns between.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Connect Four AI Robert Burns and Brett Crawford. Connect Four  A board with at least six rows and seven columns  Two players: one with red discs and.
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
Cilk Pousse James Process CS534. Overview Introduction to Pousse Searching Evaluation Function Move Ordering Conclusion.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
LECTURE 35: COLLISIONS CSC 212 – Data Structures.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
ARTIFICIAL INTELLIGENCE (CS 461D) Princess Nora University Faculty of Computer & Information Systems.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
CMSC 421: Intro to Artificial Intelligence October 6, 2003 Lecture 7: Games Professor: Bonnie J. Dorr TA: Nate Waisbrot.
Adversarial Search 2 (Game Playing)
Adversarial Search and Game Playing Russell and Norvig: Chapter 6 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2004/home.htm Prof: Dekang.
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
February 25, 2016Introduction to Artificial Intelligence Lecture 10: Two-Player Games II 1 The Alpha-Beta Procedure Can we estimate the efficiency benefit.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
Chapter 12: Pointers, Classes, Virtual Functions, Abstract Classes, and Lists.
Understanding AI of 2 Player Games. Motivation Not much experience in AI (first AI project) and no specific interests/passion that I wanted to explore.
1 Decisions in games Minimax algorithm  -  algorithm Tic-Tac-Toe game Decisions in games Minimax algorithm  -  algorithm Tic-Tac-Toe game.
Sets and Maps Chapter 9.
Lecture 5 of Computer Science II
Adversarial Search and Game Playing (Where making good decisions requires respecting your opponent) R&N: Chap. 6.
Chapter 6 : Game Search 게임 탐색 (Adversarial Search)
Kevin Mason Michael Suggs
The Alpha-Beta Procedure
Sets and Maps Chapter 9.
Minimax strategies, alpha beta pruning
Minimax strategies, alpha beta pruning
Data Structures and Algorithms
Unit II Game Playing.
Presentation transcript:

CHAPTER 10 FUN AND GAMES Group 1: Xiangling Liu

Overview of the Chapter PART I Overview of the Chapter

OBJECT How to use the binary search algorithm in word search puzzle problem to solve large instances of a word search in under 1 sec How to use the alpha-beta pruning algorithm to speed up the recursive algorithm presented in Section7.7 How to use maps to increase the speed of the Tic-Tac-Toe algorithm

10.1 WORD SEARCH PUZZLES The input to the word search puzzle problem is a two-dimensional array of characters and a list of words. The object is to find the words in the grid. Words may be oriented in one of eight directions (horizontal, vertical or diagonal).

10.1.1 THEORY The most direct algorithm is brute-force approach as follows: Algorithm for each word W in the word list for each row R for each column C for each direction D check if W exists at row R, column C in direction D The algorithm requires 8WRC checks

10.1.1 THEORY (cont) An alternative algorithm searches from each point in the grid in each direction for each word length and looks for the word in the word list. The lookups can be done by a binary search if the word list is sorted. Algorithm for each row R for each column C for each direction D for each word length L check if L chars starting at row R column C in direction D form a word The algorithm requires 8LRC checks

10.1.1 THEORY (cont) An further improved algorithm is to add an assertion. If a character sequence is not a prefix of any word, we can stop that search and look in another direction. Algorithm for each row R for each column C for each direction D for each word length L check if L chars starting at row R column C in direction D form a word if they do not form a prefix break; //the innermost loop The prefix testing can also be done by binary search

10.1.2 JAVA IMPLEMENTATION WordSearch class: to store the grid and word list, as well as the corresponding input streams. A constructor. It merely opens and reads the two files corresponding to the grid and the word list. Private openFile method. It repeatly prompts for a file until an open is successful. Private readWords method. It reads the word list. Private readPuzzle method reads the grid and is also concerned with error handling. Public solvePuzzle method nests the row, column and direction loops and then calls the private method solveDirection for each possibility.

10.1.2 JAVA IMPLEMENTATION (cont) Private solveDirection method constructs a string by starting at the base row and colunm and extending in the appropriate direction. Private prefixSearch method performs the binary search for word search. Main class is a simple routine for the word search puzzle problem

10.2 THE GAME OF TIC-TAC-TOE A simple algorithm known as mininax strategy allows the computer to select an optimal move in a game of Tic-Tac-Toe. It involves the following decisions. A terminal position can immediately be evaluated, so if the position is terminal, return its value. Otherwise, if it is the computer’s turn to move, return the maximum value of all positions reachable by making one move. The reachable values are calculated recursively. Otherwise, it is the human player’s turn to move. Return the minimum value of all positions reachable by making one move. The reachable values are calculated recursively.

10.2.1 ALPHA-BETA PRUNING The minimax strategy gives an optimal Tic-Tac-Toe move, it performs more searching than necessary. Alpha-beta pruning is the strategy of reducing the number of positions evaluated in a minimax search using refutation. A refutation is a countermove that proves that a proposed move is not an improvement over moves previously considered. If a refutation found, we do not have to examine any more moves and the recursive call can return. Alpha is the value that the human player has to

10.2.1 ALPHA-BETA PRUNING (cont) refute and beta is the value that the computer has to refute. Alpha-beta pruning requires only a few changes to chooseMove. Both alpha and beta are passed as additional parameters. Add an assertion which provides for an immediate return when a refutation is found.

10.2.2 TRANSPOSITION TABLES A transpostion table stores previously evaluated positions. A map is used to implement the transposition table. Often the underlying implementation is a hash table. The chooseMove method has additional parameters, all of which have defaults. The use of the transposition table in this tic-tac-toe algorithm can almost double the program’s speed by removing about half the positons from consideration.

10.2.3 COMPUTER CHESS Terminal positions cannot be searched in computer chess. So we have to stop the search after a certain depth of recursion is reached. In the best programs, considerable knowledge is built into the evaluation function.

Overview of TicTacToe Program PART II Overview of TicTacToe Program

WHAT HAVE BEEN REVISED Use a static final int SIZE to replace literal size of the board in class TicTacToe Replace 3*3 board with 4*4 board Change the law of winning. If one side has occupied 3 square in the diagonal or back-diagonal, the side wins the game

CLASSES OF THE PROGRAM Best class Position class TicTacToe class TicTacMain class TicTacPanel class

Best CLASS The class is to store the value, the row and column corresponding to a position. Has two constructors public Best( int v ) public Best( int v, int r, int c )

Position CLASS The class define a postion in the board and define the equals of position and the hashcode Has three methods Constructor: initialize the board equals: defines if the position is equal or not hashCode: defines the hash value of the board position in the hash table

TicTacToe CLASS The class has eleven methods. Constructor: clear the board of game getBoard: get the board of the game chooseMove with one parameter: choose the optimal move chooseMove with four parameter: choose the optimal move playMove: Play move, including checking legality clearBoard: clear the board of game

TicTacToe CLASS (cont) boardIsFull: check if the board is full isAWin: check if the side wins the game place: place the mark at a position in the board squareIsEmpty: checks if the square is empty positionValue: computes static value of current position (win, draw, etc.)

TicTacMain CLASS The class is to add TicTacPanel object and windowAdapter show all actions. Has two methods and class TicTacPanel Constructor: add TicTacPanel object and windowAdapter main: a very simple main method

TicTacPanel CLASS The class is to set a GridLayout and make every square listen to the action of button. Compute the value of the computer side and make a move. Calculate and show the game result. Has five methods Constructor: set a GridLayout and make every square listen to the action of button. After each game, reset the board. resetBoard: reset the board and make each square of the board enable

TicTacPanel CLASS (cont) doCompMove: the computer side to choose best position and make a move resetIfDone: gives information of the game at the end of the game actionPerformed: performs a move corresponding to human's or compter's move and gives the result of the game

JAVA CODE AND RUNNING RESULTS See the attached file Execute the program

Thank you all!