Winning Snake: Design Choices in Multi-Shot ASP

Elisa Böhl,Stefan Ellmauthaler,Sarah Alice Gaggl
2024-08-15
Abstract:Answer set programming is a well-understood and established problem-solving and knowledge representation paradigm. It has become more prominent amongst a wider audience due to its multiple applications in science and industry. The constant development of advanced programming and modeling techniques extends the toolset for developers and users regularly. This paper demonstrates different techniques to reuse logic program parts (multi-shot) by solving the arcade game snake. This game is particularly interesting because a victory can be assured by solving the underlying NP-hard problem of Hamiltonian Cycles. We will demonstrate five hands-on implementations in clingo and compare their performance in an empirical evaluation. In addition, our implementation utilizes clingraph to generate a simple yet informative image representation of the game's progress.
Artificial Intelligence
What problem does this paper attempt to address?
The problem that this paper attempts to solve is how to use multi - shot Answer Set Programming (ASP) techniques to design and implement different strategies for the "Snake" game in order to optimize the process of winning the game. Specifically, the paper explores how to ensure that the snake in the game can reach the maximum length by solving the NP - hard problem - Hamiltonian Cycles, and minimize the number of moves and computation time in this process. ### Main concerns of the paper: 1. **Guarantee of winning the game**: Ensure that the snake can reach the maximum length (i.e., fill the entire grid) regardless of the position of the apple. 2. **Minimizing the number of moves**: Reduce the number of snake moves required to complete the game. 3. **Minimizing computation time**: Optimize the algorithm to reduce computation time, especially in multi - shot settings. ### Implementation methods: The paper proposes five different multi - shot ASP implementation methods. Each method is designed differently in terms of how to handle the `next/2` atom to meet the requirements of multi - shot games. These methods include: - **One - Shot**: Regenerate and solve the logic program in each iteration. It is suitable for rapid development projects but has low efficiency. - **Ad Hoc**: Dynamically adjust the logic program by adding and deleting rules. It has high flexibility but increases code complexity. - **Preground**: Pre - compile all possible temporary rules and control the enabling and disabling of rules through external predicates. It is suitable for compact programs with a large number of iterations. - **Assume**: Avoid direct modification of the logic program by assuming the truth values of fixed non - external atoms, but the assumptions need to be re - specified for each solution. - **Nogood**: Add custom nogoods during the search process to affect the search progress. It is suitable for situations where the search path needs to be dynamically adjusted. ### Conclusion: Through the empirical evaluation of these methods, the paper compares the performance differences among different methods and provides insights on how to choose the appropriate method to develop multi - shot applications. In addition, the paper also shows how to use `clingraph` to generate a simple and intuitive graphical representation of the game process, enhancing the visualization of the results.