1. Trang chủ
  2. » Công Nghệ Thông Tin

Báo cáo Đồ Án Trí tuệ Nhân tạo tiếng Anh Game Caro

5 219 1
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 384,08 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Alpha-beta pruning is the optimization algorithm reduces computation time by seeking to decrease the number of nodes by cutting off branches which are not necessary to search because t

Trang 1

Developing Gomoku chess based on Minimax

algorithm

1 st Pham Dang Khoa

Department of Computer Science

Vietnam National University – Ho

Chi Minh City

University of information

Technology

18520930@gm.uit.edu.vn

2 nd Nguyen Hoang Quan

Department of Computer Science

Vietnam National University – Ho

Chi Minh City University of information Technology 17520936@gm.uit.edu.vn

3 rd Le Viet Trung

Department of Computer Science

Vietnam National University – Ho

Chi Minh City University of information Technology 17521173@gm.uit.edu.vn

Abstract— We proposed to develop a new

version of Gomoku chess game based on the idea

of Minimax algorithm as well as Alpha-Beta

Pruning Minimax is one of backtracking

algorithms that is widely applied in making

decision to search the optimal move for player, in

case that its enemy makes the optimal step too

Alpha-beta pruning is the optimization algorithm

reduces computation time by seeking to decrease

the number of nodes by cutting off branches which

are not necessary to search because there has

already been a better move in next steps In this

project, we will implement it by C# with Visual

Studio tool, NET framework, Windows Forms

library In this version, we are planning to build a

truly-sized game board and integrate some

functions depending on player's demand: give the

right to choose difficulty, undo your moves, etc.

Keywords—Minimax, Alpha-Beta Pruning,

optimization, backtracking algorithm (key words)

I I NTRODUCTION

Long time ago, searching was always a

fundamental manipulation for several tasks The main

purpose of searching is to find to optimal way to collect

the necessary information for an important decision

Generally, searching can be implied that it is the

method to find one or more objects which are

satisfactory at any requirements in a large set of

objects

We can see many problems of searching in real life

For example, some games such as Gomoku chess –

also called Caro, among many probable moves, we

must find the best one that can lead to winning position

Minimax is the specialized search algorithm to

return a series of optimal moves for a player in a

zero-sum game [1] A zero-zero-sum game is a game where the

total value of the outcome of winner is fixed Whichever

side wins (+1) finally makes the other components lose

(-1), which corresponds to a pure competitive situation,

eventually leading to a total (+ 1- 1) = 0 Our game,

Gomoku chess, is also a zero-sum game because

there is never a situation that both of two players have

a draw result Consequently, Minimax is a technique

whose purpose is to minimize the possible loss in a

worst case, and to maximize the minimum gain when

dealing with gains The Minimax algorithm helps find

the best move, by going backwards from the end of the game At each step, it will estimate that Player A is trying to maximize A's winning chances when it is his turn, and in the next move, Player B tries to minimize the chances of Player A winning (meaning maximizing B's chances of winning)

II MINIMAX ALGORITHM

A Ideas

Two players in that game are MIN and MAX MAX is supposed to be a player who tries to obtain the winning chances In contrary, MIN is the opponent who tries to minimize MAX’s score at each move We suppose that MAX also uses the same information as MIN

First, we represent it by a game tree Each node in the tree represents a specific status The root node denotes the beginning state of the game While the leaf nodes represent an end state (win or lose) of the game

in each case If the state x is represented by the node n then the children of n represent all the resulting states

of the possible moves from state x Because the two

players alternate their moves with each other, the levels (classes) on the game tree also alternate as MAX and MIN Therefore, this game tree is also called the MIN-MAX tree In the game tree, the nodes which are respective to the state where the MAX player chooses the move will belong to the MAX class, the nodes corresponding to the state from which the MIN player selects the move will belong to the MIN class The minimax strategy is represented by the rule as follows:

If this node is leaf node, then we assign it a value to denote the winning or losing state of the players After that, we take their values to determine nodes’ values in the upper levels in the game tree followed by the rule:

 The nodes belonging to MAX class will be assigned the max value of their children

 The nodes belonging to MIN class will be assigned the min value of their children These values assigned to each state based on the above rule will indicate the value of the best state which each player expects to achieve And players will use them to choose their own proper moves When MAX player is in turn, it will choose the move corresponding

