i need help in solving the attached prolog assignement
Playing SET ® With Prolog
Bonus Point Problem 30pts
Problem
You will provide a Prolog program which will return all sets which can be created from a list of SET®
cards.
The SET® Game
The game of SET® is played with cards which contain the following attributes:
–
A shape
A color
A shade
A count (number of shapes on the card)
12 or 15 cards are played to the table face up and the player must make a set of 3 cards where each of
the attributes are looked at individually and each attribute on the cards are either all same or all
different.
Here is an example of a set.
Here the set of cards have the same shape, same color, different shades, and same counts.
Another example
In this case, the set has different shapes, different colors, different shades, and different counts.
The key is that each attribute is looked at individually on each card. Each attribute can be all different or
all the same independent of each other. Here is an example where we don’t have a set.
There are 2 reasons this is not a set.
Playing SET ® With Prolog
Bonus Point Problem 30pts
– We have one purple and two green colors. The color attribute is not ALL SAME or ALL
DIFFERENT
– We have two striped shades and one solid shade. The shade attribute is not ALL SAME or
ALL DIFFERENT.
You can read more about the rules of the game at the following link
https://www.setgame.com/set/puzzle_rules
Representing a Card in Prolog
To represent a card in Prolog, and how it will be done for this assignment, is as a compound term or
functor with the following syntax.
card(shape, color, shade, count)
The terms shape, color, and shade are terms which can be the following:
Shape
–
oval
diamond
squiggle
–
red
purple
green
–
solid
striped
empty
Color
Shade
The count will be a number either 1, 2, or 3.
To represent the following card the Prolog would be card(oval, purple, striped, 2).
Before you start the project, make sure you understand the problem by trying the game your self at
https://www.setgame.com/set/puzzle.
Playing SET ® With Prolog
Bonus Point Problem 30pts
Requirements
Your solution must only have 1 functor called find_set but you may have multiple rules of the same
name. The arity of these rules must be X≥2 where X is the number of arguments. The rules therefore
must have arity find_set/X. This means that each rule with name find_set must accept the same
number of arguments where you have at least 2 arguments. No additional rules or functors may be
defined. The first two arguments are defined next.
The first argument to the find_set rule will be the list of cards. The second argument will be a free
variable that stores the result of a set that can be made. You may have additional arguments after the
first two if you need them.
A question to the Prolog interpreter, once your file has been consulted, will look like the next page.
?- find_set(
[card(shape1, color1, shade1, count1),
card(shape2, color2, shade2, count2),
… ;additional cards. Snipped to save room.
card(shape12, color12, shade12, count12)], ;end of list of cards
Result_Set, ;second argument to find_set
).
The following is an example query with the following play field of cards.
www.setgame.com/set/puzzle On Tuesday, November 14, 2023
?- find_set(
[card(diamond, purple, striped, 3), card(diamond, green, striped, 2),
card(squiggle, green, striped, 1), card(oval, green, empty, 1),
card(squiggle, red, solid, 2), card(oval, green, striped, 2),
card(diamond, green, solid, 1), card(oval, purple, empty, 2),
card(diamond, purple, empty, 2), card(diamond, red, striped, 3),
card(squiggle, red, striped, 2), card(squiggle, purple, solid, 2)],
Result_Set, ).
Playing SET ® With Prolog
Bonus Point Problem 30pts
Your output, or rather Result_Set, should contain a list of 3 cards which comprise a single set according
to the rules. When the user receives a set they may continue to ask for more sets if they exist using the
semicolon or stop the search. If no more sets can be found then Result_Set should be set to false.
When querying the above you may end up with the following results
Result_Set = [card(squiggle,red,solid,2), card(oval,green,empty,1), card(diamond,purple,striped,3)];
Result_Set = [card(squiggle,red,solid,2), card(oval,green,empty,1), card(diamond,purple,striped,3)];
Result_Set = [card(squiggle,red,solid,2), card(oval,green,empty,1), card(diamond,purple,striped,3)];
Result_Set = [card(squiggle,red,solid,2), card(oval,green,empty,1), card(diamond,purple,striped,3)];
Result_Set = [card(squiggle,red,solid,2), card(oval,green,empty,1), card(diamond,purple,striped,3)];
Result_Set = [card(squiggle,red,solid,2), card(oval,green,empty,1), card(diamond,purple,striped,3)];
Result_Set = [card(squiggle,red,solid,2), card(oval,green,empty,1), card(diamond,purple,striped,3)];
Result_Set = [card(squiggle,red,solid,2), card(oval,green,empty,1), card(diamond,purple,striped,3)];
Result_Set = [card(oval,purple,empty,2), card(squiggle,red,solid,2), card(diamond,green,striped,2)];
Result_Set = [card(oval,purple,empty,2), card(squiggle,red,solid,2), card(diamond,green,striped,2)];
Result_Set = [card(oval,purple,empty,2), card(squiggle,red,solid,2), card(diamond,green,striped,2)];
Result_Set = [card(oval,purple,empty,2), card(squiggle,red,solid,2), card(diamond,green,striped,2)];
Result_Set = [card(oval,purple,empty,2), card(squiggle,red,solid,2), card(diamond,green,striped,2)];
Result_Set = [card(diamond,green,solid,1), card(oval,green,empty,1), card(squiggle,green,striped,1)];
Result_Set = [card(diamond,green,solid,1), card(oval,green,empty,1), card(squiggle,green,striped,1)];
Result_Set = [card(diamond,green,solid,1), card(oval,green,empty,1), card(squiggle,green,striped,1)];
Result_Set = [card(diamond,green,solid,1), card(oval,green,empty,1), card(squiggle,green,striped,1)];
Result_Set = [card(diamond,green,solid,1), card(oval,green,empty,1), card(squiggle,green,striped,1)];
Result_Set = [card(diamond,green,solid,1), card(oval,green,empty,1), card(squiggle,green,striped,1)];
Result_Set = [card(squiggle,purple,solid,2), card(diamond,red,striped,3), card(oval,green,empty,1)];
Result_Set = [card(diamond,purple,empty,2), card(oval,green,striped,2), card(squiggle,red,solid,2)];
Result_Set = [card(diamond,purple,empty,2), card(oval,green,striped,2), card(squiggle,red,solid,2)];
Result_Set = [card(diamond,purple,empty,2), card(oval,green,striped,2), card(squiggle,red,solid,2)];
Result_Set = [card(diamond,purple,empty,2), card(oval,green,striped,2), card(squiggle,red,solid,2)];
Result_Set = [card(diamond,red,striped,3), card(diamond,purple,empty,2), card(diamond,green,solid,1)];
Result_Set = [card(diamond,red,striped,3), card(diamond,purple,empty,2), card(diamond,green,solid,1)];
Result_Set = [card(diamond,red,striped,3), card(diamond,purple,empty,2), card(diamond,green,solid,1)];
false.
Notice, there are multiple of the same outputs. This is because when it finds the solution for
one set it may find the solution for each card of the set and how many cards between each card will
cause Prolog to generate this many solutions. You may use the following to help eliminate repeated
results, but you will need to make the necessary call to your functor.
find_unique_sets(Cards, Result_Set):distinct(Result_Set, ).
Now you can instead just query ?-find_unique_sets([], Result_Set). and you will get
something like the following.
Result_Set = [card(squiggle,red,solid,2), card(oval,green,empty,1), card(diamond,purple,striped,3)];
Result_Set = [card(oval,purple,empty,2), card(squiggle,red,solid,2), card(diamond,green,striped,2)];
Result_Set = [card(diamond,green,solid,1), card(oval,green,empty,1), card(squiggle,green,striped,1)];
Result_Set = [card(squiggle,purple,solid,2), card(diamond,red,striped,3), card(oval,green,empty,1)];
Result_Set = [card(diamond,purple,empty,2), card(oval,green,striped,2), card(squiggle,red,solid,2)];
Result_Set = [card(diamond,red,striped,3), card(diamond,purple,empty,2), card(diamond,green,solid,1)];
false.
Notice the use of the semicolon to force Prolog to backtrack and try to satisfy the goal again but this
time we get unique solutions. If you are using SWISH, the online Prolog interpreter, you do not need to
use semicolons. Instead, you can use the NEXT button in the query.
Playing SET ® With Prolog
Bonus Point Problem 30pts
Constraints
The following are constraints on what you can use to solve the problem. Use of constructs in Prolog not
in the list will result in no points being awarded for bonus points. Please stick to only the following
constructs.
–
–
find_set (name of your rule)
Variables
== (equality)
\= (not equal)
List syntax
o []
o Head and Tail syntax
:- (creates a rule)
; (logical disjunction)
, (logical conjunction)
. (end rule)
Parentheses (in addition to creating compound terms and rules this can be used to group
conditionals)
The definition of the find_unique_sets with a call to your rule.
Submission
In addition to your file, you must also provide a Word document with 1-2 paragraphs explaining your
Prolog solution and how it works to find sets. You may save this as a .docx, .doc, or .pdf.
Your Prolog file should be called playset.pl.
Zip both the Prolog source file and your document into a zip archive with the name .zip. So
if your netid is broge2 your zip file would be called broge2.zip which would contain playset.pl and your
document file which can be named whatever you like.
Submit your zip file to Canvas.