**1. Introduction**

Board games are a form of intellectual confrontation invented over the course of a long history of production activities [1,2]; in addition, they are important applications that can help to explore and promote research into artificial intelligence [3]. The selection of pieces depends on a perfect evaluation function with a computation complexity of approximately *<sup>b</sup>d*, where *b* is the number of legal moves per position and *d* is the number of positions of the chessboard. Because different types of board games have different *b* and *d*, the total amount of calculations varies greatly [4,5]. The evaluation algorithms of chess programs involve various artificial intelligence (AI) techniques, including machine learning, expert systems, neural networks, search trees, etc. [6,7]. The critical jobs that most game software focuses on consist of two aspects: (1) how to define and obtain comprehensive evaluation factors; and (2) how to construct a perfect evaluation function.

The advance of AI chess can be attributed to two factors: (1) high performance computing devices [8]; and (2) powerful evaluation algorithms [9]. In recent years, with the rapid development of high-performance computing and network technologies, as long as a suitable evaluation algorithm can be constructed a computer will be able process a very large number of calculations. With the recent rapid development of high-performance computer and network technologies, as long as the evaluating algorithm is properly constructed the huge amount of computation can be handled by machines [10,11]. Because machines are accurate, fast, and not influenced by emotion, they often beat human players.

**Citation:** Han, F.; Zhou, M. Threat Matrix: A Fast Algorithm for Human–Machine Chinese Ludo Gaming. *Electronics* **2022**, *11*, 1699. https://doi.org/10.3390/ electronics11111699

Academic Editor: Krzysztof Szczypiorski

Received: 17 April 2022 Accepted: 23 May 2022 Published: 26 May 2022

**Publisher's Note:** MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

**Copyright:** © 2022 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https:// creativecommons.org/licenses/by/ 4.0/).

At present, computer players of classic board games such as chess, Go, Shogi [4], and Checkers [12] can beat expert human players. R. Ruben et al. [13] have described a general video game AI (GVGAI) that provides a way to benchmark AI algorithms for games written in specific description languages for many application domains. The continuous promotion of AI algorithms from games to reality is of grea<sup>t</sup> significance for the development of both robot swarm intelligent collaboration and gaming [14,15].

The world chess champion Garry Kasparov was defeated by IBM's Deep Blue computer, which has become a milestone in the advance of artificial intelligence over human beings. Deep Blue typically searches to a depth of between six and eight moves up to a maximum of twenty moves, or even more in certain positions [16]. This brute force type of search can benefit to a degree from advances in computer performance. However, moving from brute force to informed search is a grea<sup>t</sup> endeavour in AI board game research. A recent study by Ansk involved an idea to solve two-player zero-sum and extensive-form games [17]. They were able obtain perfect information and simultaneous moves using the Double-Oracle Method and Serialized Alpha-Beta Search. In addition, Branislav et al. [18] are devoted to developing synchronous move game algorithms and evaluating exact backward induction methods with efficient pruning and sampling algorithms under different settings. David B. and his group focus on evolutionary algorithms, while Sebastian presents a rules learning method for general game playing. Thus, this grea<sup>t</sup> endeavour requires a combination of methods from a variety of subdisciplines [19,20].

Due to the enormous search space needed for the combination of large moves, the development of a program that can beat humans at the ancient Chinese chess-like game Go has been considered as one of the last grea<sup>t</sup> challenges [21,22]. Tesauro's approach is already considered to outperforms the best human players in playing backgammon. AlphaGo [3], developed by Google DeepMind, has beaten a top professional human Go player without handicaps on a full-sized 1919 board. AlphaGo's algorithm uses a combination of machine learning and search tree techniques combined with extensive training on both human and computer play [23].

Similar to chess, Go, and backgammon, Chinese Ludo gaming, known as Aeroplan Chess, was invented in China by reference to other ancient board games to commemorate the Flying Tigers in World War II; the game's rules and paths are derived from Lufbery circles in air warfare [24]. To encourage students to master chemical equations in the game, a new flying chess game called CHEMTrans has been developed.

In recent years, many online programs for Chinese Ludo gaming have been developed. These simply provide a platform for interaction between game players, and the computer does not engage in intelligent competition [25]. Developing a human–machine Chinese Ludo gambling game, while an attractive idea, represents a highly challenging task. Apart from the high randomness of the dice rolling, the algorithm must ensure that the machine is smarter than humans in order to guarantee that the owner of the game machines makes a profit. As a game requires 2–4 players and random dice rolling, no such gaming machine has been developed [26,27].

It is an interesting idea and a challenging task to adapt Chinese Ludo to the gambling industry. Despite the randomness of the game, the game machines must be "smarter" than people to ensure that the game owners make money. The primary contributions in this paper are as follows.