to the state with the highest value in the sub-states, and

in contrast, when MIN player is in turn, it will choose the move corresponding to the state of the price smallest value in the sub-states

XXX-X-XXXX-XXXX-X/XX/$XX.00 ©20XX IEEE

Trang 2

Figure 1: Illustration of Minimax applied in Tic

Tac Toe game – a short version of Gomoku chess

B Minimax Illustration

From the ideas mentioned above, we can

implement the Minimax algorithm as follows: First of

all, the Minimax function takes a position named

pos and returns the value of that position If the pos

position corresponds to the leaf node in the game

tree, the value which was assigned to the leaf node

is returned In contrast, we will give pos a

temporary value of -∞ or ∞ depending on the

situation that whether the pos is the MAX or MIN

node and consider the sub-positions of pos After a

child of pos has value V, we reset value = max

(value, V) if n is node MAX and value = min (value,

V) if n is node MIN When all the children of n are

considered, the temporary value of pos becomes its

value We introduce you a pseudo-code for this

algorithm:

function Minimax(pos): integer;

value, best : integer;

begin

if pos is leaf node then return eval(pos)

else begin

{Initialize temporary value for best variable}

if pos is MAX node then

best:= -INFINITY else best := INFINITY;

{genPos function generates all possible

moves from the current position named pos}

genPos(pos);

{Check all children of pos, each time that we determine one child node’s value, we must reassign the temporary value for it.}

while (we can still take a move) do

begin

pos := (The new value computed by the

previous move);

value = Minimax(pos);

if pos is MAX node then

if (value > best) then best := value;

if pos is MIN node then

if (value < best) then best := value;

end;

Minimax := best;

end;

end;

In the program, the chess board was represented by global variables Therefore, instead of

passing parameter which is a new chess called pos

into Minimax parameter, we transform the global variable by making a “trial” move After computing based on the chess board saved by global variables, the algorithm will use some procedures to remove this move

C Minimax evaluation

Minimax algorithm traverses the entire game tree by using Depth-First Search Therefore, this algorithmic complexity algorithm is directly proportional to the size

of the search space bd, where b is the branching factor

of the tree or is the legal move at each point, d is the maximum depth of the tree The number of traversed nodes is b(bd-1)/(b-1) However, the evaluation function is the most important method and only works with leaf nodes, so it is unnecessary to traverse to nodes which are not leaf nodes [8] Hence the time complexity is O (bd) The essence of this algorithm seems to be Depth-first Search, so its memory space requirements are linear only with d and b So the spatial complexity is O (bd) If the branching factor of tree is b

= 40, and the maximum depth is d = 4, then the number

of nodes need evaluating is 404 = 2560000, it is an enormous figure To solve this problem, we consider using another more effective algorithm such as Alpha-Beta Pruning

Trang 3

III A LPHA - BETA PRUNING

In this part, we will present an algorithm decreasing

the number of nodes that are evaluated It stops

evaluating one move when that move is proven to

be worse than a previously examined move

Therefore, it is unnecessary to evaluate those

moves anymore The aim of this algorithm is to

save time execution but does not influence much

on the search results, especially final decision

A Idea

The idea of an Alpha-beta search is simple:

Instead of searching the entire space until the

specific depth, Alpha-beta search proceeds in a

depth-first fashion There are two values, called

alpha and beta, that are generated during a search:

The alpha value is an initial or temporary value

associated with MAX nodes and never decreases, it

can only go up In contrast, beta value is associated

with MIN nodes and never increases, it can only go

down Initially, both players start the game with their

own worst case The searching process win end

when beta value of MIN player becomes less than

or equal to alpha value of its MAX parent nodes,

the MIN will not need to consider descendants of

this node since it is not important The same rule is

also applied for MAX player

B Alpha-Beta Illustration

Here are some core steps that demonstrate

how the algorithm works:

 If the current level is root, it sets the values

of alpha and beta to - and +,

respectively

 If it has reached search limit (leaf nodes),

then computes the static value of current

state corresponding current player and

record result

 For MIN player: it applies Alpha-Beta

procedure with current alpha and beta

values for one child node, then store its

result Next, it compares this stored value

to beta, if that result is smaller then it sets

beta to this new value These works are

repeated until all descendants have been

considered or alpha is greater or equal to

beta

 For MAX player: it applies Alpha-Beta

