CEng 561 Term Project Implementation Report Guidelines İpek Tatlı METU Computer Engineering. Ankara, Türkiye [email protected] Abstract I have been building an agent for a Japanese puzzle Akari[1]. It was developed by Nikoli in 2001 and is also called Light Up. In this paper, I describe a brief explana tion of my project topic, description of Akari environment, my AI approach to solve this problem, overall design of my system, the things that I implemented so far within this project and evaluation of results. INTRODUCTION Akari is a binary determination logic puzzle. percepts and actions is limited, then the environment is dis crete. Environment consist of only one intelligent agent and there is a goal in the game. To sum up, the puzzle en vironment is fully observable, deterministic, sequential, static, discrete, singleagent and goalbased. GOAL FORMULATION The goal is to lit up the entire grid placing exact number of bulbs around numbered cells and not allowing two bulbs face each other. Figure 1. Initial Akari Board Status Figure 2. Goal Formulation It is played on a rectangular board having white and black cells. A black cell may have a number on it from zero to four. That number shows the number of bulbs which must be placed on the neighbors of that black cell. Neighbors of a black cell are the one above, the one below, the one on the right and the one on the left of that black cell. MY APPROACH TO SOLVE AKARI I use informed search for this problem. I cannot use unin formed search strategies; they can be a solution for this problem in only very small Akari boards because of space and time complexities. The player can place the bulbs on only white cells, but two bulbs should not shine on each other. The entire row and column of a bulb are lit up unless there is a black cell (wall) in the way. The aim of the game is to illuminate all the white cells re specting the numbers written on the black cells and no two bulbs shinning on each other[2]. PUZZLE ENVIRONMENT Agent is able to access to the complete state of the Akari environment while choosing an action, so the environment is fully observable. The next state of the environment is completely determined by the current state of the environ ment and the action of the agent, so it is deterministic. The agent engages in a series of connected episodes, therefore it is sequential. The environment does not change while the agent is thinking, then it is static. The number of distinct Let's think about a brute force algorithm. For example for an n*n Akari board there are n*n cells on the board and each cell may have a bulb or not. So the worst case of the problem is 2^(n^2) states to be controlled. For a best case approximation, let’s assume an n*n Akari board having no black cells. I can choose a solution like placing bulbs diagonally. For each cell, I can place a bulb on it or not. So the number of states is 2^n. This is reasonable for a 5*5 board, but for a 20*20 or 30*30 board it becomes intractable if it is solved in an uninformed way because of its diverge search space. Such big boards and bigger ones may be intractable. A* and greedy search algorithms are also very prohibitive because they keep all nodes of the search tree in the memo ry. So I use a best first search algorithm which uses some heuristic functions. Its structure is similar to DFS, but rather than continuing indefinitely down the current path, it keeps track of the best alternative path available from any ancestor of the current node. Later some inductive learning algorithm can also be used to construct a function that may predict solution costs for other states that arise during the search. OVERALL DESIGN OF MY SYSTEM I have built a two phase agent. In the first phase, the agent analyzes the board in terms of certain bulbs and dots (the places where a bulb can never be placed). In the second phase, the agent starts building and traversing a search tree with some heuristic functions, trying to complete the puzzle. state, before seeking to other states (for example, putting lights on both sides of 2 instead of trying to put a light on either side of 1 on bottomleft corner in Figure 4), and so the branching factor of the root is kept minimal. Secondly, my agent tries to give priority to cells according to some reasonable heuristic functions. Thirdly, according to some pruning heuristics it prunes the search tree earlier. A bulb lights up the entire row and column to help decide which originallyempty neighbors of a black cell are really empty. First Phase: Placing the certain bulbs and dots Firstly my agent finds black cells with a 4 written on them and places four bulbs on the neighbors of those black cells. It also shows the rows and columns of those black cells as lit up; so no other bulbs will be placed on the mentioned rows and columns. Then if it finds black cells with a 3 written on them having only empty white cell neighbors, it places the bulbs on those neighbors and shows the entire rows and columns of the bulbs are lit up. Figure 5. Placing bulbs Figure 6. Placing bulb around 2 around 1 It can do the same for black cells with a 2 written on them having only two empty white cell neighbors and for black cells with a 1 written on them having only one empty white cell neighbors. Figure 7. Placing bulb Figure 8. Goal state around 1 of the puzzle Figure 3. Placing bulbs around 4 Then the agent finds the black cells with a 0 and places dots on the neighbors of that black cell implying that no bulbs can be placed there. IMPLEMENTATION I have classified actions of my agent into three groups. First group consists of must actions to be taken in phase 1 and in each state transition of phase 2. Second group is composed of the actions which cause a failure and the ac tions in the third group help my agent to decrease the branching factor in its search tree. Must Actions Placing dots on the white cells on which bulbs cannot be placed is the basic action. As an example, the player should place dots on the neighbors of a black cell with a 0 written on it. Figure 4. Placing dots around 0s Second Phase: Building and traversing search tree The agent places the bulbs according to the Akari game rules by traversing a search tree. Firstly it tries to reduce the number of states by performing mustactions at every Placing bulbs on the empty neighbors of a black cell with a number on it (if the number of empty neighbors is equal to the necessary number of bulbs) is another basic action. For example; a typical starting point in the solution of an Akari puzzle is to find a black cell with a 4 written on it. The only possible configuration for the bulbs is to place them on the neighbors of that black cell. A black cell with a 3 near another black cell or on the edges of the board also has only one configuration for bulbs. So the agent should place bulbs on the remaining neighbors of that black cell. there are two bulbs around a black cell with 1 written on it, then this is a failure #2 situation (Figure 11). A black cell with a 2 in a corner also has only one configu ration of surrounding bulbs same as the situations above. According to the rules, a bulb illuminates its whole hori zontal and vertical way unless there is a black cell (wall) in the way, so placing ‘+’s to the entire row and column of that bulb until faced with a wall is also a basic action. To decrease the number of the empty cells on the board, we can also place dots on the white cells where we are sure that a bulb cannot be placed there (e.g. placing dots on the empty neighbors of black cells which already have their correct number of bulbs) (Figure 9). Figure 11. Failure #2 3 If there are no empty neighbors around a black cell and the number of bulbs around that black cell is not equal to the number written on it, this is also a failure. The black cell with a 2, which is marked in Figure 12, is an example for failure #3. Figure 9. Placing dots if there are correct number of bulbs around a black cell These actions are implemented in Phase I, in other words they are about placing the certain bulbs and dots. My agent also does these actions in every state in its search tree in Phase II. Actions which cause failure There are some situations to be avoided according to the rules of Akari which I call them “actions that causes fail ure”. I am controlling these situations while searching through a state transition tree. When the agent enters such a situation, it directly leaves that state node. Figure 12. Failure #3 4 If the number of empty neighbors is smaller than the necessary number of bulbs, then this situation also causes a failure. The black cell with a 4, which is marked in Figure 13, has zero empty white neighbors, but it needs one bulb to surround itself. This is an example for failure #4. Some actions which cause failure and should be avoided are here: 1 If two bulbs are shinning on each other, this causes a failure (Figure 10). Figure 13. Failure #4 Figure 10. Failure #1 2 If the number of bulbs around a black cell is bigger than the number written on that wall, then this is a failure. e.g. if 5 If the entire row and column of a dot is already decided, and there are no empty white cells until faced with a wall on the way, then this also causes a failure for my agent. The dot, which is marked in Figure 14, is an example for failure #5. Heuristic Functions Figure 14. Failure #5 Actions which decrease the branching factor I am using two heuristic functions for my agent. First one is about being on the same line with dots (more dots should be illuminated with as minimum number of lights as possible and then dots should become ‘+’). Another heuris tic is about being a neighbor to the black cells (black cells should be surrounded by correct number of bulbs). My first heuristic function finds how many dots are on the same line (until faced with a wall) with any of the empty cells. Some situations cause a deadend branch which should be pruned earlier when detected. For example, if an empty cell cannot be illuminated by a bulb, in other words if there are not any empty cells on its horizontal and vertical way until faced with a wall; placing a bulb on that empty cell helps my agent to decrease the size of its search tree (Figure 15). Figure 17. Board state after main actions Sample heuristic1 values for the Akari Board state in Fig ure 17 (x:0 y:0 is the upper left corner here): Figure 15. Decreasing the size of search tree And a special case that I observed while watching my agent’s solving some Akari puzzles: Let’s think about a dot. It has only one empty neighbor, and there is a wall on the same line with that dot and its empty neighbor. The other neighbors of the dot are already decided. The entire row of that dot passing through the non empty neighbors is also decided until faced with a wall. Then placing a bulb on that empty neighbor is a good action to decrease the branching factor. I saw its effect by running my program with and without this control (Figure 16). Figure 16. Decreasing the size of search tree These actions help my agent to keep its branching factor minimum. x y H1 coordinat coordinat value 3 3 0 2 3 1 2 6 2 Table 1. Heuristic1 values for some coordinates My second heuristic function finds if the empty cells are neighbor to the black cells or not. Sample heuristic2 values for the Akari Board state in Fig ure 17(x:0 y:0 is the upper left corner here): x y H1 coordinat coordinat value 2 6 0 2 3 1 Table 2. Heuristic2 values for some coordinates I created a new heuristic by using these two functions. Not to have same heuristic values for different cells, I multi plied the first one with 2, and then subtract 1 if that cell is a neighbor to any wall. According to these heuristic values of empty white cells, my agent selects one of those empty white cells, and places a bulb on the mentioned white cell. This way, it uses H1 as the primary heuristic, and H2 as the secondary heuristic when H1 values are the same for two cells.This helped to select the cells not by chance, but by some different values. Implementation Environment I am implementing my agent using Java and I also use Java Swing for presenting a graphical user interface. I have firstly implemented the agent as a command line program. Then I implemented a GUI for the agent to track progress easier. Here is a screenshot from GUI of my agent: of iteration increases when it is solved with informed search (Method1 in Table 3). Pruning dead–end branches, which is implemented with informed search, affects the so lution duration positively (Method2 in Table 3). My first heuristic function affects small Akari boards negatively, but it helps to decrease number of iterations in bigger boards(Method3 in Table 3). When heuristic1 and heuris tic2 are used together, harder Akari puzzles are solved in more reasonable time(Method4 in Table 3). I have also found and added average branching factors for my sample Akari puzzles to the table above. CONCLUSION Figure 18. GUI of my Akari Puzzle Solver EVALUATION I have solved some Akari puzzles in different levels of dif ficulty with my agent and got some results which are stated in Table 3 below: average branchin Method Method Method Method g 1 2 3 4 factor difficult y Size easy 8x10 easy mediu m 10x10 hard 16x10 - 6 4 6 8 4 389 38 46 55 8 12x10 >40000 11.150 432 256 13 1752 18 - - Table 3. Number of iterations with different methods It can be seen in the table above that as the Akari board size and average branching factor gets bigger, the number I think my search algorithm choice is good enough; consid ering Akari is NPcomplete [3]. The most obvious difficul ty is to find good heuristic functions to solve bigger puz zles in a reasonable time. I tried a simple heuristic like se lecting the empty cells (in order to place a light) in the or der of their place on the board, but it did not help me in bigger and harder puzzles. Moreover, watching the solution step by step was useful that I could find out some situations which would unnecessarily make the tree bigger. In conse quence of this, some more pruning heuristics which will help my agent to prune deadend branches earlier should be found and implemented. REFERENCES [1] Light Up, available at <http://en.wikipedia.org/wiki/Light_Up> [2] Sample Problems of Akari Puzzle, available at <http://www.nikoli.com/en/puzzles/bijutsukan> [3] Light Up is NPComplete Paper, available at <http://www.cs.umass.edu/~mcphailb/pa pers/2005lightup.pdf>
© Copyright 2025 Paperzz