9.1. B OARD G AMES AND A IMING AI Common board game AI approaches and Aiming AI.

Slides:



Advertisements
Similar presentations
7.2. AI E NGINE AND S TEERING B EHAVIOUR I Design of an AI Engine and introduction to steering in game AI.
Advertisements

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.
Artificial Intelligence Adversarial search Fall 2008 professor: Luigi Ceccaroni.
ICS-271:Notes 6: 1 Notes 6: Game-Playing ICS 271 Fall 2008.
CS 484 – Artificial Intelligence
Adversarial Search Chapter 5.
Adversarial Search: Game Playing Reading: Chapter next time.
Lecture 12 Last time: CSPs, backtracking, forward checking Today: Game Playing.
Adversarial Search CSE 473 University of Washington.
Hoe schaakt een computer? Arnold Meijster. Why study games? Fun Historically major subject in AI Interesting subject of study because they are hard Games.
MINIMAX SEARCH AND ALPHA- BETA PRUNING: PLAYER 1 VS. PLAYER 2.
Search Strategies.  Tries – for word searchers, spell checking, spelling corrections  Digital Search Trees – for searching for frequent keys (in text,
Games CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Minimax and Alpha-Beta Reduction Borrows from Spring 2006 CS 440 Lecture Slides.
Artificial Intelligence in Game Design
State Space 4 Chapter 4 Adversarial Games. Two Flavors Games of Perfect Information ◦Each player knows everything that can be known ◦Chess, Othello Games.
This time: Outline Game playing The minimax algorithm
Game Playing CSC361 AI CSC361: Game Playing.
Games and adversarial 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)
Game-Playing Read Chapter 6 Adversarial Search. Game Types Two-person games vs multi-person –chess vs monopoly Perfect Information vs Imperfect –checkers.
How computers play games with you CS161, Spring ‘03 Nathan Sturtevant.
ICS-271:Notes 6: 1 Notes 6: Game-Playing ICS 271 Fall 2006.
Adversarial Search: Game Playing Reading: Chess paper.
Alpha-Beta Search. 2 Two-player games The object of a search is to find a path from the starting position to a goal position In a puzzle-type problem,
Game-Playing Read Chapter 6 Adversarial Search. State-Space Model Modified States the same Operators depend on whose turn Goal: As before: win or win.
Game Playing: Adversarial Search Chapter 6. Why study games Fun Clear criteria for success Interesting, hard problems which require minimal “initial structure”
Game Playing State-of-the-Art  Checkers: Chinook ended 40-year-reign of human world champion Marion Tinsley in Used an endgame database defining.
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.
CSC 412: AI Adversarial Search
Game Trees: MiniMax strategy, Tree Evaluation, Pruning, Utility evaluation Adapted from slides of Yoonsuck Choe.
PSU CS 370 – Introduction to Artificial Intelligence Game MinMax Alpha-Beta.
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 2 Adapted from slides of Yoonsuck.
Lecture 5 Note: Some slides and/or pictures are adapted from Lecture slides / Books of Dr Zafar Alvi. Text Book - Aritificial Intelligence Illuminated.
Game Playing Chapter 5. Game playing §Search applied to a problem against an adversary l some actions are not under the control of the problem-solver.
Lecture 6: Game Playing Heshaam Faili University of Tehran Two-player games Minmax search algorithm Alpha-Beta pruning Games with chance.
Game Playing.
AD FOR GAMES Lecture 4. M INIMAX AND A LPHA -B ETA R EDUCTION Borrows from Spring 2006 CS 440 Lecture Slides.
Prepared by : Walaa Maqdasawi Razan Jararah Supervised by: Dr. Aladdin Masri.
Game Playing Chapter 5. Game playing §Search applied to a problem against an adversary l some actions are not under the control of the problem-solver.
1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah
Mark Dunlop, Computer and Information Sciences, Strathclyde University 1 Algorithms & Complexity 5 Games Mark D Dunlop.
Game-playing AIs Part 1 CIS 391 Fall CSE Intro to AI 2 Games: Outline of Unit Part I (this set of slides)  Motivation  Game Trees  Evaluation.
Notes on Game Playing by Yun Peng of theYun Peng University of Maryland Baltimore County.
Instructor: Vincent Conitzer
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.
1 Adversarial Search CS 171/271 (Chapter 6) Some text and images in these slides were drawn from Russel & Norvig’s published material.
For Wednesday Read chapter 7, sections 1-4 Homework: –Chapter 6, exercise 1.
Backtracking and Games Eric Roberts CS 106B January 28, 2013.
CSCI 4310 Lecture 6: Adversarial Tree Search. Book Winston Chapter 6.
Adversarial Search Chapter Games vs. search problems "Unpredictable" opponent  specifying a move for every possible opponent reply Time limits.
ARTIFICIAL INTELLIGENCE (CS 461D) Princess Nora University Faculty of Computer & Information Systems.
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.
Explorations in Artificial Intelligence Prof. Carla P. Gomes Module 5 Adversarial Search (Thanks Meinolf Sellman!)
Adversarial Search In this lecture, we introduce a new search scenario: game playing 1.two players, 2.zero-sum game, (win-lose, lose-win, draw) 3.perfect.
Artificial Intelligence in Game Design Board Games and the MinMax Algorithm.
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.
Chapter 5 Adversarial Search. 5.1 Games Why Study Game Playing? Games allow us to experiment with easier versions of real-world situations Hostile agents.
1 Decisions in games Minimax algorithm  -  algorithm Tic-Tac-Toe game Decisions in games Minimax algorithm  -  algorithm Tic-Tac-Toe game.
Adversarial Search and Game-Playing
ADVERSARIAL GAME SEARCH: Min-Max Search
Instructor: Vincent Conitzer
PENGANTAR INTELIJENSIA BUATAN (64A614)
Adversarial Search Chapter 5.
9.1. Board Games and Aiming AI
Instructor: Vincent Conitzer
Unit II Game Playing.
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning
Presentation transcript:

