Implementation of A* Algorithm for Solving Sokoban Logic Games

Sokoban is one of the puzzle category games that requires players to push boxes towards the top, bottom, left and right until the specified destination. Sometimes it takes a long time to complete a very difficult level so that a solution is needed. So that these difficulties can be overcome, we need an algorithm that can help find the right path. A * algorithm is an algorithm that minimizes the total cost of the track under the right conditions that will provide the best solution in optimal time. A * algorithm will find the distance of the fastest route to be taken by a starting point to the destination object by removing unnecessary steps. From the test results, this A * algorithm can help players in finding a solution to the road in the form of completion steps in the Sokoban game by determining the smallest F value.


INTRODUCTION
The development of science and technology will never end and will grow faster along with the development of supporting technology. One of the many technologies that is growing is artificial intelligence. Artificial intelligence (AI) is the main focus in the world of research on how a computer program is able to learn and make decisions like humans. According to Herumurti and Kuswardayan [1], AI is integrated with the system, in general technically the AI system will automatically be able to read a person's pictures, sounds and desires about something. Artificial intelligence provides the basics of science in several fields of technology that can be used commercially, including expert systems, natural language processing, speech or speech recognition, robotics and sensor systems, to game applications [2]. Artificial intelligence has several advantages compared to intelligence possessed by humans, which is more permanent, easier to publish and disseminate, consistent, can be documented and done faster and better time [3]. According to Evi Aprilia [4], Artificial Intelligence is a part of computer science that studies about how a computer can be made in such a way that it can do work as and as well as humans do, while according to Edi Wijaya [5], artificial intelligence is a computer system formed to know and model human thought processes and design machines so that they can mimic human behavior. From some of the above understanding, it can be concluded that in order for computers to act like and as good as humans, computers are given the knowledge and ability to reason in order to gain experience like humans.
The concepts used in AI include the data structures used in the representation of knowledge, the algorithms needed to apply that knowledge, as well as the language and programming techniques used in implementing it. There are many techniques or algorithms adapted from the field of artificial intelligence. Some of them are Pathfinding, Dijkstra, Neural Network, Genetic Algorithm, Breadth First Search, Depth First Search, Best First Search and A * Algorithm in the shortest path search.
Algorithm A * is one algorithm for finding a comprehensive and complete route. The point is that the resulting route is the best route and the algorithm is used to achieve the expected goals. In its application, the A * algorithm uses distance values as the best value calculation process [6]. According to Wahyu Widodo [7], the A * algorithm is an algorithm that minimizes the total cost of the track and in the right conditions that will provide the best solution in optimal time.
Sokoban game is a logic-themed game so that a player does not only need dexterity of the hand but rather dexterity in thinking. Players can push squares in four directions, North, South, East and West. In sliding boxes, players are only allowed to move one box at a time. The players cannot push several boxes simultaneously. In addition, the player can only push the box if the player is in one position before the box.
However, there will be a time when a game has reached a very difficult level so that players will need a relatively long time to complete the game. In addition, players can feel bored or give up when completing a game with a very difficult level. For that we need a feature in the form of a solution that can provide assistance in the form of steps to complete the game.
So in order to help provide a solution to the completion step, Algorithm A * is an alternative that can be used in this Sokoban game.

Research methods
The method used in this research is the experimental method. The experimental method is a series of experimental activities with the aim of investigating something or a problem so as to obtain results. The stages carried out by researchers in this study are shown in Figure 1. a. Conduct a literature : In this step the researcher collects information about the Sokoban game and the A * algorithm from journals, articles, books and the internet. b. Identify and limit research problems : In this step the researcher identifies and limits the problems of the sokoban game. c. Develop methods or measuring devices : In this step the researcher determines the A * algorithm as a solution to the sokoban game according to the problem identification done by the researcher. d. Carry out an experiment : Researchers conduct trials until the application is truly ready to use, the deficiencies that occur are fixed according to the scope of the problem. e. Make documentation : If the trials are not appropriate, then the researchers reevaluate the methods and measuring devices so that the trials are as expected. but if the trials are appropriate, the researchers make documentation in the form of research reports.

Method of collecting data
According to Sugiyono [8] the data collection method is the most strategic step in research, because the main objective of the study is to obtain data. In this study to implement the results, researchers only need secondary data.
Literature study is a supporter of research originating from expert views in written form in the form of reference books, journals, research reports or other scientific works [9]. Researchers used a data collection method in the form of literature study by collecting references in the form of books, journals and literature relating to Artificial Intelligence, A * Algorithms and Sokoban games.

