Skip to content

Commit fe3e73d

Browse files
author
Ben Coleman
committed
Initial commit
0 parents  commit fe3e73d

26 files changed

+1437
-0
lines changed

12cards0sets.dat

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 12 cards with 0 sets
2+
1 3 3 2
3+
3 3 2 2
4+
1 1 2 1
5+
1 2 3 3
6+
3 2 3 3
7+
1 3 1 3
8+
3 1 2 2
9+
2 2 3 2
10+
1 1 1 1
11+
3 2 1 1
12+
2 1 1 3
13+
2 2 1 3

3cards0sets.dat

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Lines starting with a # character are comments, and ignored
2+
# Blank lines are also ignored, even if they contain whitespace
3+
4+
# All other lines are expected to have 4 integers, separated by spaces
5+
1 1 1 1
6+
1 1 1 2
7+
2 2 2 3
8+
9+
# A file does not need to contain all 81 cards
10+
11+
12+

Card.java

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
public class Card
3+
{
4+
private int quantity;
5+
private int color;
6+
private int shading;
7+
private int shape;
8+
9+
public Card(int theQuantity, int theColor, int theShading, int theShape)
10+
{
11+
quantity = fixValue(theQuantity);
12+
color = fixValue(theColor);
13+
shading = fixValue(theShading);
14+
shape = fixValue(theShape);
15+
}
16+
17+
private int fixValue(int value)
18+
{
19+
value = value % 3;
20+
21+
if(value <= 0)
22+
value += 3;
23+
24+
return value;
25+
}
26+
27+
public int getQuantity()
28+
{
29+
return quantity;
30+
}
31+
32+
public int getColor()
33+
{
34+
return color;
35+
}
36+
37+
public int getShading()
38+
{
39+
return shading;
40+
}
41+
42+
public int getShape()
43+
{
44+
return shape;
45+
}
46+
47+
public boolean isSet(Card c2, Card c3)
48+
{
49+
int quantitySum = quantity + c2.getQuantity() + c3.getQuantity();
50+
int colorSum = color + c2.getColor() + c3.getColor();
51+
int shadingSum = shading + c2.getShading() + c3.getShading();
52+
int shapeSum = shape + c2.getShape() + c3.getShape();
53+
54+
return quantitySum % 3 == 0 && colorSum % 3 == 0 &&
55+
shadingSum % 3 == 0 && shapeSum % 3 == 0;
56+
}
57+
58+
public String toString()
59+
{
60+
char colorVal;
61+
char shadingVal;
62+
char shapeVal;
63+
64+
if(color == 1)
65+
colorVal = 'R';
66+
else if(color == 2)
67+
colorVal = 'G';
68+
else
69+
colorVal = 'P';
70+
71+
if(shading == 1)
72+
shadingVal = 'O';
73+
else if(shading == 2)
74+
shadingVal = 'T';
75+
else
76+
shadingVal = 'S';
77+
78+
if(shape == 1)
79+
shapeVal = 'O';
80+
else if(shape == 2)
81+
shapeVal = 'D';
82+
else
83+
shapeVal = 'S';
84+
85+
return "" + quantity + colorVal + shadingVal + shapeVal;
86+
}
87+
88+
public boolean equals(Object obj)
89+
{
90+
Card that = (Card)obj;
91+
92+
return quantity == that.getQuantity() &&
93+
color == that.getColor() &&
94+
shading == that.getShading() &&
95+
shape == that.getShape();
96+
}
97+
}

0 commit comments

Comments
 (0)