Winning Snake: Design Choices in Multi-Shot ASP
Elisa Böhl, Stefan Ellmauthaler, Sarah Alice Gaggl
TL;DR
Answer Set Programming (ASP) is used to model an iterative, multi-shot solving process on grid graphs $G(n,m)$ to win the Snake game by ensuring a Hamiltonian cycle (HC); this HC problem is NP-hard. The authors formalize the Snake game as Hamiltonian-snake problems (HS, MHS) and present five clingo-based multi-shot implementations (One-Shot, Ad Hoc, Preground, Assume, Nogood) with heuristic initialization and image-based visualization via clingraph. They compare approaches empirically across grid sizes, showing that reusing search progress in multi-shot ASP can reduce grounding and solving time, with results depending on $n$ and $m$ and the presence of timeouts. The study provides practical design patterns for applying multi-shot ASP to iterative, combinatorial tasks and discusses trade-offs between implementation complexity and execution efficiency, suggesting directions for future work such as alternative problem formulations and broader showcase applications.
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.