9.1. B OARD G AMES AND A IMING AI Common board game AI approaches and Aiming AI

Common AI approaches of use to board games Execution Management World Interface Moveme nt Strat egy Decision Making AnimationPhysics

The first applications of AI in computer games was applied to playing board games (e.g. Chess, Tic-Tac-Toe, Go, etc.). Most board game algorithms assume two-players (but often can be extended to cater for more players). Depending upon the game, players can make moves or take their turn.

A board game in which the win of one player is equivalent to the loss of the other player(s) is known as a zero-sum game (e.g. chess, but not some casino games where players compete against the house). In a zero-sum game the focus can be on trying to win or make the opponent lose (the outcome is the same). In a non-zero-sum game, the focus should be on the player winning. The complexity increases for games with more than two players (even in zero-sum games) as the best strategy may involve temporary alliances against a stronger opponent, etc.

In many board games the entire state of the board is known (i.e. nothing is hidden) – known as perfect information. This entails that every possible move is known and the outcome of that move can also be determined. Games involving dice rolls or other forms of uncertainty are known as imperfect information. Aside: Most common board game algorithms are for two-player, perfect information, zero-sum games.

A game tree represents the game evolution. Each node defines one possible board layout, with each branch representing a valid move. A terminal node represents an end- of-game state. Each terminal position assigns a score to each player (e.g. +1 for a win, -1 for a loss, 0 for a draw, or some other numeric measure of the size of win). In zero-sum games, the total combined score will be zero.... Aside: The number of branches from each node is called the branching factor. Games with a high branching factor tend to be more challenging to model using board game AI.

Board game AI should, given a defined board state, select the best move that is likely to lead towards a win. This is the job of a heuristic static evaluation function which scores a board position from the perspective of one player. Given a terminal node, the returned score will be the final score for the game. In non-terminal nodes, the score reflects how likely the player is to win from the position (returning an increasing score relative to the strength of the position). The heuristic function is game specific. Aside: In the game of Reversi the best mid- game strategy is to favour moves that minimise the number of own- coloured counters to maximize control (and hence counter count) in the end-game. In Chess aspects measured within the static evaluation function can include tempo, board control, piece count, etc. Different AI personalities can be easily embedded, e.g. scoring bishops higher than knights, etc.

The minimaxing approach operates by assuming each move of a player will be to maximize their score, whilst each move of the opponent will be to effectively minimise the player score (assuming a zero-sum game). Hence the minimax search alternates between maximising the player score on their turn and minimizing the player score on the opponents turn. By recording the net scores and looking a number of turns ahead the minimax search can then select the best move the player should make.