procedure with current alpha and beta

values for one child node, then store its

result Next, it compares this stored value

to alpha, if that result is larger then it sets

alpha to this new value These works are

also repeated until all descendants have

been considered or alpha is greater or

equal to beta

Figure 2: Alpha-Beta Algorithm

illustration

We also introduce pseudo-code for this algorithm as it is convenient to compare with Minimax

function AlphaBeta(alpha, beta, depth): integer; begin

if (depth = 0) or (pos is leaf node) then AlphaBeta := Eval { Calculate position’s value } else

begin best := -INFINITY;

Gen; { Generate all possible moves from the position called pos }

while (Still can get a move) and (best < beta) do begin

if best > Alpha then Alpha := best;

Make the move;

value := -AlphaBeta(-beta, -Alpha, depth-1); Cancel making the move;

if value > best then best := value;

end;

AlphaBeta := best;

end;

end;

C Alpha-Beta evaluation

Generally, alpha-beta algorithm helps us save

a lot of time compared to Minimax while making sure that search results have high accuracy However, this amount of savings is not stable since

it depends on the number of nodes cut In the worst case the algorithm could not cut a branch and must consider the exact number of nodes by the Minimax algorithm We need to accelerate the removal by accelerating the shrinking of the Alpha-beta search interval This interval is gradually narrowed when there is a new value that is better than the old value When facing the best fit value, this interval is narrowed the most Therefore, we need to make the leaf nodes arranged in order from high to low The better this order is, the more rapid the algorithm executes

Trang 4

D Comparsion between Minimax and Alpha-Beta

Dept

h No NodesMinimax Time Alpha-Beta Rate

s

No.

nodes

Time s

6 4096000000 40 127999 1.7 32000

7 16384000000

8 65536000000

00

40 512000

0

1.7 128000

0

As you can see, the increase in the number of

nodes when increasing the depth of Minimax is always

the branching factor b, in this case is 40 In contrary,

The number of Alpha-beta increases is much less: only

1.7 times when increasing from d odd to even 23.2

times when d is from even to odd, the average

increase is only about 6 times when d increases

The formula for calculating the number of

nodes displays that the number of nodes to consider

when using Alpha-beta is much less than that of

Minimax but it is still an exponential function and still

leads to combinatorial explosion Alpha-beta algorithm

does not completely avoid combinatorial explosion,

only lowers the explosion rate Due to this problem,

both players cannot search all possibilities Therefore,

the only method is to search only to a limited depth

and choose the move which leads to the best state for

us In the light of the enemy's ability to fight back, we

cannot use normal search algorithms A separate

search algorithm for the game tree must be used They

are the Minimax algorithm and its improvement called

Alpha-beta algorithm While both algorithms cannot

avoid combinatorial explosion, the Alpha-beta

algorithm just slows down it and; therefore; it is used

more often in chess games

IV DEMO APPLICATION

After presenting and concluding all the theories

researched, we will introduce some works that we have

made in our project

In our User Interfaces, there are game board with

the size of 20x20, UIT logo and three main function

buttons: New Game, Undo and Exit When you press

the button “New Game”, it will ask whether you or

Computer play first and the difficulty you want to

choose The “Undo” button helps you reverse your

previous move, even you can reverse more than one

moves Finally, the “Exit” button will quit the game if you

don’t want to play anymore

Here are some pictures of (UI) in our application:

V C ONCLUSION AND FUTURE WORK

In summary, we have created a Caro game for one player competing with the AI The algorithms that our group implements are Minmax and Alpha-Beta Pruning, we have evaluated the efficiency of each of them as well as given a general comparison between both of them

In spite of our efforts, it is certain that our program does not avoid some limitations, hopefully some potential problem will be further researched and developed with improved algorithms Our group considers installing Expectimax algorithm in the future and compare different evaluation functions to assess the states

R EFERENCES

Trang 5

[1] Jessica Billings (2008), The Minimax Algorithm,

CS 330

[2] Alpha-Beta pruning - Wikipedia

[3] CPSC 352 Artificial Intelligence Notes: Minimax and Alpha Beta Pruning

[4] Đỗ Trung Tuấn (1997), Trí tuệ nhân tạo, NXB Giáo

dục.

[5] Heylighen (1993), Zero sum games – Principia Cybernetica Web

Ngày đăng: 24/07/2020, 13:56

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w