• Threat matrix can run on an 80 × 86 SCM (Single-Chip Microcomputer), and has achieved a 97% winning rate against human players.

The rest of this paper is organized as follows. Section 2 briefly introduces the rules of the Chinese Ludo game and reviews related existing research works. Section 3 provides details on the evaluation function, threat matrix, and our proposed algorithms. To clearly show how to calculate the evaluation function, Section 4 presents a concrete example. Section 5 analyses and compares the complexity of the main algorithms. Section 6 presents experimental validations and shows comparisons of various strategies. Section 7 concludes the paper.

#### **2. Chinese Ludo Game**

In this section, for convenience in understanding our algorithms we first briefly introduce the rules of improved man–machine gambling Chinese Ludo by the Lanhai Technology Company. Note that while the rules may be slightly different among different versions, the main rules are always the same.

	- (a) Dice: One traditional dice, with each of its six faces showing a different number of dots from 1 to 6.
	- (b) Board: One board, as shown in Figure 1, with 64 square positions marked with different colors. Each player is assigned a color, either red or blue. The top left corner and the right bottom corner are staging areas ('hangars') and the two closed rectangles colored with red and blue in the center are the ending squares corresponding to each game player.
	- (c) Planes: Each player has four planes, in colors matching those of the board. There are two players, one human and one machine, and eight planes in total.

**Figure 1.** The chessboard of the Chinese Ludo game.

	- (a) Launch: At the start of the game, all of the planes of the two players are in the staging area. After randomly determine a player to roll the dice first, the players take turns rolling the dice. Only when a player rolls a 6 can s/he select one of her/his planes from its staging area to prepare to fly (in its starting square); the planes fly in the clockwise direction.
	- (b) Move: When a player has one or more planes in play, s/he selects one to move (fly) over squares of the number shown on the dice. If the landing square is the same color as the plane's color, the plane can fly directly to the next square in the same color; however, this cannot be done with circles, which is called a 'jump'. Furthermore, if the landing square has the same color and is connected with a dotted line, the plane can fly along the dotted line, which is called a 'dotfly'. The rolling of a 6 earns the player an additional roll in that turn, which can repeat until the roll is not 6.

#### **3. Evaluation Function**

According to the rules of the Chinese Ludo game, the number that the dice shows after rolling is random, and the player has to decide which of her/his planes at different positions to select. Thus, in addition to luck, for a given position winning or losing depends on the selection of planes.

Compared to traditional chess games, the randomness of the dice in Chinese Ludo brings uncertainty to the evaluation of potential moves. Additionally, multi-layered nesting judgement resulting from the rules can introduce looping and crashing during the game. These two key difficulties may explain why there is no mature algorithm for Chinese Ludo gaming suitable for human–machine gaming.

Without loss of generality, let us suppose the computer is blue and the opponent is red. In the rest of the paper, we use blue for computers and red for their human opponents.

#### *3.1. The Description and Definition of the Chess Position*

To facilitate the evaluation of the planes, we first define the chess position. First, the squares in the chessboard are numbered as shown in Figure 2. For planes of the same player, the only difference is their position (i.e., different squares). Thus, we can use the number to represent each plane's position on the game board. The position of each of the four blue planes is denoted by *Xi* with (*i* = 1, 2, 3, <sup>4</sup>). Similarly, the position of each of the red planes is denoted by *Yj* with (*j* = 1, 2, 3, <sup>4</sup>). We use *<sup>S</sup>*(*<sup>X</sup>*1, *X*2, *X*3, *<sup>X</sup>*4,*Y*1,*Y*2,*Y*3,*Y*4) to represent the eight planes' positions on the board and *R* to represent the number that the dice shows after rolling. Thus, (*<sup>S</sup>*, *R*) can determine a specific Chinese Ludo position.

**Figure 2.** The definition of a chess position on the chessboard.

#### *3.2. Evaluation Function*

Next, we define the value of a position, denoted as *<sup>I</sup>*(*Xi*), which is the number of squares from the starting square to the current position; *I*(*Xi*) varies with the change of *Xi*, and the closer it is to the ending square, the greater it is. Note that the position of blue restarts from 1 after a modulo operation of 26.

At a chess position (*<sup>S</sup>*, *R*) we need to define an evaluation function, *f* , in order to determine which plane to move. Obviously, *f* is determined by position (*<sup>S</sup>*, *<sup>R</sup>*); thus, we use *fi*(*<sup>S</sup>*, *R*)(*i* = 1, 2, 3, 4) to represent the evaluation function of the *i*-th blue plane at position (*<sup>S</sup>*, *<sup>R</sup>*). By computing and comparing *fi*(*i* = 1, 2, 3, <sup>4</sup>), we can make our decision as to which plane to move. Certainly, *fi*(*<sup>S</sup>*, *R*) can be used to evaluate the red/opponent's planes as well.

