Abstract
In this paper, we present the techniques, such as bitboard, iterative-deepening aspiration search algorithm, endgame tablebase, used in our Surakarta program Fuchou. A bijective function similar to Schadd’s is developed to map a Surakarta board position to a unique address of the endgame tablebase. The function is one-to-one and onto and can be computed very quickly using some techniques compared to conventional methods. We have implemented it on our Surakarta program FuChou. Experimental results show that we have gotten advantages of speedup as well as accuracy on the endgame boards.
Keywords
Introduction
In the area of computer games, many researchers studied and presented many useful techniques, such as the alpha-beta pruning (Knuth and Moore, 1975) and MCTS (Coulom, 2006; Kocsis and Szepesvári, 2006), in order to promote their programs’ strengths. Among them, the policy network (Silver et al., 2016) used in AlphaGo by DeepMind team, or many parallel search algorithms are developed to increase the search depth and to get more accurate evaluation scores about the board positions. However, in many endgames, one player usually needs a long sequence of moves to beat his/her opponent. If we only use the game search algorithms, it will be very difficult to find a winning path within a short period of game-playing time.
The endgame tablebase (Chess Programming) is a possible technique to relieve the above problem. We can apply the retrograde method (Ströhlein, 1970) in advance to find the best move for a large amount of endgames, and store the results in a tablebase. In the game playing time, if the board is entering into the endgame state, then we can directly access the information in the tablebase and quickly get the best move to play. Hence, it is very favorable to have a large endgame tablebase to help the program to beat its opponent in advantage positions or to postpone the possible losses or even to reverse the victory in disadvantage positions.
Surakarta is a two-player game, named after the ancient city of Surakarta in central Java. It is also named Permainan or Roundabouts. The game is also a competition item in many computer competitions, such as Computer Olympiad (ICGA), Technologies and Applications of Artificial Intelligence (TAAI), Taiwan Computer Game Association (TCGA), University Computer Games Championship, and National Computer Games Tournament.
Surakarta is still an unsolved game. Our objective is to develop a program with a high strength. The rest of this paper is organized as follows. Section 2 goes through the related work in Surakarta programs and related techniques, such as bitboard, search algorithms, and endgame tablebases. Section 3 presents our approach for developing the Surakarta agent. A bijective function similar to Schadd (2011) for fast indexing the board is used in our program and is introduced in Section 4. Sections 5 and 6 show the implementation details of the DTC (Distance To Conversion) endgame tablebases and experimental results. Section 7 concludes the paper and provides some remarks.
Surakarta and related work
Pieces and chessboard
The Surakarta board has 6 horizontal and 6 vertical lines resulting in 36 intersections and 8 circular arcs. The two players, Black and White, begin the game with 12 isotype pieces each, located at both sides, as shown in Fig. 1(a).
The rules of moves and captures
Players make moves alternate. On a turn, a player either moves one of his pieces to an unoccupied point in any one of the 8 directions (4 diagonal and 4 orthogonal directions) as shown in Fig. 1(b) and (c) or makes a capturing move as shown in Fig. 1(d). A capturing move consists of traversing along an inner or outer circuit around at least one of the eight corner loops of the board, and then finally followed by landing on an enemy piece, capturing it. Any number of unoccupied points may be traveled over, before or after traversing a corner loop. An unoccupied point may be traveled over more than once during the capturing piece’s journey. Only unoccupied points may be traveled over; jumping over pieces is not permitted. Captured piece is removed from the board.
Basically, pieces that occupied the center of the board are more powerful, where they are in one or two loops. On the other hand, pieces on the corner are difficult to move, as the spaces next to the corner can be attacked by the opponent. Due to the special property of Surakarta, it is a challenging problem for creating a program with a high strength.

