Hostname: page-component-77f85d65b8-hzqq2 Total loading time: 0 Render date: 2026-03-29T21:35:36.183Z Has data issue: false hasContentIssue false

Winning Snake: Design Choices in Multi-Shot ASP

Published online by Cambridge University Press:  15 January 2025

ELISA BÖHL
Affiliation:
Logic Programming and Argumentation, TU Dresden, Germany (e-mails: elisa.boehl@tu-dresden.de, sarah.gaggl@tu-dresden.de)
STEFAN ELLMAUTHALER
Affiliation:
Knowledge-Based Systems Group, ScaDS.AI/cfaed, TU Dresden, Germany (e-mail: stefan.ellmauthaler@tu-dresden.de)
SARAH ALICE GAGGL
Affiliation:
Logic Programming and Argumentation, TU Dresden, Germany (e-mails: elisa.boehl@tu-dresden.de, sarah.gaggl@tu-dresden.de)
Rights & Permissions [Opens in a new window]

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 compiles and 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 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.

Information

Type
Original Article
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited.
Copyright
© The Author(s), 2025. Published by Cambridge University Press
Figure 0

Fig 1. Examples for a snake on a $6\times{}6$ grid generated by our software. The snake head is marked with eyes.

Figure 1

Fig 2. Examples for a snake on a $6\times{}6$ grid. Black lines indicate HCs.

Figure 2

Algorithm 1 base logic program to solve one iteration of snakes

Figure 3

Algorithm 2 Main Algorithm for iteratively computing snake paths

Figure 4

Algorithm 3. retrieve for one-shot

Figure 5

Algorithm 4. retrieve for ad hoc; Input: Π, ; Output: Π, path

Figure 6

Algorithm 5. retrieve for preground; Input: Π, ; Output: Π, path

Figure 7

Algorithm 6. retrieve for assume; Input: Π, Output: Π, path

Figure 8

Algorithm 7. retrieve for nogood; Input: Π, ; Output: Π, path

Figure 9

Algorithm 8. my_func - code snipped to add as search restriction

Figure 10

Table 1. (a) Average number of total steps per run. Outliers are underlined. (b) Average total time per game in seconds, timeout $60\,{\rm s}$, best value bold

Figure 11

Fig 3. Average number of steps (solid lines) and timeout rate in percent (dashed lines) per iteration for different grid sizes for timeout 60s. Dotted gray line is the expected step count for the naive strategy (baseline).