Learning patterns for playing strategies

2 downloads 0 Views 221KB Size Report
is the rst attempt to learn patterns in Chess using a rst-order framework. To test if the patterns learned by PAL can be used to play, a simple endgame was ...
Learning patterns for playing strategies Eduardo Morales M. Instituto Tecnologico y de Estudios Superiores de Monterrey { Campus Morelos, Apto. Postal C{99, Cuernavaca, Morelos, 62050, Mexico Tel: (73) 14{21{28, Fax: (73) 14{13{82 email: [email protected] Abstract A rst order system, PAL, that can learn Chess patterns in the form of Horn clauses from simple example descriptions and general purpose knowledge about Chess is described. This is the rst time that Chess patterns which can be used for over-the-board play have been learned. To test if the patterns learned by PAL can be used to play, a simple playing strategy for the King and Rook against King (KRK) endgame was constructed with patterns learned by PAL. Limitations of PAL in particular, and rstorder systems in general, are exposed in domains like Chess where a large number of background de nitions may be required for induction. Conclusions and future research directions are given. Keywords:

First-order concept learning, ILP, Chess, rlgg, automatic example generator, experimental evaluation.

1 Introduction It is believed that chess masters use a pattern-based knowledge to analyze a position, followed by a pattern-based controlled search to verify or correct the analysis [5, 7]. Some attempts have been made to use a pattern-based approach by hand-coding the required patterns in some \simple" endgames (e.g., Bramer [1], Bratko [2], etc.) or \tactically sharp" middle games (e.g., Wilkins [19]). While the emphasis has been made on ways of how to use and combine patterns to produce plans, very little progress has been made within the machine learning community to try to learn them. We have developed a system, called PAL1, that uses  1

This research was completed while the author was doing his Ph.D. thesis at the Turing Institute, Glasgow. PAtterns and Learning

1

general purpose Chess knowledge in the form of Horn clauses to learn patterns such as threat, fork, pin, skewer, discovery check/attack, etc. from simple example descriptions [10, 11]. This is the rst attempt to learn patterns in Chess using a rst-order framework. To test if the patterns learned by PAL can be used to play, a simple endgame was considered, where a playing strategy designed around the recognition of patterns can be easily constructed and tested. Section 2 provides some de nitions from logic. The concepts and notations will be used in the sections to follow. Section 3 brie y describes PAL and its generalization method. Section 4 describes the KRK playing strategy, the concepts learned by PAL to construct it, and how it was evaluated. Section 5 shows how extra background knowledge can be used to improve the strategy with less development e ort. Finally, conclusions and future research work are given.

2 Preliminaries A variable is represented by a string of letters and digits starting with an upper case letter. A function symbol is a lower case letter followed by a string of letters and digits. A predicate symbol is a lower case letter followed by a string of letters and digits. A term is a constant, variable or the application of a function symbol to the appropriate number of terms. An atom or atomic formula is the application of a predicate symbol to the appropriate number of terms. A literal is an atom or the negation of an atom. Two literals are compatible if they have the same symbol, name and number of arguments. The negation symbol is :. A clause is a disjunction of a nite set of literals, which can be represented as fA1; A2; : : :; An; :B1; : : :; :Bm g. The following notation is equivalent:

A1; A2; : : :; An

B1; B2; : : :; Bm.

A Horn clause is a clause with at most one positive literal (e.g., H B1; : : :; Bm). The positive literal (H ) is called the head, the negative literals (all Bis) the body. A clause with empty body is a unit clause. A set of Horn clauses is a logic program. F1 syntactically entails F2 (or F1 ` F2 ) i F2 can be derived from F1 using the deductive inference rules. A substitution  = fV1=t1; V2 =t2 ; : : :; Vn =tng consists of a nite sequence of distinct variables paired with terms. An instance of a clause C with substitution , represented by C , is obtained by simultaneously replacing each occurrence of a component variable of  in C by its corresponding term.

2

3 Generalization method and PAL Inductive Logic Programming (ILP) is a fast growing research area which combines Logic Programming and Machine Learning [14]. The general setting for ILP is, given a background knowledge K (in the form of Horn clauses) and sets of positive (E + ) and negative (E ? ) examples, nd a hypothesis H (another set of Horn clauses) for which K ^ H ` E + and K ^ H 6` E ? . That is, nd a hypothesis which can explain the data in the sense that all the positive (E + ) but none of the negative (E ? ) examples can be deduced from the hypothesis and the background knowledge. This inductive process can be seen as a search for logic programs over the hypothesis space and several constraints have been imposed to limit this space and guide the search. For learning to take place eciently, it is often crucial to structure the hypothesis space. This can be done with a model of generalization. Searching for hypothesis can then be seen as searching for more general clauses given a known specialized clause. Plotkin [16, 17, 18] was the rst to study in a rigorous manner the notion of generalization based on -subsumption. Clause C -subsumes clause D i there exists a substitution  such that C  D. Clause C1 is more general than clause C2 if C1 -subsumes C2. Plotkin investigated the existence and properties of least general generalizations or lgg between clauses and the lgg of clauses relative to some background knowledge or rlgg. That is, generalizations which are less general, in terms of -subsumption, than any other generalization. The lgg algorithm replaces all the di erent terms that have the same place within compatible literals by new variables (see [16] for more details). For example, if we have two compatible literals: L1 = threat(white,rook,square(1,3),black,bishop,square(4,3)) and L2 = threat(white,queen,square(1,4),black,bishop,square(7,4)) then lgg(L1 ; L2) = threat(white,Piece1,square(1,Y),black,bishop,square(X,Y)) This generalization process is repeated between all the pairs of compatible literals within clauses. More recently, Buntine [3] de ned a model-theoretic characterization of -subsumption, called generalized subsumption for Horn clauses (see [3] for more details). Buntine also suggested a method for constructing rlgg s using Plotkin's lgg algorithm between clauses. The idea, for unit clauses, is as follows. Given two unit clauses C1 and C2, the rlgg of C1 and C2 relative to some background knowledge K can be obtained by taking the lgg of C1' and C2' de ned as: C1' = C1 A1; A2; : : :. 3

C2' = C2

A1; A2; : : :.

Where Ais are facts derived from the background knowledge (representing a model of K). The general idea of the rlgg algorithm is to augment the body of the example clauses with facts derived from the background knowledge de nitions and the current body of the example clauses, and then generalized these \saturated" clauses using the lgg algorithm. In general, rlgg does not exists2 as an in nite number of facts can be derived from the background knowledge (BK). However, rlgg exists for BK without variables (as in Golem [13]), BK without function symbols (as in Clint [8]), and when only a nite number of facts are deducible from the BK, either by limiting the depth of the resolution steps taken to derive facts and/or by constraining the BK, as in PAL. Even with a nite set of facts, the lgg of two clauses can generate a very large number of literals and some additional constraints are required to achieve practical results. In PAL we apply a novel constraint which identi es the role of the pieces in di erent example positions to reduce the complexity of the lgg algorithm.

3.1 PAL Examples in PAL are given as descriptions of Chess positions (i.e., a set of ground atoms stating the position of each piece in the board), and unlike other systems, the exact arguments involved in the target concept are not speci ed in advance. A Chess position can be completely described by a set of four-place atoms (contents/4) stating the side, name, and place of each piece in the board. For instance, contents(white, rook, square(2,3), pos1) states that a white Rook is at the second le and third rank in position 1. Other pieces in a board position can be described in the same way. In general, other descriptions can be used as well [12]. Each example description is added to the background knowledge from which a nite set of facts are derived. PAL induces pattern de nitions with the following format: Head

D1; D2; : : :; Di ; F1; F2; : : : ; Fj ; MV; Fj+1; : : : ; Fj+m

where,

 Head is the head of the pattern de nition. Instantiations of the head are regarded as the patterns recognized by the system.

 The Di s are \input" predicates used to describe positions (i.e., contents/4) and represent the pieces which are involved in the pattern.

2

See [15] for a more thorough discussion on generalization.

4

 The Fis are instances of de nitions which are either provided as background knowledge or learned by PAL, and represent the conditions (relations between pieces and places) to be satis ed by the pattern.

 MV is the \move" predicate representing a legal move with the opponent's side not

in check. With MV, the actual movement of a piece is performed (changing the description of the board). The Fj+ns are instances of pattern de nitions that change as a consequence of the move.

PAL starts with some pattern de nitions as background knowledge and use them to learn new patterns. For instance, the de nition of being in check is given to PAL as follows: in check(Side,KPlace,OPiece,OPlace,Pos) contents(Side,king,KPlace,Pos), contents(OSide,OPiece,OPlace,Pos), other side(Side,OSide), piece move(Oside,OPiece,OPlace,KPlace,Pos). This de nition gets instantiated only with example descriptions with a King at KPlace and an opponent's piece OPiece at OPlace which could be moved to KPlace. Given an example description, PAL \collects" instantiations of its background knowledge de nitions to construct an initial hypothesis clause. The head of the clause is initially constructed with the arguments used to describe the rst example position. The initial head, in conjunction with the facts derived from the background knowledge and the example description, constitutes an initial concept clause. This clause is generalized by taking the lgg of it and clauses constructed from other example descriptions. Once a generalization is produced, heuristics are used to reduce the size of the clause and the number of arguments used in the head. New head compatible with the current concept head, are constructed from subsequent examples by considering only the arguments of the descriptions of the relevant pieces (this is further described below). Even with a nite theory for Chess, the large number of plausible facts derivable from it, makes the niteness irrelevant in practice (e.g., consider all the possible legal moves of the pieces in Chess). In PAL a fact F is relevant to example description D if at least one of the ground atoms of D occurs in the derivation of F . PAL only considers facts which are relevant to the example description to construct a clause3. The size of the clause is limited by requiring all the variables arguments to appear at least twice in the clause. In addition, every constant occurring in the atoms used to describe 3

Background de nitions given as ground unit clauses are also considered as relevant.

5

positions are labeled with unique constant symbols. For instance, if we have an example position with the following piece (for presentation purpose we have adopted the following notation: bl = black, wh = white, and square(X,Y) = (X,Y)): contents(wh,bishop,(2,3),pos1) ?! contents(wh ,bishop ,(2 ,3 ),pos1) The labels are kept during the derivation process, so the system can distinguish which piece(s) is(are) \responsible" for which facts derived from the background knowledge by following the labels. If the above description of the bishop is used to derive an instance of the background clause describing threats, then the same labels used in the description are used in this derivation, e.g., threat(wh,bishop,(2,3),bl,knight,(4,1),pos1) ?! threat(wh ,bishop ,(2 ,3),bl ,knight,(4,1 ),pos1) The lgg between compatible literals is guided by the associated labels to produce a smaller number of literals as lggs are produced only between compatible literals with common labels (a simple matching procedure is used for this purpose). PAL follows an experimentation process by automatically generating positive and negative examples (validated by the user), from which other facts are deduced and similar clauses constructed. The example generator takes the current concept de nition and tries to fail on at least one of its literals by changing (perturbing) some of the arguments involved in the example description. For instance, changing the place of a piece, changing its side, or changing one piece for another. If the perturbation method generates a negative example, then the system analyses which literals failed on that example and tries to construct a new example that will succeed on at least one of them. If a positive example is generated, then PAL constructs a clause as de ned above, and generalizes it using the constrained lgg algorithm, with the current concept de nition. If the system cannot generate a new example (i.e., a new generalization of the current de nition will require producing an example that involves changing di erent arguments), then PAL continues with a di erent set of arguments. PAL rst considers sets with the smallest number of arguments, e.g., it changes the position of each piece at a time, before changing the positions of several pieces at a time. PAL stops when there are no more sets left, or when the user decides to terminate the process. PAL has been used to learn several patterns in Chess. In the following section, it is shown how the patterns learned by PAL can be used in a playing strategy for a simple endgame.

6

4 Designing a playing strategy Perception (based on pattern recognition) seems to be the key to skill in Chess [5, 7, 6]. Some systems have designed their playing strategy around the recognition of patterns. Due to the complexity of Chess, the correctness of a playing strategy can only be tested over \very simple" endgames. Designing a pattern-based strategy involves the following steps: (1) Think on the general strategy of the game, (2) De ne the patterns required for it, (3) Check the strategy and return to (1) if necessary. Within this framework, PAL is used to learn the patterns from starting positions given by the user where the pattern appears. There is a tradeo between the number of patterns used by the playing strategy and the amount of search that the strategy performs. A larger number of patterns tends to compensate for smaller searches. A simple strategy which involves 1-ply search was chosen for the King and Rook against King (KRK) endgame. It consists of ordered rules with the following format: IF pattern(s) in current position, MOVE piece to form a new position, Check for pattern(s) in new position. For instance, a rule for a KRK playing strategy is as follows: IF both Kings are in opposition, (Patt1) MOVE Rook to new position, Check that: the opposite King is in check, (Patt2) and that the Rook is not threatened. (Patt3) Where Patt1, 2 and 3 represent particular patterns of the game. A broad winning strategy in KRK endgame is to force the opposite King to the edge, or into a corner if necessary, and then deliver mate in a few moves. The basic principles and the main concepts learned by PAL are outlined in Table 1 and illustrated in Figures 1 and 2 (some of the learned concepts and rules used in the strategy are given in Appendix A and B respectively). The following background vocabulary was all the time accessible to PAL:

 contents(Side,Piece,Place,Pos): Describes the position of each piece in a position. 7

While making sure that stalemate is never created or the Rook left undefended under attack, repeat until mate.  If the Kings are in opposition, try to force the opposite King to move backwards  else, try to move the King to one square away from opposition.  else, try to move the King closer to the opposite King, while maintaining the Rook dividing both Kings.  else, try to move the Rook closer to the opposite King, while maintaining the Rook dividing both Kings.  else, try to move the rook to divide both Kings either vertically or horizontally. Table 1: KRK Strategy

Figure 1: If Kings are in opposition, move the Rook to form an L shaped pattern (left). If both Kings are on the same side, move the Rook to divide both Kings (center). If the Kings are already divided, move the Rook closer to the opposite King (right).

8

Figure 2: With the Rook dividing both Kings, move the King to be \almost" in opposition with the opposite King (left). If the Rook is threatened (center), in a rKk pattern, move the Rook to the edge away of the threat into a rkK pattern

 sliding piece(Piece,Place,Pos): Piece in Place is a Rook, Bishop or Queen.  other side(Side1,Side2): Side1 is the opponent side of Side2.  legal move(Side,Piece,Place,NewPlace,Pos): Piece in Place can move to NewPlace.  make move(Side,Piece,Place,NewPlace,Pos1,Pos2): Piece in Place moves to NewPlace, changing the state description.

 stale(Side,Piece,Place,Pos): Piece in Place has no legal moves.  in check(Side,Place,OPiece,OPlace,Pos): King in Place is in check by OPiece in OPlace.  check mate(Side,Place,Pos): Side with King in Place is in check mate. Some Chess endgames concepts, depend on \geometrical" concepts, like distances between pieces, areas, etc., and on comparisons between them, for instance, if a piece is closer or moves closer to another piece or even to a particular place. To learn such concepts, the following \geometrical" background vocabulary was provided to PAL, although not all of it was available to the system at the same time. Table 2 speci es which of this background knowledge was available, in conjunction with the rest of the background knowledge, to learn particular concepts.

 distance(Place1,Place2,Dist,Pos): Distance (Dist) between piece in Place1 and piece in Place2.

9

 retr distance(Place1,Place2,Dist,Pos)4: Distance (Dist) between King in Place1 and the Rook in Place2.

 manh dist(Place1,Place2,Dist,Pos): Manhattan distance between any two pieces.  restr manh dist(Place1,Place2,Dist,Pos): Manhattan distance between a King and the Rook.

 coordx(Place,X,Pos): The le of a piece in Place.  coordy(Place,Y,Pos): The rank of a piece in Place.  less than(Num1,Num2): Num1 is less than Num2. The number of examples generated by PAL can be improved if symmetric properties of concepts in the board are considered. Some concepts do not depend on any particular orientation of the board and for each example, 7 equivalent examples can be generated, considering re ections along the horizontal, vertical and diagonal axes. PAL can take advantage of this knowledge to produce further generalizations between all the \symmetric" examples before presenting the user with a new example. For the KRK domain, the number of clauses required to de ned each concept depends on their symmetry (i.e., concepts de ned with one clause are highly symmetric, while concept de nitions with 4 clauses have only one symmetry along a particular axis). As di erent concepts have di erent symmetries, the user was prompted for the particular symmetry. The minimum number of examples that a trained user (the author) could generated to produce the same de nitions was also recorded. When learning disjunctive concepts (concepts which require for their de nition more than one clause), as the perturbation process cannot guarantee to produce an instance for each disjunct, an instance of each disjunct was provided in advance. Table 2 shows the main results. The rst column has the name of the concept to learn with its arity (complete de nitions of some concepts are given in Appendix A). The next three columns have the number of examples produced by PAL without/with symmetries and by the user. The fth column has the number of clauses required to de ned the concept and the last column has the additional background knowledge added to PAL. The last row shows the average number of examples produced per clause. The use of a restricted distance and a restricted Manhattan distance facilitates the learning process and simpli es the pattern de nitions. 4

10

Concept threatkR/7 rook divs/10 opposition/8 alm oppos/9 r edge/4 ks same side/10 l patt/12 rKk/10 rkK/10 mvcloserKk/10 mvrcloserKk/10 mvawayRk/10 mvrawayRk/10 mvrcloserRk/10 in lineRk/7 distRK2/8 distkR6/8 Average per clause (tot.)

Generated Examples 13 + 9 ? 72 + 15 ? 11 + 43 ? 16 + 15 ?

Gen. Exs. Symmetry 2+1? 46 + 16 ? 2+0? 1+0?

G.E. Man. 2+ 28 + 2+ 2+

No. Cls. 1 4 2 1

36 + 8 ? 95 + 5 ? 69 + 148 ? 70 + 18 ? 64 + 9 ? 15 + 1 ? 18 + 3 ? 27 + 4 ? 26 + 16 ? 48 + 15 ? 32 + 10 ? 8+3? 13 + 10 ?

29 + 6 ? 60 + 10 ? 15 + 2 ? 55 + 19 ? 57 + 20 ? 2+0? 2+0? 8+3? 7+0? 18 + 4 ? 9+2? 5+2? 7+2?

8+ 28 + 14 + 28 + 28 + 4+ 4+ 7+ 7+ 10 + 6+ 2+ 2+

4 4 2 4 4 1 1 1 1 2 2 1 1

26.8

11.4

5.1

?

Table 2: Results for the KRK endgame

11

Additional Back. Knowledge

?

coordx, coordy distance distance, manh distance

?

coordx, coordy opposition coordx, coordy coordx, coordy distance manh distance restrict distance restr manh dist restr manh dist coordx, coordy distance distance

?

While making sure that stalemate is never created or the Rook left undefended under attack, repeat until mate.  Move the Rook to reduce the area of the opposite King until it is trapped in a corner.  Else, move the King to keep the current area, closer to the Rook and/or closer to the opposite King.  If the opposite King is trapped in a corner, deliver mate in a few moves. Table 3: New KRK Strategy

4.1 Checking the Strategy The strategy outlined in Table 1 can checkmate the opposite King for all possible starting positions where the winning side makes the rst move (roughly 40,000 considering re ections and rotations), regardless of opposite moves. The correctness of the strategy was tested by following every possible path of a starting position until a checkmate was delivered, checking that the opposite King was never in stalemate and could not capture the Rook. Finding the correct strategy took a couple of weeks, although all the patterns can be learned in one day. In general, it was relatively easy to identify a aw in the strategy and correct it, possibly by learning a new concept. A larger amount of time was spent in checking the correctness of the strategy each time a new change was made.

5 Improving the Strategy Although the strategy will checkmate the opposite King for every starting position with the winning side to move, the longest \path" involves 57 moves5. The design of the above strategy follows a very naive approach, however, it can be improved if the concept of the area on which the opposite King is \con ned" by our Rook is included in the background knowledge. This can be used to learn how to \squeeze" the opposite King's area until mate can be delivered in a few moves. The design of such strategy was developed in 5 days, it uses 8 concepts of the previous strategy with 7 new concepts in 19 rules. The new strategy outlined in Table 3 and illustrated in Figure 3, requires a smaller The worst case is when the opponent's King is in le/rank 3 and the winning-side King is in the le/rank 1. The strategy takes at most 9 moves to force the opponent's King to move \backwards". Thus, it takes 54 moves to mate plus 3 initial moves in the worst case to get the Rook in the \right" position. 5

12

Figure 3: Squeeze the area of the opposite King (left) and keep the area (center) until the opposite King is trapped in a corner (right)

Concept

Generated Examples squeeze/12 27 + 20 ? closerkKR/12 20 + 4 ? closerKkR/12 16 + 3 ? k trap/7 43 + 12 ? distKR1/12 16 + 7 ? corner/6 4+0? corner2/7 8+0?

Add. Back. Knowledge area distance distance

? ? ? ?

Table 4: New Concepts for the Improved Strategy

13

number of patterns and was developed in less time. Results for the new concepts are given in Table 4 (without considering symmetries). Although it is far from being optimal, the new strategy safely mates the opposite King for every starting position of the winning side in less than 50 moves. A complete game-score of both strategies for the worst case initial position is given in Appendix C.

6 Conclusions and Future Work In this paper it is shown how Chess patterns which can be used to play a simple endgame can be automatically learned using a rst-order inductive system. Changing the strategy and learning new concepts proved to be relatively easy and most of the time was spent in checking its correctness. Additional geometrical knowledge is required to learn some of the endgame concepts. Adding a \powerful" concept for this endgame, like con ned-area, can be used to improve a playing strategy, however, a more interesting question is how to learn it from more \basic" concepts. PAL has been applied to other endgames (King Pawn against King) and other domains (qualitative modeling) [12]. The next step is to automatically learn the rules of the playing strategy from traces of games. PAL can be used to compare subsequent positions to identify patterns that change/emerge as a consequence of the move. A more dicult problem is to identify which of the moves in di erent traces of games, correspond to the same general rule in the strategy. Learning from traces of games is a natural way in which to learn Chess. This is already done by Morph [9] using a xed set of relations between pieces. Morph, however, is limited to learn patterns which express attack/defend relations. For instance, it is unabled to learn is two Rooks are in diagonal or if a Rook is in a border. Once a pattern is learned by Morph, it cannot be used to construct other patterns. In PAL, Chess board positions are described in a simpler way, and a set of background knowledge de nitions, used to identify relations between the pieces and the places in the board, can be incrementally augmented with new relations learned from a set of example descriptions. A powerful learning system could be constructed by combining PAL's learning capabilities to learn appropriate relations, with a learning system that could take these relations with traces of games, to learn playing strategies. Acknowledgements. I would like to thank Tim Niblett and in general all the members of the Machine Learning Group in the Turing Institute, Glasgow, for helpful comments in the development of this work. This research was made possible by a grant from CONACyT (Mexico).

14

References [1] M.A. Bramer. An Optimal Algorithm for king and pawn against king using pattern-knowledge, In M.R.B. Clarke, editor, Advances in Computer Chess, pages 82-96. Edinburgh University Press, 1980. [2] I. Bratko. Knowledge-based problem-solving in AL3. In J.E. Hayes, D. Michie and Y.H. Pao, editors, Machine Intelligence 10, pages 73-100, Ellis Harwood, 1982. [3] W. Buntine. Generalised subsumption an its applications to induction and redundancy. Arti cial Intelligence 36(2):149-176, 1988. [4] M.S. Campbell. Chunking as an abstraction mechanism. Technical Report CMU-CS-88-116, Carnegie-Mellon University, Computer Science Department, Pittsburgh, PA, 1988. [5] N. Charness. Human Chess Skill. In P.W. Fred, editor, Chess Skills in Man and Machine, pages 34-53, Spinger-Verlag, 1977. [6] W.G. Chase and H.A. Simon. The mind's eye in Chess. In A. Collins and E.E. Smith, editors, Readings of cognitive science: a perspective from psychology and arti cial intelligence, pages 461 - 494, Morgan Kaufmann, San Mateo, CA., 1988. [7] A.D. de Groot. Thought and Choice in Chess. Mouton, The Hague, 1965. [8] L. De Raedt, and Bruynooghe M. On Interactive Concept-Learning and Assimilation. In D. Sleeman and J. Richmond, editors, Proc. of the third european working session on learning, EWSL-88, pages 167-176, London, Pittman, 1988. [9] R. Levinson and R. Snyder. Adaptive pattern-oriented chess. In Proceedings of the Ninth National Conference on Arti cial Intelligence, pages 601-606, AAAI Press - MIT Press, Boston, 1991. [10] E. Morales. Learning Features by Experimentation in Chess. In Y. Kodrato , editor, Proceedings of the European Working Session on Learning, (EWSL-91), pages 494 - 511, Springer-Verlag, Berlin, 1991. [11] E. Morales. Learning Chess Patterns. In S. Muggleton, editor, Inductive Logic Programming, pages 517-537, Academic Press, The Apic Series, 1992. 15

[12] E. Morales. First-Order Induction of Patterns in Chess, Ph.D. Thesis, The Turing Institute - University of Strathclyde, 1992 [13] S. Muggleton and Cao Feng. Ecient induction of logic programs. In S. Arikaxa, S. Soto, S. Ohsuya, and T. Yokomari, editors, Proceedings of First International Workshop on Algorithmic Learning Theory (ALT90), pages 368-381, Ohmsha, Tokyo, Japan, 1990. [14] S. Muggleton, Inductive Logic Programming, New Generation Computing 8: 295-318, 1991. [15] T. Niblett. A study of generalisation in logic programs. In D. Sleeman and J. Richmond, editors, Proc. of the Third European Working Session on Learning (EWSL-88), Pittman, The Turing Institute, Glasgow, 1988. [16] G.D. Plotkin. A note on inductive generalisation. In B. Meltzer and D. Michie, editors, Machine Intelligence 5, pages 153-163, Edinburgh University Press, Edinburgh, 1969. [17] G.D. Plotkin. A furhter note on inductive generalisation. In B. Meltzer and D. Michie, editors, Machine Intelligence 6, pages 101-124, Edinburgh University Press, Edinburgh, 1971. [18] G.D. Plotkin. Automatic Methods of Inductive Inference. Ph.D. Thesis, Edimburgh University, 1971. [19] D. Wilkins. Using Patterns and Plans to Solve Problems and Control Search. Techinical Report MEMO-AIM-329; STAN-CS-79-747, Stanford University, Arti cial Intelligence Laboratory, Standord, CA., 1979.

16

A KRK Concepts This Appendix has some of the concepts learned by PAL for the rst strategy. Similar concepts were learned for the improved strategy. The more interested reader is refered to [12]. ThreatkR/7: The opposite King threatens our Rook (Figure 2 center). threatkR(S1,king,square(X1,Y1),S2,rook,square(X2,Y2),Pos1) contents(S2,rook,square(X2,Y2),Pos1), contents(S1,king,square(X1,Y1),Pos1), other side(S2,S1), sliding piece(rook,square(X1,Y1),Pos1), make move(S1,king,square(X1,Y1),square(X2,Y2),Pos1,Pos2), not contents(S2,rook,square(X2,Y2),Pos2). Rook divs/10: Rook divides both Kings either vertically or horizontally (Figure 1 center after the move). The following clause is one of the four clauses needed to de ne the concept. Similar de nitions are used for the rKk, rkK, ks same side concepts. rook divs(S1,king,square(X1,Y1),S1,rook,square(X2,Y2),S2,king,square(X3,Y3),Pos) contents(S1,king,square(X3,Y3),Pos), contents(S1,king,square(X1,Y1),Pos), contents(S1,rook,square(X2,X2),Pos), other side(S1,S2), sliding piece(rook,square(X2,Y2),Pos), coordx(square(X3,Y3),X3,Pos), coordx(square(X2,Y2),X2,Pos), coordx(square(X1,Y1),Y1,Pos), less than(X3,X2), less than(X3,X1), less than(X2,X1). Opposition/8: The Kings are in front of each other with one square between them (Figure 1 left). The de nitions for distkR/8 and in line/7 are similar. opposition(S1,king,square(X1,X2),S2,king,square(X1,Y2),2,Pos) contents(S2,king,square(X1,Y2),Pos), contents(S1,king,square(X1,Y1),Pos), other side(S1,S2), distance(square(X1,Y1),square(X1,Y2),2,Pos), distance(square(X1,Y2),square(X1,Y1),2,Pos). opposition(S1,king,square(X1,Y1),S2,king,square(X2,Y1),2,Pos) contents(S1,king,square(X1,Y1),Pos), contents(S2,king,square(X2,Y1),Pos), other side(S2,S1), distance(square(X2,Y1),square(X1,Y1),2,Pos), distance(square(X1,Y1),square(X2,Y1),2,Pos). 17

Alm opp/9: King is \almost" in opposition with the opposite King (Figure 2 left after the move). alm opp(S1,king,square(X1,Y1),S2,king,square(X2,Y2),2,3,Pos) contents(S2,king,square(X2,Y2),Pos), contents(S1,king,square(X1,Y1),Pos), other side(S1,S2), distance(square(X1,Y1), square(X2,Y2),2,Pos), distance(square(X2,Y2), square(X1,Y1),2,Pos), manh dist(square(X1,Y1),square(X2,Y2),3,Pos), manh dist(square(X2,Y2),square(X1,Y1),3,Pos). L patt/12: The 3 pieces form an L shaped pattern with the opposite King in check by the Rook (Figure 1 after the move). l patt(S1,king,square(X1,Y1),S2,king,square(X2,Y1),S2,rook,square(X1,Y3), 2,square(X2,Y3),Pos) contents(S2,king,square(X2,Y1),Pos), contents(S2,rook,square(X1,Y3),Pos), contents(S1,king,square(X1,Y1),Pos), other side(S1,S2), sliding piece(rook,square(X1,Y3),Pos), in check(S1,square(X1,Y1),rook,square(X1,Y3),Pos), legal move(S2,rook,square(X1,Y3),square(X2,Y3),Pos), opposition(S1,king,square(X1,Y1),S2,king,square(X2,Y1),2,Pos), opposition(S2,king,square(X2,Y1),S1,king,square(X1,Y1),2,Pos). l patt(S1,king,square(X1,Y1),S2,king,square(X1,Y2),S2,rook,square(X3,Y1), 2,square(X3,Y2),Pos) contents(S1,king,square(X1,Y1),Pos), contents(S2,king,square(X1,Y2),Pos), contents(S2,rook,square(X3,Y1),Pos), other side(S2,S1), sliding piece(rook,square(X3,Y1),Pos), in check(S1,square(X1,Y1),rook,square(X3,Y1),Pos), legal move(S2,rook,square(X3,Y1),square(X3,Y2),Pos), opposition(S2,king,square(X1,Y2),S1,king,square(X1,Y1),2,Pos), opposition(S1,king,square(X1,Y1),S2,king,square(X1,Y2),2,Pos). mv closerKk/10: The distance of the King to the opposite King decreases after a move. Similar de nitions are given for mv closer/away and squeeze (with area instead of distance). mv closerKk(S1,king,square(X1,Y1),S2,king,square(X2,Y2),D1,D2,square(X3,Y3),Pos1) contents(S1,king,square(X1,Y1),Pos1), contents(S2,king,square(X2,Y2),Pos1), other side(S1,S2), distance(square(X2,Y2),square(X1,Y1),D1,Pos1), make move(S1,king,square(X1,Y1),square(X3,Y3),Pos1,Pos2), distance(square(X2,Y2),square(X3,Y3),D2,Pos2), less than(D2,D1). 18

B Rules for KRK This Appendix has some of the rules used in both strategies. If the conditions before a move hold, and the move makes the conditions after the move to succeed, then that move is followed. The strategy follows a 1-ply search. The rst strategy has 18 rules and the improved strategy 19. In both strategies the rules are tried in order. The way to force the King to move backwards IF rook divs, AND opposition, AND WITH MOVE move rook, FORCES in check, AND not threatkR, AND l patt. Move to almost oppostion IF WITH MOVE move king, FORCES almost opposition, AND rook divs, AND not stale, AND not threatkR. Divide both Kings either vertically or horizontally IF ks same side, AND WITH MOVE move rook, FORCES rook divs, AND not stale, AND not threatkR. If the King is trapped and cannot move, let some space but keep it trapped IF k trap AND stale AND WITH MOVE move rook FORCES k trap AND not stale AND not threatkR.

A wait move IF rook divs, AND almost opposition, AND WITH MOVE move rook, FORCES not stale, AND not in check, AND almost opposition, AND rook divs, AND not threatkR. Move the King closer to the opposite King IF rook divs, AND mv closerKk, AND WITH MOVE move king, FORCES not threatkR, AND not stale, AND rook divs. Try to check mate IF k edge AND WITH MOVE move rook FORCES check mate. Squeeze the area of the opposite King without getting too close to it IF squeeze AND WITH MOVE move rook FORCES not closerkKR AND not stale.

C Game-scores This Appendix has complete game-scores for both strategies for a worst case initial position, following the longest path. The initial position is illustrated in Figure 4. 19

Figure 4: Worst-case initial position for the rst strategy. Strategy 1 White Black h3-g3 c2-d2 g3-b3 d2-c2 b3-b8 c2-c3 a1-a2 c3-c4 a2-a3 c4-c5 a3-a4 c5-c6 a4-a5 c6-c7 b8-b1 c7-c6 b1-b2 c6-c7 a5-a6 c7-c8 a6-a7 c8-c7 b2-c2y c7-d6 a7-b7 d6-d5 b7-b6 d5-d4 b6-b5 d4-d3 c2-c8 d3-d4 c8-c7 d4-d3 b5-b4 d3-d2 b4-b3 d2-d1

cont... (Str.1) White Black b3-b2 d1-d2 c7-d7y d2-e3 b2-c2 e3-e4 c2-c3 e4-e5 c3-c4 e5-e6 d7-d1 e6-e5 d1-d2 e5-e6 c4-c5 e6-e7 c5-c6 e7-e8 c6-c7 e8-e7 d2-e2y e7-f6 c7-d7 f6-f5 d7-d6 f5-f4 d6-d5 f4-f3 e2-e8 f3-f4 e8-e7 f4-f3 d5-d4 f3-f2 d4-d3 f2-f1 d3-d2 f1-f2

cont... (Str.1) White Black e7-f7y f2-g3 d2-e2 g3-g4 e2-e3 g4-g5 e3-e4 g5-g6 f7-f1 g6-g5 f1-f2 g5-g6 e4-e5 g6-g7 e5-e6 g7-g8 e6-e7 g8-g7 f2-g2y g7-h6 e7-f7 h6-h5 f7-f6 h5-h4 f6-f5 h4-h3 g2-g8 h3-h4 g8-g7 h4-h3 f5-f4 h3-h2 f4-f3 h2-h1 f3-f2 h1-h2 g7-h7yy ?

20

Strategy 2 White Black h3-g3 c2-d2 g3-a3 d2-c2 a1-a2 c2-d2 a3-b3 d2-c2 a2-a3 c2-d2 a3-b2 d2-e2 b2-c3 e2-d2 b2-b3 d2-e2 b3-c2 e2-f2 c3-d3 f2-e2 c2-c3 e2-f2 c3-d2 f2-g2 d3-e3 g2-f2 d2-d3 f2-g2 d3-e2 g2-h2 e3-f3 h2-g2 e2-e3 g2-h2 e3-f2 h2-h1 f3-h3yy ?