CSI 2165, Winter 2006
Assignment 3
Due Monday, Mar 20, 11am, extended till 11pm
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 …
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.
The
stack of john has 3 points
The
stack of emma has 11
points
emma wins this round!
?-
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!!!