(a) the initial state of Surakarta, (b) non-capturing moves, (c) non-capturing moves, (d) capturing moves.
The player capturing all 12 of the opponent’s pieces wins the game. Winands’s (2016) paper and recent ICGA Surakarta tournaments further apply the threefold repetition rule or the 50-move rule, which states that the game is ended if the same board position occurs three time or no captures in the past 50 moves. When the game is ended, the player with more pieces remaining on the board than the opponent wins the game. Otherwise, it is a draw for both sides.
Here we review some research results about the design of agent programs, bitboard, and aspiration search. Zhang and Ding (2011) implemented a Surakarta program using arrays to store the board information, where 0 indicates empty position, 1 and 2 indicate Black and White pieces respectively. They created two circular queues to store the intersection positions of two loops. When touching these intersections, the program needs to search the loops to check if capturing move is available.
Winands (2016) developed a Surakarta agent program named SIA which performs an
Adelson-Velsky et al. (1970) used bitboard techniques on games. They introduced many bitboard operations such as XOR, AND, OR. Those are adopted in many later developed programs.
Kaindl et al. (1991) compared the minmax algorithm with the alpha-beta using aspiration window. They used the number of bottom positions (NBP) as an evaluation item, and analyzed the details of their aspiration window method.
Allis et al. (1994a; 1994b) applied the threat-space search and the PN search to prove that free-style Gomoku is a first-player win game. However, at the present time, Surakarta is still unsolved. Hence, we can construct the endgame tablebases to promote the program’s strength.
Basically, there are two kinds of endgame tablebases: DTM (Distance To Mate) and DTC (Distance To Conversion). The goal of DTM is to find a shortest path to beat its opponent. On the other hand, the goal of DTC is to find a shortest path to capture its opponent’s piece in order to reduce the number of remaining pieces and to get an advantage over its opponent. Our Surakarta program applied DTC for implementation.
An endgame tablebase is used in querying a position for getting its best move. We need a function to map a board position to an identification number which is the address for storing its best move. The function must be one-to-one because we cannot let two different board positions refer to the same address in the endgame tablebase. Furthermore, we prefer to reduce the total amount of space used in the endgame tablebase.
Among the researches of the Chess endgame tablebases, most researches used 6 bits to reference the 64 squares of Chess board. For an endgame with n pieces, it needs
Unfortunately, this kind of encoding may waste lots of space for some other games, such as Surakarta. For a Surakarta board with n pieces, the total number of possible board positions is
Our Surakarta agent
FuChou is our Surakarta program developed with C++. It is based on the bitboard data structure and Iterative-Deepening Aspiration Search in the PVS framework (Marsland and Campbell, 1982).
BitBoard and bit operation
Bitboard is a popular technique that is used in many kinds of games for a long time. But, at the present, there are not so many research papers utilizing bitboard in Surakarta program. Bitboard is a numeric variable representing a board state. For a board size under
We map each bit of the bitboard to a position of the Surakarta board shown in Fig. 2(c). The Bit Manipulation Instruction Sets (BMI 1) have specified functions to extract a piece, get its position number, and then convert the number to its board state. The non-capturing moves of Surakarta means moving a piece to an unoccupied point in any one of the 8 directions. The masks for each position is established in advance. When we want to generate the non-capturing moves, we just get a piece and “exclusive or” the bitboard of non-empty positions with the corresponding mask to find all its legal non-capturing moves. Figure 3 shows this process. Figure 3(a) gets a piece to move. Figure 3(b) is its mask. Now the non-empty positions (including White and Black pieces) are indicated as a bitboard in Fig. 3(c). We can xor Fig. 3(b) with Fig. 3(c) to get Fig. 3(d) which removes the non-empty positions and reserves the empty positions in the 8 directions. Hence Fig. 3(d) represents all the non-capturing moves of the piece shown in Fig. 3(a). The above process just takes logic operations to get the final results with a very efficient way. This bitboard data structure is surely better than the arrays from the performance point of view.

(a) the bitboard of White pieces, (b) the bitboard of Black pieces, (c) the mapped position number for each bit.

