CO2301 - Games Development 1 Week 11 Search Methods

Preview:

DESCRIPTION

CO2301 - Games Development 1 Week 11 Search Methods. Gareth Bellaby. Topics. Search Methods in Traditional Games - Tower of Hanoi example Combinatorial Explosion Chess. Search Methods in Traditional Games - Tower of Hanoi example. Traditional Games. - PowerPoint PPT Presentation

Citation preview

1

CO2301 - Games Development 1Week 11

Search Methods

CO2301 - Games Development 1Week 11

Search Methods

Gareth BellabyGareth Bellaby

2

TopicsTopics

• Search Methods in Traditional Games - Tower of Hanoi example

• Combinatorial Explosion

• Chess

3

Search Methods in Traditional Games - Tower of Hanoi

example

4

Traditional GamesTraditional Games

The approach described in this lecture is not one that is used much within computer games.

Useful for games such as Chess. I've called these "traditional" games for want of a better phrase.

The approach may be applicable to certain problems in modern computer games.

5

Towers of Hanoi (1)Towers of Hanoi (1)

A simple game played with three pegs and a pile of disks of different sizes. The pegs are stacked on a peg in order of size.

• The object is to stack the disks onto a new peg.

• Only one disk may be moved at a time.

• A disk can never be placed on top of a smaller disk.

6

Towers of Hanoi (2)Towers of Hanoi (2)

7

ListsLists

The disks can be represented as numbers:

the small disk is 1

the medium sized disk is 2

the large disk is 3.

This will allow us to easily describe the rule about "A disk can never be placed on top of a smaller disk".

A useful (and common) representation of a problem is the list structure.

A empty list is given by: []

8

ListsLists

The disks on a single peg can be represented as a list. One common convention is to use square brackets for a list. The elements of the list are separated by commands. A peg with the small disk on top, the medium sized disk in the middle and the large disk on the bottom would therefore be: [1, 2, 3]

The state of all three pegs would be represented by a list of lists: [ [2,3], [1], [ ] ]

9

Towers of Hanoi (4)Towers of Hanoi (4)

[1,2,3][ ][ ]

/ \

[2,3][1][ ] [2,3][ ][1]

| |

[3][1][2] [3][2][1]

10

Towers of Hanoi (5)Towers of Hanoi (5) [1,2,3][ ][ ]

/ \

[2,3][1][ ] [2,3][ ][1]

| |

[3][1][2] [3][2][1]

| |

[3][ ][1,2] [3][1,2][ ]

| |

[ ][3][1,2] [ ][1,2][3]

| |

[1][3][2] [1][2][3]

| |

[1][2,3][ ] [1][ ][2,3]

| |

[ ][1,2,3][ ] [ ][ ][1,2,3]

11

Search trees

12

SearchesSearches

Search is a basic problem-solving technique.

Grow a tree from the start position to the goal.

13

Trees Again... Trees Again...

The Tower of Hanoi problem can be represented as a set of states.

A new state is generated by applying a rule.

The states form a tree structure.

A route through the tree to a goal state represents a solution.

Search is a basic problem-solving technique.

14

Search TreesSearch Trees

A tree is:

• A representation of a problem

• A way to solve the problem using a search technique, e.g. breadth-first search, best-first search, etc.

15

Conceptional Search & Conceptional Search & PathfindingPathfinding

Pathfinding searches a map. The map is just a representation.

A Conceptional Search searches a problem space. The space is just a representation of states within the problem.

Dijkstra's algorithm uses a graph. In other algorithms the nodes, linked together, can form a tree-like structure.

16

RulesRules

Rules are used to generate new nodes. For example, in the pathfinding exercise you used a grid and rules to move north, south, east and west.

For the Towers of Hanoi a good representation of the problem state is:

[1,2,3][ ][ ]

A rule would be "Can only remove the topmost disk" and, in this representation, this would be the leftmost number in the list.

17

SearchSearch

A state space (or problem space) represents a problem.

Indeed the full tree represents the whole of the problem in every possible permutation.

A state space is a graph whose nodes correspond to problem situations. A given problem is a path in this graph.

18

Search Tree (Graph)Search Tree (Graph)

The nodes, linked together, form a tree-like structure.

The whole tree is described as the search state (or problem state)

Lots of generate and search techniques have been developed.

19

Search Tree (Graph)Search Tree (Graph)

• Nodes correspond to situations, e.g. a node represents a move, or position, in a game.

• A link (or arc) between nodes represents a legitimate move, or action, according to the rules.

20

Search Tree (Graph)Search Tree (Graph)

A specific problem is defined by:

• state space

• start node (root node)

• goal condition (may be more than one node)

21

Evaluation FunctionEvaluation Function

The Tower of Hanoi problem was represented using lists. Lists are a commonly used technique in AI for representing a problem state.

Another common technique is to describe a problem using a number.

A number is an evaluation of a state, e.g. a node (a move or position) in a game.

Numbers are useful because they mean that states can be compared with one another.

22

Combinatorial Explosion

23

Combinatorial ExplosionCombinatorial Explosion

• Combinatorial Explosion:

• A rapid increase in the amount of possible outcomes due to the large number of combinations.

• Towers of Hanoi is a simple problem, but most problems are far more complex.

• A directed search is used to overcome the problem of combinatorial explosion. A heuristic is used to guide the search and hopefully remove the need to evaluate every possible permutation of the problem.

24

Travelling Salesman (1)Travelling Salesman (1)

• An example of combinatorial explosion.

• Plan the quickest route for a salesman visiting different cities.

• Initially appears a simple problem.

25

Travelling Salesman (2)Travelling Salesman (2)

nottinghamnottingham

leicesterleicester

derbyderby

15151515

37373737

20202020

26

Travelling Salesman (3)Travelling Salesman (3)

nottinghamnottingham

leicesterleicester

derbyderby

sheffieldsheffield

15151515

30303030

37373737

18181818

20202020

40404040

27

Chess

28

ChessChess

• Consider chess. How would you:

• Build a chess game?

• Represent a move?

• What are the rules?

• Create an evaluation function?

• Wwhat are the characteristics of the game of chess?

• The same approach as solving the Tower of Hanoi problem

• Each node of the tree represents one move (or position) in the game

• Each layer of the tree is all of the moves either Black or White could take that turn

29

ChessChess and Combinatorial and Combinatorial ExplosionExplosion

Average number of moves in a single turn of chess is 35.

The number of moves in an average game is around 50 for each player.

Therefore, full evaluation of a game requires 35100 moves

30

HeuristicsHeuristics

Heuristics can be used to guide search.

 

• non-heuristic: blind search

• heuristic: directed search

 

Chess heuristic: put pawns into the center squares.

Employ a search algorithm.

31

ChessChess

• 2-player game

• Perfect information

• Certain outcomes, e.g. success and failure clearly defined for the game and for a move.

• What about computer games?

32

Computer GamesComputer Games

• n-player games. This does not mean that there are necessarily lots of people playing the game but that lots of units or NPCs are moving at the same time (contrast to one piece moving in Chess or Draughts).

• Imperfect information - outcomes are unpredicatable.

• Success and failure may not be clearly defined for the game or an instance within the game (The player has cleared an area of enemies but how much life and ammo has been lost?).

Recommended