Data analysis method
In the preparation of this study, the method used by researchers is a qualitative analysis method. Qualitative analysis is a research procedure that intends to understand phenomena about what is experienced by research subjects such as behavior, perception, motivation, action, and so on.

RESULTS AND DISCUSSION
This section will explain how to apply the theory of the A * algorithm in the Sokoban logic game. In this explanation, an example calculation from the A * algorithm will also be given later.

Analysis of algorithm A*
One algorithm that can be used to find the shortest path is the A* algorithm. The A* algorithm was first discovered by Peter Hart, Nils Nilsson and Bertram Raphael in 1968. The A Star or A* algorithm is one of the search algorithms that analyzes inputs, evaluates a number of possible paths and produces solutions.
According to Kiki Setiawan [10], the A* algorithm is a computer algorithm that is widely used in graph traversal and path discovery and path planning processes that can be efficiently traversed around points called nodes. The characteristic that explains the A* algorithm is the development of a closed list to record the area being evaluated. This closed list is a list for recording adjacent areas that have been evaluated, then calculating the distance visited from the starting point with the distance estimated to the destination point [10].
To be able to find the way from the initial node to the destination node, a search is made of the graph. Tracing is usually done by following the edge of the connecting link between nodes as shown in figure 2 below : According to Naufal W. [11], A* has 2 main functions in determining the best solution. The first function called g (n) is a function used to calculate the total cost needed from the initial node to a specific node. The second function commonly referred to as h (n) is a function of the estimated total cost that is estimated from a node to the end node.
In finding the shortest route, algorithm A * uses the evaluation function expressed by the following formula / equation (1) G(n) = √Xn + Yn H(n) = |X(target) -X(n)| + |Y(target) -Y(n)| F(n) = G(n) + H(n) A* algorithm in this game will be applied to the completion of the game where the player pushes the box towards the target. In preparing this thesis the author uses the heuristic manhattan distance function which has 4 directions of movement (cannot move diagonally) because according to the application to be made the writer can only be shifted to 4 directions namely up, down, right and left. By using the heuristic manhattan distance function, the iteration value and the smallest number of steps are obtained. The steps for implementing the A * algorithm in the completion of the sokoban game can be explained as follows : 1. The destination node has been added to the open list, which means the route has been found. 2. Have not found the goal node while the open list is empty or means there is no route. 3. Save the route backward, starting from the goal node to its parent until it reaches the initial node while storing the node into a database.

Application of A* algorithm in sokoban games
A* algorithm is implemented in the sokoban game application which is used to find the shortest path of the player in pushing boxes to the target. The first step is to look for nodes around the current node and then we all fit into an array. Once accommodated, we calculate the value of F for each node in the array and we select the node that has the smallest F value as the best node. Then we move the current node to the best node. Do this repeatedly until the current node value is the same as the target node value. consider the following figure 3 :  Figure 3 is a view of the Sokoban level 1 board game with the initial node (player position) at coordinates (5.5) and target coordinates (5.9); (9.5); (1,5) and (5,1). Then the first step in calculating the A * algorithm is to detect all nodes around the box that allow for the box to pass. Calculate the value of G is the value needed to walk one node, H is the heuristic value or the estimate of the node to the target and F the sum of G and H. Then the information can be given in the generation of nodes as follows : 1). The first node in coordinates (5.6) and destination coordinates (5.9) has an F value of 10, 07106781 Gn = √Xn + Yn The calculation above is done repeatedly until all the coordinates of the box or box are in the coordinates of the destination or taget. In applying the A * algorithm in the sokoban game application, each coordinate movement is symbolized by the letters l, r, u and d taken from the prefixes of the words left, right, up and down to move from the player in the left, right, up, or down direction, while the capital letters L, R, U, D if the player moves to push a box. The solution step by using the A * algorithm at level 1, UUUdddRRlllLLLrrrDDD, is that the current node can reach the target node with 21 iterations using the smallest F value shown in table 1 below :

CONCLUSION
Based on the results of research made by the author about the Application of Algorithm A * in the concept of Artificial Intelligence on the completion of the sokoban game, the following conclusions can be drawn: 1. Algorithm A * is successfully applied to the sokoban game to find the shortest path from an initial coordinate to the coordinates of the game or destination by using the smallest F value. 2. With the A * algorithm the game can be solved with a step solution so that the path search can be found in a short time.

FUTURE WORKS
The research conducted at this time aims to apply the rules in the A * algorithm in solving the problem solving step of the Sokoban logic game. For further development in the process of finding a path in the Sokoban game, another search algorithm can be added, so that the fastest path solution can be produced. In addition to making it more interesting, it is necessary to add a meatball and the level changes automatically if the player successfully completes a level.