
Card games as pointer structures: case studies in mobile CSP modelling A.W. Roscoe Oxford University Department of Computer Science Abstract. The author has long enjoyed using the CSP refinement checker FDR to solve puzzles, as witnessed by examples in [7, 8]. Recent exper- iments have shown that a number of games of patience (card games for one) are now well within bounds. We discuss the modelling approaches used to tackle these and avoid symmetric states. For two such games we reveal much higher percentages of winnable games than was previ- ously believed. The techniques developed for some of these card games { which employ various dynamic patterns of cards { suggest techniques for modelling pointer structures in CSP and FDR analogous to those used with the π-calculus. Most of these use CSP's ability to express mobile systems. 1 Introduction The author has long enjoyed solving mathematical and combinatorial puzzles, so the advent of FDR in the early 1990's quickly led to him to try some of them out. The interested reader will find solutions to peg solitaire in [7, 8] and to Sudoku in [8]. The former has become perhaps the best known benchmark for different versions and implementations of FDR, for example in [1, 2]. These examples proved very useful for demonstrating how much better model checking is than humans at finding counter-examples in many situations, and for teaching students how to use FDR effectively. At the same time they have been a useful source of student exercises.1 At the same FDR has been used in a wide range of practical contexts, and the methods developed for efficiently coding these and puzzles frequently cross- fertilise. The author had never, until recently, coded a game of cards in CSP. This was for a variety of reasons: { The 52! different orderings of a pack of cards seems prohibitive in contem- plating potential possibilities. 1 The author gives an annual advanced course in the use of FDR and CSP, and often uses a puzzle as the first half of the take-home assignment. Previous years have included sudoku, magic squares, the unique non-trivial magic hexagon, reversible peg solitaire, knights exchange (also used as a benchmark in [1, 2]), and \jumping frogs" in multiple dimensions. The 2015 and 2016 ones were based respectively on on Freecell and Montana solitaire, two of the examples from the present paper. { CSP's models and the way FDR works do not provide an efficient means for deciding the winner in games with multiple players trying to beat each other.2 { Most games of patience (i.e. card games for one, getting round the previous objection) have dynamic structures, with the cards being moved around into structures that change size or shape as the game progresses. FDR has generally been considered as much more suitable for static structures. The first (state-space) objection can be addressed by observing that solving a particular deal of patience need not have anything like 52! states, though plainly the state space sizes of games with dynamic structure are potentially increased by this in a way not directly related to the number of deals. Also, the ever improving capabilities of FDR [1, 2] (for example parallelising efficiently on multi-core and cluster architectures: the 187M states of peg solitaire have been brought down to 23 seconds on our 32-core server and less than 2 seconds on a 1024 core cluster) mean that the sizes of problems that can be addressed routinely using FDR has increased greatly in the last few years. In fact virtually none of the patience game checks that the author has run from the examples quoted here exceed 109 states, a pretty routine level with the multi-core implementation of FDR at the time of writing, though the time taken for runs is a little more than implied by the solitaire figures above, because of the greater complexity of the CSP models. Few take more than 5 minutes exploring the state space on the server discussed here. The second objection is addressed by considering patience games. The third is alleviated by the observation that CSP has been shown, for example in [9] and Chapter 20 of [8] to be capable of handling mobile structures. In this paper we consider the issues of coding patience games in CSP, which includes building various dynamic structures and avoiding various ways in which symmetry can multiply state spaces. Some of these structures are in effect linked lists and other pointer-based constructions. This work gives us insight into how to support the translation into CSP of more general programming models requiring similar structures, particularly ones based on pointers. Most readers will be familiar with the card games called patience or solitaire, having played them via programs, apps, websites, or if they are (like the author) sufficiently old, with real cards.3 We use the name patience in this paper, to provide a clear distinction from peg solitaire. A game starts by shuffling one, or sometimes two packs of cards, then dealing some or all of them into a pre-set pattern. The player then manipulates the cards according to the rules of the particular game, usually aiming to arrange all the 2 The received wisdom has been that they cannot do this at all, however in writing this paper I have discovered that there is a contrived way (that would not scale well to difficult problems) of doing it, illustrated the accompanying file tictactoe.csp, which analyses the winnability of the simple game noughts and crosses or tic tac toe. It shows how the algebra of CSP can calculate a general minimax over a tree. 3 The latter (see figures) also proved useful in checking CSP descriptions. cards into ordered suits in some way. A given deal is winnable if this is a possible outcome. In some cases the question of winnability is complicated by hidden cards or further nondeterminism beyond the initial shuffle. We will discuss this later. In the next section we give background information about CSP, FDR and a few games of patience. Section 3 discusses how to code them, together with our results. All the CSP programs discussed in this paper can be downloaded from the author's publications web page, along with this paper. 2 Background 2.1 CSP In this paper we will make extensive use of the extension of CSP by functional programming constructs, known as CSPM , and described in detail in [7]. This allows to create data types, use inbuilt structures such as tuples, lists and sets, and to write concise programs which lay out large networks of component pro- cesses indexed by such structures. Thus we can model the various components of a card game at the programming level, and then, for example, lay out the initial configuration of a game as a network of one process per card. For this reason the notation given below is that of CSPM rather than the blackboard language seen in most books and papers. The main CSP operators used in this paper are: { STOP The process that does nothing. { a -> P The process that communicates the event a and then behaves like P. The single event a can be replaced by various choice constructs such as c!e?x:D. This particular one assumes that c is a channel with two data components. This construct fixes the first to be the value of the expression e and allows the second to vary over D, assumed to be a subset of the type of the second component. If D is absent it varies over the whole of this type. In cases with such an input, the successor program P can include the input identifier x. { P [] Q is the external choice operator, giving the choice of the initial visible events of P and Q, and then continuing to behave like the one chosen. Like a number of other CSP operators, CSPM has both the binary and an indexed form [] x:A @ P(x), meaning the external choice over all the processes P(x) as x varies over the set D. The effect of the blackboard CSP ?x : D ! P(x) (which has no literal translation in CSPM ) can be achieved via [] x:D @ x -> P. CSPM also has P |~| Q as its internal, or nondeterministic choice operator, which allows the process to choose between the arguments. However this operator will not feature in this paper. { The final constructs we will use for building sequential processes allow us to put two processes in sequence: SKIP is a process that terminates successfully and P;Q lets P run until it terminates successfully and then runs Q. Successful termination is represented by the process communicating the special event X, and is distinct from STOP. Thus STOP;P = STOP and SKIP;P = P. { CSP has a number of parallel operators. The ones we shall use here are al- phabetised parallel and generalised parallel. Alphabetised parallel is written P [A||B] Q, where P and Q are respectively communicating in their alpha- bets A and B, with them forced to synchronise on actions in the intersection of their alphabets. Most of our uses of this operator will be in its indexed form || i:I@[A(i)]P(i) where A(i) is the alphabet of P(i), and an ac- tion in the union of these alphabets occurs just when all the P(i) with it in their alphabet perform it. Generalised parallel P [|A|] Q specifies just the interface A that P and Q must synchronise on, with them being free to communicate anything else independently.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages16 Page
-
File Size-