Docsity

Introduction to Artificial Intelligence: Game-Playing, Slides of Introduction to Computing

Partial preview of the text

Download Introduction to Artificial Intelligence: Game-Playing and more Slides Introduction to Computing in PDF only on Docsity!

Game-playing

Part 1

CS613 INTRODUCTION TO

ARTIFICIAL INTELLIGENCE

Games: Outline of Unit

Part I (this set of slides)

 Motivation

 Game Trees

 Evaluation Functions

Part II

 The Minimax Rule

 Alpha-Beta Pruning

 Game-playing AI successes

Game Playing: Adversarial Search

Introduction

Different kinds of games:

Chess, Checkers Go, Othello

Backgammon, Monopoly

Battleship Bridge, Poker,Scrabble,

Deterministic Chance

Perfect Information

Imperfect

Information

 Games with perfect information. No randomness is involved.

 Games with imperfect information. Random factors are part of the game.

Game Playing: Adversarial Search

Searching in a two player game

 Traditional (single agent) search methods only consider how close the agent is to the goal state (e.g. best first search).

 In two player games, decisions of both agents have to be taken into account: a decision made by one agent will affect the resulting search space that the other agent would need to explore.

 Question: Do we have randomness here since the decision made by the opponent is NOT known in advance?

  No. Not if all the moves or choices that the opponent can make are finite and can be known in advance.

Partial game tree for Tic-Tac-Toe

  • Each level of search nodes in the tree corresponds to all possible board configurations for a particular player MAX or MIN.
  • Utility values found at the end can be returned back to their parent nodes.

Idea : MAX chooses the board with the max utility value, MIN the minimum.

The Simple Case

Chess, checkers, go, Mancala, Tic-Tac-Toe,

Othello, Nim, …

Two players alternate moves

Zero-sum: one player’s loss is another’s gain

Perfect Information: each player knows the entire

game state

Deterministic: no element of chance

Clear set of legal moves

Well-defined outcomes (e.g. win, lose, draw)

Game setup

Two players: A and B

A moves first and they take turns until the game is over. Winner gets award, loser gets penalty.

Games as search:

  • Initial state: e.g. board configuration of chess
  • Successor function: list of (move,state) pairs specifying legal moves.
  • Terminal test: Is the game finished?
  • Utility function: Gives numerical value of terminal states. E.g. win (+1), lose (-1) and draw (0) in tic-tac-toe

A uses search tree to determine next move.

How to Play a Game by Searching

General Scheme

  • Consider all legal moves, each of which will lead to some new state of the environment (‘board position’)
  • Evaluate each possible resulting board position
  • Pick the move which leads to the best board position.
  • Wait for your opponent’s move, then repeat.

Key problems

  • Representing the ‘board’
  • Representing legal next boards
  • Evaluating positions
  • Looking ahead

Hexapawn: A very Simple Game

Hexapawn is played on a chessboard cut down to

3x3 squares. A player can

  • move a pawn directly forward one square onto an empty square or
  • move a pawn diagonally forward one square, provided that square contains an opponents pawn. The opponents pawn is removed from the board.

A player P 1 wins the game agains P 2 when:

  • One of P 1 ’s pawns reaches the far side of the board.
  • P 2 cannot move because no legal move is possible.
  • P 2 has no pawns left.

Hexapawn: Three Possible First Moves

     

     

     

  

  

White moves

MAX & MIN Nodes

When I move, I attempt to MAXimize my performance.

When my opponent moves, he or she attempts to MINimize my performance. TO REPRESENT THIS:

If we move first, label the root MAX; if our opponent does, label it MIN.

Alternate labels for each successive tree level.

  • if the root (level 0) is our turn (MAX), all even levels will represent turns for us (MAX), and all odd ones turns for our opponent (MIN).

Evaluation functions

Evaluations how good a ‘board position’ is

  • Based on static features of that board alone

Zero-sum assumption lets us use one function to

describe goodness for both players.

  • f(n)>0 if we are winning in position n
  • f(n)=0 if position n is tied
  • f(n)<0 if our opponent is winning in position n

Build using expert knowledge,

  • Tic-tac-toe: f(n)=(# of 3 lengths open for me)
    • (# open for you)

A Partial Game Tree for Tic-Tac-Toe

f(n)=6-4=

f(n)=6-6=

f(n)=4-4=

f(n)=4-3=1 (^) f(n)=4-3=1 f(n)=4-2=

  • ∞ 0 + ∞

f(n)=2 f(n)=2 f(n)=2 f(n)=2 f(n)=2 f(n)=2 f(n)=2 f(n)=

f(n)=0 f(n)=

f(n)=# of potential three-lines for X –

of potential three-line for Y if n is

not terminal f(n)=0 if n is a terminal tie f(n)=+ ∞ if n is a terminal win f(n)=- ∞ if n is a terminal loss