9.1. Board Games 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 Chapter 6 Section 1 – 4. Types of Games.
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,
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.
Adversarial Search Reference: “Artificial Intelligence: A Modern Approach, 3 rd ed” (Russell and Norvig)
Adversarial Search Chapter 5.
Adversarial Search CSE 473 University of Washington.
Artificial Intelligence in Game Design
This time: Outline Game playing The minimax algorithm
Game Playing CSC361 AI CSC361: Game Playing.
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: 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.
CSC 412: AI Adversarial Search
Game Trees: MiniMax strategy, Tree Evaluation, Pruning, Utility evaluation Adapted from slides of Yoonsuck Choe.
9.1. B OARD G AMES AND A IMING AI Common board game AI approaches and Aiming AI.
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 2 Adapted from slides of Yoonsuck.
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.
Game Playing.
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.
Mark Dunlop, Computer and Information Sciences, Strathclyde University 1 Algorithms & Complexity 5 Games Mark D Dunlop.
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
Adversarial Search Chapter Games vs. search problems "Unpredictable" opponent  specifying a move for every possible opponent reply Time limits.
Game tree search Chapter 6 (6.1 to 6.3 and 6.6) cover games. 6.6 covers state of the art game players in particular. 6.5 covers games that involve uncertainty.
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.
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.
Search: Games & Adversarial Search Artificial Intelligence CMSC January 28, 2003.
1 Decisions in games Minimax algorithm  -  algorithm Tic-Tac-Toe game Decisions in games Minimax algorithm  -  algorithm Tic-Tac-Toe game.
Game playing Types of games Deterministic vs. chance
Adversarial Search and Game-Playing
ADVERSARIAL GAME SEARCH: Min-Max Search
Instructor: Vincent Conitzer
Last time: search strategies
PENGANTAR INTELIJENSIA BUATAN (64A614)
CS Fall 2016 (Shavlik©), Lecture 11, Week 6
Adversarial Search and Game Playing (Where making good decisions requires respecting your opponent) R&N: Chap. 6.
Pengantar Kecerdasan Buatan
State Space 4 Chapter 4 Adversarial Games.
David Kauchak CS52 – Spring 2016
Adversarial Search Chapter 5.
Game Playing in AI by: Gaurav Phapale 05 IT 6010
Artificial Intelligence
Game playing.
Chapter 6 : Game Search 게임 탐색 (Adversarial Search)
Alpha-Beta Search.
Game Playing: Adversarial Search
NIM - a two person game n objects are in one pile
Artificial Intelligence
Alpha-Beta Search.
Instructor: Vincent Conitzer
Alpha-Beta Search.
Minimax strategies, alpha beta pruning
Alpha-Beta Search.
Instructor: Vincent Conitzer
Game Playing: Adversarial Search
CSE (c) S. Tanimoto, 2007 Search 2: AlphaBeta Pruning
Game Playing Chapter 5.
Adversarial Search CS 171/271 (Chapter 6)
Alpha-Beta Search.
Games & Adversarial Search
Minimax strategies, alpha beta pruning
Data Structures and Algorithms
CS51A David Kauchak Spring 2019
CS51A David Kauchak Spring 2019
Unit II Game Playing.
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning
Presentation transcript:

9.1. Board Games and Aiming AI Common board game AI approaches and Aiming AI

Board Game AI Common AI approaches of use to board games Movement Execution Management Movement Strategy Decision Making World Interface Animation Physics ... Board Game AI Common AI approaches of use to board games

Board game AI 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.

Board game AI (zero-sum games) 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.

Board game AI (perfect/imperfect information) 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.

Board game AI (the game tree) 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. O X X O ... O X O X O X ... O X ... O X O X 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 (move evaluation) 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.

Board game AI (minimaxing approach) 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.

[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 ) { } return [bestScore, bestMove]; Minimaxing algorithm A recursive minimax is defined below, a maximum search depth is used to determine when the search will stop. Stop the recursion if maximum depth reached or terminal node found Else, find best move Consider each possible move Move getBestMove( Board boardState, Player player) { [Score score, Move move] = minimax(boardState, player, maxDepth, 0); return move } Perform recursion Update current best score depending on if we will maximise or minimise The code assumes the minimax search returns a best move and score. In Java/C# either return a wrapper or pass move by reference

Board game AI (other approaches) 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 Aiming and firing solutions Movement Execution Management Movement Strategy Decision Making World Interface Animation Physics ... Aiming and Firing Aiming and firing solutions

Aiming and Firing 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

movement due to gravity Aiming and Firing (projectile trajectory) 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 Initial position movement due to firing movement due to gravity 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.

Aiming and Firing (landing position) 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 x2). Quadratic equations can be solved using the following (which provides two solutions – not necessarily distinct, and maybe not real).

Aiming and Firing (landing position) 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): Aside: As gravity is often only in the y (downward) direction, the eq. can be simplified to:

Aiming and Firing (firing direction) 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. Aside: Usually there will be two solutions representing different firing arcs to the target. Typically the arc with the lower time is selected. Short-term trajectory Long-term trajectory Target

Aiming Algorithm 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); Aiming Algorithm Calculate (a,b,c) coefficients of the normal quadratic equation The scalar product of two vectors, i.e. A●B is defined as AxBx + AyBy +... Return if no real solutions can be found Determine the two solutions Return null if no positive time solutions were found Return firing vector

Summary Today we explored: Board game AI and the use of the minimax algorithm Aiming and firing algorithms for simple trajectories 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.