Logic Programming WhatversusHow

 Assignment - Chess

Consider the game of chess. (If you are unfamiliar with Chess, look up the rules on Wikipedia.) A sample board configuration is shown below.

We can describe a board configuration with the following vocabulary. We use the object constants a, ..., h to represent files (i.e. columns left to right) and we use 1, ..., 8 to represent ranks (i.e. rows bottom to top). There are two players - white and black. Each of the white player's pieces can be of one of six types - white king (wk), white queen (wq), white bishops (wb), white knight (wn), white rook (wr), and white pawn (wp). Black's pieces have analogous types - black king (bk), black queen (bq), black bishop (bb), black knight (bn), black rook (br), and black pawn (bp). We use the ternary relation constant cell to record the placement of pieces on the board. The sentence cell(file,rank,type) means that there is a piece of type type on the square in column file and row rank.

Using this vocabulary, we can describe the board configuration shown above with the dataset shown below. This is the initial configuration of the game.

 cell(a,1,wr) cell(a,2,wp) cell(a,7,bp) cell(a,8,br) cell(b,1,wn) cell(b,2,wp) cell(b,7,bp) cell(b,8,bn) cell(c,1,wb) cell(c,2,wp) cell(c,7,bp) cell(c,8,bb) cell(d,1,wq) cell(d,2,wp) cell(d,7,bp) cell(d,8,bq) cell(e,1,wk) cell(e,2,wp) cell(e,7,bp) cell(e,8,bk) cell(f,1,wb) cell(f,2,wp) cell(f,7,bp) cell(f,8,bb) cell(g,1,wn) cell(g,2,wp) cell(g,7,bp) cell(g,8,bn) cell(h,1,wr) cell(h,2,wp) cell(h,7,bp) cell(h,8,br)

Different pieces move in different ways and can attack opposing pieces in accordance with the rules of the game. A king is in check if and only if it is attacked by a piece of the opposite color.

Your mission in this assignment is to write a logic program that defines the unary relation check, which is true of a player if and only if that player's king is in check in any board configuration described using this vocabulary. (Obviously, you will want to define some intermediate relations as well to make your description more compact. These are totally up to you.) We will test your program by loading it into Sierra and applying it to one or more board configurations defined using the vocabulary mentioned above.

Suggestion. To help you test your definitions, we have created a tool to make it easy for you to create and visualize board configurations. Click here to access the tool. Instructions are on the web page. Once you have created a board configuration you like, you ca n copy and paste to Sierra to test your definitions.