Considering the game rules, we analyze the four key factors that affect *fi*(*<sup>S</sup>*, *<sup>R</sup>*), as follows.

First, according to its rules (see Section 2), Chinese Ludo allows Jump and Dotfly moves. Therefore, planes at different squares may move different distances with the same dice roll. This is referred to as 'Incremented Distance', denoted by *V*1. Without considering other factors, players intend to choose the plane that can move the longest distance.

Second, we consider Hits, i.e., whether, after moving, a blue plane lands on a square occupied by a red plane and the red plane is hit back to its staging area. We call this the 'Opponent's Hit Value', denoted by *V*2. Clearly, *V*2 greatly reduces the chances of the opponent/red player winning and increases the chance that the blue player wins.

Third, if after moving a plane does not hit the opponent's plane on the current roll, it may hit the opponent's plane on the next roll. This means that a plane's threat to the opponent's planes changes with each move. Certainly, players intend to choose the plane which offers the largest increase in the threat, which we call the 'Increased Threat Value of Blue on Red', denoted by *T*1.

In the same way, the threat represented by the opponent's plane changes after each move. We aim to choosing the plane which will result in the smallest increase in the opponent's threat, which we call the 'Increased Threat Value of Red on Blue', denoted by *T*2.

Through the analysis of the above four factors, it can be seen that all four values actually reflect changes in position, and position is the ultimate determination of which player wins or loses the game. Thus, the four values are linearly correlated with the evaluation function, *fi*(*<sup>S</sup>*, *R*)(*i* = 1, 2, 3, <sup>4</sup>), where the evaluation function is defined as

$$f\_i(S, R) = V\_1 + V\_2 + T\_1 - T\_2.(i = 1, 2, 3, 4) \tag{1}$$

By calculating each *fi*(*<sup>S</sup>*, *R*)(*i* = 1, 2, 3, 4) according to Equation (1), we are able choose the plane with the greatest *fi*(*<sup>S</sup>*, *<sup>R</sup>*). Next, we provide details on how to calculate the four values. For the convenience of the reader, we list the main symbols used in this paper below in Table 1.

**Table 1.** Notations of the main symbols.


3.2.1. Incremented Distance after Moving ( *V*1)

According to the above definition of *V*1, at position (*<sup>S</sup>*, *<sup>R</sup>*), if blue's *i*-th plane is on *Xi* and the number on the dice is *R*, according to the game rules, there are three cases for *Xi* to move:


$$V\_1 = R + 4 + 16 = R + 20,\tag{2}$$

thus,

$$|V\_1 = R \| (R+4) \| (R+20) \tag{3}$$

where " " means the logical operation "OR".

#### 3.2.2. Opponent's Hit Value (*V*2)

According to the rules, a plane can hit an opponent's plane if the square on which it lands is occupied by the opponent's plane.


For the above two cases, *V*2 is the position value of the opponent's plane that is lost by the hit; otherwise, the opposing plane has no value to lose:

$$V\_2 = \begin{cases} I(\mathbf{Y}\_j)\_\prime & \text{if } X\_i + R = \mathbf{Y}\_j \text{ or } X\_i + V\_1 = \mathbf{Y}\_j\\ 0, & \text{otherwise.} \end{cases} \tag{4}$$

The reason we calculate *V*1 and *V*2 separately from *T*1 and *T*2 is that the action of *V*2 is a definite effect; the valuation of *T*1 and *T*2 is based on the randomness of the dice, which is a probabilistic event belonging to the threat, which we introduce below.

#### 3.2.3. Increased Threat Value of Blue on Red (*T*1)

In addition to the specific threat of blue to red *V*2, we must consider the change in the overall threat due to moving.

At a (*<sup>S</sup>*, *<sup>R</sup>*), assume a red plane at *Yj* has the position value *I*(*Yj*) and the positions of a blue plane before and after moving are *Xi* and *Xi* + *V*1, respectively. We use *<sup>p</sup>*(*Xi*,*Yj*) and *p*(*Xi* + *<sup>V</sup>*1,*Yj*) to represent the respective threat of the blue plane to the red plane before and after the move. Then, their difference, *p*(*Xi* + *<sup>V</sup>*1,*Yj*) − *<sup>p</sup>*(*Xi*,*Yj*), can denote the increasing threat of *Xi* to *Yj*. If we let the difference multiply the position value of *Yj*, we obtain the increased threat value of of *Xi* to *Yj*, i.e., *T*1 = (*p*(*Xi* + *<sup>V</sup>*1,*Yj*) − *<sup>p</sup>*(*Xi*,*Yj*)) × *<sup>I</sup>*(*Yj*).

