41
COMP4031 Artificial Intelligence for Games and Puzzles 1 The Shape of a Game Tree Fragment •Standard - is an algorithm which performs the same computation as minimax for a given tree - avoiding generating useless parts of that tree. •Quiescence Search can be seen as a method for defining the shape of a tree by means other than truncating it at a fixed depth. •Quiescence Search can be used as an evaluation function at the leaves of an - search (or any other for that matter, even itself: Second Order Quiescence). •It allows further search to be used as if it were a static evaluation function. •Null-Move Quiescence Search generates at least a fringe of null- moves one ply beyond the normal fixed depth of the tree (though null moves are very cheap)

COMP4031Artificial Intelligence for Games and Puzzles1 The Shape of a Game Tree Fragment Standard - is an algorithm which performs the same computation

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

COMP4031 Artificial Intelligence for Games and Puzzles 1

The Shape of a Game Tree Fragment

•Standard - is an algorithm which performs the same computation as minimax for a given tree - avoiding generating useless parts of that tree.

•Quiescence Search can be seen as a method for defining the shape of a tree by means other than truncating it at a fixed depth.

•Quiescence Search can be used as an evaluation function at the leaves of an - search (or any other for that matter, even itself: Second Order Quiescence).

•It allows further search to be used as if it were a static evaluation function.

•Null-Move Quiescence Search generates at least a fringe of null-moves one ply beyond the normal fixed depth of the tree (though null moves are very cheap)

COMP4031 Artificial Intelligence for Games and Puzzles 2

Null Move Quiescence as an Evaluation Function

NMQuiesce (real lower, real upper) /* initially -, + */

