CSI 2165, Winter 2006

 

Assignment 3

Due Monday, Mar 20, 11am, extended till 11pm

 

!!! See the FAQ page for some hints and clarifications. !!!


Submission instructions: The submission is done electronically through Virtual Campus.

Please submit a file called a3.pl with comments inside. The first comment should include your name and student number. The file should contain the Prolog code for the required predicates, and comments explaining what they do and how they do it. Add in comments example queries that you ran for testing each predicate and what the Prolog output was (thorough testing is important). Make sure your program can be loaded (consulted) in Prolog without giving errors. Make sure the name of the file and the names of the predicates are the required ones. 

Note: No late assignments are allowed.

 

Tarologic is a card game that is played with 52 cards. At the end of a game, the points obtained by each of the two players are counted to determine the winner. The number of points is the sum of the points of all the cards from the stack collected by a player during the game. At each round each player gets two more cards that are added to his/her current stack (until there are no more cards or the players decide to stop playing). For each round the player with the higher score for the two new cards wins the round, but at the end of the game the player with the higher accumulated score wins.

 

Data representation:

 

Each card is represented by its value (ace, king, queen, jack, 10, 9, 8, 7, 6, 5, 4, 3, 2) and its colour (hearts, diamonds, spades, clubs). Use a predicate card/2 to store this information. For example, the king of clubs is card(king, clubs).

A stack of cards is represented by a list containing its cards. What’s left now is to count the points …

  1. A king is worth 3 points, a queen 2 points and the rest 0 points. Use a predicate points(Card, Points) for defining this information.
  2. Write a predicate value(Stack, Points) which succeeds if and only if Points corresponds to the number of points in the stack of cards represented by Stack (in other words it computes the number of points if the variable is uninstantiated).
  3. The ace of clubs makes a player loose 6 points. Adapt your program to take into account this new rule. In any case, the total number of points in a stack cannot be negative (it stops at zero points). This adaptation might require some helper predicates.
  4. If the stack contains only figures (king, queen, jack), a player wins 5 extra points. Modify your program to include this new rule; use a predicate figure of arity 1.
  5. If the value of the opponent’s stack is zero, a player wins 10 extra points.

Write a predicate values(Stack1, Value1, Stack2, Value2) which succeeds if and only if Value1 and Value2 correspond to the number of points of Stack1 and Stack2, respectively.

  1. Write a predicates round(Player1, Player2, Stack1, Stack2) where Player1 and Player2 are the names of two players. This predicate displays the scores of the two players at the end of a round of the game. The displayed information could look like this:

 

The stack of john has 3 points

The stack of emma has 11 points

emma wins this round!

 

  1. Finally, write a predicate game(Player1, Player2) where Player1 and Player2 are the names of two players. This predicate displays the scores of the two players at the end of each round and also the accumulated scores from previous rounds of the game. At the end of each round, the question: “Do you want to continue?” is asked. The  display could look like this:

 

?- game(john,paul).

Describe the stack of john:

[card(king, hearts),card(4,spades)]

Describe the stack of paul:

[card(queen, hearts),card(3,clubs)]

 

The stack of john has 3 points

The stack of paul has 2 points

john wins this round!

 

john has a total of 3 points

paul has a total of 2 points

 

--------------------------------

Do you want to continue [y/n]: y

--------------------------------

Describe the stack of john:

[card(ace,clubs),card(10,spades)]

Describe the stack of paul:

[card(jack,hearts),card(3,clubs)]

 

The stack of john has 0 points

The stack of paul has 2 points

paul wins this round!

 

john has a total of 0 points

paul has a total of 4 points

--------------------------------

Do you want to continue [y/n]: n

--------------------------------

paul is the winner! Good-bye.

 

Hints: use the builtin predicate random/1 do deal the cards. Use write/1 and nl/0 to display information. Use read/1 or put/1 to read input from the keyboard for continuing the game.

 

Have fun!!!