Each player has four planes; thus, before moving, the respective overall threat of the blue plane compared to the four red planes is the sum of the product of *<sup>p</sup>*(*Xi*,*Yj*) and *<sup>I</sup>*(*Yj*),

$$\sum\_{j=1}^{4} p(X\_{i\prime}, Y\_{j}) \times I(Y\_{j}).\tag{5}$$

After moving, the respective overall threat of the blue plane compared to the four red planes is the sum of the product of *p*(*Xi* + *<sup>V</sup>*1,*Yj*) and *<sup>I</sup>*(*Yj*),

$$\sum\_{j=1}^{4} p(X\_i + V\_{1"\prime} Y\_j) \times I(Y\_j). \tag{6}$$

Thus, the sum of the increased value of the threat of *Xi* to all *Yj*(*j* = 1, 2, 3, 4) *T*1 can be computed as

$$\begin{split} T\_1 &= \sum\_{j=1}^{4} p(X\_i + V\_1, Y\_j) \times I(Y\_j) - \sum\_{j=1}^{4} p(X\_i, Y\_j) \times I(Y\_j) \\ &= \sum\_{j=1}^{4} (p(X\_i + V\_1, Y\_j) - p(X\_i, Y\_j)) \times I(Y\_j) .\end{split} \tag{7}$$

When *T*1 ≥ 0, which indicates the threat of the blue plane to the red plane, is increasing, it is beneficial for blue; similarly, if *T*1 < 0, which indicates the threat of the blue plane to

the red plane, is decreasing, this is disadvantageous for blue. Thus, we should choose the plane with the largest *T*1.

#### 3.2.4. Increased Threat Value of Red on Blue ( *T*2)

Similar to the above *T*1, before and after the move of the blue plane, the threat of the red plane to the blue plane changes. We call the difference between the product of the blue threat to red and the position value of the blue plane before and after the move as the "increased threat value of red on blue", denoted by *T*2.

At position (*<sup>S</sup>*, *<sup>R</sup>*), if the red plane is on *Yj* and the blue plane is on *Xi* and *Xi* + *V*1 before and after the blue plane move, the position values of the blue plane before and after the move will be *I*(*Xi*) and *I*(*Xi* + *<sup>V</sup>*1). Thus, the respective threat of the red plane to the blue plane before and after the move is *<sup>p</sup>*(*Yj*, *Xi*) and *<sup>p</sup>*(*Yj*, *Xi* + *<sup>V</sup>*1).

Then, the total threat value of the four red planes to the blue plane can be calculated as the product of *<sup>p</sup>*(*Yj*, *Xi*) and *I*(*Xi*) before the move

$$\sum\_{j=1}^{4} p(Y\_j, X\_i) \times I(X\_i). \tag{8}$$

and as the product of *<sup>p</sup>*(*Yj*, *Xi* + *<sup>V</sup>*1) and *I*(*Xi* + *<sup>V</sup>*1) after the move

$$\sum\_{j=1}^{4} p(Y\_{j}, X\_{i} + V\_{1}) \times I(X\_{i} + V\_{1}).\tag{9}$$

Therefore, according to its definition, the threat increment, *T*2, is

$$T\_2 = \sum\_{j=1}^{4} p(Y\_{j\prime}, X\_i + V\_1) \times I(X\_i + V\_1) - \sum\_{j=1}^{4} p(Y\_{j\prime}, X\_i) \times I(X\_i). \tag{10}$$

Intuitively, *T*2 ≥ 0 indicates that the threat of the red plane to the blue plane increases and is disadvantageous for blue, while *T*2 < 0 indicates that the threat to the blue plane decreases and is advantageous to blue.

Based on the above analysis, when entering Equations (3)–(10) into Equation (1), we can obtain *fi*(*<sup>S</sup>*, *R*) as follows:

$$\begin{aligned} f\_l(\mathcal{S}, \mathcal{R}) &= V\_1 + V\_2 + T\_1 - T\_2 \\ &= (\mathcal{R} \| (\mathcal{R} + 4) \| (\mathcal{R} + 20)) + (I(Y\_{\mathcal{I}}) \| 0) + \sum\_{j=1}^4 (p(\mathcal{X}\_l + V\_{1\prime}, Y\_{\mathcal{I}}) - p(\mathcal{X}\_l, Y\_{\mathcal{I}})) \times I(Y\_{\mathcal{I}}) \\ &+ \sum\_{j=1}^4 p(Y\_{\mathcal{I}} + X\_l + V\_1) \times I(\mathcal{X}\_l + V\_1) - p(Y\_{\mathcal{I}}, X\_l) \times I(\mathcal{X}\_l). \end{aligned} \tag{11}$$

By computing and comparing each *fi* with *i* = 1, 2, 3, 4, we can select the plane which has the largest *fi* to move.

Until now, we have not ye<sup>t</sup> shown how to calculate *p*. As *p* is the most frequently used variable in the evaluation function, the key to improving the efficiency of this algorithm is calculating *p* rapidly. Next, we address this problem, then focus on the calculation of *p* in a separate section.

#### *3.3. Calculating Threat and Threat Matrix*

#### 3.3.1. Calculating Threat

From a given position, *<sup>p</sup>*(*Xi*,*Yj*) is computable according to the rules and the definition of *p*.

At a position (*<sup>S</sup>*, *<sup>R</sup>*), suppose the blue plane is on *Xi* and the red plane is on *Yj*. If a hit happens, i.e., (*Yj* = *Xi*), we have *<sup>p</sup>*(*Yj*, *Xi*) = 1. Sometimes, after moving a plane cannot hit an opponent's plane because the moving distance is too short. Then, we must consider the case of rolling the dice continuously until it is not 6. Next, we use an example to explain how to calculate *<sup>p</sup>*(*Yj*, *Xi*).

Assume the opponent's red plane is on *Yj*, a blue plane is on *Xi*, and the number on the die is *R*. According to the rules, there are three cases we must consider in order to calculate *<sup>p</sup>*(*Yj*, *Xi*).

1. If *Yj* < *Xi* ≤ *Yj* + 6, the possibility of the opponent's plane on *Yj* hitting blue's plane on *Xi* by rolling once is

$$p(\boldsymbol{\chi}\_{j}, \boldsymbol{\chi}\_{i}) = 1/6. \tag{12}$$

2. If *Yj* + 6 < *Xi* ≤ *Yj* + 12, the opponent's red plane on *Yj* cannot hit blue's plane on *Xi* by rolling once. For it to be possible to hit, the red player must roll 6 the first time, landing on position *Yj* + 6, then roll again. Thus, the probability is *<sup>p</sup>*(*Yj*, *Xi*) = 1/6 × 1/6 = 1/36. By analogy to more general cases, if rolling 6 up to seven times continuously the opponent's red plane on *Yj* does not threaten the blue plane on *Xi* according to the board. Thus, if *Yj* + 6*k* < *Xi* ≤ *Yj* + 6(*k* + 1) (*k* = 0, 1, 2, 3, 4, 5, 6, <sup>7</sup>), then

$$p(\boldsymbol{\gamma}\_{j}, \boldsymbol{X}\_{i}) = \left(\mathbf{1}/\boldsymbol{\theta}\right)^{k+1}.\tag{13}$$

3. Calculate the probabilities for special positions. According to the rules, a plane can jump if the landing square is the same color, such as 2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, and 50 for red, which can add the extra possibility of the plane on *Yj* jumping and hitting *Xi*, in addition to the above two cases.

Squares of the same color are separated by three squares. Therefore, after each roll it is possible to land on the same color square. There are thus two cases, as follows.

(a) When *Yj* < *Xi* ≤ *Yj* + 6 and *Xi* is on the red square (e.g., *Yj* = 1 and *Xi* = 6), if the dice roll is 5, the plane on *Yj* hits the plane on *Xi*, thus there is no jump; if the dice roll is 2, the plane on *Yj* first moves onto square 2, then jump onto square 6, then hits the plane on *Xi*. The probability is

$$p(\mathbf{Y}\_{\mathbf{j}}, \mathbf{X}\_{\mathbf{i}}) = 1/6 + 1/6 = 1/3. \tag{14}$$

(b) When *Yj* + 6*k* < *Xi* ≤ *Yj* + 6(*k* + 1) and *Xi* is on a red square, then

$$p(Y\_{j'}X\_i) = (1/6)^{k+1} + (1/6)^k. \tag{15}$$

With the above analysis and formulae, we can calculate any position's threat to another position and calculate the evaluation function, then make the choice of which plane to move.

#### 3.3.2. Threat Matrix

Based on the above discussion, we have two methods to calculate the threat *p*:

1. Real-time computing

> Real-time computing calculates *p* for current position (*<sup>S</sup>*, *R*) using Equations (12)–(15) each time the dice is rolled.

However, in order to reduce the manufacturing cost of the game machine, the program runs on an 80 × 86 SCM, which has limited computing and storage power. Although the computing load decreases with respect to certain specific chess positions (such as all eight planes moving into the circle), the computation takes about 3.7 s in extreme cases, which is intolerable to players. We therefore sought faster algorithms to perform the same job.

Through our observations, we found that no matter how the game changes, the threat is only ever determined by the positions. This naturally triggers a new idea, i.e., to compute the threat between any two positions and store them in a lookup table that is independent of any single position, herein called the 'Threat Matrix'.

2. Using the Threat Matrix to store pre-calculated threat values There are 64 positions on a chessboard. Therefore, we built a 64 × 64 matrix, *P* = (*pij*)<sup>64</sup>×64, where *pij* = *<sup>p</sup>*(*Xi*,*Yj*) is the threat of a plane located on *Xi* to a plane located on *Yj*. From the above discussion, the threat can be calculated using Equations (12)–(15). Part of the threat matrix is as shown in Table 2.

**Table 2.** An illustration of our threat matrix.


#### **4. Threat Matrix-Based Movement Strategy**

In order for readers to better understand our algorithm, we use the following chess position (as shown in Figure 3) as an example to illustrate how our algorithm operates. In this example, it is assumed that *S* = (3, 5, 0, 0, 1, 11, 0, 0) and *R* = 3 and it is blue's turn to make the choice of its plane.

**Figure 3.** An example with chess position (*<sup>S</sup>*, *<sup>R</sup>*), where *S* = (3, 5, 0, 0, 1, 11, 0, 0) and *R* = 3.

In this example, there are two blue planes (shown as the third and fifth squares in Figure 3) and two red planes (shown as the first and eleventh squares in Figure 3) on the circle, and all other planes are in their staging areas. The threat matrix-based movement strategy for the plane is shown in Algorithm 1.



**8 end**

**6**

**9 return** Choose suitable number to move based on evaluation values;

#### **5. Recursion and Complexity Analysis for Multiple Moves**

#### *5.1. Recursive for n Plies*

In the algorithm and example described above, we have evaluated only one move for the plane based on the current position, which is somewhat short-sighted. For most chess games, in order to win the game multiple moves need to be considered, and this is true for Chinese Ludo.

As the game rules are the same for both sides, the evaluation function applies to both blue's planes and red's planes. The plies of (*<sup>S</sup>*, *R*) are limited because there are only four planes and the number of *R* can only be 1 to 6, which makes it possible to look multiple moves ahead. This means that we can evaluate the opponent's planes based on their hypothetical choices and then consider the opponent's hypothetical assessment.

Let (*Sn*, *Rn*) represent the hypothetical position of *n* moves ahead; we can obtain the evaluation of *n* + 1 steps based on *fi*(*Sn*, *Rn*), denoted by *fi*(*Sn*<sup>+</sup>1, *Rn*+<sup>1</sup>). Thus, based on the Equations (1)–(15), we have

$$f\_i(S^{n+1}, R^{n+1}) = V\_1 \times f\_i(S^n, R^n) + V\_2 \times f\_i(S^n, R^n) + T\_1 \times f\_i(S^n, R^n) + T\_2 \times f\_i(S^n, R^n). \tag{16}$$

It is apparent that Equation (16) is a recursive formula; the initial computation is expressed as Equation (11), with which we can look any number of moves ahead. Although the more moves we look ahead, the more beneficial it is to the blue, the computation cost increases exponentially with the increase in the number of moves. Next, we analyze the relationship between the complexity and the number of moves ahead.

#### *5.2. Complexity Analysis*

#### 5.2.1. Computation Complexity of One Move

Let us first look at the computation complexity of evaluating *fi*(*<sup>S</sup>*, *R*) based on the current position.

First, according to the evaluation functions in Equations (3) and (4), the calculation of *V*1 and *V*2 does not need to consider the opponent's threat; *Xi* and *Yj*, the positions of planes, are both integers and not more than 64, and only judgement and a simple addition operation of the positions are needed. For each side, there are only thirteen special positions. Therefore, to calculate *V*1 + *V*2, there are at most 13 + 13 = 26 comparisons of special positions.

Next, according to Equations (7) and (10), the calculation of *T*1 and *T*2 mainly involves computing *<sup>p</sup>*(*Xi*,*Yj*), which is essentially the comparison of positions.

As the real-time computing and threat matrix are two different methods, we discuss them separately in order to compare their respective advantages and disadvantages.

1. Complexity of Real-Time Computing Considering the most complicated case, where each of Equations (12) and (13) need to be calculated, Equation (12) includes one comparison and Equation (13) includes eight comparisons, while Equations (14) and (15) include two special cases with special positions; thus, there are at most (1 + <sup>8</sup>)*α* comparisons. The number of all comparisons is at most (1 + 8)+(1 + <sup>8</sup>)*<sup>α</sup>*.

There are at most four opposing planes in play, and the number of all comparisons is therefore *β* × (1 + 8 + *α* × (1 + <sup>8</sup>)).

The above represents the calculation of one blue plane, and the blue player has four planes; the number of comparisons is therefore

$$
\beta \times (2\alpha + \beta \times (1 + 8 + \alpha \times (1 + 8))) = 9\alpha\beta^2 + 9\beta^2 + 2\alpha\beta. \tag{17}
$$

#### 2. Computing Complexity Using Threat Matrix

According to the definition of the threat matrix, there is no need to calculate *<sup>p</sup>*(*Xi*,*Yj*) using Equations (12)–(15) each time, as we can simply look up the pre-calculated matrix. According to Equation (7), we look up the threat matrix twice for each opposing plane. As there are *β* opposing planes, there are at most 2*β* search instances. Similarly, according to Equation (10), there are at most 2*β* search instances for *T*2. Then, considering the calculation of *V*1 and *V*2, which is 2*α*, the full computation for one of blue's planes is 2*α* + 4*β*.

As there are at most four blue planes in play, the maximum computation is

$$
\beta \times (2\alpha + 4\beta) = 4\beta^2 + 2\alpha\beta. \tag{18}
$$

Comparing Equation (18) with Equation (17), the computation required for the threat matrix is obviously only (4*β*<sup>2</sup> +2*αβ*)/(9*αβ*<sup>2</sup> +9*β*<sup>2</sup> +2*αβ*) = 7.92% with real-time computing, showing that the computation of the threat matrix is only one-eighth that required by real-time computing. In this game, we use the threat matrix instead of realtime computing.

#### 5.2.2. Complexity of More Moves Ahead/per *n* Plies

According to Equation (11), each player has four planes; thus, there are at most four cases of *S*. *R* takes a value from 1 to 6; thus, the complexity of computing *fi*(*Sn*<sup>+</sup>1, *Rn*+<sup>1</sup>) is 6*β* instances required to compute *fi*(*Sn*, *Rn*). Therefore, if we look *k* moves ahead, (6*β*)*k*, i.e., the computation complexity is *<sup>O</sup>*((6*β*)*k*).

Using the real-time computing method, the complexity is 9*αβ*<sup>2</sup> + 9*β*<sup>2</sup> + 2*αβ*, according to Equation (17). If we look one move ahead, the computation is (9*αβ*<sup>2</sup> + 9*β*<sup>2</sup> + 2*αβ*) × 6*β*, and if we look *k* steps forward, the computation complexity will be O((54*αβ*<sup>3</sup> + 54*β*<sup>3</sup> + 2*αβ*<sup>2</sup>)*k*);

When using the threat matrix, according to Equation (18) the computation is 4*β*<sup>2</sup> + 2*αβ*. If we look one-step forward, the computation is (4*β*<sup>2</sup> + 2*αβ*) × 6*β*, and if we look *k* steps forward, the computation complexity will be O((24*β*<sup>3</sup> + 12*αβ*<sup>2</sup>)*k*);

It is apparent that there is a clear advantage when using the threat matrix, especially in multiple recursions, which we validate in the following experimental section.

#### **6. Experiment Validation**

The development of the Chinese Ludo game used an 80 × 86 SCM 32-bit single board computer with a 100 MHz CPU. Because the computing power was very limited, we used the threat matrix and evaluated only one move ahead of the current position. For more advanced game players, we have developed a more complex two-layer recursive algorithm which can evaluate two moves ahead. We used the 32-bit Windows XP OS as the development platform because the game was eventually expected to run on the 80 × 86 32-bit microprocessor. In addition, we chose Microsoft Visual C as the programming language for easier adoption.

To verify the effectiveness of our algorithms, we carried out three groups of experiments to contrast human play versus the machine, evaluation of one move ahead versus two moves ahead, and real-time computing versus using the threat matrix.

#### *6.1. Contrasting Results for Human versus Machine Play*

When the development of the game had finished, a team of 50 players was assigned to play against the machine. The whole test lasted for about one month during which there were more than 15,000 matches played, including 5000 matches with no time limit, 5000 matches with a 10 s limit, and 5000 matches witha5s limit. The time limit is the maximum time allowed before reacting after the dice are rolled. It was proposed by the company to increase fun and accelerate the game speed. Figure 4 shows the match results. Figure 5 shows the contrast in reaction times between human players and the machine.

**Figure 4.** Contrast in match results between humans and machine: (**a**) statistics on the match results; (**b**) comparison of wins.

**Figure 5.** Comparison of reaction time between humans and machine.

From Figure 5, the following can be seen:

1. Aside from the randomness of dice rolling, the machine is much smarter than humans at this game. Even without the time limit, the winning rate of human players is only 12%. When there is a 10 s time limit, human players win 7% of the time, and when there is a 5 s time limit, human players only win 2% of the time. In addition, from the comparison of reaction times human players takes eight times as long to play as the machine does.


#### *6.2. Comparison of One Move Ahead and Two Moves Ahead*

Obviously, for different positions (*<sup>S</sup>*, *<sup>R</sup>*), the amount of computation is likely to be different, which leads to different levels of computational complexity. This indicates that the evaluations of one move and multiple moves are not comparable. To show the pros and cons of evaluating one move and two moves, we must compare (*<sup>S</sup>*, *R*) at the same position. Thus, we set up twenty different typical positions (*<sup>S</sup>*, *R*) in order to evaluate the difference. Figure 6a shows the comparison of the evaluation result, *f* , and Figure 6b shows the comparison of the evaluation times.

**Figure 6.** Comparison of the evaluation of one move and two moves ahead. The vertical axis indicates the evaluation results, *f* , in (**a**) and indicates the evaluation time in (**b**).

From Figure 6a, two evaluations are consistent. In order to see their impact on the selection of planes, we created the following formula:

$$\mu(i,j) = \frac{\left\| f\_i^1(S,R) - f\_j^2(S,R) \right\|}{\left\| f\_i^1(S,R) - f\_j^1(S,R) \right\|},\tag{19}$$

where *f* 1*i* (*<sup>S</sup>*, *R*) and *f* 2*i* (*<sup>S</sup>*, *R*) represent the evaluation of the number *i* plane at one move ahead and at two moves ahead, respectively. Similarly, *f* 1*j* (*<sup>S</sup>*, *R*) represents the evaluation of the number *j* plane at one move ahead.

In Equation (19), if *μ*(*<sup>i</sup>*, *j*) ≥ 1, it indicates that the difference between the evaluations of one move and two moves of the same plane is larger than those of one move of two different planes. Therefore, the choice of planes at the same position will be different. Otherwise, if *μ*(*<sup>i</sup>*, *j*) < 1, it means that the evaluations of one move ahead and two moves ahead will not change the choice of planes. According to Equation (19), we calculate *μ*(*<sup>i</sup>*, *j*) for the twenty positions, as shown in Table 3.

**Table 3.** *μ*(*<sup>i</sup>*, *j*) for twenty different chess positions (*<sup>S</sup>*, *<sup>R</sup>*). The \* in the table means blank, indicating that the opponent's plane is in the staging area.


In addition to the above twenty positions, we compared another fifty positions which provided a consistent result, i.e., the evaluation of two moves ahead did not change the choice of planes based compared to the evaluation of one move ahead. In fact, by looking at Equation (16), cited below, we can find the theoretical reasons for this:

$$f\_i(S^{n+1}, R^{n+1}) = V\_1 \times f\_i(S^n, R^n) + V\_2 \times f\_i(S^n, R^n) + T\_1 \times f\_i(S^n, R^n) + T\_2 \times f\_i(S^n, R^n). \tag{20}$$

In the evaluation of two moves ahead, the two moves need two more rolls of the dice; however, these are hypothetical. Thus, the further evaluation of the second move ahead is evaluated under the weight of 1/6 × 1/6 = 1/36, which makes the impact on the further evaluation small. We can see that this is different from other forms of chess.

However, from Figure 6b, the time cost of evaluating two moves ahead is twenty times of that of evaluating one move ahead. In addition, the memory consumption is increased by a large amount.

#### *6.3. Comparison of Real-Time Computing and the Threat Matrix*

In order to compare real-time computing and the threat matrix, we conducted experiments using a 32-bit Windows XP platform.

According to the game rules, the results of dice rolling is random, which means that it is hard to acquire the same position (i.e., the initial conditions for the computation) to compare the two evaluations. Therefore, similar to the previous comparison in Section 5.2, we set typical chess positions in order to ensure the consistency of the initial conditions. The results are shown in Figure 7.

**Figure 7.** Comparison of real-time computing and the threat matrix in terms of time complexity and memory usage: (**a**) comparison of time complexity; (**b**) comparison of memory usage.

It can be seen from the results that the time consumption of evaluation using the threat matrix takes no more than 0.001 s, while the average time when using real-time calculation is 0.008 s, which is highly unstable compared to the threat matrix. The memory consumption of real-time computation is far greater than that of the threat matrix as well.