A recursive minimax is defined below, a maximum search depth is used to determine when the search will stop. [Score, Move] minimax (Board boardState, Player player, int maxDepth, int currentDepth) { if(boardState.gameOver() || currentDepth == maxDepth ) return [boardState.evaluate(player), None] Move bestMove ; float bestScore = (board.currentPlayer() == player ? -maxScore:maxScore); foreach( Move move in boardState.getValidMoves() ) { Board newBoardState = boardState.makeMove(move); [int currentScore, Move currentMove]= minimax ( newBoardState, player, maxDepth, currentDepth+1); if( boardState.currentPlayer() == player ) { if( currentScore > bestScore ) { bestScore = currentScore; bestMove = move; } } else if( currentScore < bestScore ) { bestScore = currentScore; bestMove = move; } } return [bestScore, bestMove]; Stop the recursion if maximum depth reached or terminal node found Else, find best move The code assumes the minimax search returns a best move and score. In Java/C# either return a wrapper or pass move by reference Update current best score depending on if we will maximise or minimise Consider each possible move Perform recursion Move getBestMove ( Board boardState, Player player) { [Score score, Move move] = minimax (boardState, player, maxDepth, 0); return move }

A wide range of other techniques can be used within board game AI, including: Use of alpha-beta pruning (AB pruning) to prune out sections of the search tree that cannot hold the optimal solution Use of transposition tables to avoid creating duplicate game states and improving search times Use of opening books and other databases of expert encoded knowledge, including set plays.

Aiming and firing solutions Execution Management World Interface Moveme nt Strat egy Decision Making AnimationPhysics

A lot of games involve projectiles of some sort (be they arrows, missiles, footballs, etc.). It can be important for an AI controlled character to ‘understand’ the projectile’s trajectory in order to aim or react to incoming projectiles

A projectile fired with an initial force that is subject to a gravitational force (ignoring air resistance and powered projectiles, e.g. rockets) will follow a curved trajectory (a parabola). The path can be defined as: is the position at time t is the initial position is the initial direction of firing is the speed of firing is the gravitational vector Aside: Earth’s gravitational force is 9.81 ms-2 ‘downwards’. This may not be the best value to use in a game, i.e. experiment with different values. Initial position movement due to firing movement due to gravity

The landing spot is found by solving for a given ‘floor’ height for the target (i.e. the y vector component). is the y component of the direction of firing, gravity, position at time 0 and time t respectively. There can be 0, 1 or 2 solutions. If zero, the projectile never reaches the target. If one, it reaches it at the apex of travel. If there are two solutions, target height is reached on way up and way down (the later projectile descending is of interest). Aside: The previous equation is a quadratic equation (i.e. involving x 2 ). Quadratic equations can be solved using the following (which provides two solutions – not necessarily distinct, and maybe not real).

Aside: As gravity is often only in the y (downward) direction, the eq. can be simplified to: Substituting the solution time into the trajectory equation of the point, the point of collision is found by (in 3D, for 2D remove z component):

In order to hit a target at a specific location we need to solve the previous equations for a given target location. The firing location will be known and often gravitational attraction and initial firing speed are assumed to be fixed, i.e. the direction of firing is varied in order to hit the target location. Short-term trajectory Long-term trajectory Target Aside: Usually there will be two solutions representing different firing arcs to the target. Typically the arc with the lower time is selected.

Vector? calculateFiringSolution ( Vector start, Vector target, Vector gravity, float speed ) { Vector delta = start – end; float a = gravity ● gravity; float b = -4 * (gravity ● delta + speed * speed) float c = 4 * delta ● delta if( 4*a*c > b*b ) return null; float t1 = Math.sqrt((-b + sqrt(b*b-4*a*c)) / (2*a)); float t2 = Math.sqrt((-b - sqrt(b*b-4*a*c)) / (2*a)); float t; if( t1 < 0 ) { if( t2 < 0 ) return null; else t = t1; } else { if( t2 < 0 ) t = t1; else t = Math.min( t1, t2 ); } return (2 * delta – gravity * t*t) / (2 * speed * t); Calculate (a,b,c) coefficients of the normal quadratic equation Return if no real solutions can be found The scalar product of two vectors, i.e. A●B is defined as A x B x + A y B y +... Determine the two solutions Return null if no positive time solutions were found Return firing vector

To do: Consider use of minimax or aiming and firing algorithms if applicable to game Work towards the alpha- handin at the end of this week. Today we explored: Board game AI and the use of the minimax algorithm Aiming and firing algorithms for simple trajectories