computer go - university of tamperetp54752/pres/game-algorithms/go_alg.pdf · " computer go...

21
Computer Go Timo Poranen Department of Computer Sciences, University of Tampere February 26, 2004 , and Go boards 1

Upload: duongkhanh

Post on 14-Jul-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Computer Go

Timo Poranen

Department of Computer Sciences, University of Tampere

February 26, 2004

�� � � � � � � � � � � � � � � � � ��� � �� � � � � � � � � � � � � � � ��� � � � �� � � � � � � � � � � � � ��� � � � � � � � � � � � � � �� � � ��� � � � � � � � � � � � � � � � � ��� �� � � � � � � � � � � � � � �� � ��� � � � � � � � � � � � � � � � � ��� � � � � � � � � � � � � � � � � ��� � � � � � � � � � � � � � � � � ��� � � � � � � � � � � � � � �� � � ��� � � � � � � � � � � � � � � � � ��� � � � � � � � � � � � � � � � � ��� � � � � � � � � � � � � � � � � ��� �� � � � � � � � � � � � � �� �� � ��� � � � � � � � � � � � � � �� �� � ��� � �� � � � � � � � � � � � � �� � ��� � � � �� � � � � � � � � � �� � � ��� � �� � � � � � � � � � � � � � � ��� � � � � � � � � � � � � � � � � ��� � � � � � � � � � � ��� � � � � � � � � � � ��� � � � � � � � � � � ��� � � � � � � � � � � ��� � � � � � � � � � � ��� � � � � � � � � � � ��� � � � � � � � � � � ��� � � � � � � � � � � ��� � � � � � � � � � � ��� � � � � � � � � � � ��� � � � � � � � � � � ��� � � � � � � � � � � ��� � � � � � � � � � � �

�� � � � � � � ��� � � � � � � ��� � � � � � � ��� � � � � � � ��� � � � � � � ��� � � � � � � ��� � � � � � � ��� � � � � � � ��� � � � � � � �

� � � � , � ! � ! and � � Go boards

1

Page 2: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Presentation structure (26.2.2004)

" History

" Rules (liberties, eyes, ko-rule, blocks...)

" Computer Go

– Computational complexity

– Why is Go difficult game for computers?

– Global move generation

– Single and multiple goal move generation

– Modelling and representing Go knowledge

" Further reading

2

Page 3: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

History of Go

" Go is an ancient game originated in China

" The game was invented more than !# # # years a go

" Go’s legendary history is that it was used as a teaching tool, when an ancient

Chinese Emperor designed the game for his son, who he thinks needs to

learn discipline, concentration, and balance. The son goes on to become the

first great player, a good emperor, and a balanced human being

" The Chinese call the game Weigi, Korean Baduk and Japanese Igo

" The game has always been popular in China, Japan and Korea, and now it is

also getting popular in Europe and American countries

– Internet, computational complexity, other games are more or less “solved”

– In a game between players of unequal skills, handicaps can be used: the

weaker player starts out with a number of stones on the board

3

Page 4: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Go rules

" Two players, black and white, take turns placing a piece (called a ”stone”) on

(empty) intersections of a 19 by 19 grid (board). Black goes first. Once

played, a stone is not moved on the board

" When a stone or a connected group of stones is surrounded by opponent

stones, so that it is not adjacent to any empty intersections (liberties) any

more, it is ”captured” and removed from the board. Stones are connected by

the board’s grid lines, not diagonally

" A player may not play a stone at a particular point if doing so would recreate

the previous board position (Ko rule)

" A player should pass when no more productive moves can be made. Two

consecutive passes ends a game; after that, the players count scores

" The score of a player is the total number of captured opponent’s stones and

the number of intersections in the area that he controls. The player with the

higher score wins

4

Page 5: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Blocks and liberties

" A block is a set of connected stones of the same color (two stones are

connected if they are in horizontally or vertically adjacent intersections)

" A liberty is an empty point adjacent to a block of stones

" The capturing rule states that a block of stones of one color that have been