Use bitboards to generate non-capturing moves: (a) the moving piece, (b) the mask of the moving piece, (c) non-empty positions, (d) final non-capturing moves.
We use Iterative-Deepening Aspiration Search in the PVS framework (Marsland and Campbell, 1982) in our Surakarta program, where the values of alpha and beta are not fixed values
FuChou was written based on the algorithm. Now we introduce how to set the window size Δ, which has a dynamic range. Initially, the center of the aspiration window is set as the value of previous search level as follows.
Iterative-deepening aspiration search
Iterative-deepening aspiration search
We think that the board is more unstable when the absolute function of value is larger. Hence we set a larger window size. Furthermore, when the value equals 0, we add an extra quantity 20 in order to prevent Δ from being 0.
When
Parallel computing in PVS
The number of legal moves of a Surakarta board is around 20 to 40. Most programs used a single thread to search the game tree. In Marsland and Campbell (1982), PVS is introduced. They also describe how to implement the parallel version of PVS. FuChou also applies the same technique. After searching the first branch using PVS, it uses the OpenMP library to parallelize the execution of the remaining branches according to the available cores and store the search results in an array.
A bijective function for fast indexing
In this section, we refer to the Formula 4.1 in Schadd (2011), which was used to construct the endgame tablebase of Fanorona game. We develop a similar bijective function for fast indexing a board position. We design the mapping function for Surakarta. The board of Surakarta has 36 positions. Firstly, we encode the non-empty positions as 1 and the empty positions as 0, as shown in Fig. 4. For the 1-piece endgame, row 1 in Fig. 4(a) means the only one piece is put at the first position of the Surakarta board which has 36 positions. We encode this board as 0. Row 2 in Fig. 4(a) means the only one piece is put at the second position of the Surakarta board. We encode this board as 1. And so on. We can see that there will have totally 36 rows in Fig. 4(a) and the encoding numbers are
Let

The encoding of non-empty board positions: (a) 1-piece endgame, (b) 2-piece endgame, (c) 3-piece endgame.
Let
For the 3-piece endgame shown in Fig. 4(c), row 2 depicts

