Two Classic Chess Problems Solved by Answer Set Programming

The n-Queen and the Knight’s tour problem are studied by several authors who have proposed some methods to solve them. The ASP (Answer Set Programming) is a form of declarative programming oriented to difficult search problems; however, the literature does not present its use in solving these two classic and interesting chess puzzles. Thus, this work aims to solve the n-Queen and Knight’s Tour problems by ASP and show it can solve combinatorial problems. Keywords— Combinatorial problems, Answer Set Programming, Computation applied.


I. INTRODUCTION
Answer Set Programming (ASP), is a form of declarative programming oriented to a difficult search problem, mainly NP-hard [16,17,18].The ASP has application in relevant industrial projects because to the availability of some efficient ASP systems [16,17].Nevertheless, ASP can be applied to several areas of science and technology, for example: automated product configuration, decision support for space shuttle and automatic route search [17].The classical problems involving chess are a constant subject of heuristic and optimization studies [10,12,13].The n-Queen Problem consists of finding the position of n-queens on a chessboard n x n.The Knight's Tour Problem aims to construct a sequence of admissible moves made by a chess knight from one square to another so that they land on each square of a board exactly once.Both problems are interesting classical chess puzzles solved by many computational and mathematical methods [9,11].In this sense, the objective of this work is to propose the solution of these two classic challenges of chess through Answer Set Programming (ASP), proving that ASP is able to solve combinatorial problems.

II.
CHESS PROBLEMS DESCRIPTION a.The Knight's Tour Problem The knight's tour problem consists of a series of moves (in an L-shape, see Fig. 1) made by a knight visiting every square of an n x n chessboard exactly once [ 14,15,19].We can define the problem as knight's graph for n x n chessboard to be graph  = (, ) where  = {(, )|1 ≤ ,  ≤ }, and  = {((, ), (, ))|{| − |, | − |} = {1,2}}.Such that, there is a vertex for every square of the board and an edge between two vertices exactly when there is a knight move from one to another.A knight's tour is called closed if the last square visited is also reachable from the first square by a knights move, i.e., an open knight's tour is defined to be a Hamiltonian path; and open otherwise, i.e., closed knight's tour is defined to be Hamiltonian cycle on a knight's graph [19].

Fig. 1: Knight possible moves in an L-shape
The knight's tour problem is used as the basis of studies for the development of cryptographic schemes [14] and implementation of random binary numbers [15].The literature points to some methods that propose the solution of the knight's tour problem, such as Artificial Bee Colony [10] and structural algorithms with predefined heuristic rules [20].
b.The n-Queens Problem The n-Queens problem is to place n queens (a queen can move as far as she pleases, horizontally, vertically, or diagonally.See Fig. 2), on an n × n chessboard in such a way that no queen can attack another, i.e., so that no two queens are placed in the same row or column or on the same diagonal.This problem is a generalization of the original 8-Queen's problem [7].Survey of known results is given in [1].The n-Queens problem is often studied because there are several practical applications: VLSI (Very Large Scale Integration) testing, traffic control, parallel memory storage schemes, and deadlock prevention [6,5], memory storage scheme for conflict free acces s for parallel memory systems [2,3,4].

III. IMPLEMENTATION AND EXPERIMENTAL RESULTS
All the experiments presented in this section have been performed with CLINGO 4.5.We also present solutions to the problem of n-Queens on square boards 5x5, 6x6, 7x7, and 8x8, proving that the ASP algorithm is able to solve combinatorial problems.

Fig. 2 :
Fig. 2: Queen piece available moves Let  = {0,1, . . .,  − 1}, we can uniquely assign to each position on the board a par (i,j) of coordinates in the usual manner, with ,  ∈ .Then a solution can be thought of as a permutation f from K to K satisfying (1) e (2) for all x, y in K,  ≠  (1) () −  ≠ () −  (2) () +  ≠ () +  Such permutation f will be called ordinary solution.Instead of condition (1) and (2) one might also consider permutations f satisfying (a) and (b) for all x, y in K,  ≠  (a) () −  ≠ () −  () (b) () +  ≠ () +  () A permutation f satisfying (a) and (b) is called modular solution.Any modular solution is also an ordinary solution.The n-Queens problem is often studied because there are several practical applications: VLSI (Very Large Scale Integration) testing, traffic control, parallel memory storage schemes, and deadlock prevention[6,5], memory storage scheme for conflict free acces s for parallel memory systems[2,3,4].