completely surrounded by the opponent (the number of liberties is# ) are

removed from the board

" The capturing player increases he’s score by the number of removed stones

�� � � � ��� � �$ � ��� �$ �% �$ ��� �$ �% �$ ��� � �'& � ��� � � � ��� � � � ��� � �$ � ��� �$ � �$ ��� �$ � �$ ��� � �� � ��� � � � �

�� � � � ��� � �$ � ��� �$ �% �$ ��� �$ �% �$ ��� �'& �( �') ��� � * + � �

White’s block with one liberty, black captures white’s stones, white creates more

liberties

5

Page 6: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Suicide and Eyes

" Making a move that causes your stones to have no liberties is known as

suicide

" Suicides are forbidden!

" A block of stones can be permanently secured by creating two or more safe

liberties, called eyes� � � � � � � �� � �% �% �% �% �% �� � �% �$ �$ �$ �% �� � �% �$ � �$ �% �� � �% �$ �$ �$ �% �� � �% �$ � �$ �% �� � �% �$ �$ �$ �% �� � * % * % * % * % * % �

Black’s block is alive since it has two eyes

6

Page 7: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Ko-rule

" A “suicide” move is allowed, if it creates immedialitely liberties for the stone

�� � � � � � ��� �% �% �% �% �% ��� �% �$ �$ �$ �% ��� �% �$ �'& �$ �% ��� �% �$ �$ �$ �% ��� �% �$ �$ �$ �% ��� �% �$ �$ �$ �% ��� * % * % * % * % * % �� � � � � � � �� � �% �% �% �% �% �� � �% �$ �$ �$ �% �� � �% �$ �( �$ �% �� � �% �$ �$ �$ �% �� � �% �$ �$ �$ �% �� � �% �$ �$ �$ �% �� � * % * % * % * % * % ��� � � � � � ��� �% �% �% �% �% ��� �% � � � �% ��� �% � �( � �% ��� �% � � � �% ��� �% � � � �% ��� �% � � � �% ��� * % * % * % * % * % �

Black’s block has only one eye, white plays to ’a’ and creates liberties

" This may lead to an infinite loop...

� � � � � �� � �$ �% � �� �$ �% �'& �% �� � �$ �% � �� � � � � �� � � � � �� � �$ �% � �� �$ � + �� �% �� � �$ �% � �� � � � � �� � � � � �� � �$ �% � �� �$ � �') �% �� � �$ �% � �� � � � � �

" Ko rule: white has to wait one turn before he can take back the ko

7

Page 8: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Territory

" The objective of Go is to obtain more territory than your opponent

" A territory is an area surrounded and controlled by one player. The territory

may contain dead opponent’s stones (if the stones are known to be dead,

they can be removed and counted when the game ends)

" It might be sometimes hard to recognize the player who controls a territory

�� � � � � � �,% �% �% �% �% �% �% �,$ �$ �$ �$ �$ �$ �% ��� � � � �$ �% ��� � � � * $ * % �

�� � � � � � �,% �% �% �% �% �% �% �,$ �$ �$ �$ �$ �$ �% �,- �. �( �/ � �$ �% �01 * 2 � * 3 * 4 * $ * % �� � � � � � � �,% �% �% �% �% �% �% �,$ �$ �$ �$ �$ �$ �% �,- �. �( �/ � �$ �% �� * 2 � * 3 * 4 * $ * % �

" Black’s territory contains �# points. White does not have counter-play

possibilities inside the territory...

" After white’s attack, black has still �# points: � captured stone, ! “prisoners”

(stones � , ! and 5 ) and 6 points in the territory

8

Page 9: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Too big territory

" If a player tries to have a too big territory, the opponent can try make his own

territory inside it

�� � � � � � � � � �,% �% �% �% �% �% �% �% �% �% �,$ �$ �$ �$ �$ �$ �$ �$ �$ �% ��� � � � � � � �$ �% ��� � � � � � � �$ �% ��� � � � � � � �$ �% ��� � � � � � � �$ �% ��� � � � � � � �$ �% ��� � � � � � � �$ �% ��� �( � � � � � �$ �% ��� � � � � � � �$ �% ��� � � � � � � * $ * % �

" Unsolved, living, dead and still dead blocks/territories

� � � � � � � � �� �% �% �% �% �% �% �% �� �% �$ �$ �$ �$ �$ �% �� * % * $ � � � * $ * % �� � � � � � � � �� �% �% �% �% �% �% �% �� �% �$ �$ �$ �$ �$ �% �� * % * $ � * � � * $ * % �

� � � � � � � �� �$ �$ �$ �$ �$ �$ �� �$ �% �% �% �% �$ �� �$ �% � � �% �$ �� * $ * % � � * % * $ �� � � � � � � �� �$ �$ �$ �$ �$ �$ �� �$ �% �% �% �% �$ �� �$ �% �/ � �% �$ �� * $ * % � * ( * % * $ �

9

Page 10: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Score count in the end

� � � � � 7 % 7 % 7 % �� �$ �$ �% � �% �$ �% 8$� � �% � � �% �$ �$ �,% �% � � � �% �$ � �,$ �$ �% � �$ �% �$ �% �� �$ �% �% �% �$ �% �$ �� �$ �$ � �% �$ � �$ �� �$ �% �$ �% �$ � � �� * % � * $ * $ � � � �

�� � � � 7 % 7 % 7 % 9 (� �: �: �% � �% �$ �% 8$�� �% � � �% �$ �$ 8/,% �% � � � �% �$ � �,$ �$ �% � �: �% �$ �; �� �$ �% �% �% �$ �; �$ �� �$ �$ �. �% �$ � �$ �� �$ �; �$ �% �$ � � �� * ; � * $ * $ � � � �

�� � � � 7 % 7 % 7 % 9 %�� � �% � �% �$ �% 8$�� �% � � �% �$ �$ 8$,% �% �; �; � �% �$ � �,$ �$ �% �; �; �% �$ � �,: �$ �% �% �% �$ � �$ �,: �$ �$ �% �% �$ � �$ �,: �$ � �$ �% �$ � � ��� � * $ * $ � � � �

� � � � � 7 % 7 % 7 % 9 %� � � � � �% �$ �% 8$� � � � �% �% �$ �$ 8$,% �% �; �; �% �% �$ �$ 8$,$ �$ �% �; �; �% �$ � �,: �$ �% �% �% �$ � � �,: �$ �$ �% �% �$ � � �,: �$ � �$ �% �$ � � �� � � * $ * $ � � � �

" To count the score, it is usefull to:

– Fill first neutral intersections (moves � ,< and ! )

– Move the captured stones to the opponent’s territory (marked with squares

and triangles)

– Do some groupings to make it easier to count the intersections in

controlled areas

" Black’s score is � � and white’s score is �=

10

Page 11: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Computational complexity of Go

" The search space for � � � � Go is large compared other board games. The

number of distinct board positions is !?> @ A > @ B �# > CD

" About �E < percentages of the positions are legal, but since the move history

need to be taken account, the total number of positions is extremely high!

" The total number of nodes in the game-tree is approximately �# F @ C

Solved Over champion World champion Grand master Amateur

Connect-four Checkers Chess Go ( GH G ) Go ( I GH I G )

Qubic Renju Draughts Chi. Chess

9 men’s morris Othello Bridge

Go-moku Backgammon

Awari Scrabble

11

Page 12: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Go algorithms

1 9 Dan

professional

20 Kyu 5 4 3 2 1

Go algorithms

654321 DanAmateur

15 10

" Even Go programs have advanced considerably in the last �# - � 5 years, they

can still be beaten easily even by human players of only moderate skills

" Why Go is difficult game for computers?

– Large search space

– Position evaluation is very complicated

– Quality and quantity of human knowledge

12

Page 13: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Shicho (ladder)

" Ladder is a basic capturing sequence where human can see the result upto

5# moves ahead

� � � � � �� �$ � � � �� �$ �( � � �� �% �$ � � �� �% � � � �� � �% � �% �� � � � � �

�� � 7J 7K 7L 7M ��� � � 2 �N �O � ��� � - � 1 �P �Q � �� �$ �. � 3 � 4 � � �� �$ �( �/ � � � �� �% �$ � � � � �� �% � � � � � ��� �% � �% � � ��� � � � � � �

" Since Go stones don’t move on the board once placed, it is much easier for

people to look ahead and visualize positions with many more stones on the

board, compared to chess and other games

" In chess and checkers, humans often get lost in the “combinatorial chaos”

" But in Go, amateur players can look on � 5SR < # half-moves ahead in a

complex local fight

13

Page 14: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Global move generation

" The visual nature of the game fits human perception but is hard to model in a

program

" There is no such a good evaluation functions for general positions as in Chess

" Searching methods for groups, chains, connections and blocks suggests only

locally good moves

" Also some (multiple) goal oriented searches are performed

Type of object Move generators for goals

Block escape, capture, stabilize, gain liberties

Group attack, defend, live, kill, expand, run, cut

Territory create, extend, reduce, defend, make eye, invade

" Finally bad moves are filtered out (tactically dubious moves, moves inside

opponent’s territory, moves that continue to expand a dead group)

14

Page 15: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Modelling and representing Go knowledge: patterns

" Patterns are a simple and powerfull way of encoding Go knowledge

�� � � � � � � � ��� � �% � � � � � ��� �$ � � �% � � �% ��� � �$ � � � � � ��� � � � � � � � ��� � �$ � � � � � ��� � � � � � � � ��� � � � � � � � � � � � � � � � � ��� � �% � � � � � � � � � � � � � � ��� �$ � � �% � � �% � � � � � � � � �% ��� � �$ � � � � � � � � �% � � � � � ��� � � � � � � � � � � � � � � � � ��� � �$ � � � � � � � � � � �% � � �% ��� � � � � � � � � � � � � � � � � ��� � � � � � � � � � � � � � � � � ��� � � � � � � � � � � � � � �$ � � ��� �$ � � � � � � � � � � � � � � � ��� � � � � � � � � � � � � � � �$ � ��� � � � � � � � � � � � � � � � � ��� � � � � � � � � � � � � � � � � ��� � � � � � � � � � � � � � � �$ � ��� �$ � � � � � � � � � � � � � � � ��� � � � � � � � � � � � �% � �% � �$ ��� � �$ � � �$ � � �% � � � � � � �% � ��� � � � � � � � � � � � � � � � � ��� � � � � � � � � � � � � � � � � �

" Patterns can be used in opening, midgame and endgame positions

" Each pattern can appear in the board up to � 6 different ways

" To recognize patterns filtering techinques are used: hash tables and tries

15

Page 16: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Definitions of patterns

" A pattern used in a Go pogram typically consists of three parts

– The pattern map indicates which points belong to a pattern, and which

state among TSU V WYX Z[]\ ^_` a [cb de Xf g each point in the pattern is

allowed to have. It is useful to distinguish between corner, edge and

center patterns because this affects the validity of many patters

– The pattern context specifies additional non-local constraints that an

overall board position much satisfy (for example, the total liberty count)

– The pattern information contains knowledge which can be applied if the

pattern mathes (for example, locally good or bad moves)

" A typical midgame position produces about 5# # mathces from a database of

!# # # standard patters

16

Page 17: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Stuctured representation of the game position: blocks and connections

" To obtain a high level description of the game positions, a hierarhical

representation is constructed: blocks, connections, chains, territories, groups

" Blocks

– number of stones, liberties, connections and references to larger

structures such as territories that contain the block.

" A connection is an empty place which connects two or more blocks

– Is it possible to connect blocks?

" A divider is a place which stops opponent’s connection from one side to

another (a dual concept of connectios)

� � � � �� �% �$ � �� �% �$ �ih �� �% �ih �$ �� � � � �� � � � �� �% �$ � �� �% �$ �ih �� �% �% �$ �� � � � �

� � � � � �� �$ �ih �ih � �� � �ih �ih �$ �� � � � � �

� � � � � � � � �� �$ �ih �ih �ih �ih �ih �$ �� � � � � � � � �

17

Page 18: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Stuctured representation of the game position: chains and surrounded

areas

" A chain is a set of blocks joined by pairwise independent connections

" Recognizing board regions surrounded by a single player is of fundamental

importance in Go

" A possible territory can be found by detecting contiguous areas of very high

influence, or by finding boundaries consisting of blocks, connections, and

dividers

� � � � � � � �� �$ �$ �$ � �$ �$ �� � � � �$ � � �� �$ � � �$ � � �� �$ � � �$ � � �� � � � � � � �� � � � � � � �

�� � � � � � � � � �,h �ih �% � � � � � � � ��� �ih � � � � � � � ��� � �% �ih �ih �% �ih �ih �% ��� � �ih � � � � � �ih ��� � * h � � � � � * h �

18

Page 19: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Stuctured representation of the game position: Groups

" A Group is a loosely connected set of blocks (chains) of the same color

�� � 7kj 7kj 7kj � � � � � � � 7ml 7ml 7ml 7ml 7ml 9cl�� � �$ �j �j � � � � � � � �l �l �l �l �l 8l�� � �j �j �$ � � � � � � � �$ �l �l �l �l 8l� �kn � �% �kn �kn � � � � � � � � �l �$ �l �$ 8l,n �kn �kn �kn �kn �kn �% � � � � � � � � � � � �,n �kn �% � �kn � � � � � � � � � �% �ko �% �ko 8po�� � � � � � � � � � � � � � �ko �ko �ko 8po�� � � � � � � � � � � � � � �ko �ko �ko 8po�� � � � � � � � � � � � � � �ko �ko �ko 8po�� � � � � � � � � � � � � � �% �ko �ko 8po�� � � � � � � � � � � � � � �ko �ko �ko 8po�� � � � � � � � � � � � � � �ko �ko �ko 8po�� � � � � � � � � � � � � � �ko �ko �ko 8po,cq � q �% � � � � � � � � � � � � �% �% �ko 8po,cq � q � q � q� � � � � � � � � � � �% �$ �mr 8cr� � q� �% � � � � � � � � � � �$ �mr �$ �mr 8cr�� � �ms �ms �$ � � � � � � � �mr �mr �$ �mr �mr 8cr�� � �$ �ms �ms � � � � � � � � �mr �mr �mr �mr 8cr�� � * s * s * s � � � � � � � � * r * r * r * rt r

" Go programs recognize groups as contiguous regions of certain minimum

influence, by an iterative growing or shrinking process, by other distance

measures, or using potential connections and dividers

19

Page 20: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Go on small boards and goals for Go research

" The largest square board which is solved completely is= =

– 5 5 should be controlled totally by the first player

– u u is believed to be a � points win for Black

" Develop a search-bound Go program (currently there is no clear correlation

between deeper search depth and playing strenght)

" Sure-win program for high handicaps

" Develop local and global analysis methods

" Develop pattern learning and recognizion methods

" Win the million dollar prize for a first professional level Go program (The Ing

Foundation)

20

Page 21: Computer Go - University of Tamperetp54752/pres/game-algorithms/go_alg.pdf · " Computer Go – Computational complexity – Why is Go difficult game for computers? ... " The Chinese

Go resources

" Martin Muller: Computer Go. Artificial Intelligence, 134(2002) 145-179

http://www.sciencedirect.com/

" Werf et al.: Solving Go on small boards. ICGA Journal, 26 (2003) 92-107

http://www.cs.unimaas.nl/icga/

" Free Go engine for Linux and Windows: GnuGo

(http://www.gnu.org/software/gnugo/gnugo.html) and

Go viewer for Linux

(http://www.igoweb.org/˜wms/comp/cgoban/)

" Many commercial programs: Many faces Go, Handtalk, Go4++, KCC Igo...

21