{real Temp, Best;

makenull();

Score:= - realevaluationfunction( - upper, - lower)

unmakenull();

for every move M

{if Score>=upper then Return Score;

makemove(M);

Temp:= - NMQuiesce( - upper, - best);

unmakemove();

Score:=Max(Score,Temp)}

Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 3

Animation of Null-Move Quiescence Search

Nodes in search tree generally have six attributes:

After consideration of a node is complete, collapse it to:

Integers, not reals, will be used for simplicity.

Whose Move Lower bound Upper bound

Value Produced Best Value Temporary Value

Whose Move

Value Produced

COMP4031 Artificial Intelligence for Games and Puzzles 4

What is the value of the position?

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

W - +

COMP4031 Artificial Intelligence for Games and Puzzles 5

Generate null move

W - +

B - +

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 6

Generate null move and evaluate it

W - +

B - +

+0

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 7

Use that evaluation

W - +

-0

B

+0

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 8

Since 0 < +, generate 1st real move

W - +

-0

B

+0

B - 0

K-h3

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 9

Start with null move

W - +

-0

B

+0

B - 0

K-h3

W 0 +

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 10

Statically evaluate

W - +

-0

B

+0

B - 0

K-h3

W 0 +

0

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 11

Use that evaluation

W - +

-0

B

+0

B - 0

0

K-h3

W

0

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 12

Since “best 0” <= “upper 0”,

W - +

-0

B

+0

B - 0

0

K-h3

W

0

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 13

Since “best 0” <= “upper 0”, immediately return 0

W - +

-0 0

B

+0

B

0

W

0

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 14

0 = 0, and 0 < +, so generate next move available

W - +

-0 0

B

+0

B

0

W

0

B - 0NxP

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 15

Obtain null-move evaluation

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1

NxP

W

+1

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 16

Since “upper 0” > “best -1”, try 1st move

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1

NxP

W

+1

W 0 +1

K-g7

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 17

Obtain null-move evaluation

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1

NxP

W

+1

W 0 +1

+1

K-g7

B

-1

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 18

Now “best +1” >= “upper +1”,

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1

NxP

W

+1

W 0 +1

+1

K-g7

B

-1

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 19

Now “best +1” >= “upper +1”, so return value +1

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1 +1

NxP

W

+1

W

+1

K-g7

B

-1

NMQuiesce (real lower, real upper) {real Temp, Best; makenull(); Score:= - realevaluationfunction( - upper, - lower) unmakenull(); for every move M {if Score>=upper then Return Score; makemove(M); Temp:= - NMQuiesce( - upper, - best); unmakemove(); Score:=Max(Score,Temp)} Return Score}

COMP4031 Artificial Intelligence for Games and Puzzles 20

Try another move

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1 +1

NxP

W

+1

W

+1

B

-1

W 0 +1

BxN

COMP4031 Artificial Intelligence for Games and Puzzles 21

Null move evaluation

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1 +1

NxP

W

+1

W

+1

B

-1

W 0 +1

-2

BxN

B

+2

COMP4031 Artificial Intelligence for Games and Puzzles 22

“best -2” < “upper +1”, so off again …

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1 +1

NxP

W

+1

W

+1

B

-1

W 0 +1

-2

BxN

B

+2

COMP4031 Artificial Intelligence for Games and Puzzles 23

Try a move

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1 +1

NxP

W

+1

W

+1

B

-1

W 0 +1

-2

BxN

B

+2

B -1 +2K-h3

COMP4031 Artificial Intelligence for Games and Puzzles 24

Use null move evaluation, test, return

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1 +1

NxP

W

+1

W

+1

B

-1

W 0 +1

-2

BxN

B

+2

B -1 +2

+2 +2

K-h3

W

-2

COMP4031 Artificial Intelligence for Games and Puzzles 25

Try another move

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1 +1

NxP

W

+1

W

+1

B

-1

W 0 +1

-2 -2

BxN

B

+2

B

+2

W

-2

B

+2

P-f4

W

-2

COMP4031 Artificial Intelligence for Games and Puzzles 26

Try all moves in turn

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1 +1

NxP

W

+1

W

+1

B

-1

W 0 +1

-2 -2

BxN

B

+2

B

+2

W

-2

B

+2

K-g1

W

-2

B

+2

W

-2

COMP4031 Artificial Intelligence for Games and Puzzles 27

Eventually settling on a value

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1 +1

NxP

W

+1

W

+1

B

-1

W 0 +1

-2 -2 -2

BxN

B

+2

B

+2

W

-2

B

+2

K-g1

W

-2

B

+2

W

-2

COMP4031 Artificial Intelligence for Games and Puzzles 28

.. Which is returned

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1 +2

NxP

W

+1

W

+1

B

-1

W

-2

BxN

B

+2

B

+2

W

-2

B

+2

K-g1

W

-2

B

+2

W

-2

COMP4031 Artificial Intelligence for Games and Puzzles 29

.. Which is returned, compared

W - +

-0 0

B

+0

B

0

W

0

B - 0

-1 +2

NxP

W

+1

W

+1

B

-1

W

-2

BxN

B

+2

B

+2

W

-2

B

+2

K-g1

W

-2

B

+2

W

-2

COMP4031 Artificial Intelligence for Games and Puzzles 30

.. Which is returned, compared, found to be better

W - +

-0 0

B

+0

B

0

W

0

B - 0

+2 +2

NxP

W

+1

W

+1

B

-1

W

-2

BxN

B

+2

B

+2

W

-2

B

+2

K-g1

W

-2

B

+2

W

-2

COMP4031 Artificial Intelligence for Games and Puzzles 31

All other black moves are considered, (null not shown)

W - +

-0 0

B

+0

B

0

W

0

B - 0

+2 +2

NxP

W

+1

W

+1

B

-1

W

-2

B-a3

B

+2

B

+2

W

-2

B

+2

W

-2

B

+2

W

-2

W - +

0 -2

COMP4031 Artificial Intelligence for Games and Puzzles 32

Eventually determining a value

W - +

-0 -2

B

+0

B

0

W

0

B

+2

NxP

W

+1

W

+1

B

-1

W

-2

B-a3

B

+2

B

+2

W

-2

B

+2

W

-2

B

+2

W

-2

W

-2

COMP4031 Artificial Intelligence for Games and Puzzles 33

Demonstrating that that capture is not good

W - +

-0 -2

B

+0

B

0

W

0

B

+2

W

+1

W

+1

B

-1

W

-2

B

+2

B

+2

W

-2

B

+2

W

-2

B

+2

W

-2

W

-2

COMP4031 Artificial Intelligence for Games and Puzzles 34

Other moves are considered (null again not shown)

W - +

-0 0

B

+0

B

0

W

0

B - 0

+2 +2 +2

W

+1

W

+1

B

-1

W

-2

B

+2

B

+2

W

-2

B

+2

W

-2

B

+2

W

-2

W

-2

B - 0

0 0

N-c3

COMP4031 Artificial Intelligence for Games and Puzzles 35

Eventually determining a value for the initial position

W - +

0 -0 0

B

+0

B

0

W

0

B - 0

+2 +2 +2

W

+1

W

+1

B

-1

W

-2

B

+2

B

+2

W

-2

B

+2

W

-2

B

+2

W

-2

W

-2

B

0

N-c3

COMP4031 Artificial Intelligence for Games and Puzzles 36

Null-Move values as bounds

The value determined for every node arises originally as the result of an evaluation of a null move.

These evaluations - assuming the position is not zugzwang - are properly thought of as providing (lower) bounds on the value of a position. (Not to be confused with alpha and beta - achievable and hope - which are bounds on the range of values one is interested in exploring.)

•“The value of this position is at least N” is more reliable than

•“The value of this position is N”

The value of the topmost node arises not from one evaluation providing one bound, but from two or more opposing evaluations providing touching bounds.

COMP4031 Artificial Intelligence for Games and Puzzles 37

Touching bounds

The smallest possible tree for null-move quiescence:

+4

-4-4

+4

COMP4031 Artificial Intelligence for Games and Puzzles 38

Quiescence as Evaluation

The sort of evaluation performed by QUIESCE is to be performed at every leaf node of a MINIMAX (or AlphaBeta) search.

COMP4031 Artificial Intelligence for Games and Puzzles 39

Second Order Quiescence

Since Quiescence Search can be regarded as an evaluation function, it can be used as such within another quiescence search: wherever the main quiescence search generates and evaluates a null move, that evaluation is performed using quiescence search with the real evaluation function.

COMP4031 Artificial Intelligence for Games and Puzzles 40

Evaluations that produce bounds on values

Null moves may be regarded as producing a lower bound on a position’s value.

A quiescence search that is terminated early - for example, by being restricted in terms of the depth of tree it may build or the number of nodes it may generate - may produce a “fat value” - a combination of

•A reliable lower bound (assuming no zugzwang)

•A reliable upper bound (assuming no zugzwang)

•Possibly, an unreliable value in between

Fat values may also be produced by other means, for instance a pairing of a pessimistic evaluation function and an optimistic one.

Some search algorithms, eg Berliner’s B* algorithm, work with value ranges rather than point values. More on B* another day …

COMP4031 Artificial Intelligence for Games and Puzzles 41

Bounds on values of interest to a search

The AlphaBeta tree search algorithm uses its parameters (achievable) and (hope) to cut off search of parts of the game tree which cannot affect the minimaxed value ultimately found at the root. Once it is determined that a subtree’s value falls outside certain bounds, it can be abandoned.

Conventionally, AlphaBeta is started off (at a root node) in an agnostic manner: =- and =+ corresponds to having no idea what the value of the position is.

Some interesting algorithms use an AlphaBeta search with different and : using a narrower search window in the expectation of getting more cutoffs.

•Aspiration Search

•NegaScout & PVS (Principal Variation Search)

•Scout

•MTD(f)