The scheme for computing the offsets.
The last step can be proven by induction. Due to the page limit, we omit it here.
From previous derivations, we can compute and store the values of
Now suppose that a Surakarta endgame board has n pieces located at positions
This method uses the patterns of the n non-empty positions to accumulate the values
As mentioned earlier, Schadd (2011) has used the similar function to construct the endgame tablebase of Fanorona game. He got rid of all-black and all-white configurations and reduced slightly the space used. If we want to get the same effect, we can replace the above formula with the following one.
However, the ratio of all-black and all-white configurations in an endgame tablebase is quite small. Hence we didn’t apply his idea in our implementation for saving the computation time.
We used the retrograde method to establish the DTC endgame tablebases starting from 1-piece. At the present time, 1-piece to 6-pieces endgame tablebases have already been constructed. The number of boards for 1-piece to 6-pieces are 72, 2529, 57120, 942480, 12063744, and 124658688, respectively. Their construction time are 0, 0.01, 0.65, 6.07, 84.39, 1264.88 seconds, respectively.
The 6-pieces DTC endgame tablebase is combined with the aspiration search. When the search reaches the depth limit and the number of pieces is less than or equal to 6, the board will be given a value according to the tablebase. If the DTC value is positive, it means how far the player will win the game. In this case, the board will be given a value of winValue–(DTC_value
DTC_Evaluation (board)
DTC_Evaluation (board)
The experimental environment of the development of our program Fuchou is as follows: CPU: INTEL i7-6700K 4.0 GHz, GPU: NVIDIA GeForce GTX 1080Ti, RAM: 24 GB DDR4 2400 MHz, Hard Drives: INTEL SSD 535 Series 240 GB.
We designed two experiments. In Experiment 1, we randomly generate 1000 10-pieces Surakarta boards. In order to test the performance of the DTC endgame tablebase, we let FuChou with the endgame tablebase play with FuChou without the endgame tablebase starting from those generated boards, alternating Black or White first, taking turns, and totally derive 4000 game results of win, lose or draw. In addition, we also want to know whether more pieces boards will have different performance since we only have the 5-pieces endgame tablebase. Hence in Experiment 2, we randomly generate 1000 12-pieces Surakarta boards for testing.
Although we generate the boards randomly, in order to avoid the boards having an obvious advantage for one side, we only generate the boards with the condition that the difference of the number of pieces between two sides is not more than 4. So Experiment 1 only generates boards with a ratio of 3:7, 4:6, 5:5, 6:4, or 7:3 for both sides. Experiment 2 only generates boards with a ratio of 4:8, 5:7, 6:6, 7:5 or 8:4 for both sides.
Besides, we used the following manner to run all the experiments. Starting from the initial board, the two programs will execute the Aspiration Search with a depth of 8 to 10 to play with each other until the game is ended.
The player capturing all of the opponent’s pieces wins the game. We apply the threefold repetition rule to check the end of the game. Experiment 1 took about 9 hours to play the 4000 games, and Experiment 2 took about 28 hours to play the 4000 games.
Experiment 1: The effect of DTC tablebase
In this experiment, we use 1000 boards to let FuChou with DTC tablebase play 4000 games with FuChou without DTC tablebase. The number of wins, draws, and loses of FuChou with DTC tablebase are 2115, 12, and 1873, respectively.
We see that the version with DTC tablebase has more number of wins and has a win rate of 52.88% due to the fact that many boards take advantage of the DTC tablebase to select more correct moves. The version without DTC tablebase suffers from lacking the information, and therefore gets more number of loses.
Experiment 2: The effect of different number of pieces
This experiment want to check if the boards with more pieces are less likely to use the DTC tablebase and the performance will degrade. Similarly, we let the two versions play the 12-pieces boards for 4000 games. The number of wins, draws, and loses of FuChou with DTC tablebase are 2129, 14, and 1857, respectively.
The DTC version gets 53.23% win rate and is close to the results of Experiment 1. These experiments present the obvious advantages of using endgame tablebase because the value of endgame board is accurate and the evaluation of the endgame board is not needed.
Concluding remarks
In this paper, a bijective function is developed to map a Surakarta board position to a unique address of the endgame tablebase. The function is one-to-one and onto and can be computed very quickly compared to conventional methods. Our method can also be applied to other kinds of games such as Checkers and Breakthrough where both players have only one kind of pieces. At the present, we don’t deal with the fourfold symmetry of the board. If we apply Thompson’s (1991; 1996) method to confine one particular piece to a specified area by horizontal, vertical, or diagonal reflections, then it seems that we can further reduce the size of the endgame tablebase to one sixth (6/36) of the original size. However, this is not true because Thompson’s method can only save the time to generate lots of symmetric boards and cannot save the total space used. On the other hand, Thompson’s method needs extra computation cost and should be taken into account in the implementation.
When to use the endgame tablebase? Basically, there are two situations. The first is when the board has only n or less pieces, then the program can always access the endgame tablebase to optimally play the game. In this case, the computation cost for dealing with the fourfold symmetry is minor.
The second is when using game search algorithm a piece is captured and the board has only n pieces, then it is the time to access the endgame tablebase. In this case, the total computation cost for dealing with the fourfold symmetry for all the searched boards is quite huge.
Finally, we would like to thank all the reviewers for their detailed comments and suggestions. One reviewer suggests the following idea: “It is still possible to exploit some form of symmetry. Without loss of generality you can only consider positions in which white has equal or more pieces than black. If in the actual game black has more pieces, you can just switch the colors around and look up the value. This might conflict with the current turn though.” For this insightful suggestion, our reply is this can only deal with the cases of the first player (white) having more pieces than the second player (black). If in the actual game the first player is black and black has more pieces, we surely can just switch the colors around and look up the value. However, if in the actual game the first player is black and black has less pieces, indeed we cannot just switch the colors around and look up the value. This will let the second player become the first player and will result in a wrong decision.
The review also suggests the following idea: “You can also save a little bit of space by assuming that the pieces on the highest position number (Fig. 5) is always white, and switch the colors around if this is not the case. This halves your size.” For this suggestion, our reply is as follows. Assume that the pieces on the highest position number (Fig. 5) is always white and the first player is white to look up the value. Then for a board being not the case, we switch the colors and the second player will become the first player and will also result in a wrong decision.
Since 2016, our program FuChou attended many Surakarta tournaments and won the silver medal at TAAI 2016, ICGA 2017, TAAI 2017, ICGA 2018 and the gold medal at TCGA 2017.
Footnotes
Acknowledgements
This research was supported in part by a grant MOST 106-2221-E-003-027-MY2 from Ministry of Science and Technology, R.O.C.
