Professional Documents
Culture Documents
Project3-9340
Project3-9340
Project3-9340
Project 03
Due: Friday, May 5th 11:59pm
1 Description
In this project, you will write two artificial intelligences for the card game Twenty. Project
2 had you write these AIs in scheme, but this project has you write them in Prolog. You
can find the rules at https://www.pagat.com/invented/20.html. The first AI will try
to maximize the number of cards it plays. The second will try to minimized the value of
its hand.
2 Specifications
You are required to write two predicates: project3 ai 1 and project3 ai 2. These predicates
implement the first and second AI, respectively. In addition to these two predicates you
will need a few other helper predicates. These predicates will be placed in a file named
“project3.pl”, and will be included from the file “base.pl”. To run the game you need to
follow three steps. First, create the player1/2 predicate which is a wrapper around the
player 1 AI predicate. Second, create the player2/2 predicate which is a wrapper around
the player 2 AI predicate. Finally, query the playgame/0 predicate. There are examples in
the provided “project3.pl” file.
2.1 AI Functions
The driver code contains all the logic for implementing the game. When ever it is your
AI’s turn, its predicate will be called. The predicate should have two arguments. The first
is a game state, which is a structure containing five arguemnts, detailed as follows.
1. Normally the constant no error, but if your AI give an invalid play, the predicate is
called a second time with this parameter as the constant error.
5. player state
This is the state for the player controlled by your AI. A player state is a structure,
with functor pstate, containing the player’s current score, hand, and a custom state
that can be anything you want. In the “Utilities” section of “base.pl”, you will find
the predicate pstate/3 that can be used to get parts of the player state.
The second argument to the AI should unify with a play structure. The play structure
has the functor play, and two arguments. The first argument is the play you want to make.
It can be the constant drawcard or a list of cards, pairs, and kings as wild. The second
argument is a custom state, and you can leave it as the constant empty. It is an advanced
feature the IA can use to remember information about previous turns, which is not needed
by either AI.
If the AI predicate fails, then the driver code considers this as giving up. It is similar
to returning the empty list in project 2.
• A card
A card is a structure, with functor card and arity 2. The first argument is the atom
representing the suit. The second is an constant representing the value. You can see
the definition at the top of “base.pl”. There are helper predicates that work on cards
in the “Utilities” section of “base.pl”. This can be any card except a king.
• A wild card
Kings are wild cards in Twenty, and can take on any value between 1 and 20. A wild
card play is a structure, with functor card and arity 2. The first argument is a king
card. The second is the value (between 1 and 20) the card will be played as.
• A pair
A pair 2-arity structure, with functor pair, where the two argument are 10s jacks,
or queens with matching faces. A pair play indicates you want the play the pair of
cards as the value 10 rather than 20.
The values of all card plays in the list must sum to the current count.
2.2 AI 1 (project3 ai 1)
The first AI will always make the legal play that gets rid of the most cards. If there is
multiple ways to do this, the AI will prioritize keeping the most kings. All other choices
are arbitrary. This means if you can make the count with both a 3 and 4 or a 6 and an
ace, then either one may be chosen.
2.3 AI 2 (project3 ai 2)
The second AI will make the legal pay that leaves it with the lowest score hand. In general
this will mean getting rid of high scoring cards, but sometimes getting rid of more cards
is better. As an example, if the count is 10, then a pair of queens would make the count.
These queens are worth 20 points at the end of the hand, but 4 aces and a 6 are worth 25
points.
• AI 1 and AI 2 are very similar and will share most of their code.
• Before converting your algorithm to prolog, be sure to study the “Utilities” section of
“base.pl”. Make sure you understand how I am representing everything in the game.
• You do not need any predicates not presented in the book/class, but you may use
them to make things easier. There is no combinations predicate in prolog, so I created
one, and made it available in “base.pl”.
5 What to Turn in
Upload your submission as a zip archive containing the following:
• Source code (project3.pl)
– You should not submit base.pl.
– The TAs will use their own
• Readme (Plain text document)
– List the files included in the archive and their purpose
– Explain how to compile and run your project
– Include any other notes that the TA may need
• Write-up (Microsoft Word or pdf format)
– How did you approach the project?
– How did you organize the project? Why?
– What problems did you encounter?
– How did you fix them?
– What did you learn doing this project?
– If you did not complete some feature of the project, why not?
∗ What unsolvable problems did you encounter?
∗ How did you try to solve the problems?
∗ Where do you think the solution might lay?
· What would you do to try and solve the problem if you had more time?
6 Grading
The grade for this project will be out of 100. It must be written in scheme, and run in
racket. Violating this is an automatic zero. The grade is broken down as follows.
Followed Specifications 50
Use of Prolog style (tail recursion, non-imperative strategies, etc) 20
Output 20
Write-up 10
If you were not able to complete some part of the program discussing the problem and
potential solutions in the write-up will reduce the points deducted for it. For example,
suppose there is a bug in your code that sometimes allows two customers to approach the
same worker, and could not figure out the problem before the due date. You can write 2-3
paragraphs in the write-up to discuss this issue. Identify the error and discuss what you
have done to try to fix it/find the problem point, and discuss how you would proceed if
you had more time. Overall, inform me and the TA that you know the problem exists and
you seriously spend time trying to fix the problem. Normally you may lose 5 points (since
it is a rare error) but with the write-up you only lose 2. These points can make a large
difference if the problem is affecting a larger portion of the program.