+ All Categories
Home > Documents > 07 Game Playing

07 Game Playing

Date post: 08-Mar-2016
Category:
Upload: shyamd4
View: 8 times
Download: 0 times
Share this document with a friend
Description:
game playing in AI

of 30

Transcript
  • Game Playing

  • OverviewGame PlayingGame problem vs State space problemStatus labeling procedure in Game treeNim game problemBounded Lood-Ahead Strategy and Use of Evaluation FunctionsUsing evaluation functionsMINIMAX procedureAlpha- Beta Pruning

  • Typical simple case for a gameWhat is a Game?A sequence of choices where each choice is made from a number of discrete alternatives.Each sequence ends in a certain outcome and every outcome has a definite value for the opening player.

  • Typical simple case for a gameTypes of Games:Perfect information games: both the players have access to the same information about the game in progress.Ex: Chess, Tic-Tac-ToeImperfect information games: players do not have access to complete information about the gameEx: cards

  • Typical simple case for a gameTwo player, turn-takingPlayers alternate moves Zero-sum games one players win is the others lossDiscrete: Finite number of states or configurationsPerfect information: Fully observableNo information is hidden from either player.Deterministic: The outcome of actions is known Examples: Tic-Tac-Toe, Chess, Nim, etc.

  • How to play a gameA way to play such a game is to:Consider all the legal moves you can makeCompute new position resulting from each moveEvaluate each to determine which is bestMake that moveWait for your opponent to move and repeat

  • Game problem vs State space problemStart state, legal moves, and winning positions (goals)many games can be formulated as search problemsA game can be represented as a treeA game tree is an explicit representation of all possible plays of the game. MIN nodes:Select the minimum cost successorMAX nodes:Select the maximum cost successorThe leaves represent the terminal positionsAt the leaf position, when the game is finished we can assign utility to the player (WIN, LOSS, DRAW)

  • Game problem vs State space problemIn game playing involving computers, one player is assumed to be the computer, while other is a human.Computer- MAX playerAim: to make the computer win the game by always making the best possible move at its turn.Lookahead at all possible moves by generating the complete game tree and then decide which move is the best for MAX.

  • Search Problem Formulationinitial stateboard, positions of pieceswhose turn is itsuccessor function (operators)list of (move, state)defines the legal moves, and the resulting statesterminal testalso called goal test determines when the game is overcalculate the resultusually win, lose, draw; sometimes a score (see below)utility or payoff function numeric value for the outcome of a game

  • Two-Person Gamesgames with two opposing playersoften called MIN and MAXusually MAX moves first, then they take turnsin game terminology, a move comprises two steps (plies)one by MAX and one by MINMAX wants a strategy to find a winning state no matter what MIN doesMIN does the sameor at least tries to prevent MAX from winningfull information both players know the full state of the environmentpartial informationone player only knows part of the environmentsome aspects may be hidden from the opponent, or from both players

  • Status labeling procedure in Game treeThe leaf nodes are labelled as WIN, LOSS, or DRAW each non-terminal node in the game tree can be labelled as WIN, LOSS, or DRAW by using the bottom-up process. Status labelling procedure: If j is a non-terminal MAX node, then STATUS (j) = WIN, if any of j's successor is a WIN = LOSS, if all j's successor are LOSS = DRAW, if any of j's successor is a DRAW and none is WIN. If j is a non-terminal MIN node, then STATUS (j) = WIN, if all j's successor are WIN = LOSS, if any of j's successor is a LOSS =DRAW, if any of j's successor is a DRAM and none is LOSS.

  • Game Tree: Example

  • Nim Game ProblemThe Game: There is a single pile of five stones and two players. Moves are made by the players alternately. In a move, each player removes either one or two stones from the pile. Player who removes the last stone loses the game.

  • Nim Game Problem

  • Bounded Look- Ahead Strategy and use of Evaluation FunctionsStatus labelling procedure requires the generation of the complete game tree.Producing a complete game tree is only possible for simple gamesWhen you go for games like chess, then you cannot apply status labelling procedure because state space is just too big.we will expand the game tree up to a certain depth, and we will use some heuristics functions to evaluate the position of the game after that many look- aheads.

  • Evaluation functionEvaluation function or static evaluator is used to evaluate the goodness of a game positionZero-sum assumption lets us use a single evaluation function to describe goodness of a board wrt both playersf(n) >> 0: position n good for me and bad for youf(n)
  • MINIMAX ProcedureThe procedure through which the scoring information travels up the game tree is called MINIMAX procedure.

  • MINIMAX Procedure

  • Minimax procedureCreate start node as a MAX node with current board configuration Expand nodes down to some depth (a.k.a. ply) of lookahead in the gameApply the evaluation function at each of the leaf nodes Back up values for each of the non-leaf nodes until a value is computed for the root nodeAt MIN nodes, the backed-up value is the minimum of the values associated with its children. At MAX nodes, the backed-up value is the maximum of the values associated with its children. Pick the operator associated with the child node whose backed-up value determined the value at the root

  • Minimax AlgorithmGenerate the game treeApply the utility function to each terminal state to get its valueUse these values to determine the utility of the nodes one level higher up in the search treeFrom bottom to topFor a max level, select the maximum value of its successorsFor a min level, select the minimum value of its successorsFrom root node select the move which leads to highest value

  • Minimax AlgorithmThis is the moveselected by minimaxStatic evaluator value

  • Tic-Tac-Toe

    e(p) = 6 - 5 = 1Initial State: Board position of 3x3 matrix with 0 and X.Operators: Putting 0s or Xs in vacant positions alternativelyTerminal test: Which determines game is overUtility function: e(p) = (No. of complete rows, columns or diagonals are still open for player ) (No. of complete rows, columns or diagonals are still open for opponent )

    X O

  • Partial Game Tree for Tic-Tac-Toef(n) = +1 if the position is a win for X.f(n) = -1 if the position is a win for O.f(n) = 0 if the position is a draw.

  • Alpha-Beta StrategyMaintain two bounds: Alpha (): a lower bound on best that the player to move can achieve Beta (): an upper bound on what the opponent can achieve Search, maintaining and Whenever higher, or higher further search at this node is irrelevant

  • How to Prune the Unnecessary PathIf beta value of any MIN node below a MAX node is less than or equal to its alpha value, then prune the path below the MIN node.

    If alpha value of any MAX node below a MIN node exceeds the beta value of the MIN node, then prune the nodes below the MAX node.

  • Alpha-beta pruningWe can improve on the performance of the minimax algorithm through alpha-beta pruningBasic idea: If you have an idea that is surely bad, don't take the time to see how truly awful it is. -- Pat Winston 271=2>=2
  • Alpha-beta pruningTraverse the search tree in depth-first order At each MAX node n, alpha(n) = maximum value found so farAt each MIN node n, beta(n) = minimum value found so farThe alpha values start at - and only increase, while beta values start at + and only decreaseBeta cutoff: Given MAX node n, cut off search below n (i.e., dont generate/examine any more of ns children) if alpha(n) >= beta(i) for some MIN node ancestor i of n. Alpha cutoff: stop searching below MIN node n if beta(n)
  • Alpha-beta general example312821413MINMAX32 - prune141 - prune

  • Alpha-beta algorithmfunction MAX-VALUE (state, , ) ;; = best MAX so far; = best MINif TERMINAL-TEST (state) then return UTILITY(state)v := -for each s in SUCCESSORS (state) do v := MAX (v, MIN-VALUE (s, , )) if v >= then return v := MAX (, v)endreturn v

    function MIN-VALUE (state, , )if TERMINAL-TEST (state) then return UTILITY(state)v := for each s in SUCCESSORS (state) do v := MIN (v, MAX-VALUE (s, , )) if v

  • Effectiveness of alpha-betaAlpha-beta is guaranteed to compute the same value for the root node as computed by minimax, with less or equal computationWorst case: no pruning, examining bd leaf nodes, where each node has b children and a d-ply search is performed Best case: examine only (2b)d/2 leaf nodes. Result is you can search twice as deep as minimax! Best case is when each players best move is the first alternative generated In Deep Blue, they found empirically that alpha-beta pruning meant that the average branching factor at each node was about 6 instead of about 35!

    ************************


Recommended