From e12e64b29e78fa36ec7a1ef56042a4d77b6056da Mon Sep 17 00:00:00 2001 From: Chris Sheehan Date: Wed, 1 Apr 2015 00:15:19 -0400 Subject: [PATCH 01/47] Card and CardTest classes for Set Project. --- src/Card.java | 114 ++++++++++++++++++++++++++++- src/CardTest.java | 179 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 291 insertions(+), 2 deletions(-) mode change 100755 => 100644 src/Card.java create mode 100644 src/CardTest.java diff --git a/src/Card.java b/src/Card.java old mode 100755 new mode 100644 index 9eed9a5..f0e00cc --- a/src/Card.java +++ b/src/Card.java @@ -1,5 +1,114 @@ -public class Card { - // Create the rest of this class yourself +public class Card{ + + private int quantity; + private int color; + private int shading; + private int shape; + + private String quan; + private String col; + private String shad; + private String shap; + + public Card(int cardQuantity, int cardColor, int cardShading, int cardShape) { + if (cardQuantity < 1 || cardQuantity > 3) { + quantity = (((cardQuantity % 3) + 3) % 3) + 1; + } + else { + quantity = cardQuantity; + } + if (cardColor < 1 || cardColor > 3) { + color = (((cardColor % 3) + 3) % 3) + 1; + } + else { + color = cardColor; + } + if (cardShading < 1 || cardShading > 3) { + shading = (((cardShading % 3) + 3) % 3) + 1; + } + else { + shading = cardShading; + } + if (cardShape < 1 || cardShape > 3) { + shape = (((cardShape % 3) + 3) % 3) + 1; + } + else { + shape = cardShape; + } + } + + public int getQuantity() { + return quantity; + } + + public int getColor() { + return color; + } + + public int getShading() { + return shading; + } + + public int getShape() { + return shape; + } + + public boolean isSet(Card two, Card three) { + + int totalQuantity = getQuantity() + two.getQuantity() + three.getQuantity(); + int totalColor = getColor() + two.getColor() + three.getColor(); + int totalShading = getShading() + two.getShading() + three.getShading(); + int totalShape = getShape() + two.getShape() + three.getShape(); + + if (totalQuantity % 3 == 0 && totalColor % 3 == 0 && totalShading % 3 == 0 && totalShape % 3 == 0) { + return true; + } + else { + return false; + } + } + + public String toString() { + + if (quantity == 1) { + quan = ("1"); + } + else if (quantity == 2) { + quan = ("2"); + } + else {// (quantity == 3) { + quan = ("3"); + } + if (color == 1) { + col = ("R"); //red + } + else if (color == 2) { + col = ("G"); //green + } + else{ //(color == 3) { + col = ("P"); //purple + } + if (shading == 1) { + shad = ("O"); //empty + } + else if (shading == 2) { + shad = ("T"); //striped/shaded + } + else{// (shading == 3) { + shad = ("S"); //solid/filled + } + if (shape == 1) { + shap = ("O"); //oval + } + else if (shape == 2) { + shap = ("D"); //diamond + } + else{// (shading == 3) { + shap = ("S"); //squiggle + } + String sequence = quan + col + shad + shap; + return sequence; + } public boolean equals(Object obj) { Card that = (Card)obj; @@ -9,4 +118,5 @@ public boolean equals(Object obj) { shading == that.getShading() && shape == that.getShape(); } + } diff --git a/src/CardTest.java b/src/CardTest.java new file mode 100644 index 0000000..bcca89c --- /dev/null +++ b/src/CardTest.java @@ -0,0 +1,179 @@ +import junit.framework.TestCase; + +/** + * A JUnit test case class. + * Every method starting with the word "test" will be called when running + * the test with JUnit. + */ +public class CardTest extends TestCase { + + /** + * A test method. + * (Replace "X" with a name describing the test. You may write as + * many "testSomething" methods in this class as you wish, and each + * one will be called when running JUnit over this class.) + */ + public void test123() + { + //testing when everything is different + Card card1 = new Card(1, 1, 1, 1); + assertEquals(card1.getQuantity(), 1); + assertEquals(card1.getColor(), 1); + assertEquals(card1.getShading(), 1); + assertEquals(card1.getShape(), 1); + assertEquals(card1.toString(), "1ROO"); + Card card2 = new Card(2, 2, 2, 2); + assertEquals(card2.getQuantity(), 2); + assertEquals(card2.getColor(), 2); + assertEquals(card2.getShading(), 2); + assertEquals(card2.getShape(), 2); + assertEquals(card2.toString(), "2GTD"); + Card card3 = new Card(3, 3, 3, 3); + assertEquals(card3.getQuantity(), 3); + assertEquals(card3.getColor(), 3); + assertEquals(card3.getShading(), 3); + assertEquals(card3.getShape(), 3); + assertEquals(card3.toString(), "3PSS"); + assertEquals(card1.isSet(card2, card3), true); + } + public void testStupidNumbers() + { + //testing when all shading is different + Card negCard = new Card(-3, -33, -333, -3333); + assertEquals(negCard.getQuantity(), 1); + assertEquals(negCard.getColor(), 1); + assertEquals(negCard.getShading(), 1); + assertEquals(negCard.getShape(), 1); + assertEquals(negCard.toString(), "1ROO"); + Card lrgCard = new Card(2147483647, 172831, 7910, 457); + assertEquals(lrgCard.getQuantity(), 2); + assertEquals(lrgCard.getColor(), 2); + assertEquals(lrgCard.getShading(), 3); + assertEquals(lrgCard.getShape(), 2); + assertEquals(lrgCard.toString(), "2GSD"); + Card ranCard = new Card(24, 0, -2147483648, 2); + assertEquals(ranCard.getQuantity(), 1); + assertEquals(ranCard.getColor(), 1); + assertEquals(ranCard.getShading(), 2); + assertEquals(ranCard.getShape(), 2); + assertEquals(ranCard.toString(), "1RTD"); + assertEquals(negCard.isSet(lrgCard, ranCard), false); + } + + public void test3() + { + //testing when all the same + Card card4 = new Card(3, 3, 3, 3); + assertEquals(card4.getQuantity(), 3); + assertEquals(card4.getColor(), 3); + assertEquals(card4.getShading(), 3); + assertEquals(card4.getShape(), 3); + assertEquals(card4.toString(), "3PSS"); + Card card5 = new Card(3,3,3,3); + assertEquals(card5.getQuantity(), 3); + assertEquals(card5.getColor(), 3); + assertEquals(card5.getShading(), 3); + assertEquals(card5.getShape(), 3); + assertEquals(card5.toString(), "3PSS"); + Card card6 = new Card(3,3,3,3); + assertEquals(card6.getQuantity(), 3); + assertEquals(card6.getColor(), 3); + assertEquals(card6.getShading(), 3); + assertEquals(card6.getShape(), 3); + assertEquals(card6.toString(), "3PSS"); + assertEquals(card4.isSet(card5, card6), true); + } + + public void test2() + { + Card card1 = new Card(2, 2, 2, 2); + assertEquals(card1.getQuantity(), 2); + assertEquals(card1.getColor(), 2); + assertEquals(card1.getShading(), 2); + assertEquals(card1.getShape(), 2); + assertEquals(card1.toString(), "2GTD"); + Card card2 = new Card(2, 2, 2, 2); + assertEquals(card2.getQuantity(), 2); + assertEquals(card2.getColor(), 2); + assertEquals(card2.getShading(), 2); + assertEquals(card2.getShape(), 2); + assertEquals(card2.toString(), "2GTD"); + Card card3 = new Card(2, 2, 2, 2); + assertEquals(card3.getQuantity(), 2); + assertEquals(card3.getColor(), 2); + assertEquals(card3.getShading(), 2); + assertEquals(card3.getShape(), 2); + assertEquals(card3.toString(), "2GTD"); + assertEquals(card1.isSet(card2, card3), true); + } + + public void test1() + { + Card card1 = new Card(1, 1, 1, 1); + assertEquals(card1.getQuantity(), 1); + assertEquals(card1.getColor(), 1); + assertEquals(card1.getShading(), 1); + assertEquals(card1.getShape(), 1); + assertEquals(card1.toString(), "1ROO"); + Card card2 = new Card(1, 1, 1, 1); + assertEquals(card2.getQuantity(), 1); + assertEquals(card2.getColor(), 1); + assertEquals(card2.getShading(), 1); + assertEquals(card2.getShape(), 1); + assertEquals(card2.toString(), "1ROO"); + Card card3 = new Card(1, 1, 1, 1); + assertEquals(card3.getQuantity(), 1); + assertEquals(card3.getColor(), 1); + assertEquals(card3.getShading(), 1); + assertEquals(card3.getShape(), 1); + assertEquals(card3.toString(), "1ROO"); + assertEquals(card1.isSet(card2, card3), true); + } + + public void testAgainWheeee() + { + Card card1 = new Card(3, 3, 1, 2); + assertEquals(card1.getQuantity(), 3); + assertEquals(card1.getColor(), 3); + assertEquals(card1.getShading(), 1); + assertEquals(card1.getShape(), 2); + assertEquals(card1.toString(), "3POD"); + Card card2 = new Card(1, 2, 3, 3); + assertEquals(card2.getQuantity(), 1); + assertEquals(card2.getColor(), 2); + assertEquals(card2.getShading(), 3); + assertEquals(card2.getShape(), 3); + assertEquals(card2.toString(), "1GSS"); + Card card3 = new Card(2, 1, 2, 1); + assertEquals(card3.getQuantity(), 2); + assertEquals(card3.getColor(), 1); + assertEquals(card3.getShading(), 2); + assertEquals(card3.getShape(), 1); + assertEquals(card3.toString(), "2RTO"); + assertEquals(card1.isSet(card2, card3), true); + } + + public void testAgainAgain() + { + Card card1 = new Card(3, 3, 1, 23); + assertEquals(card1.getQuantity(), 3); + assertEquals(card1.getColor(), 3); + assertEquals(card1.getShading(), 1); + assertEquals(card1.getShape(), 3); + assertEquals(card1.toString(), "3POS"); + Card card2 = new Card(1, 2, 3, 3); + assertEquals(card2.getQuantity(), 1); + assertEquals(card2.getColor(), 2); + assertEquals(card2.getShading(), 3); + assertEquals(card2.getShape(), 3); + assertEquals(card2.toString(), "1GSS"); + Card card3 = new Card(2, 1, 2, 1); + assertEquals(card3.getQuantity(), 2); + assertEquals(card3.getColor(), 1); + assertEquals(card3.getShading(), 2); + assertEquals(card3.getShape(), 1); + assertEquals(card3.toString(), "2RTO"); + assertEquals(card1.isSet(card2, card3), false); + } + +} \ No newline at end of file From 302d2025c51ec88f3eedbffebef925bd17d44dde Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Tue, 7 Apr 2015 15:22:29 -0400 Subject: [PATCH 02/47] Commit --- src/Card.java | 0 src/CardMain.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/CardTest.java | 0 src/Deck.java | 46 ++++++++++++++++++++++++++++++++++++++++++++-- src/DeckTest.java | 19 +++++++++++++++++++ 5 files changed, 108 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/Card.java create mode 100755 src/CardMain.java mode change 100644 => 100755 src/CardTest.java create mode 100755 src/DeckTest.java diff --git a/src/Card.java b/src/Card.java old mode 100644 new mode 100755 diff --git a/src/CardMain.java b/src/CardMain.java new file mode 100755 index 0000000..7f303e7 --- /dev/null +++ b/src/CardMain.java @@ -0,0 +1,45 @@ +public class CardMain{ + public static void main(String[] args){ + System.out.println("Hello"); + Card c = new Card(20,7,0,8); + Card d = new Card(20,7,0,8); + Card e = new Card(20,7,0,8); + + System.out.println(c.getQuantity()); + System.out.println(c.getColor()); + System.out.println(c.getShading()); + System.out.println(c.getShape()); + System.out.println(c.toString()); + String a = "heyy"; + System.out.println(a + c); + System.out.println(c.isSet(d, e)); + System.out.println("yeah!"); + +// for (int i = -1; i<=2147483647; i++) { +// int j = i; +// j = (((j % 3)+3)%3)+1; +// if (j < 1 || j > 3) { +// System.out.println(i + " fuck"); +// } +// if(i==500000000){ +// System.out.println("booty thumper"); +// } +// if(i==1000000000){ +// System.out.println("jungle boogie"); +// } +// if(i==2000000000){ +// System.out.println("jungle booger"); +// } +// if(i==2007000000){ +// System.out.println("almost!"); +// } +// if(i==2100000000){ +// System.out.println("ALMOST!"); +// } +// if(i==2147483646){ +// System.out.println("THER WE ARE GOOD SHOW"); +// } +// } +// System.out.println("DONE"); + } +} \ No newline at end of file diff --git a/src/CardTest.java b/src/CardTest.java old mode 100644 new mode 100755 diff --git a/src/Deck.java b/src/Deck.java index ab3a2a3..e338365 100755 --- a/src/Deck.java +++ b/src/Deck.java @@ -1,13 +1,54 @@ +import java.util.Collections; import java.io.BufferedReader; import java.io.FileReader; import java.util.StringTokenizer; import java.util.ArrayList; + public class Deck { // Implement the rest of this class yourself + private int nextCardIndex = 0; + private ArrayList cards = new ArrayList(81); + + public Deck(){ + for (int i=1; i<=3; i++) { + for (int j=1; j<=3; j++) { + for (int k=1; k<=3; k++) { + for (int m=1; m<=3; m++) { + Card card = new Card(i, j, k, m); + } + } + } + } + + Collections.shuffle(cards); + } + + public boolean hasNext() { + if (nextCardIndex < cards.size()) { + return true; + } + else { + return false; + } + } + + public Card getNext() { + //returns card + + if (hasNext() == true) { + nextCardIndex +=1; + return cards.get(nextCardIndex-1); + } + + else{ + return null; + } + } public Deck(String filename) { - cards = new ArrayList(81); + //file is named 3cards.txt + //ArrayList cards = new ArrayList(81); try { String line; @@ -35,11 +76,12 @@ public Deck(String filename) { int shape = Integer.parseInt(tokenizer.nextToken()); cards.add(new Card(quantity, color, shading, shape)); - nextCardIndex = 0; + int nextCardIndex = 0; } } catch(Exception e) { throw new RuntimeException("Error while reading file: " + e.toString()); } } + } diff --git a/src/DeckTest.java b/src/DeckTest.java new file mode 100755 index 0000000..462c25d --- /dev/null +++ b/src/DeckTest.java @@ -0,0 +1,19 @@ +import junit.framework.TestCase; + +/** + * A JUnit test case class. + * Every method starting with the word "test" will be called when running + * the test with JUnit. + */ +public class DeckTest extends TestCase { + + /** + * A test method. + * (Replace "X" with a name describing the test. You may write as + * many "testSomething" methods in this class as you wish, and each + * one will be called when running JUnit over this class.) + */ + public void testX() { + } + +} From f42a0c418c0dc72f06e4a60567710ab824b03261 Mon Sep 17 00:00:00 2001 From: Chris Sheehan Date: Tue, 7 Apr 2015 15:53:28 -0400 Subject: [PATCH 03/47] DeckTest Commit --- src/DeckTest.java | 3 +++ 1 file changed, 3 insertions(+) mode change 100755 => 100644 src/DeckTest.java diff --git a/src/DeckTest.java b/src/DeckTest.java old mode 100755 new mode 100644 index 462c25d..2316d97 --- a/src/DeckTest.java +++ b/src/DeckTest.java @@ -14,6 +14,9 @@ public class DeckTest extends TestCase { * one will be called when running JUnit over this class.) */ public void testX() { + Deck d = new Deck("3cards.txt"); + assertEquals(d.hasNext(), true); + assertEquals(d.getNext(), Card); } } From 9628080a5092a87d13feec9ec6d279b1a74e19e0 Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Wed, 8 Apr 2015 00:03:29 -0400 Subject: [PATCH 04/47] Deck and DeckTest commit --- src/DeckTest.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) mode change 100755 => 100644 src/DeckTest.java diff --git a/src/DeckTest.java b/src/DeckTest.java old mode 100755 new mode 100644 index 462c25d..73e5494 --- a/src/DeckTest.java +++ b/src/DeckTest.java @@ -13,7 +13,24 @@ public class DeckTest extends TestCase { * many "testSomething" methods in this class as you wish, and each * one will be called when running JUnit over this class.) */ - public void testX() { + public void testAllCards() { + Deck d = new Deck("81cards.txt"); + for (int i=0; i<81; i++) { + assertEquals(d.hasNext(), true); + d.getNext(); + } + d.getNext(); + assertEquals(d.hasNext(), false); + } + + public void test3Cards() { + Deck d = new Deck("3cards.txt"); + for (int i=0; i<3; i++) { + assertEquals(d.hasNext(), true); + d.getNext(); + } + d.getNext(); + assertEquals(d.hasNext(), false); } } From ab0503e74889a1513ddecab4f3993e800a85612f Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Wed, 8 Apr 2015 00:17:54 -0400 Subject: [PATCH 05/47] DeckTest commit --- src/DeckTest.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/DeckTest.java b/src/DeckTest.java index b1b88d0..73e5494 100644 --- a/src/DeckTest.java +++ b/src/DeckTest.java @@ -13,7 +13,6 @@ public class DeckTest extends TestCase { * many "testSomething" methods in this class as you wish, and each * one will be called when running JUnit over this class.) */ -<<<<<<< HEAD public void testAllCards() { Deck d = new Deck("81cards.txt"); for (int i=0; i<81; i++) { @@ -32,12 +31,6 @@ public void test3Cards() { } d.getNext(); assertEquals(d.hasNext(), false); -======= - public void testX() { - Deck d = new Deck("3cards.txt"); - assertEquals(d.hasNext(), true); - assertEquals(d.getNext(), Card); ->>>>>>> f42a0c418c0dc72f06e4a60567710ab824b03261 } } From c02381dbcd5ec6fc60d7adebc105a6a237e693a7 Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Wed, 8 Apr 2015 00:30:04 -0400 Subject: [PATCH 06/47] Deck and DeckTest --- src/Deck.java | 1 + src/DeckTest.java | 1 + 2 files changed, 2 insertions(+) mode change 100755 => 100644 src/Deck.java diff --git a/src/Deck.java b/src/Deck.java old mode 100755 new mode 100644 index e338365..6ddcd1f --- a/src/Deck.java +++ b/src/Deck.java @@ -84,4 +84,5 @@ public Deck(String filename) { } } + } diff --git a/src/DeckTest.java b/src/DeckTest.java index 73e5494..85093ee 100644 --- a/src/DeckTest.java +++ b/src/DeckTest.java @@ -33,4 +33,5 @@ public void test3Cards() { assertEquals(d.hasNext(), false); } + } From e76746af7bf6115dedc1b856285fecaffb8ce609 Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Wed, 8 Apr 2015 10:14:47 -0400 Subject: [PATCH 07/47] Text files used for Deck class --- src/3cards.txt | 4 +++ src/81cards.txt | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100755 src/3cards.txt create mode 100644 src/81cards.txt diff --git a/src/3cards.txt b/src/3cards.txt new file mode 100755 index 0000000..3c2b949 --- /dev/null +++ b/src/3cards.txt @@ -0,0 +1,4 @@ +#3cards +1 1 1 1 +1 1 1 2 +1 1 1 3 \ No newline at end of file diff --git a/src/81cards.txt b/src/81cards.txt new file mode 100644 index 0000000..9e0b11b --- /dev/null +++ b/src/81cards.txt @@ -0,0 +1,81 @@ +1 1 1 1 +1 1 1 2 +1 1 1 3 +1 1 2 1 +1 1 2 2 +1 1 2 3 +1 1 3 1 +1 1 3 2 +1 1 3 3 +1 2 1 1 +1 2 1 2 +1 2 1 3 +1 2 2 1 +1 2 2 2 +1 2 2 3 +1 2 3 1 +1 2 3 2 +1 2 3 3 +1 3 1 1 +1 3 1 2 +1 3 1 3 +1 3 2 1 +1 3 2 2 +1 3 2 3 +1 3 3 1 +1 3 3 2 +1 3 3 3 +2 1 1 1 +2 1 1 2 +2 1 1 3 +2 1 2 1 +2 1 2 2 +2 1 2 3 +2 1 3 1 +2 1 3 2 +2 1 3 3 +2 2 1 1 +2 2 1 2 +2 2 1 3 +2 2 2 1 +2 2 2 2 +2 2 2 3 +2 2 3 1 +2 2 3 2 +2 2 3 3 +2 3 1 1 +2 3 1 2 +2 3 1 3 +2 3 2 1 +2 3 2 2 +2 3 2 3 +2 3 3 1 +2 3 3 2 +2 3 3 3 +3 1 1 1 +3 1 1 2 +3 1 1 3 +3 1 2 1 +3 1 2 2 +3 1 2 3 +3 1 3 1 +3 1 3 2 +3 1 3 3 +3 2 1 1 +3 2 1 2 +3 2 1 3 +3 2 2 1 +3 2 2 2 +3 2 2 3 +3 2 3 1 +3 2 3 2 +3 2 3 3 +3 3 1 1 +3 3 1 2 +3 3 1 3 +3 3 2 1 +3 3 2 2 +3 3 2 3 +3 3 3 1 +3 3 3 2 +3 3 3 3 \ No newline at end of file From e00c8cd30c93ba5e9efcdc067a97b95ed6dab766 Mon Sep 17 00:00:00 2001 From: Chris Sheehan Date: Sat, 11 Apr 2015 18:30:31 -0400 Subject: [PATCH 08/47] Updated files 4/11/15 --- src/CardMain.java | 44 ++++++++++++++++++++++++++++++-------------- src/CardTest.class | Bin 0 -> 3185 bytes src/Deck.java | 9 +++++++-- src/DeckTest.class | Bin 0 -> 837 bytes 4 files changed, 37 insertions(+), 16 deletions(-) mode change 100755 => 100644 src/CardMain.java create mode 100644 src/CardTest.class create mode 100644 src/DeckTest.class diff --git a/src/CardMain.java b/src/CardMain.java old mode 100755 new mode 100644 index 7f303e7..df9bbf2 --- a/src/CardMain.java +++ b/src/CardMain.java @@ -1,19 +1,35 @@ +import java.util.ArrayList; + public class CardMain{ public static void main(String[] args){ - System.out.println("Hello"); - Card c = new Card(20,7,0,8); - Card d = new Card(20,7,0,8); - Card e = new Card(20,7,0,8); - - System.out.println(c.getQuantity()); - System.out.println(c.getColor()); - System.out.println(c.getShading()); - System.out.println(c.getShape()); - System.out.println(c.toString()); - String a = "heyy"; - System.out.println(a + c); - System.out.println(c.isSet(d, e)); - System.out.println("yeah!"); + Deck d = new Deck("81cards.txt"); +// for (int i=0; i<81; i++) { +// System.out.print(i + " "); + System.out.print(d.getSize() + " "); + System.out.print(d.hasNext() + " "); + System.out.println(d.getNext()); +// } + + + + + + + +// System.out.println("Hello"); +// Card c = new Card(20,7,0,8); +// Card d = new Card(20,7,0,8); +// Card e = new Card(20,7,0,8); +// +// System.out.println(c.getQuantity()); +// System.out.println(c.getColor()); +// System.out.println(c.getShading()); +// System.out.println(c.getShape()); +// System.out.println(c.toString()); +// String a = "heyy"; +// System.out.println(a + c); +// System.out.println(c.isSet(d, e)); +// System.out.println("yeah!"); // for (int i = -1; i<=2147483647; i++) { // int j = i; diff --git a/src/CardTest.class b/src/CardTest.class new file mode 100644 index 0000000000000000000000000000000000000000..7c6457dab6a1fafab70c60dc85f6f1be3a5e36ce GIT binary patch literal 3185 zcmc(h>2nlC7{;H;UX!qaWC;*a!6Qm8SaNV*CILcVlO@>&OcZsJ49SFL7j|cZcmOIT z9ta+YM_G7)DBwj|B`K})yZ#e?^AGT=CHTC(olR2NV41SY*{XiK-|n|(`q$6fy}#c2 z@n-;y=qtfutO{Ut35u{rinS%U3+tq|UWyG;Y?NY?iOtft#l#~fTEx{V?KaPe+qZ9f zP;_ajiLIWKoY%xQ6WdL+o7iEZBY>R&>@wir=p-F?vjIA|?2aW@zUxU>z8O$K}e^fvGns+(QP z(Wos4l*`bVn?39d=HA7*0!e#FW@9ap9%BBbG?T)OnbbKKzMyydQh`Vu*FyZ$|JrYDGx`K#ecM#oD z>yaWRMI3uLvY{s$m3|@F*dE_X)3iGl3t}H06@Rbt$Hd>zqr0Q3)gFsUUr#)$VxnxB z;~!(7awN-L3Li*YhwP)N^uchP>uR$y{NzA&2OrtHIYYMFowbs#;~rD{*wHcoX1m;u>YNmEWlf)aP+wooUffU3E~ZFDriM^wc`sXGT7%YCdlSYD zR*JBMrC&KsEM+~I8-V*b30Qw%JlNRGabEha{e+@kFQ1$6MCyKk*EK)qK^^4h!=SF^4DvIG)~{_qTT|QOP$`4z>N#XC zUp{YQg*~X?m(SS#zVM@hZU{b91%?`h>ILkMQSZ@II4<#N72l&Rq)WeEYC8cS&j*ovcJlHE5G%9 z`5%A&YoejDP1-^-0(X5uPn$a#WmNOLW#^n~Wib||v4S3*`>wH<7$Fxui!MV_pu z0NGlEP)COKfmoDRl18RjZmeXRB0D^ zMyb->RB1O=+C!DbsM0u9x@Qv0Ym-!3uULvomn)W{(iNIzxG+ndyo#kHsj$>msYO`o z_C)f|D&uvKVkt9?6y^xTeRszWrqR1X(^wmQRtTMPmJAIl$T= zS=wZIfGmf|a+oX~vK%4HgJhYQf#sbteq~{nvpPL>kkX~3shpnLsv}o)soN7rt_~`g z<1$!sT-#jG%q$O+b4?ktbjdQSvbhCE$?|EkJVut!kma+a_8eJ0PnO5Y@&s9) zB+D1b@f~b%yC)S6kRURho9G{E|n=PMPdbWe4!5Vd3|!{P0^)h zm)B*U<)S<4@-$h#LYA*`O|OyV>tuO`EZ?9m&ywXivV4;)-y+Mm$?_etJWrDElH~=C zc#q}#WcdMEemD!3jd_+^^i6aq+hi{1UTSkA!o*R>3Ue^a^ WY5rPo&0p(BCtd4J{A*E!=Dz`WdPT(m literal 0 HcmV?d00001 diff --git a/src/Deck.java b/src/Deck.java index 6ddcd1f..4cf9ec0 100644 --- a/src/Deck.java +++ b/src/Deck.java @@ -16,6 +16,7 @@ public Deck(){ for (int k=1; k<=3; k++) { for (int m=1; m<=3; m++) { Card card = new Card(i, j, k, m); + cards.add(card); } } } @@ -24,6 +25,10 @@ public Deck(){ Collections.shuffle(cards); } + public int getSize(){ + return cards.size(); + } + public boolean hasNext() { if (nextCardIndex < cards.size()) { return true; @@ -48,7 +53,7 @@ public Card getNext() { public Deck(String filename) { //file is named 3cards.txt - //ArrayList cards = new ArrayList(81); + //cards = new ArrayList(81); try { String line; @@ -76,7 +81,7 @@ public Deck(String filename) { int shape = Integer.parseInt(tokenizer.nextToken()); cards.add(new Card(quantity, color, shading, shape)); - int nextCardIndex = 0; + nextCardIndex = 0; } } catch(Exception e) { diff --git a/src/DeckTest.class b/src/DeckTest.class new file mode 100644 index 0000000000000000000000000000000000000000..37c8f7aced52b532f76fbd13c6707783678b74ca GIT binary patch literal 837 zcmaKq-EPxB5QWdiNo-t)wxK_vP1_{2;H1!~$qiBf2?dal+)5}_5xLtYCUxT`U^~zU z;5k6zhHGvp0*MFUQQ!@b_&ICRhzmfLcgEv0GvDm)=N}(F0jS}c2@`o8D+X3gB(SEI zf{Ak|Dz9YVl8$v98v^MY-oT4)321hCUm)2Wc3pvK#~Zl2qvHcN*pml7BUxwIk^a66 zJoP;eCZj_y6fm7TZl}NJhEYSnifC{9ep3cr{u3VG`+U3X73-+Uv?AH*@5m={9dfdU zN~@2P%+_!ebliKM>YO<%zI7y@Neff3$f<$?Q`fgUs?Sz*5~)9zEnIHAN-RHxgUsd=`8M5KL?Wj&wUk-ZJRup)HUPJATekj9T_aut< zs?AAd7`j1p_vuLboHS*(+p(H!E_y7O^ literal 0 HcmV?d00001 From 018448b67987beab19c8bb7c811c1971a46327b6 Mon Sep 17 00:00:00 2001 From: Chris Sheehan Date: Sat, 11 Apr 2015 20:30:43 -0400 Subject: [PATCH 09/47] Table and Table Node --- src/Table.java | 32 ++++++++++++++++++++++++++++++++ src/TableNode.java | 21 +++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/Table.java create mode 100644 src/TableNode.java diff --git a/src/Table.java b/src/Table.java new file mode 100644 index 0000000..13e6d72 --- /dev/null +++ b/src/Table.java @@ -0,0 +1,32 @@ +public class Table{ + private TableNode head; +// private int theLength; + + + public Table() + // + { + head = null; +// theLength = 0; + } + + public void add(Card){ + // + } + + public void removeSet(Card, Card, Card){ + //removes set from table + } + + public int numCards(){ + // + } + + public Card getCard(int index){ + //returns card at given int + } + + public int numSets(){ + //returns the number of Sets on the table + } +} \ No newline at end of file diff --git a/src/TableNode.java b/src/TableNode.java new file mode 100644 index 0000000..f47139e --- /dev/null +++ b/src/TableNode.java @@ -0,0 +1,21 @@ +public class TableNode{ + private Card card; + private TableNode next; + + public TableNode(Card){ + } + + public void setNext(Node newNext){ + next = newNext; + } + + public TableNode getNext(){ + return next; + } + + public Card getCard(){ + return Card; + } + +} + From fa372b6ed1246386d72e6dd5b8d3fed1a66a3d46 Mon Sep 17 00:00:00 2001 From: Chris Sheehan Date: Mon, 13 Apr 2015 15:21:11 -0400 Subject: [PATCH 10/47] Updated Table & TableNode files --- src/Table.java | 80 ++++++++++++++++++++++++++++++++++++++++++++++ src/TableNode.java | 3 +- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/src/Table.java b/src/Table.java index 13e6d72..e13971b 100644 --- a/src/Table.java +++ b/src/Table.java @@ -3,6 +3,17 @@ public class Table{ // private int theLength; + public Table() + // + { + head = null; +// theLength = 0; + } + public class Table{ + private TableNode head; +// private int theLength; + Card card = new Card(); + public Table() // { @@ -10,6 +21,75 @@ public Table() // theLength = 0; } + public void add(Card){ + //new cards should be added to the front of the list + + TableNode newCard = new TableNode(Card); + + // for an empty table + if (head == null) { + head = newNode; + } + + else { + newCard.setNext(head); + head = newCard; + } + + } + + public void removeSet(Card, Card, Card){ + //removes set from table + + } + + public int numCards(){ + //returns number of cards on table + TableNode temp = head; + int i = 0; + if (head == null) { + return 0; + } + else{ + while (temp != null) { + i += 1; + temp = temp.getNext(); + } + return i; + } + } + + public Card getCard(int index){ + //returns card at given int + TableNode temp = head; + if (temp == null) { + return null; + } + if (index == 0) { + return temp.getCard(); + } + for (int j = 0; j Date: Mon, 13 Apr 2015 17:43:48 -0400 Subject: [PATCH 11/47] Updated files 17:43 13/4/2015 --- src/CardMain.java | 10 ++- src/Table.java | 184 ++++++++++++++++++++------------------------- src/TableNode.java | 39 +++++----- 3 files changed, 109 insertions(+), 124 deletions(-) diff --git a/src/CardMain.java b/src/CardMain.java index df9bbf2..23dd4aa 100644 --- a/src/CardMain.java +++ b/src/CardMain.java @@ -2,13 +2,15 @@ public class CardMain{ public static void main(String[] args){ - Deck d = new Deck("81cards.txt"); +// Deck d = new Deck("81cards.txt"); // for (int i=0; i<81; i++) { // System.out.print(i + " "); - System.out.print(d.getSize() + " "); - System.out.print(d.hasNext() + " "); - System.out.println(d.getNext()); +// System.out.print(d.getSize() + " "); +// System.out.print(d.hasNext() + " "); +// System.out.println(d.getNext()); // } + + Card c = new Card(1,1,1,1); diff --git a/src/Table.java b/src/Table.java index e13971b..59b9e82 100644 --- a/src/Table.java +++ b/src/Table.java @@ -1,112 +1,94 @@ public class Table{ - private TableNode head; -// private int theLength; - - - public Table() - // - { - head = null; -// theLength = 0; - } - public class Table{ - private TableNode head; -// private int theLength; - Card card = new Card(); - - public Table() - // - { - head = null; -// theLength = 0; - } - - public void add(Card){ - //new cards should be added to the front of the list - - TableNode newCard = new TableNode(Card); + private TableNode head; + private int theLength; + // Card newCard = new Card(); - // for an empty table - if (head == null) { - head = newNode; + public Table(){ + head = null; + theLength = 0; } - else { - newCard.setNext(head); - head = newCard; - } - - } - - public void removeSet(Card, Card, Card){ - //removes set from table - - } - - public int numCards(){ - //returns number of cards on table - TableNode temp = head; - int i = 0; - if (head == null) { - return 0; + public void add(Card newCard){ + //new cards should be added to the front of the list + + TableNode newTableNode = new TableNode(newCard); + + // for an empty table + if (head == null) { + head = newTableNode; + } + + else { + newTableNode.setNext(head); + head = newTableNode; + } + } - else{ - while (temp != null) { - i += 1; - temp = temp.getNext(); - } - return i; - } - } - - public Card getCard(int index){ - //returns card at given int - TableNode temp = head; - if (temp == null) { - return null; + + public void removeSet(Card card1, Card card2, Card card3){ + //removes set from table } - if (index == 0) { - return temp.getCard(); + + public int numCards(){ + //returns number of cards on table + TableNode temp = head; + int i = 0; + if (head == null) { + return 0; + } + else{ + while (temp != null) { + i += 1; + temp = temp.getNext(); + } + return i; + } } - for (int j = 0; j Date: Mon, 13 Apr 2015 18:25:46 -0400 Subject: [PATCH 12/47] Updated files 6:25 13/4 --- src/CardMain.java | 4 +++- src/Table.java | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/CardMain.java b/src/CardMain.java index 23dd4aa..f7f4c64 100644 --- a/src/CardMain.java +++ b/src/CardMain.java @@ -10,7 +10,9 @@ public static void main(String[] args){ // System.out.println(d.getNext()); // } - Card c = new Card(1,1,1,1); + Table t = new Table(); + + System.out.print(t.numSets()); diff --git a/src/Table.java b/src/Table.java index 59b9e82..931fa00 100644 --- a/src/Table.java +++ b/src/Table.java @@ -1,7 +1,6 @@ public class Table{ private TableNode head; private int theLength; - // Card newCard = new Card(); public Table(){ head = null; @@ -27,6 +26,38 @@ public void add(Card newCard){ public void removeSet(Card card1, Card card2, Card card3){ //removes set from table + + TableNode temp = head; + TableNode prev = head; + TableNode newNext = head; + + /// for an empty list + if (head == null) { + break; + } + + else { + + ///if you're removing the head + if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ + head = temp.getNext(); + } + + ///otherwise + else{ + temp = temp.getNext(); + + if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ + newNext = temp.getNext(); + prev.setNext(newNext); + } + + //if the head is the only item + if (temp == null){ + prev.setNext(newNode); + } + } + } } public int numCards(){ @@ -70,11 +101,8 @@ public Card getCard(int index){ public int numSets(){ //returns the number of Sets on the table - - int sets = 0; - for (int i=0; i==numCards()-2; i++) { for (int j=1; j==numCards()-1; j++){ for (int k=2; k==numCards(); k++){ From 5c24ecae6de3de91599d25b45778a646facfcff4 Mon Sep 17 00:00:00 2001 From: Chris Sheehan Date: Mon, 13 Apr 2015 21:47:28 -0400 Subject: [PATCH 13/47] Updated Table 21:47 4/13 --- src/Table.java | 77 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 23 deletions(-) diff --git a/src/Table.java b/src/Table.java index 931fa00..af68cff 100644 --- a/src/Table.java +++ b/src/Table.java @@ -27,37 +27,67 @@ public void add(Card newCard){ public void removeSet(Card card1, Card card2, Card card3){ //removes set from table - TableNode temp = head; - TableNode prev = head; - TableNode newNext = head; - - /// for an empty list - if (head == null) { - break; - } - - else { + TableNode temp = head; + TableNode prev = head; + TableNode newNext = head; - ///if you're removing the head - if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ - head = temp.getNext(); + /// for an empty list + if (head == null) { + break; } - ///otherwise - else{ - temp = temp.getNext(); + else { + ///if you're removing the head first if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ - newNext = temp.getNext(); - prev.setNext(newNext); + head = temp.getNext(); + temp = head; + //loop until end. + while (temp.getNext != null) { + if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ + head = temp.getNext(); + temp = head; + if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ + head = temp.getNext(); + temp = head; + } + } + else { + temp = temp.getNext(); + } + } + ///FROM SORTED LINKED LIST NEEDS TO BE CHANGED + if (temp.getNext() == null){ + if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ + newNode.setNext(temp); + prev.setNext(newNode); + } + //adds to the end + else { + temp.setNext(newNode); + } + } + ///FROM SORTED LINKED LIST NEEDS TO BE CHANGED + } + + } - //if the head is the only item - if (temp == null){ - prev.setNext(newNode); + ///otherwise + else{ + temp = temp.getNext(); + + if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ + newNext = temp.getNext(); + prev.setNext(newNext); + } + + //if the head is the only item + if (temp == null){ + prev.setNext(newNode); + } } - } - } + } } public int numCards(){ @@ -77,6 +107,7 @@ public int numCards(){ } public Card getCard(int index){ + // find out if its asking for the index or for the nth card on the table //returns card at given int TableNode temp = head; From 2fd46dcfaecf7cd288d77e03b178bc167907ef50 Mon Sep 17 00:00:00 2001 From: Chris Sheehan Date: Mon, 13 Apr 2015 22:43:44 -0400 Subject: [PATCH 14/47] 22:43 4/13 --- src/Table.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Table.java b/src/Table.java index af68cff..5b9a102 100644 --- a/src/Table.java +++ b/src/Table.java @@ -46,21 +46,24 @@ public void removeSet(Card card1, Card card2, Card card3){ while (temp.getNext != null) { if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ head = temp.getNext(); + prev = head; temp = head; if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ head = temp.getNext(); + prev = temp; temp = head; } } else { + prev = temp; temp = temp.getNext(); + } } ///FROM SORTED LINKED LIST NEEDS TO BE CHANGED if (temp.getNext() == null){ if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ - newNode.setNext(temp); - prev.setNext(newNode); + prev.setNext(null); } //adds to the end else { @@ -87,6 +90,7 @@ public void removeSet(Card card1, Card card2, Card card3){ prev.setNext(newNode); } } + // } } From bf76c826390ffd4ff67064fd4f10920bc4d4ad99 Mon Sep 17 00:00:00 2001 From: Chris Sheehan Date: Mon, 13 Apr 2015 22:57:24 -0400 Subject: [PATCH 15/47] Table.java 22:57 4/13 --- src/Table.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Table.java b/src/Table.java index 5b9a102..11b860e 100644 --- a/src/Table.java +++ b/src/Table.java @@ -38,16 +38,22 @@ public void removeSet(Card card1, Card card2, Card card3){ else { - ///if you're removing the head first + ///if you're removing the head first GET RID OF THIS MAYBE if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ head = temp.getNext(); temp = head; + prev = head; + newNext = head; //loop until end. - while (temp.getNext != null) { + while (temp.getNext != null) { + //for removing head first if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ head = temp.getNext(); prev = head; temp = head; + newNext = head; + + // this can probably go too if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ head = temp.getNext(); prev = temp; @@ -57,6 +63,7 @@ public void removeSet(Card card1, Card card2, Card card3){ else { prev = temp; temp = temp.getNext(); + newNext = head; } } From 4da7345f4499cd629d0c699ce540b6bdbad08c9e Mon Sep 17 00:00:00 2001 From: Chris Sheehan Date: Tue, 14 Apr 2015 15:14:02 -0400 Subject: [PATCH 16/47] Table, TableTest, TableNodeTest, CardMain 15:13 4/14 --- src/CardMain.java | 10 ++- src/Table.java | 142 ++++++++++++++++++++++++----------------- src/TableNodeTest.java | 21 ++++++ src/TableTest.java | 31 +++++++++ 4 files changed, 144 insertions(+), 60 deletions(-) create mode 100644 src/TableNodeTest.java create mode 100644 src/TableTest.java diff --git a/src/CardMain.java b/src/CardMain.java index f7f4c64..8773f0c 100644 --- a/src/CardMain.java +++ b/src/CardMain.java @@ -11,9 +11,13 @@ public static void main(String[] args){ // } Table t = new Table(); - - System.out.print(t.numSets()); - + Card c = new Card(1,1,1,1); + Card c2 = new Card(2,2,2,2); + Card c3 = new Card(3,3,3,3); + t.add(c); + t.add(c2); + t.add(c3); + System.out.println(t.getCard(0)); diff --git a/src/Table.java b/src/Table.java index 11b860e..aea422e 100644 --- a/src/Table.java +++ b/src/Table.java @@ -1,10 +1,8 @@ public class Table{ private TableNode head; - private int theLength; public Table(){ head = null; - theLength = 0; } public void add(Card newCard){ @@ -20,87 +18,115 @@ public void add(Card newCard){ else { newTableNode.setNext(head); head = newTableNode; - } - + } } + public void removeSet(Card card1, Card card2, Card card3){ //removes set from table + //makes sure they're a set + if (card1.isSet(card2,card3) != true) { + return; + } + //check if they're on the table + TableNode temp = head; TableNode prev = head; - TableNode newNext = head; + int i = 0; - /// for an empty list - if (head == null) { - break; - } - - else { + while (temp != null) { - ///if you're removing the head first GET RID OF THIS MAYBE - if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ - head = temp.getNext(); + //check for first card + if (temp.getCard() == card1) { + i+=1; temp = head; prev = head; - newNext = head; - //loop until end. - while (temp.getNext != null) { - //for removing head first - if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ - head = temp.getNext(); - prev = head; + while (temp != null) { + //only checks for second card if first is there + if (temp.getCard() == card2) { + i+=1; temp = head; - newNext = head; - - // this can probably go too - if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ - head = temp.getNext(); - prev = temp; - temp = head; + prev = head; + while (temp != null) { + //only checks for third card if 1&2 are there + if (temp.getCard() == card3) { + i+=1; + temp = head; + prev = head; + } + //3rd card check + else { + temp = temp.getNext(); + } } } + //2nd card check else { - prev = temp; temp = temp.getNext(); - newNext = head; - - } - } - ///FROM SORTED LINKED LIST NEEDS TO BE CHANGED - if (temp.getNext() == null){ - if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ - prev.setNext(null); - } - //adds to the end - else { - temp.setNext(newNode); } } - ///FROM SORTED LINKED LIST NEEDS TO BE CHANGED } - - - } - - ///otherwise - else{ + //moves through list for first card + else { temp = temp.getNext(); + } + } + + //if all cards are on the table i will equal 3 + if (i == 3) { + + //If they are on table. + temp = head; + prev = head; - if (temp.getCard == card1 || temp.getCard == card2 || temp.getCard == card3){ - newNext = temp.getNext(); - prev.setNext(newNext); + /// for an empty list + if (head == null) { + return; } - //if the head is the only item - if (temp == null){ - prev.setNext(newNode); + else { + //loop until end. + while (temp.getNext() != null) { + //for removing head first + if (temp.getCard() == card1 || temp.getCard() == card2 || temp.getCard() == card3){ + if (temp == head){ + head = temp.getNext(); + prev = head; + temp = head; + } + else { + temp = temp.getNext(); + prev.setNext(temp); + } + } + else { + temp = temp.getNext(); + if (prev != head){ + prev=prev.getNext(); + } + } + } + + //for last card + if (temp.getNext()==null) { + if (temp.getCard() == card1 || temp.getCard() == card2 || temp.getCard() == card3){ + prev.setNext(null); + } + //might not need to be here + else { + return; + } + } } } - // + else { + return; } } + + public int numCards(){ //returns number of cards on table TableNode temp = head; @@ -118,7 +144,7 @@ public int numCards(){ } public Card getCard(int index){ - // find out if its asking for the index or for the nth card on the table + // parameter is the index although it will remove the (n-1)th card on the table //returns card at given int TableNode temp = head; @@ -129,7 +155,7 @@ public Card getCard(int index){ return temp.getCard(); } else { // this may cause errors maybe change to j < index - for (int j = 0; j==index; j++){ + for (int j = 0; j Date: Tue, 14 Apr 2015 15:55:28 -0400 Subject: [PATCH 17/47] Table & TableTest 15:55 4/14 --- src/Table.java | 7 ++++--- src/TableTest.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Table.java b/src/Table.java index aea422e..fad520f 100644 --- a/src/Table.java +++ b/src/Table.java @@ -170,10 +170,11 @@ public Card getCard(int index){ public int numSets(){ //returns the number of Sets on the table int sets = 0; + int numCards = numCards(); - for (int i=0; i==numCards()-2; i++) { - for (int j=1; j==numCards()-1; j++){ - for (int k=2; k==numCards(); k++){ + for (int i=0; i Date: Tue, 14 Apr 2015 18:56:11 -0400 Subject: [PATCH 18/47] Table&tabletest 6:56 --- src/Table.java | 82 +++++++++++++++++++++++++++++++++++++++++----- src/TableTest.java | 6 +++- 2 files changed, 78 insertions(+), 10 deletions(-) diff --git a/src/Table.java b/src/Table.java index fad520f..9c08b4f 100644 --- a/src/Table.java +++ b/src/Table.java @@ -35,20 +35,20 @@ public void removeSet(Card card1, Card card2, Card card3){ TableNode prev = head; int i = 0; - while (temp != null) { + while (temp.getNext() != null) { //check for first card if (temp.getCard() == card1) { i+=1; temp = head; prev = head; - while (temp != null) { + while (temp.getNext() != null) { //only checks for second card if first is there if (temp.getCard() == card2) { i+=1; temp = head; prev = head; - while (temp != null) { + while (temp.getNext() != null) { //only checks for third card if 1&2 are there if (temp.getCard() == card3) { i+=1; @@ -88,8 +88,8 @@ public void removeSet(Card card1, Card card2, Card card3){ else { //loop until end. while (temp.getNext() != null) { - //for removing head first - if (temp.getCard() == card1 || temp.getCard() == card2 || temp.getCard() == card3){ + //1st card: for removing head or middle + if (temp.getCard() == card1){ if (temp == head){ head = temp.getNext(); prev = head; @@ -110,14 +110,78 @@ public void removeSet(Card card1, Card card2, Card card3){ //for last card if (temp.getNext()==null) { - if (temp.getCard() == card1 || temp.getCard() == card2 || temp.getCard() == card3){ + if (temp.getCard() == card1){ prev.setNext(null); } //might not need to be here else { - return; + while (temp.getNext() != null) { + //2nd card: for removing head or middle + if (temp.getCard() == card2){ + if (temp == head){ + head = temp.getNext(); + prev = head; + temp = head; + } + else { + temp = temp.getNext(); + prev.setNext(temp); + } + } + else { + temp = temp.getNext(); + if (prev != head){ + prev=prev.getNext(); + } + } + } + + //for last card + if (temp.getNext()==null) { + if (temp.getCard() == card2){ + prev.setNext(null); + } + //might not need to be here + else { + while (temp.getNext() != null) { + //2nd card: for removing head or middle + if (temp.getCard() == card2){ + if (temp == head){ + head = temp.getNext(); + prev = head; + temp = head; + } + else { + temp = temp.getNext(); + prev.setNext(temp); + } + } + else { + temp = temp.getNext(); + if (prev != head){ + prev=prev.getNext(); + } + } + } + + //for last card + if (temp.getNext()==null) { + if (temp.getCard() == card2){ + prev.setNext(null); + } + //might not need to be here + else { + return; + } + } + } + } + } + } } } + + //end } } else { @@ -173,8 +237,8 @@ public int numSets(){ int numCards = numCards(); for (int i=0; i Date: Tue, 14 Apr 2015 21:31:34 -0400 Subject: [PATCH 19/47] Table & TableTest --- src/Table.java | 104 ++++++++++++++++++++++++--------------------- src/TableTest.java | 3 ++ 2 files changed, 58 insertions(+), 49 deletions(-) diff --git a/src/Table.java b/src/Table.java index 9c08b4f..f9f9005 100644 --- a/src/Table.java +++ b/src/Table.java @@ -23,70 +23,80 @@ public void add(Card newCard){ public void removeSet(Card card1, Card card2, Card card3){ - //removes set from table + //removes set from table //makes sure they're a set if (card1.isSet(card2,card3) != true) { return; } - //check if they're on the table + //make sure the table isn't empty + if (head == null) { + return; + } + + //check if they're on the table and if they are assign them to variables + Card firstCard = null; + Card secondCard = null; + Card thirdCard = null; + + //temp traverses through the list TableNode temp = head; TableNode prev = head; int i = 0; - - while (temp.getNext() != null) { + //goes through list + while (temp != null) { + //check for first card - //check for first card - if (temp.getCard() == card1) { - i+=1; - temp = head; - prev = head; - while (temp.getNext() != null) { - //only checks for second card if first is there - if (temp.getCard() == card2) { - i+=1; - temp = head; - prev = head; - while (temp.getNext() != null) { - //only checks for third card if 1&2 are there - if (temp.getCard() == card3) { - i+=1; - temp = head; - prev = head; - } - //3rd card check - else { - temp = temp.getNext(); - } - } - } - //2nd card check - else { - temp = temp.getNext(); - } - } + //make instance of card class + //Card c = new Card + + //THIS IS WHERE THE PROBLEM OCCURS + //temp.getCard() is equal to 1ROO, as is card1 + // when I run it through the debugger it confirms this, + // however the if statement seems to ignore this + // and procedes to move to the else statement, + // but for some reason it will recognize the + // second card that is also equal to 1ROO when temp is + // equal to its Node to it in the linked list. + if (card1.equals(temp.getCard())) { + firstCard = card1; + //temp = head; + //check for second + //while (temp != null) { } - //moves through list for first card + else if (card2.equals(temp.getCard())) { + secondCard = card2; + //temp = head; + //check for third + //while (temp != null) { + } + else if (card3.equals(temp.getCard())) { + thirdCard = card3; + } + //else { + // temp = temp.getNext(); + // } + // } + // } + //else { + // temp = temp.getNext(); + // } + // } + // } else { temp = temp.getNext(); } } - //if all cards are on the table i will equal 3 - if (i == 3) { + //if all cards are on table variables will equal cards given in parameter + if (firstCard == card1 && secondCard == card2 && thirdCard == card3) { - //If they are on table. + //sets the temp back to the head temp = head; prev = head; - /// for an empty list - if (head == null) { - return; - } - - else { - //loop until end. + //loop until end to remove cards while (temp.getNext() != null) { //1st card: for removing head or middle if (temp.getCard() == card1){ @@ -179,11 +189,7 @@ public void removeSet(Card card1, Card card2, Card card3){ } } } - } - - //end - } - } + //if cards are not on table the method ends else { return; } diff --git a/src/TableTest.java b/src/TableTest.java index a9bc74b..e643f71 100644 --- a/src/TableTest.java +++ b/src/TableTest.java @@ -42,6 +42,9 @@ public void testTable() { assertEquals(t.numCards(), 6); assertEquals(t.numSets(), 8); + assertEquals(t.getCard(0), c1); + + t.removeSet(c1,c2,c3); assertEquals(t.numCards(), 3); From 56743f9a903517956b4818c50914170f40462e10 Mon Sep 17 00:00:00 2001 From: Chris Sheehan Date: Tue, 14 Apr 2015 22:14:06 -0400 Subject: [PATCH 20/47] Updated Table&TableNode classes and tests 22:13 --- src/Table.java | 100 ++++------------------------------------- src/TableNodeTest.java | 13 +++++- 2 files changed, 19 insertions(+), 94 deletions(-) diff --git a/src/Table.java b/src/Table.java index f9f9005..3625186 100644 --- a/src/Table.java +++ b/src/Table.java @@ -43,47 +43,23 @@ public void removeSet(Card card1, Card card2, Card card3){ //temp traverses through the list TableNode temp = head; TableNode prev = head; - int i = 0; + //goes through list while (temp != null) { //check for first card //make instance of card class - //Card c = new Card - //THIS IS WHERE THE PROBLEM OCCURS - //temp.getCard() is equal to 1ROO, as is card1 - // when I run it through the debugger it confirms this, - // however the if statement seems to ignore this - // and procedes to move to the else statement, - // but for some reason it will recognize the - // second card that is also equal to 1ROO when temp is - // equal to its Node to it in the linked list. + //This if statement is where the infinite loop occurs if (card1.equals(temp.getCard())) { firstCard = card1; - //temp = head; - //check for second - //while (temp != null) { } else if (card2.equals(temp.getCard())) { secondCard = card2; - //temp = head; - //check for third - //while (temp != null) { } else if (card3.equals(temp.getCard())) { thirdCard = card3; } - //else { - // temp = temp.getNext(); - // } - // } - // } - //else { - // temp = temp.getNext(); - // } - // } - // } else { temp = temp.getNext(); } @@ -97,9 +73,9 @@ else if (card3.equals(temp.getCard())) { prev = head; //loop until end to remove cards - while (temp.getNext() != null) { - //1st card: for removing head or middle - if (temp.getCard() == card1){ + while (temp.getNext() != null) { + //for removing card at head or in middle + if (temp.getCard() == card1 || temp.getCard() == card2 || temp.getCard() == card3){ if (temp == head){ head = temp.getNext(); prev = head; @@ -125,70 +101,10 @@ else if (card3.equals(temp.getCard())) { } //might not need to be here else { - while (temp.getNext() != null) { - //2nd card: for removing head or middle - if (temp.getCard() == card2){ - if (temp == head){ - head = temp.getNext(); - prev = head; - temp = head; - } - else { - temp = temp.getNext(); - prev.setNext(temp); - } - } - else { - temp = temp.getNext(); - if (prev != head){ - prev=prev.getNext(); - } - } - } - - //for last card - if (temp.getNext()==null) { - if (temp.getCard() == card2){ - prev.setNext(null); - } - //might not need to be here - else { - while (temp.getNext() != null) { - //2nd card: for removing head or middle - if (temp.getCard() == card2){ - if (temp == head){ - head = temp.getNext(); - prev = head; - temp = head; - } - else { - temp = temp.getNext(); - prev.setNext(temp); - } - } - else { - temp = temp.getNext(); - if (prev != head){ - prev=prev.getNext(); - } - } - } - - //for last card - if (temp.getNext()==null) { - if (temp.getCard() == card2){ - prev.setNext(null); - } - //might not need to be here - else { - return; - } - } - } - } - } - } + return; } + } + } //if cards are not on table the method ends else { return; diff --git a/src/TableNodeTest.java b/src/TableNodeTest.java index 7c13f89..72047c6 100644 --- a/src/TableNodeTest.java +++ b/src/TableNodeTest.java @@ -14,8 +14,17 @@ public class TableNodeTest extends TestCase { * one will be called when running JUnit over this class.) */ public void testTableNode() { - // TableNode t = new TableNode(); - // assertEquals(); + Card c = new Card(1,1,1,1); + Card c2 = new Card(2,2,2,2); + TableNode t = new TableNode(c); + TableNode t2 = new TableNode(c2); + Table table = new Table(); + + + assertEquals(t.getNext(), null); + t.setNext(t2); + assertEquals(t.getNext(), t2); + assertEquals(t.getCard(), c); } } From feffa28c49c356413efdebf5dd57254fc08cb596 Mon Sep 17 00:00:00 2001 From: Chris Sheehan Date: Tue, 14 Apr 2015 22:47:04 -0400 Subject: [PATCH 21/47] Finished Table --- src/Table.java | 65 ++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/src/Table.java b/src/Table.java index 3625186..345e6d6 100644 --- a/src/Table.java +++ b/src/Table.java @@ -53,57 +53,66 @@ public void removeSet(Card card1, Card card2, Card card3){ //This if statement is where the infinite loop occurs if (card1.equals(temp.getCard())) { firstCard = card1; + temp = temp.getNext(); } else if (card2.equals(temp.getCard())) { secondCard = card2; + temp = temp.getNext(); } else if (card3.equals(temp.getCard())) { thirdCard = card3; + temp = temp.getNext(); } - else { + else{ temp = temp.getNext(); } } //if all cards are on table variables will equal cards given in parameter - if (firstCard == card1 && secondCard == card2 && thirdCard == card3) { + if (card1.equals(firstCard) && card2.equals(secondCard) && card3.equals(thirdCard)) { + int i = 0; + while(i < 3) { - //sets the temp back to the head + //sets the temp back to the head temp = head; prev = head; - //loop until end to remove cards - while (temp.getNext() != null) { - //for removing card at head or in middle - if (temp.getCard() == card1 || temp.getCard() == card2 || temp.getCard() == card3){ - if (temp == head){ - head = temp.getNext(); - prev = head; - temp = head; - } - else { - temp = temp.getNext(); - prev.setNext(temp); - } + //loop until end to remove cards + while (temp.getNext() != null && i < 3) { + //for removing card at head or in middle + if (card1.equals(temp.getCard()) || card2.equals(temp.getCard()) || card3.equals(temp.getCard())){ + if (temp == head){ + head = temp.getNext(); + prev = head; + temp = head; + i+=1; } else { temp = temp.getNext(); - if (prev != head){ - prev=prev.getNext(); - } + prev.setNext(temp); + i+=1; } } - - //for last card - if (temp.getNext()==null) { - if (temp.getCard() == card1){ - prev.setNext(null); - } - //might not need to be here - else { - return; + else { + temp = temp.getNext(); + if (prev != head){ + prev=prev.getNext(); } } + } + + //for last card + if (temp.getNext()==null) { + if (card1.equals(temp.getCard()) || card2.equals(temp.getCard()) || card3.equals(temp.getCard())){ + prev.setNext(null); + i+=1; + } + //might not need to be here + else { + return; + } + } + } } //if cards are not on table the method ends else { From 715ab2db1496d3ec4e4a6396e2748b565ddf2c40 Mon Sep 17 00:00:00 2001 From: Chris Sheehan Date: Tue, 14 Apr 2015 23:03:15 -0400 Subject: [PATCH 22/47] TableTest final --- src/TableTest.java | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/TableTest.java b/src/TableTest.java index e643f71..7c6ba14 100644 --- a/src/TableTest.java +++ b/src/TableTest.java @@ -51,4 +51,43 @@ public void testTable() { } + public void fullTable() { + Table t = new Table(); + Card c1 = new Card(2,1,1,1); + Card c2 = new Card(2,2,1,2); + Card c3 = new Card(3,1,3,3); + Card c11 = new Card(1,1,1,1); + Card c22 = new Card(2,3,3,1); + Card c33 = new Card(3,3,3,3); + Card c111 = new Card(2,1,2,1); + Card c222 = new Card(2,2,2,2); + Card c333 = new Card(3,3,2,1); + Card c1111 = new Card(1,3,1,2); + Card c2222 = new Card(3,3,2,2); + Card c3333 = new Card(3,3,3,3); + Card c4 = new Card(1,1,1,1); + Card c5 = new Card(2,2,2,2); + Card c6 = new Card(3,3,3,3); + + t.add(c1); + t.add(c2); + t.add(c3); + t.add(c11); + t.add(c22); + t.add(c33); + t.add(c111); + t.add(c222); + t.add(c333); + t.add(c1111); + t.add(c2222); + t.add(c3333); + t.add(c4); + t.add(c5); + t.add(c6); + + t.removeSet(c1,c2,c3); + + assertEquals(t.numCards(), 9); + } + } From 2783f4155510996d3ef4230fc4f335a68df2be25 Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Mon, 20 Apr 2015 16:29:55 -0400 Subject: [PATCH 23/47] Current src folder --- src/.DS_Store | Bin 0 -> 8196 bytes src/12cards0setsMilestone.dat | 13 ++ src/12cards14setsMilestone.dat | 12 ++ src/Card.class | Bin 0 -> 2330 bytes src/Deck.class | Bin 0 -> 2573 bytes src/README.md | 4 + src/Table.class | Bin 0 -> 2369 bytes src/Table.java~ | 188 +++++++++++++++++++++ src/TableNode.class | Bin 0 -> 647 bytes src/TableTestMilestone.class | Bin 0 -> 4711 bytes src/TableTestMilestone.java | 295 +++++++++++++++++++++++++++++++++ src/TableTestMilestone.java~ | 295 +++++++++++++++++++++++++++++++++ 12 files changed, 807 insertions(+) create mode 100644 src/.DS_Store create mode 100755 src/12cards0setsMilestone.dat create mode 100755 src/12cards14setsMilestone.dat create mode 100644 src/Card.class create mode 100644 src/Deck.class create mode 100644 src/README.md create mode 100644 src/Table.class create mode 100644 src/Table.java~ create mode 100644 src/TableNode.class create mode 100644 src/TableTestMilestone.class create mode 100644 src/TableTestMilestone.java create mode 100755 src/TableTestMilestone.java~ diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0b0bb26392b39210ecbcb8c0fa3b19c5ded0f7cb GIT binary patch literal 8196 zcmeI1zmC&D5XQefuE-x2x<(j^FZ~=9p#Bd(x^-QMI7Qt@4^*Efz;euxuDio*Q z$z?hnuJG1IQ@|8xDj>D{ZH#aqb4)As`-WBg1gBWCmS1Co72fkGXN5n-=Gk&JpDkB2 z(sILnWxxAF8;^iHwG~HrsNV$sU`=;iTeF7;QH(hwI%~x7w8r%Dh>?_;B`NogqG!n8(+Mlo@)BPN`GN_BH2NmU{y2Rrg4>`iN&np@14 zUQ0IV70l3eq6~W&)7uCmDMg9UCTbpucNXaA1c;NflDcH%~M0E|Bu?g|6gitgG>Qa;Qvs-?T=rK z4;gEyts7BGt(~#IVwWcKw%#hjLCbMkEyrnhe;D#O<5XdaV7K1#4BKD-5O7|{*!y4g Jx8Z6k@DtV~yO96@ literal 0 HcmV?d00001 diff --git a/src/12cards0setsMilestone.dat b/src/12cards0setsMilestone.dat new file mode 100755 index 0000000..dc7c2c6 --- /dev/null +++ b/src/12cards0setsMilestone.dat @@ -0,0 +1,13 @@ +# 12 cards with 0 sets +1 3 3 2 +3 3 2 2 +1 1 2 1 +1 2 3 3 +3 2 3 3 +1 3 1 3 +3 1 2 2 +2 2 3 2 +1 1 1 1 +3 2 1 1 +2 1 1 3 +2 2 1 3 diff --git a/src/12cards14setsMilestone.dat b/src/12cards14setsMilestone.dat new file mode 100755 index 0000000..1b3ea71 --- /dev/null +++ b/src/12cards14setsMilestone.dat @@ -0,0 +1,12 @@ +1 1 1 1 +1 1 1 2 +1 1 1 3 +1 1 2 1 +1 1 2 2 +1 1 2 3 +1 1 3 1 +1 1 3 2 +1 1 3 3 +1 2 1 1 +1 3 1 1 +1 2 1 2 diff --git a/src/Card.class b/src/Card.class new file mode 100644 index 0000000000000000000000000000000000000000..8f20a979003fce6c7fb23f8393b0c9f89f8a87d6 GIT binary patch literal 2330 zcmZux%TrTV82{bm-sC1+9tIMX1kpZ2c!>(Mpq7eNu|d=*6||U3xP?GWVz_9#>2%R9 zy6mDGS9GQ`Zd|l84bHSPo$j3WFY2OG`}@v`0V$CCy}$2#uXFzT_t)P6oWVvEJ;+9o z!mNO60_FrHl|!C!M(NHka3sujFTMVUZEnmi<=AX3QupktO;PvMVa84BBXN@kT^XWgeCsJ96x3n; z%tV6dC!9bVVJl4HHng+k7{}IyLBw&6@4*FhBa0;NQRA`^4{!osvb?W3x&eBg(M8dI zh#bqqFq>m2>LjUvqDDvs6?KY~iPNN$a9;9AD~vM+|A2NgqJAwM76Wjnbmth5>p=%A z^9uscNCZ^oAtmfnSvcCDk%b|*x!3CJ)fX=dQ=kNjl7cs@rPpfRN=!}}9UZUL)^JSK_ z9%9Drn8SHB>R#n7qaNn}6lE4Az4(w{NR2-M<0V6fIez`qOTc)%-nt8h$C$D}f6C;| zZ8(`&w2qdi=oW#c1db9!GO<{wJ`z`P zh&SvgX8D$0=Yw$*Cz0bDdYjFfr*?tTyST$%xomV1_ff+#KF12af`@Ohitn(7C)mI? zZ|4h?)vyw}agAZUAa{|s)=;f)gLA0E>Ui~|^dnr-Eywq?l$$!<{|8dDEGQt0w~aK( zpe)@sdPthGZ`+8Gv}Dz`5$5}2?%Ak>dKhYiKA(~;9LFPG+s7)ogRlF2|JI|ErV)@bP~VT!z5_ literal 0 HcmV?d00001 diff --git a/src/Deck.class b/src/Deck.class new file mode 100644 index 0000000000000000000000000000000000000000..aec0e8d916c01f536fd14b1fce763163be0ac85a GIT binary patch literal 2573 zcmZ`)-BVO$9DZK*>^ZyZ0da9r!fFumu%RTr2aidw>JW?t1pDqJ0;A zmvz-lHPe(`aN~u}OG<22Fpp0j)<0q=W$@5k@?eLcUI-~RdG zM*xrEvk>-RG>8VA(Qq~dAI9Y3oQ7BkD$dKD=R7oWh!*~c~h=)*$ zgq+L}CNL?dsQ@hboz^fDLZ!S@iDU?~NNGrG$Y{6}LJdX(u;n)!!VWl6;#7^ehMb1W z0;MT)&gnDk#6T)x&IyPC0e_t9tUx3>ZCp0ma*ma3J8Ij;)u@$qIt79w)?~_Xa<(Z@ zyV0Gls6_1S;a#=MN?A^ifUl|ftbo#&PEc!e)JmB{x!G~k9yP|3+zCh1aU*%wur0YR zZYt6dVt84;;*X9kUotIrSxv`Nz$v98eq9bjzQ zl#v}`$nN^QckZnNP0h=8B28XYNh3AcHsaV;YO+&$A9T_)W{POGK=qoyy(^>3hx8GCQRE* z44X#6w55?uI%_#rI>l`8X0co@PXAoo%*Z2oO#-EiSyRImmsDwi&`3IG$IaueiJ(m1 z0qKN}eQ4Fuh`j<88x&uj&*^vsO|q0Mj@-Da;~HMp@QRLC@tTg;(W#>g-8$aDn*x3AFSbXdnbnAhH=l@gCk6s9JUHKdIO8fmHiY$4B^h zIfnHa5!m6XySu|VR%zB;NteL3)k6=vH)kc8Z>sg%cG|ALGDUamZ5DyWte3g%sMqlc zuIu;|^URCPra<{B&dKp+47)yxoJQWOKTe7kCc2yf{b5BKu^81nQV=$2HuxW zCW*=tvjfO2l0(v^qDWo0Y2AKx+b-+10GmOA4>Yf#ToHa%m8B|DOsWQCq_SNFwz5N3 zqw+#vSrj%18&f68CY>pAE9)4xlO40z2_d!AqyU)w!=rc3xs(z_DL4S{A?Zh@aNdxG8|0YTj{Cg=b+NAL=+0U7NN$f zYic7(0a}N@<$L(6{CNb%<`uE9bbsE*`SDMYQLO`= zUg8MO_N8h-29-zXCgl=0DAnDsb)D0_J4I7MJ|f&<;xWkEQa?=nk|M?pCj6#PB6;a4 z;}8A$_UlnM4?Xk2fxffo3(c^1VV&{zTB=Z#skh|<_1%3}Kp*jzyQ zkgr|YpU0Ni;IBxx<`Ev`RPiO$g{41R!&~!+d?Drgi>QpX7O<_urPcPksA^Xw!CXmO zkpe4HP=+T-8BrrzBoGObmy(YzuNRiCFJSlJBC6?2O{{?0a9tidX}X@DJa!eZ`={Fs zs1je}TawGG!3At%VC`!t+C>6&vz?AGKSxQSV@!QNrDt&h1FUNlV;F*glceY=?&k;)s|Lp@ z1*w_FGqhU5)f_FKpvTR;`5e~@@$2Y`WEsm+teupGs3Ba^AA-6>1wToz(OC_rNSY;v YTioHMx3}ppoa)tZx{iv&ge$?wzlZZFr~m)} literal 0 HcmV?d00001 diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..bd9ba63 --- /dev/null +++ b/src/README.md @@ -0,0 +1,4 @@ +## CS II Set project + +See the full spec for this project here: +http://groot.cs.moravian.edu/cs121/CSII-SetProject.pdf diff --git a/src/Table.class b/src/Table.class new file mode 100644 index 0000000000000000000000000000000000000000..d5b5068ccdb54853d515af9b6df0e53d19206bd9 GIT binary patch literal 2369 zcma)6U2KzO6n;+oef|2i-8#UIbw9{9f3~(`jGqDB7~ljQb|W&tDfrWMAJF}Dv+MY| zLdld6uheL=MI%`vRhh~_2f=8(g2a#*@4Pk98>3emFUVv*@Aq|O=#5$Te&;>!dCz&y zbIy6cyL;ms0GqJShZ1Zt5x`ah+k9{%u9h|*+Ob_p9ZK4vq@6xm?NZBQ209HqF3^r! z$pL{saUj`0Z1s!|SZxANdpeWObqL%IjfZH{NwpxDNN22`iIILQYa0tzCPq`q;X}!6 zT3s$EwcPRaxWI5c(wjRuzzAkTqBEHtXj2Z2jCE3N7|Brz0#p?t2ugZ$$<$DHa?I8- zFFMFtBcms*UMnXE6`VP@?>UyVK)M8air!la-wlQDM*29K&W`7t(7tgiHJTZ4HYP!5 z3$m88M#h-+Sk^jW)3jUQ%}k6aOD0B67{NGZ75tbDU5!gw$RJ~-GXvHsmE^<-!SaR- z(c8E!`g%tvvMFm%dYFXz?Bv!BCQl>-D8q^XN)aT;A`ePi5x^ciVPJOvPogV;b=Vug zQ%D5Rjh+BvXi~an#CtgS07IMT!%kgtv-mw4s(QSHf-;xKxgmJd~L-*OlD0 zQ!o7bBG(`h`4X-KwUmtuX#CS*^4yCT@*Dd%XF?!9TET;DJ(Cxj7;XO3g8+%=zwzl#>+n9%td2O^YCaNK$~-5X>$_SB(6)`qZDz& zUcF)CCib zw}qdY!X8`r(cNl>OwSB%-;ab*Z{m!7a=Hj<8dXIU(+DmL+!nTTxQI0oJ1SXsa&o** znv!4qw16kfL|F=3H&xUr!w(nFhrKFaZ+`KNeR6Bj`XAAQVXrKC+&q^j&-Y4vgL49w z%g4(2QOCxsXOSOefg4!NMiwweZ4-Cvxwc{(wy-g`a{S`hk2W0S?nQK92s@C$PMks~ z&T=TGkA8_E zC9OzH2L`1dLvkF$lEIjaA}3j#lyRK4Tkt56U%>Zl#acERyJ@KzDb?A{sC4y|T=wZh zl-wwn7udv=9G|cpX4_VBjH;!Nd8?MMll{y$2m=k0AO}Hs?M9AcrQcX&SkpknK=ePq z8a6q}tf(*-P$Mf^>Q{xM{yS=B+4FpqoX*D^{Hk%RRYgs>x2w-B=>rMSeOLs# zj$H)2NuY1B9&dB^4*7eR;HLN_OcTTu`F;-(c1VnsQ_o0*LCcxWdID6uv@F$-QVVr_ ziD|1U;=o@4eF1*L_bx!>4uU#OHZ0LAEp)Z=3}7-&NBtiq{yVsq<@&yxPEODaH;BE zf#NI)kSD^ANcJbp<`R2hmfiCi^ZJ|jH+in zv|erZtid}$sGjw5zX2P`hE8_&*j#D6(`T1ev6d>Z=AzF{Hfsiskhi6xSHidpQ$)xe T|4Sr#2fFhkeVggQh1P!n3Lc-q literal 0 HcmV?d00001 diff --git a/src/Table.java~ b/src/Table.java~ new file mode 100644 index 0000000..345e6d6 --- /dev/null +++ b/src/Table.java~ @@ -0,0 +1,188 @@ +public class Table{ + private TableNode head; + + public Table(){ + head = null; + } + + public void add(Card newCard){ + //new cards should be added to the front of the list + + TableNode newTableNode = new TableNode(newCard); + + // for an empty table + if (head == null) { + head = newTableNode; + } + + else { + newTableNode.setNext(head); + head = newTableNode; + } + } + + + public void removeSet(Card card1, Card card2, Card card3){ + //removes set from table + + //makes sure they're a set + if (card1.isSet(card2,card3) != true) { + return; + } + + //make sure the table isn't empty + if (head == null) { + return; + } + + //check if they're on the table and if they are assign them to variables + Card firstCard = null; + Card secondCard = null; + Card thirdCard = null; + + //temp traverses through the list + TableNode temp = head; + TableNode prev = head; + + //goes through list + while (temp != null) { + //check for first card + + //make instance of card class + + //This if statement is where the infinite loop occurs + if (card1.equals(temp.getCard())) { + firstCard = card1; + temp = temp.getNext(); + } + else if (card2.equals(temp.getCard())) { + secondCard = card2; + temp = temp.getNext(); + } + else if (card3.equals(temp.getCard())) { + thirdCard = card3; + temp = temp.getNext(); + } + else{ + temp = temp.getNext(); + } + } + + //if all cards are on table variables will equal cards given in parameter + if (card1.equals(firstCard) && card2.equals(secondCard) && card3.equals(thirdCard)) { + int i = 0; + while(i < 3) { + + //sets the temp back to the head + temp = head; + prev = head; + + //loop until end to remove cards + while (temp.getNext() != null && i < 3) { + //for removing card at head or in middle + if (card1.equals(temp.getCard()) || card2.equals(temp.getCard()) || card3.equals(temp.getCard())){ + if (temp == head){ + head = temp.getNext(); + prev = head; + temp = head; + i+=1; + } + else { + temp = temp.getNext(); + prev.setNext(temp); + i+=1; + } + } + else { + temp = temp.getNext(); + if (prev != head){ + prev=prev.getNext(); + } + } + } + + //for last card + if (temp.getNext()==null) { + if (card1.equals(temp.getCard()) || card2.equals(temp.getCard()) || card3.equals(temp.getCard())){ + prev.setNext(null); + i+=1; + } + //might not need to be here + else { + return; + } + } + } + } + //if cards are not on table the method ends + else { + return; + } + } + + + + public int numCards(){ + //returns number of cards on table + TableNode temp = head; + int i = 0; + if (head == null) { + return 0; + } + else{ + while (temp != null) { + i += 1; + temp = temp.getNext(); + } + return i; + } + } + + public Card getCard(int index){ + // parameter is the index although it will remove the (n-1)th card on the table + //returns card at given int + + TableNode temp = head; + if (temp == null) { + return null; + } + if (index == 0) { + return temp.getCard(); + } + else { // this may cause errors maybe change to j < index + for (int j = 0; jJ!G;By*HL%dIFEGIxED03#XK5laap4c}M;Xry zl{AJ-a_7$6bH00LzJETy09@kKMh^Q07&uVj(87_0V*z6jOosxd-{yYBb0lA4fuesG z^vAL@8A@K7*I^XKErEi&)HQlkwpkRY_+cbF^T)oNYKuV4pA3R=FPMf3kz5+_eK-@a zBKfR3F`LP_qkEOzR5L|ZqGib%{fSC$Bc-B-l_e<8N;15CJDE=h@+KT}u=45!7Z1Tx z;K0U-0~3~mJPLfvsxDAfism?oM$K;jK@Ru>S+~){8NVvW|I2XEsWY0n8xRB*86BRw zS^-qN4+!skfs7{>$i8VqiLpilh%yK%uz#7c%$sc*Y2#8*l~t(_TpRQ(;jIL2DsYNv zYp+9UDaA5ZEEAigDpnm^39G5koWy%a_LU7YG=pywj8%Bvf+Oy%F=zgp>ub%s Hy2aivr@%=C7@6$MCToUQ{ zod4zfec$hP{^$GueD#|ErcmoZFD`{~xdT4&yU>9E-XR{|DK5DV^k7lk<;C5SxO+T; zC&a^Y1S=5~#L$xwTnXc;4kYokxU7oHS{ToS@h%IYN6Xc6bH;*yWb}%Kz-+DLSU8v~ zSDpOM_PSFq*y|OJBy+W*UAbb{%i>uN2AUh?hK25&d@eYR=3=?RYpv>>v(VM#?QE^u zXx4X%&02kVr^>}v(?VEn;F<$s&4p4)&B+}!J8RcVjeJf1XdHKRsp^Pf8WlU;(ZVfv zaZ(Ila++e1S!)$3G$)2!T6#rmpRYJ>!B?EHaL9vD*r+?w9*O&klX{X?SDa>JZu>^_ zecBUplOCUxyvMo3LXT!C)=w6NtW)CFLZ4@1d_wJ*Qd7NRYT4PY-E=tMwbChOR<`X* zMVpmQXbt3R3PC!dHLR#4@obw`t$BvlY8~J-gDZm#f#$ zjhYmRTw_jE?QNNaZR?m&v>(b{bc$OH?n5h0ySTMz-;e^C_N*QY9V?Vmbmj?Up;t~7 z$jKz@NdX%}ANnl>wQB+*CSvT}F}w%wjo~V|WF5sAN^r#8wHU6$CZG!Jc*F4^mh5H> zk7AmU)^X=_qh*ovbldoZ%!%=-w#gVaP`1#oSDb2Fz*-fW1;fo4wor*-8&!I{T^>1X z?y$c zG>|A8b|ddRN58U{ttnROIWnS2;VtZqy=<MvcDnWYGLJblj%pf@l+s6!C z0b#kS&xK3fLtr%!3JGwp z5!nmfL+Cz&_j{ld20Ch>-)f+*YVw0Fv?NdNK}9~$W+};+8tBsq(R%5IqZsm78#LDX zjJ087t)Z=D@3Tf@A!Tik=YnmKWRPP)S1Yi~qXP!I8s)XxT5+*AFe9O@6a z5;CrYbc%&>zmrem04?RI<#B3xf{d0K+X5!=Bwc<5(|DSyRyn)I>oZc+vwUQs-pZL!}2`i`Vp4qN0}oZ z^YEE5d2z<@nKXQUtaE#HEGeBR?2?RZ1o~c9qNb)&JER+uOXojJ?J+t8c!4haIJ)o& zcFa$*$Uem{hEKCZU&K5rr+eRjz4IT2C2quW51i zef%aQ=wn9cX;Z(ajnG%L&^cXXd!y*~Q!(CZP?@w8`rzbJjrA_Yyh<_mDCQd!^DT<` zHpP60V!rDUFlPkJ7y%PTz;Pp>-v~Hk1l-mFroE9;FM&msdI6Doc_~00DMW|8KT@q% z)e%w#zQ^kiNc@K+{v#6q35oxd#DC@?J#9$4)zL-DuGfzk(g{Oay!h1VYhTh2s2vWw zuZ4e4`WGbqOOpN-Nxw$Yzb5J5ko0f=FVYVi(rdaO5A5x2@tCgamK)U>=XYfEdp5a0 z5aW-Mg*svk7}s@~#`1`<^I_fS&TBhvpA%k?=^2tuM&1VXF)JRAY7X&8TgO$M?oTB1 z7rN!I>~w#_4F2vRblwnp*bq8v2;J0#&g>y1TAgGO2)1tZp|wS5uTx$}*a{$R@i1h0 z&&X#Chpgdn&Tx29b66TnCgh97^|{+gm6t*x(Q~zzT!#gNGK1KeOr+dhEpjsPtxl4Q zBW@+oXC30lTtDWm0pzX29%n5XqL(#MAG2&)r}hgx0*Mpa@I53~Q@iM570QohH~s5OX$b&TeRFk}r&v+DFUtj!Xd(K}Cb!h3J$ h$<4Ei7;lvxR~I&Iga@-|1Zug1y29~ literal 0 HcmV?d00001 diff --git a/src/TableTestMilestone.java b/src/TableTestMilestone.java new file mode 100644 index 0000000..d29b2ad --- /dev/null +++ b/src/TableTestMilestone.java @@ -0,0 +1,295 @@ +import junit.framework.TestCase; + +public class TableTestMilestone extends TestCase +{ + + public void testConstructorRuns() + { + Table t = new Table(); + } + + + public void testAddRuns() + { + Table t = new Table(); + + t.add(new Card(1, 2, 3, 1)); + } + + + public void testNumCardsNoCards() + { + Table t = new Table(); + + assertEquals(0, t.numCards()); + } + + + public void testNumCardsOneCard() + { + Table t = new Table(); + + t.add(new Card(2, 3, 1, 2)); + + assertEquals(1, t.numCards()); + } + + + public void testNumCardsTwoCards() + { + Table t = new Table(); + + t.add(new Card(3, 1, 2, 3)); + t.add(new Card(1, 2, 3, 1)); + + assertEquals(2, t.numCards()); + } + + + public void testGetCardOneCard() + { + Table t = new Table(); + + Card c = new Card(1, 1, 1, 1); + + t.add(c); + + assertEquals(c, t.getCard(0)); + } + + + public void testGetCardTwoCards() + { + Table t = new Table(); + + Card c1 = new Card(1, 1, 1, 1); + Card c2 = new Card(2, 2, 2, 2); + + t.add(c1); + t.add(c2); + + assertEquals(c2, t.getCard(0)); + assertEquals(c1, t.getCard(1)); + } + + + public void testGetCardThreeCards() + { + Table t = new Table(); + + Card c1 = new Card(1, 1, 1, 1); + Card c2 = new Card(2, 2, 2, 2); + Card c3 = new Card(3, 3, 3, 3); + + t.add(c1); + t.add(c2); + t.add(c3); + + assertEquals(c3, t.getCard(0)); + assertEquals(c2, t.getCard(1)); + assertEquals(c1, t.getCard(2)); + } + + + public void testNumSetsEmptyTable() + { + Table t = new Table(); + + assertEquals(0, t.numSets()); + } + + + public void testNumSets3Cards1Set() + { + Table t = makeTable("3cards1setMilestone.dat"); + + assertEquals(1, t.numSets()); + } + + /////here + public void testNumSets3cards0Sets() + { + Table t = makeTable("3cards0setsMilestone.dat"); + + assertEquals(0, t.numSets()); + } + + + public void testNumSets12Cards14Sets() + { + Table t = makeTable("12cards14setsMilestone.dat"); + + assertEquals(14, t.numSets()); + } + + + public void testRemoveSetEmptyTable() + { + Table t = new Table(); + + // Removing a valid set from an empty table shouldn't + // do anything. + t.removeSet(new Card(1, 1, 1, 1), + new Card(2, 2, 2, 2), + new Card(3, 3, 3, 3)); + + assertEquals(0, t.numCards()); + assertEquals(0, t.numSets()); + } + + + public void testSmallTable() + { + Table t = makeTable("3cards0setsMilestone.dat"); + + Card c1 = new Card(1, 1, 1, 1); + Card c2 = new Card(1, 1, 1, 2); + Card c3 = new Card(2, 2, 2, 3); + + assertEquals(3, t.numCards()); + assertEquals(0, t.numSets()); + + // because we're doing head insertion + // the Cards are indexed in the reverse + // order from which they are added + assertEquals(c3, t.getCard(0)); + assertEquals(c2, t.getCard(1)); + assertEquals(c1, t.getCard(2)); + } + + + public void testSmallTableNoSets() + { + Table t = makeTable("3cards0setsMilestone.dat"); + + Card c1 = new Card(1, 1, 1, 1); + Card c2 = new Card(1, 1, 1, 2); + Card c3 = new Card(2, 2, 2, 3); + + // trying to remove the cards as a set + // should do nothing + t.removeSet(c1, c2, c3); + + assertEquals(3, t.numCards()); + assertEquals(0, t.numSets()); + + assertEquals(c3, t.getCard(0)); + assertEquals(c2, t.getCard(1)); + assertEquals(c1, t.getCard(2)); + } + + + public void testSmallTable1Set() + { + Table t = makeTable("3cards1setMilestone.dat"); + + Card c1 = new Card(1, 1, 1, 1); + Card c2 = new Card(2, 2, 2, 2); + Card c3 = new Card(3, 3, 3, 3); + + // This will result in a middle remove, + // a tail remove and a head remove + t.removeSet(c2, c1, c3); + + assertEquals(0, t.numCards()); + assertEquals(0, t.numSets()); + } + + + public void testSetNotOnTable() + { + Table t = makeTable("3cards0setsMilestone.dat"); + + Card c1 = new Card(1, 2, 2, 2); + Card c2 = new Card(2, 2, 1, 3); + Card c3 = new Card(3, 2, 3, 1); + + // These cards form a set, but are not on the table + t.removeSet(c1, c2, c3); + + assertEquals(3, t.numCards()); + } + + + public void testNotAllOnTable() + { + Table t = makeTable("3cards0setsMilestone.dat"); + Card c1 = new Card(1, 1, 1, 1); + Card c2 = new Card(1, 1, 1, 2); + Card c3 = new Card(1, 1, 1, 3); + + // c1 and c2 are on the table, but c3 is not. The cards from a set + t.removeSet(c1, c2, c3); + + assertEquals(3, t.numCards()); + } + + + public void testFourteenInTwelve() + { + Table t = makeTable("12cards14setsMilestone.dat"); + + assertEquals(14, t.numSets()); + assertEquals(12, t.numCards()); + } + + + public void testRemoveMiddleMiddleHead() + { + Table t = makeTable("12cards14setsMilestone.dat"); + // 1 1 1 3 (3rd to last card) + // 1 3 1 1 (second card) + // 1 2 1 2 (first card) + t.removeSet(new Card(1, 1, 1, 3), + new Card(1, 3, 1, 1), + new Card(1, 2, 1, 2)); + + assertEquals(9, t.numCards()); + // that removed 6 of the 14 sets. + assertEquals(8, t.numSets()); + } + + + public void testRemoveTailMiddleMiddle() + { + Table t = makeTable("12cards14setsMilestone.dat"); + + // 1 1 1 1 (last card) + // 1 1 2 1 (middle) + // 1 1 3 1 (middle) + t.removeSet(new Card(1, 1, 1, 1), + new Card(1, 1, 2, 1), + new Card(1, 1, 3, 1)); + + assertEquals(9, t.numCards()); + } + + + public void testNoSetsinTwelve() + { + Table t = makeTable("12cards0setsMilestone.dat"); + + assertEquals(12, t.numCards()); + assertEquals(0, t.numSets()); + + // try to remove first, middle, and last cards + // which do not form a set so should do nothing + t.removeSet(new Card(1, 3, 3, 2), + new Card(1, 3, 1, 3), + new Card(2, 2, 1, 3)); + + assertEquals(12, t.numCards()); + assertEquals(0, t.numSets()); + } + + private Table makeTable(String filename) + { + Deck d = new Deck(filename); + Table t = new Table(); + + while(d.hasNext()) + t.add(d.getNext()); + + return t; + } +} diff --git a/src/TableTestMilestone.java~ b/src/TableTestMilestone.java~ new file mode 100755 index 0000000..6c0bc7c --- /dev/null +++ b/src/TableTestMilestone.java~ @@ -0,0 +1,295 @@ +import junit.framework.TestCase; + +public class TableTestMilestone extends TestCase +{ + + public void testConstructorRuns() + { + Table t = new Table(); + } + + + public void testAddRuns() + { + Table t = new Table(); + + t.add(new Card(1, 2, 3, 1)); + } + + + public void testNumCardsNoCards() + { + Table t = new Table(); + + assertEquals(0, t.numCards()); + } + + + public void testNumCardsOneCard() + { + Table t = new Table(); + + t.add(new Card(2, 3, 1, 2)); + + assertEquals(1, t.numCards()); + } + + + public void testNumCardsTwoCards() + { + Table t = new Table(); + + t.add(new Card(3, 1, 2, 3)); + t.add(new Card(1, 2, 3, 1)); + + assertEquals(2, t.numCards()); + } + + + public void testGetCardOneCard() + { + Table t = new Table(); + + Card c = new Card(1, 1, 1, 1); + + t.add(c); + + assertEquals(c, t.getCard(0)); + } + + + public void testGetCardTwoCards() + { + Table t = new Table(); + + Card c1 = new Card(1, 1, 1, 1); + Card c2 = new Card(2, 2, 2, 2); + + t.add(c1); + t.add(c2); + + assertEquals(c2, t.getCard(0)); + assertEquals(c1, t.getCard(1)); + } + + + public void testGetCardThreeCards() + { + Table t = new Table(); + + Card c1 = new Card(1, 1, 1, 1); + Card c2 = new Card(2, 2, 2, 2); + Card c3 = new Card(3, 3, 3, 3); + + t.add(c1); + t.add(c2); + t.add(c3); + + assertEquals(c3, t.getCard(0)); + assertEquals(c2, t.getCard(1)); + assertEquals(c1, t.getCard(2)); + } + + + public void testNumSetsEmptyTable() + { + Table t = new Table(); + + assertEquals(0, t.numSets()); + } + + + public void testNumSets3Cards1Set() + { + Table t = makeTable("3cards1setMilestone.dat"); + + assertEquals(1, t.numSets()); + } + + + public void testNumSets3cards0Sets() + { + Table t = makeTable("3cards0setsMilestone.dat"); + + assertEquals(0, t.numSets()); + } + + + public void testNumSets12Cards14Sets() + { + Table t = makeTable("12cards14setsMilestone.dat"); + + assertEquals(14, t.numSets()); + } + + + public void testRemoveSetEmptyTable() + { + Table t = new Table(); + + // Removing a valid set from an empty table shouldn't + // do anything. + t.removeSet(new Card(1, 1, 1, 1), + new Card(2, 2, 2, 2), + new Card(3, 3, 3, 3)); + + assertEquals(0, t.numCards()); + assertEquals(0, t.numSets()); + } + + + public void testSmallTable() + { + Table t = makeTable("3cards0setsMilestone.dat"); + + Card c1 = new Card(1, 1, 1, 1); + Card c2 = new Card(1, 1, 1, 2); + Card c3 = new Card(2, 2, 2, 3); + + assertEquals(3, t.numCards()); + assertEquals(0, t.numSets()); + + // because we're doing head insertion + // the Cards are indexed in the reverse + // order from which they are added + assertEquals(c3, t.getCard(0)); + assertEquals(c2, t.getCard(1)); + assertEquals(c1, t.getCard(2)); + } + + + public void testSmallTableNoSets() + { + Table t = makeTable("3cards0setsMilestone.dat"); + + Card c1 = new Card(1, 1, 1, 1); + Card c2 = new Card(1, 1, 1, 2); + Card c3 = new Card(2, 2, 2, 3); + + // trying to remove the cards as a set + // should do nothing + t.removeSet(c1, c2, c3); + + assertEquals(3, t.numCards()); + assertEquals(0, t.numSets()); + + assertEquals(c3, t.getCard(0)); + assertEquals(c2, t.getCard(1)); + assertEquals(c1, t.getCard(2)); + } + + + public void testSmallTable1Set() + { + Table t = makeTable("3cards1setMilestone.dat"); + + Card c1 = new Card(1, 1, 1, 1); + Card c2 = new Card(2, 2, 2, 2); + Card c3 = new Card(3, 3, 3, 3); + + // This will result in a middle remove, + // a tail remove and a head remove + t.removeSet(c2, c1, c3); + + assertEquals(0, t.numCards()); + assertEquals(0, t.numSets()); + } + + + public void testSetNotOnTable() + { + Table t = makeTable("3cards0setsMilestone.dat"); + + Card c1 = new Card(1, 2, 2, 2); + Card c2 = new Card(2, 2, 1, 3); + Card c3 = new Card(3, 2, 3, 1); + + // These cards form a set, but are not on the table + t.removeSet(c1, c2, c3); + + assertEquals(3, t.numCards()); + } + + + public void testNotAllOnTable() + { + Table t = makeTable("3cards0setsMilestone.dat"); + Card c1 = new Card(1, 1, 1, 1); + Card c2 = new Card(1, 1, 1, 2); + Card c3 = new Card(1, 1, 1, 3); + + // c1 and c2 are on the table, but c3 is not. The cards from a set + t.removeSet(c1, c2, c3); + + assertEquals(3, t.numCards()); + } + + + public void testFourteenInTwelve() + { + Table t = makeTable("12cards14setsMilestone.dat"); + + assertEquals(14, t.numSets()); + assertEquals(12, t.numCards()); + } + + + public void testRemoveMiddleMiddleHead() + { + Table t = makeTable("12cards14setsMilestone.dat"); + // 1 1 1 3 (3rd to last card) + // 1 3 1 1 (second card) + // 1 2 1 2 (first card) + t.removeSet(new Card(1, 1, 1, 3), + new Card(1, 3, 1, 1), + new Card(1, 2, 1, 2)); + + assertEquals(9, t.numCards()); + // that removed 6 of the 14 sets. + assertEquals(8, t.numSets()); + } + + + public void testRemoveTailMiddleMiddle() + { + Table t = makeTable("12cards14setsMilestone.dat"); + + // 1 1 1 1 (last card) + // 1 1 2 1 (middle) + // 1 1 3 1 (middle) + t.removeSet(new Card(1, 1, 1, 1), + new Card(1, 1, 2, 1), + new Card(1, 1, 3, 1)); + + assertEquals(9, t.numCards()); + } + + + public void testNoSetsinTwelve() + { + Table t = makeTable("12cards0setsMilestone.dat"); + + assertEquals(12, t.numCards()); + assertEquals(0, t.numSets()); + + // try to remove first, middle, and last cards + // which do not form a set so should do nothing + t.removeSet(new Card(1, 3, 3, 2), + new Card(1, 3, 1, 3), + new Card(2, 2, 1, 3)); + + assertEquals(12, t.numCards()); + assertEquals(0, t.numSets()); + } + + private Table makeTable(String filename) + { + Deck d = new Deck(filename); + Table t = new Table(); + + while(d.hasNext()) + t.add(d.getNext()); + + return t; + } +} From 95f9ed0bfe929436ea7ef08d6813ba4791754935 Mon Sep 17 00:00:00 2001 From: Chris Sheehan Date: Mon, 20 Apr 2015 19:51:40 -0400 Subject: [PATCH 24/47] Updated files 4/20 --- src/.DS_Store | Bin 8196 -> 6148 bytes src/Card.class | Bin 2330 -> 2318 bytes src/Deck.class | Bin 2573 -> 2573 bytes src/Table.class | Bin 2369 -> 2444 bytes src/Table.java | 19 ++++++++++++++++--- src/TableNode.class | Bin 647 -> 647 bytes src/TableTest.class | Bin 0 -> 1874 bytes 7 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 src/TableTest.class diff --git a/src/.DS_Store b/src/.DS_Store index 0b0bb26392b39210ecbcb8c0fa3b19c5ded0f7cb..400b58de2610244adec07808117ed36ee67843f6 100644 GIT binary patch delta 135 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50C@KV!2aBaJ6f@{ClrU52x<(j^FZ~=9p#Bd(x^-QMI7Qt@4^*Efz;euxuDio*Q z$z?hnuJG1IQ@|8xDj>D{ZH#aqb4)As`-WBg1gBWCmS1Co72fkGXN5n-=Gk&JpDkB2 z(sILnWxxAF8;^iHwG~HrsNV$sU`=;iTeF7;QH(hwI%~x7w8r%Dh>?_;B`NogqG!n8(+Mlo@)BPN`GN_BH2NmU{y2Rrg4>`iN&np@14 zUQ0IV70l3eq6~W&)7uCmDMg9UCTbpucNXaA1c;NflDcH%~M0E|Bu?g|6gitgG>Qa;Qvs-?T=rK z4;gEyts7BGt(~#IVwWcKw%#hjLCbMkEyrnhe;D#O<5XdaV7K1#4BKD-5O7|{*!y4g Jx8Z6k@DtV~yO96@ diff --git a/src/Card.class b/src/Card.class index 8f20a979003fce6c7fb23f8393b0c9f89f8a87d6..d98a2776f4b04c2e259ba49b07d33d8e127a305a 100644 GIT binary patch delta 39 ucmbOw)F;Go>ff$?3=9lL8##(N7&|9db9iubF)#r|iWpcKN+#dpZ~y@D?h2Uz delta 51 zcmeAZnkB?>>ff$?3=9k=8##(N7^hCI=I{^~V_*e}6amQ+22qAm1_g#P25pA&$>%s6 E0C8LlcmMzZ diff --git a/src/Deck.class b/src/Deck.class index aec0e8d916c01f536fd14b1fce763163be0ac85a..e8a5b6ae34e7b17e39327b2cbf83b8054d194870 100644 GIT binary patch delta 17 YcmeAb=@sEP^>5cc1_lPBjU23806MP)g#Z8m delta 17 YcmeAb=@sEP^>5cc1_lO`jU23806Mt^hX4Qo diff --git a/src/Table.class b/src/Table.class index d5b5068ccdb54853d515af9b6df0e53d19206bd9..23de909f170e18a0ef0590499e13149c04be3b41 100644 GIT binary patch delta 636 zcmXYu%S%*Y7{-6EXXaeACev~1q=V&{={P}!R=B8E)xzwCWEquV&j`0+l^_wao0_pvTrZ-4pw>K(8yZ)c5a zV*>`&AX%?qT<&v2B^J8j61HoW3FSN8P!apSI4L(A0IOZo2Ywstod(Cu@FV$*svavi zZPzN|l(-fsSGo?e{yYqVCO0$!Ju3jRC}VU)%UAXCX$o_RpXB2 zDlM)pMZy8c@;NP**B2Pn>-n87uRFYVbQ@D_=Qh2}vV%GLD6*S3?BNsrd}ANK7~l{4 z#pHl2U{LBfC`&mk%^Z<7h9t#N>1J3qb4<2!Ty}9%1~?@bIV}^MksF+qDbC3~&dUQX z$uwi~m~qK4L3C8B4C^N6_{nls;P^YGftb#HYGD}?P(rCHpjIV=m`t)#DTFK6X;TW* zBv)CbWYQvIw6h3{cDX=@l1-CFZX#A=RfytPBrQ6<6J}#1!aQ+Vyf#r^SKAr&JhL~R z*0f2zeUk{csMQ5U@mRtgnz`%Eo9T{ebv)F*kEkJ|`B`<$&`3_-F{6E+kmM;TX1%=i swOfCOg62KftQW+2shwW4Mi;%2w`}3Pe!vHI>bzg|LG=ys*(=!Tf79uOPXGV_ delta 551 zcmW-dOK4MJ5QV?V&3#2Q+Stg|gx1DK(ne9RMIsb;K8T8~)nZg=ec%ffEl5|<;)6mq z_M#9`2$q_lqQ*y%E<`s9B6RCY5L}6FT?OOhZierlIseSzlwuz{oG<_8-ve9f&a4p$ z{l*{yGU2~9rUv`Ga092zudHVV@MD8#1@O%na64V=5np@X5X#v>bv(O)`-x&One-Q% zDZdup)~(H)?Ky4DTx;5M+Ha@YDhBe;t&?qGSJZQ)fqBD~YOB9qC0wtoErXcWc{chd z%;Dlr9v$HjEX}+q8yPpMiw?KsT##+j-DQ{ICw%*uzRBpp;T5pfySc zaXH3Xr7)fpSf^x?kWtnvS@g&dX`v4Y!lG41cLOPM>Wm{ET|i@2-n?x~{8D(Aokr>nTaiFT-;-@q(?qWV>dW=QaDZKce%3>c)6C5cc1_lPBjU4q%067^2%>V!Z delta 17 YcmZo?ZD-{;^>5cc1_lO`jU4q%068NC&j0`b diff --git a/src/TableTest.class b/src/TableTest.class new file mode 100644 index 0000000000000000000000000000000000000000..f1fc2b6249a41f116c3eaf8a9a2f5bd78089857d GIT binary patch literal 1874 zcmZWpOKcle6g|(L8GkZ~oumQW4zwwhCUsmlzkZywrA?EN;-t`|5e=}IIMd+ZIN(n! z#Htbt#G(=lR!A(mB@%)~649zV78HpEMM5kP3j`Ywhz%7B5a+&`X%qEXx^vHY_r3ex zy~pqFe_z}IFo5YK(l{JLK8c8Yk0fEBU%)^TDGZ7?BxYFPQSpvR$Z>%u1Quc#iD6X1 z8ZB4LjZ+HIp5A!{V{C27Q%DudRd1%by6DyB+{Fr+j^bL$t<1Z%vfzL;8n2h@3N1yA z=e&AjL?O}OHwaJ-g_u9fnMkRh35#QHZAqg6p$5eai5V7ilp9=WRw}^;(NaIxL`wsV zjg|%(Y>**kkRoT0BWVgr))bbsDKz=y>{_!{@+Qi1g|-K$JiOvwb#1hxgP}ntLyjff zNgJnd+QxG@W8*BwY@EZmzzG|ZGVwg71fI9?0*XBDgKZU_SZT7F`71Sd)w{MMkvD`yRhw!o-$6?pD+6 zRBu?wgFQvLPrl+-m-81ESG-bV`5QUOz(smN%`BnUyhc=-;qZ7d{T1%60bkVo{06d1riCDOBvAV~& zIJx_`5V^dGXz><|%Ld0L%xUpW4*E0VTO9NYMs@>MbPKU;-v;6W3<0?Sm;y3JfGk1L z4J0xQN@htXa^jeD`o!5li!7G}F%C&!3W#$Eumq$n|0e`D=i+!aV`&?s&6pW0L&xS$ zt#Y8WPRp&+@i4zm)|ZomwMmFXJS3U{J}@% zZw%?yT=dHyv?h)}nPWFwv< z>82Os>iuDZBiA|8&Yll$Z?L(e!N$V|8$pAmGlJJ`m>Ol9*G)z4cmo2SiJ~x{{x#$Mdkni literal 0 HcmV?d00001 From 866073014bd5550acfc18f903e67fd89fcfeba9d Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Mon, 20 Apr 2015 19:52:29 -0400 Subject: [PATCH 25/47] Delete 12cards0setsMilestone.dat --- src/12cards0setsMilestone.dat | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100755 src/12cards0setsMilestone.dat diff --git a/src/12cards0setsMilestone.dat b/src/12cards0setsMilestone.dat deleted file mode 100755 index dc7c2c6..0000000 --- a/src/12cards0setsMilestone.dat +++ /dev/null @@ -1,13 +0,0 @@ -# 12 cards with 0 sets -1 3 3 2 -3 3 2 2 -1 1 2 1 -1 2 3 3 -3 2 3 3 -1 3 1 3 -3 1 2 2 -2 2 3 2 -1 1 1 1 -3 2 1 1 -2 1 1 3 -2 2 1 3 From 96bd324404f24287e7f67ed863657f94ee42ea2b Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Mon, 20 Apr 2015 19:52:39 -0400 Subject: [PATCH 26/47] Delete 12cards14setsMilestone.dat --- src/12cards14setsMilestone.dat | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100755 src/12cards14setsMilestone.dat diff --git a/src/12cards14setsMilestone.dat b/src/12cards14setsMilestone.dat deleted file mode 100755 index 1b3ea71..0000000 --- a/src/12cards14setsMilestone.dat +++ /dev/null @@ -1,12 +0,0 @@ -1 1 1 1 -1 1 1 2 -1 1 1 3 -1 1 2 1 -1 1 2 2 -1 1 2 3 -1 1 3 1 -1 1 3 2 -1 1 3 3 -1 2 1 1 -1 3 1 1 -1 2 1 2 From 4c4fc5757cd6543fee0599ab6c68c3d4d88d25fb Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Mon, 20 Apr 2015 19:52:46 -0400 Subject: [PATCH 27/47] Delete TableTestMilestone.class --- src/TableTestMilestone.class | Bin 4711 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/TableTestMilestone.class diff --git a/src/TableTestMilestone.class b/src/TableTestMilestone.class deleted file mode 100644 index c99ebd7765a29ce0d6ec562dc8f47280bdda8ae0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4711 zcmbtXTWni*9sZ8*PQBE2(%cGdXh@sHcHLZBwsuMB(xeSI&X#!Hl5y#YecCv2?9O)D z0WS#l0K80qKtcl~grE-yv@xlvR)i4n!c8FH0hol~1pzMz@qj>r@%=C7@6$MCToUQ{ zod4zfec$hP{^$GueD#|ErcmoZFD`{~xdT4&yU>9E-XR{|DK5DV^k7lk<;C5SxO+T; zC&a^Y1S=5~#L$xwTnXc;4kYokxU7oHS{ToS@h%IYN6Xc6bH;*yWb}%Kz-+DLSU8v~ zSDpOM_PSFq*y|OJBy+W*UAbb{%i>uN2AUh?hK25&d@eYR=3=?RYpv>>v(VM#?QE^u zXx4X%&02kVr^>}v(?VEn;F<$s&4p4)&B+}!J8RcVjeJf1XdHKRsp^Pf8WlU;(ZVfv zaZ(Ila++e1S!)$3G$)2!T6#rmpRYJ>!B?EHaL9vD*r+?w9*O&klX{X?SDa>JZu>^_ zecBUplOCUxyvMo3LXT!C)=w6NtW)CFLZ4@1d_wJ*Qd7NRYT4PY-E=tMwbChOR<`X* zMVpmQXbt3R3PC!dHLR#4@obw`t$BvlY8~J-gDZm#f#$ zjhYmRTw_jE?QNNaZR?m&v>(b{bc$OH?n5h0ySTMz-;e^C_N*QY9V?Vmbmj?Up;t~7 z$jKz@NdX%}ANnl>wQB+*CSvT}F}w%wjo~V|WF5sAN^r#8wHU6$CZG!Jc*F4^mh5H> zk7AmU)^X=_qh*ovbldoZ%!%=-w#gVaP`1#oSDb2Fz*-fW1;fo4wor*-8&!I{T^>1X z?y$c zG>|A8b|ddRN58U{ttnROIWnS2;VtZqy=<MvcDnWYGLJblj%pf@l+s6!C z0b#kS&xK3fLtr%!3JGwp z5!nmfL+Cz&_j{ld20Ch>-)f+*YVw0Fv?NdNK}9~$W+};+8tBsq(R%5IqZsm78#LDX zjJ087t)Z=D@3Tf@A!Tik=YnmKWRPP)S1Yi~qXP!I8s)XxT5+*AFe9O@6a z5;CrYbc%&>zmrem04?RI<#B3xf{d0K+X5!=Bwc<5(|DSyRyn)I>oZc+vwUQs-pZL!}2`i`Vp4qN0}oZ z^YEE5d2z<@nKXQUtaE#HEGeBR?2?RZ1o~c9qNb)&JER+uOXojJ?J+t8c!4haIJ)o& zcFa$*$Uem{hEKCZU&K5rr+eRjz4IT2C2quW51i zef%aQ=wn9cX;Z(ajnG%L&^cXXd!y*~Q!(CZP?@w8`rzbJjrA_Yyh<_mDCQd!^DT<` zHpP60V!rDUFlPkJ7y%PTz;Pp>-v~Hk1l-mFroE9;FM&msdI6Doc_~00DMW|8KT@q% z)e%w#zQ^kiNc@K+{v#6q35oxd#DC@?J#9$4)zL-DuGfzk(g{Oay!h1VYhTh2s2vWw zuZ4e4`WGbqOOpN-Nxw$Yzb5J5ko0f=FVYVi(rdaO5A5x2@tCgamK)U>=XYfEdp5a0 z5aW-Mg*svk7}s@~#`1`<^I_fS&TBhvpA%k?=^2tuM&1VXF)JRAY7X&8TgO$M?oTB1 z7rN!I>~w#_4F2vRblwnp*bq8v2;J0#&g>y1TAgGO2)1tZp|wS5uTx$}*a{$R@i1h0 z&&X#Chpgdn&Tx29b66TnCgh97^|{+gm6t*x(Q~zzT!#gNGK1KeOr+dhEpjsPtxl4Q zBW@+oXC30lTtDWm0pzX29%n5XqL(#MAG2&)r}hgx0*Mpa@I53~Q@iM570QohH~s5OX$b&TeRFk}r&v+DFUtj!Xd(K}Cb!h3J$ h$<4Ei7;lvxR~I&Iga@-|1Zug1y29~ From 9d2b6b3e4806d40910ee881337468fe3789e48ed Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Mon, 20 Apr 2015 19:52:54 -0400 Subject: [PATCH 28/47] Delete TableTestMilestone.java~ --- src/TableTestMilestone.java~ | 295 ----------------------------------- 1 file changed, 295 deletions(-) delete mode 100755 src/TableTestMilestone.java~ diff --git a/src/TableTestMilestone.java~ b/src/TableTestMilestone.java~ deleted file mode 100755 index 6c0bc7c..0000000 --- a/src/TableTestMilestone.java~ +++ /dev/null @@ -1,295 +0,0 @@ -import junit.framework.TestCase; - -public class TableTestMilestone extends TestCase -{ - - public void testConstructorRuns() - { - Table t = new Table(); - } - - - public void testAddRuns() - { - Table t = new Table(); - - t.add(new Card(1, 2, 3, 1)); - } - - - public void testNumCardsNoCards() - { - Table t = new Table(); - - assertEquals(0, t.numCards()); - } - - - public void testNumCardsOneCard() - { - Table t = new Table(); - - t.add(new Card(2, 3, 1, 2)); - - assertEquals(1, t.numCards()); - } - - - public void testNumCardsTwoCards() - { - Table t = new Table(); - - t.add(new Card(3, 1, 2, 3)); - t.add(new Card(1, 2, 3, 1)); - - assertEquals(2, t.numCards()); - } - - - public void testGetCardOneCard() - { - Table t = new Table(); - - Card c = new Card(1, 1, 1, 1); - - t.add(c); - - assertEquals(c, t.getCard(0)); - } - - - public void testGetCardTwoCards() - { - Table t = new Table(); - - Card c1 = new Card(1, 1, 1, 1); - Card c2 = new Card(2, 2, 2, 2); - - t.add(c1); - t.add(c2); - - assertEquals(c2, t.getCard(0)); - assertEquals(c1, t.getCard(1)); - } - - - public void testGetCardThreeCards() - { - Table t = new Table(); - - Card c1 = new Card(1, 1, 1, 1); - Card c2 = new Card(2, 2, 2, 2); - Card c3 = new Card(3, 3, 3, 3); - - t.add(c1); - t.add(c2); - t.add(c3); - - assertEquals(c3, t.getCard(0)); - assertEquals(c2, t.getCard(1)); - assertEquals(c1, t.getCard(2)); - } - - - public void testNumSetsEmptyTable() - { - Table t = new Table(); - - assertEquals(0, t.numSets()); - } - - - public void testNumSets3Cards1Set() - { - Table t = makeTable("3cards1setMilestone.dat"); - - assertEquals(1, t.numSets()); - } - - - public void testNumSets3cards0Sets() - { - Table t = makeTable("3cards0setsMilestone.dat"); - - assertEquals(0, t.numSets()); - } - - - public void testNumSets12Cards14Sets() - { - Table t = makeTable("12cards14setsMilestone.dat"); - - assertEquals(14, t.numSets()); - } - - - public void testRemoveSetEmptyTable() - { - Table t = new Table(); - - // Removing a valid set from an empty table shouldn't - // do anything. - t.removeSet(new Card(1, 1, 1, 1), - new Card(2, 2, 2, 2), - new Card(3, 3, 3, 3)); - - assertEquals(0, t.numCards()); - assertEquals(0, t.numSets()); - } - - - public void testSmallTable() - { - Table t = makeTable("3cards0setsMilestone.dat"); - - Card c1 = new Card(1, 1, 1, 1); - Card c2 = new Card(1, 1, 1, 2); - Card c3 = new Card(2, 2, 2, 3); - - assertEquals(3, t.numCards()); - assertEquals(0, t.numSets()); - - // because we're doing head insertion - // the Cards are indexed in the reverse - // order from which they are added - assertEquals(c3, t.getCard(0)); - assertEquals(c2, t.getCard(1)); - assertEquals(c1, t.getCard(2)); - } - - - public void testSmallTableNoSets() - { - Table t = makeTable("3cards0setsMilestone.dat"); - - Card c1 = new Card(1, 1, 1, 1); - Card c2 = new Card(1, 1, 1, 2); - Card c3 = new Card(2, 2, 2, 3); - - // trying to remove the cards as a set - // should do nothing - t.removeSet(c1, c2, c3); - - assertEquals(3, t.numCards()); - assertEquals(0, t.numSets()); - - assertEquals(c3, t.getCard(0)); - assertEquals(c2, t.getCard(1)); - assertEquals(c1, t.getCard(2)); - } - - - public void testSmallTable1Set() - { - Table t = makeTable("3cards1setMilestone.dat"); - - Card c1 = new Card(1, 1, 1, 1); - Card c2 = new Card(2, 2, 2, 2); - Card c3 = new Card(3, 3, 3, 3); - - // This will result in a middle remove, - // a tail remove and a head remove - t.removeSet(c2, c1, c3); - - assertEquals(0, t.numCards()); - assertEquals(0, t.numSets()); - } - - - public void testSetNotOnTable() - { - Table t = makeTable("3cards0setsMilestone.dat"); - - Card c1 = new Card(1, 2, 2, 2); - Card c2 = new Card(2, 2, 1, 3); - Card c3 = new Card(3, 2, 3, 1); - - // These cards form a set, but are not on the table - t.removeSet(c1, c2, c3); - - assertEquals(3, t.numCards()); - } - - - public void testNotAllOnTable() - { - Table t = makeTable("3cards0setsMilestone.dat"); - Card c1 = new Card(1, 1, 1, 1); - Card c2 = new Card(1, 1, 1, 2); - Card c3 = new Card(1, 1, 1, 3); - - // c1 and c2 are on the table, but c3 is not. The cards from a set - t.removeSet(c1, c2, c3); - - assertEquals(3, t.numCards()); - } - - - public void testFourteenInTwelve() - { - Table t = makeTable("12cards14setsMilestone.dat"); - - assertEquals(14, t.numSets()); - assertEquals(12, t.numCards()); - } - - - public void testRemoveMiddleMiddleHead() - { - Table t = makeTable("12cards14setsMilestone.dat"); - // 1 1 1 3 (3rd to last card) - // 1 3 1 1 (second card) - // 1 2 1 2 (first card) - t.removeSet(new Card(1, 1, 1, 3), - new Card(1, 3, 1, 1), - new Card(1, 2, 1, 2)); - - assertEquals(9, t.numCards()); - // that removed 6 of the 14 sets. - assertEquals(8, t.numSets()); - } - - - public void testRemoveTailMiddleMiddle() - { - Table t = makeTable("12cards14setsMilestone.dat"); - - // 1 1 1 1 (last card) - // 1 1 2 1 (middle) - // 1 1 3 1 (middle) - t.removeSet(new Card(1, 1, 1, 1), - new Card(1, 1, 2, 1), - new Card(1, 1, 3, 1)); - - assertEquals(9, t.numCards()); - } - - - public void testNoSetsinTwelve() - { - Table t = makeTable("12cards0setsMilestone.dat"); - - assertEquals(12, t.numCards()); - assertEquals(0, t.numSets()); - - // try to remove first, middle, and last cards - // which do not form a set so should do nothing - t.removeSet(new Card(1, 3, 3, 2), - new Card(1, 3, 1, 3), - new Card(2, 2, 1, 3)); - - assertEquals(12, t.numCards()); - assertEquals(0, t.numSets()); - } - - private Table makeTable(String filename) - { - Deck d = new Deck(filename); - Table t = new Table(); - - while(d.hasNext()) - t.add(d.getNext()); - - return t; - } -} From 4edbaf81e7afa8b7e87c34eff15f6b867854f2ec Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Mon, 20 Apr 2015 19:53:06 -0400 Subject: [PATCH 29/47] Delete TableTestMilestone.java --- src/TableTestMilestone.java | 295 ------------------------------------ 1 file changed, 295 deletions(-) delete mode 100644 src/TableTestMilestone.java diff --git a/src/TableTestMilestone.java b/src/TableTestMilestone.java deleted file mode 100644 index d29b2ad..0000000 --- a/src/TableTestMilestone.java +++ /dev/null @@ -1,295 +0,0 @@ -import junit.framework.TestCase; - -public class TableTestMilestone extends TestCase -{ - - public void testConstructorRuns() - { - Table t = new Table(); - } - - - public void testAddRuns() - { - Table t = new Table(); - - t.add(new Card(1, 2, 3, 1)); - } - - - public void testNumCardsNoCards() - { - Table t = new Table(); - - assertEquals(0, t.numCards()); - } - - - public void testNumCardsOneCard() - { - Table t = new Table(); - - t.add(new Card(2, 3, 1, 2)); - - assertEquals(1, t.numCards()); - } - - - public void testNumCardsTwoCards() - { - Table t = new Table(); - - t.add(new Card(3, 1, 2, 3)); - t.add(new Card(1, 2, 3, 1)); - - assertEquals(2, t.numCards()); - } - - - public void testGetCardOneCard() - { - Table t = new Table(); - - Card c = new Card(1, 1, 1, 1); - - t.add(c); - - assertEquals(c, t.getCard(0)); - } - - - public void testGetCardTwoCards() - { - Table t = new Table(); - - Card c1 = new Card(1, 1, 1, 1); - Card c2 = new Card(2, 2, 2, 2); - - t.add(c1); - t.add(c2); - - assertEquals(c2, t.getCard(0)); - assertEquals(c1, t.getCard(1)); - } - - - public void testGetCardThreeCards() - { - Table t = new Table(); - - Card c1 = new Card(1, 1, 1, 1); - Card c2 = new Card(2, 2, 2, 2); - Card c3 = new Card(3, 3, 3, 3); - - t.add(c1); - t.add(c2); - t.add(c3); - - assertEquals(c3, t.getCard(0)); - assertEquals(c2, t.getCard(1)); - assertEquals(c1, t.getCard(2)); - } - - - public void testNumSetsEmptyTable() - { - Table t = new Table(); - - assertEquals(0, t.numSets()); - } - - - public void testNumSets3Cards1Set() - { - Table t = makeTable("3cards1setMilestone.dat"); - - assertEquals(1, t.numSets()); - } - - /////here - public void testNumSets3cards0Sets() - { - Table t = makeTable("3cards0setsMilestone.dat"); - - assertEquals(0, t.numSets()); - } - - - public void testNumSets12Cards14Sets() - { - Table t = makeTable("12cards14setsMilestone.dat"); - - assertEquals(14, t.numSets()); - } - - - public void testRemoveSetEmptyTable() - { - Table t = new Table(); - - // Removing a valid set from an empty table shouldn't - // do anything. - t.removeSet(new Card(1, 1, 1, 1), - new Card(2, 2, 2, 2), - new Card(3, 3, 3, 3)); - - assertEquals(0, t.numCards()); - assertEquals(0, t.numSets()); - } - - - public void testSmallTable() - { - Table t = makeTable("3cards0setsMilestone.dat"); - - Card c1 = new Card(1, 1, 1, 1); - Card c2 = new Card(1, 1, 1, 2); - Card c3 = new Card(2, 2, 2, 3); - - assertEquals(3, t.numCards()); - assertEquals(0, t.numSets()); - - // because we're doing head insertion - // the Cards are indexed in the reverse - // order from which they are added - assertEquals(c3, t.getCard(0)); - assertEquals(c2, t.getCard(1)); - assertEquals(c1, t.getCard(2)); - } - - - public void testSmallTableNoSets() - { - Table t = makeTable("3cards0setsMilestone.dat"); - - Card c1 = new Card(1, 1, 1, 1); - Card c2 = new Card(1, 1, 1, 2); - Card c3 = new Card(2, 2, 2, 3); - - // trying to remove the cards as a set - // should do nothing - t.removeSet(c1, c2, c3); - - assertEquals(3, t.numCards()); - assertEquals(0, t.numSets()); - - assertEquals(c3, t.getCard(0)); - assertEquals(c2, t.getCard(1)); - assertEquals(c1, t.getCard(2)); - } - - - public void testSmallTable1Set() - { - Table t = makeTable("3cards1setMilestone.dat"); - - Card c1 = new Card(1, 1, 1, 1); - Card c2 = new Card(2, 2, 2, 2); - Card c3 = new Card(3, 3, 3, 3); - - // This will result in a middle remove, - // a tail remove and a head remove - t.removeSet(c2, c1, c3); - - assertEquals(0, t.numCards()); - assertEquals(0, t.numSets()); - } - - - public void testSetNotOnTable() - { - Table t = makeTable("3cards0setsMilestone.dat"); - - Card c1 = new Card(1, 2, 2, 2); - Card c2 = new Card(2, 2, 1, 3); - Card c3 = new Card(3, 2, 3, 1); - - // These cards form a set, but are not on the table - t.removeSet(c1, c2, c3); - - assertEquals(3, t.numCards()); - } - - - public void testNotAllOnTable() - { - Table t = makeTable("3cards0setsMilestone.dat"); - Card c1 = new Card(1, 1, 1, 1); - Card c2 = new Card(1, 1, 1, 2); - Card c3 = new Card(1, 1, 1, 3); - - // c1 and c2 are on the table, but c3 is not. The cards from a set - t.removeSet(c1, c2, c3); - - assertEquals(3, t.numCards()); - } - - - public void testFourteenInTwelve() - { - Table t = makeTable("12cards14setsMilestone.dat"); - - assertEquals(14, t.numSets()); - assertEquals(12, t.numCards()); - } - - - public void testRemoveMiddleMiddleHead() - { - Table t = makeTable("12cards14setsMilestone.dat"); - // 1 1 1 3 (3rd to last card) - // 1 3 1 1 (second card) - // 1 2 1 2 (first card) - t.removeSet(new Card(1, 1, 1, 3), - new Card(1, 3, 1, 1), - new Card(1, 2, 1, 2)); - - assertEquals(9, t.numCards()); - // that removed 6 of the 14 sets. - assertEquals(8, t.numSets()); - } - - - public void testRemoveTailMiddleMiddle() - { - Table t = makeTable("12cards14setsMilestone.dat"); - - // 1 1 1 1 (last card) - // 1 1 2 1 (middle) - // 1 1 3 1 (middle) - t.removeSet(new Card(1, 1, 1, 1), - new Card(1, 1, 2, 1), - new Card(1, 1, 3, 1)); - - assertEquals(9, t.numCards()); - } - - - public void testNoSetsinTwelve() - { - Table t = makeTable("12cards0setsMilestone.dat"); - - assertEquals(12, t.numCards()); - assertEquals(0, t.numSets()); - - // try to remove first, middle, and last cards - // which do not form a set so should do nothing - t.removeSet(new Card(1, 3, 3, 2), - new Card(1, 3, 1, 3), - new Card(2, 2, 1, 3)); - - assertEquals(12, t.numCards()); - assertEquals(0, t.numSets()); - } - - private Table makeTable(String filename) - { - Deck d = new Deck(filename); - Table t = new Table(); - - while(d.hasNext()) - t.add(d.getNext()); - - return t; - } -} From b708f77c4512b7148960d66b907782e1ce18b6e9 Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Mon, 20 Apr 2015 19:53:27 -0400 Subject: [PATCH 30/47] Delete README.md --- src/README.md | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/README.md diff --git a/src/README.md b/src/README.md deleted file mode 100644 index bd9ba63..0000000 --- a/src/README.md +++ /dev/null @@ -1,4 +0,0 @@ -## CS II Set project - -See the full spec for this project here: -http://groot.cs.moravian.edu/cs121/CSII-SetProject.pdf From 80844e0708103fc4216884dce082c2776a6c13e5 Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Mon, 20 Apr 2015 22:05:28 -0400 Subject: [PATCH 31/47] Initial Game class --- src/Game.java | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/Game.java diff --git a/src/Game.java b/src/Game.java new file mode 100644 index 0000000..9d3a0b6 --- /dev/null +++ b/src/Game.java @@ -0,0 +1,62 @@ +public class Game{ + private Table t; + private Deck d; + + public Game(){ + //begins with randomly generated deck of 12 cards + Deck d = new Deck(); + } + + public Game(String filename){ + //loads specific deck + } + + public int numSets(){ + //returns number of sets on the table + return 0; + } + + public int numCards(){ + //returns number of cards on table which is 12 + //or less if deck has lest than 12 cards + return 0; + } + + public void playRound(){ + //used to advance game from one round to the next + // + //a round deals with removing one set + //and adding additional cards + // + //when no sets on table but still cards in deck: + // this means just add 3 cards + //most of the time: + // cards in deck and 12 on table containing 1+ sets + // in this situation we move from one round + // to the next by removing one set and adding 3 cards + // to the table from the deck + //if a round starts with 12+ cards on table: + // (due to no sets) + // and theres is at least one set, + // then after removing a set we do not add cards + //if there is at least one set but no cards left: + // we move to next round by just removing set + //if no cards in deck or sets on table: + // game over + // + //sometimes when you use custom decks: + // there may be only 1-2 cards remaining + // when you have to add cards to table + // in this case cards are added like normal + // and the table remains short a few cards + // + } + + public boolean isGameOver(){ + //returns true only if there are no sets on table + // and no cards in deck + return true; + } + +//end } +} \ No newline at end of file From ef23afcced56c0c7071fe83b2ef6db7bd8075e77 Mon Sep 17 00:00:00 2001 From: Chris Sheehan Date: Tue, 21 Apr 2015 14:19:50 -0400 Subject: [PATCH 32/47] Game and GameTest Files 4/21 --- src/Game.java | 151 +++++++++++++++++++++++++++++++++++++++++++--- src/GameTest.java | 19 ++++++ 2 files changed, 160 insertions(+), 10 deletions(-) create mode 100644 src/GameTest.java diff --git a/src/Game.java b/src/Game.java index 9d3a0b6..2470784 100644 --- a/src/Game.java +++ b/src/Game.java @@ -5,21 +5,56 @@ public class Game{ public Game(){ //begins with randomly generated deck of 12 cards Deck d = new Deck(); + for (int i = 0; i<12; i++){ + d.getNext(); + } } public Game(String filename){ //loads specific deck + try { + String line; + BufferedReader infile = new BufferedReader(new FileReader(filename)); + int position = 0; + + while((line = infile.readLine()) != null) { + // Blank lines might contain white space, so trim it off + line = line.trim(); + + // ignore blank lines + if(line.length() == 0) + continue; + + // ignore comments + if(line.startsWith("#")) + continue; + + // a valid line contains 4 integers + StringTokenizer tokenizer = new StringTokenizer(line); + + int quantity = Integer.parseInt(tokenizer.nextToken()); + int color = Integer.parseInt(tokenizer.nextToken()); + int shading = Integer.parseInt(tokenizer.nextToken()); + int shape = Integer.parseInt(tokenizer.nextToken()); + + cards.add(new Card(quantity, color, shading, shape)); + nextCardIndex = 0; + } + } + catch(Exception e) { + throw new RuntimeException("Error while reading file: " + e.toString()); + } } public int numSets(){ //returns number of sets on the table - return 0; + return t.numSets(); } public int numCards(){ //returns number of cards on table which is 12 //or less if deck has lest than 12 cards - return 0; + return t.numCards(); } public void playRound(){ @@ -28,35 +63,131 @@ public void playRound(){ //a round deals with removing one set //and adding additional cards // - //when no sets on table but still cards in deck: + //1.)when no sets on table but still cards in deck: // this means just add 3 cards - //most of the time: + //2.)most of the time: // cards in deck and 12 on table containing 1+ sets // in this situation we move from one round // to the next by removing one set and adding 3 cards // to the table from the deck - //if a round starts with 12+ cards on table: + //3.)if a round starts with 12+ cards on table: // (due to no sets) // and theres is at least one set, // then after removing a set we do not add cards - //if there is at least one set but no cards left: + //4.)if there is at least one set but no cards left: // we move to next round by just removing set - //if no cards in deck or sets on table: + //5.)if no cards in deck or sets on table: // game over // - //sometimes when you use custom decks: + //6.)sometimes when you use custom decks: // there may be only 1-2 cards remaining // when you have to add cards to table // in this case cards are added like normal // and the table remains short a few cards - // + + + + //1.) + if (t.numSets() == 0 && d.hasNext() == true){ + for (int i = 0; i < 3; i++){ + t.add(d.getNext()); + } + } + + //2.) + else if (t.numSets() > 0 && d.hasNext() == true){ + //call the number of cards in the begining to make it quicker + int numCards = t.numCards(); + //go through the table looking for the set + for (int i=0; i 12 && t.numSets() > 0){ + //call the number of cards in the begining to make it quicker + int numCards = t.numCards(); + //go through the table looking for the set + for (int i=0; i 0 && d.hasNext() == false){ + //call the number of cards in the begining to make it quicker + int numCards = t.numCards(); + //go through the table looking for the set + for (int i=0; i Date: Tue, 21 Apr 2015 14:53:54 -0400 Subject: [PATCH 33/47] Updated Game && GameTest 4/21 --- src/CardMain.java | 70 +++++------------------------------------------ src/Game.java | 43 +++++++---------------------- src/GameTest.java | 8 +++++- 3 files changed, 24 insertions(+), 97 deletions(-) diff --git a/src/CardMain.java b/src/CardMain.java index 8773f0c..5a0a457 100644 --- a/src/CardMain.java +++ b/src/CardMain.java @@ -1,69 +1,13 @@ -import java.util.ArrayList; - public class CardMain{ public static void main(String[] args){ -// Deck d = new Deck("81cards.txt"); -// for (int i=0; i<81; i++) { -// System.out.print(i + " "); -// System.out.print(d.getSize() + " "); -// System.out.print(d.hasNext() + " "); -// System.out.println(d.getNext()); -// } - - Table t = new Table(); - Card c = new Card(1,1,1,1); - Card c2 = new Card(2,2,2,2); - Card c3 = new Card(3,3,3,3); - t.add(c); - t.add(c2); - t.add(c3); - System.out.println(t.getCard(0)); - - - + Game g = new Game(); + System.out.println(g.numCards()); + System.out.println(g.numSets()); + g.playRound(); + System.out.println(g.numSets()); + } +} -// System.out.println("Hello"); -// Card c = new Card(20,7,0,8); -// Card d = new Card(20,7,0,8); -// Card e = new Card(20,7,0,8); -// -// System.out.println(c.getQuantity()); -// System.out.println(c.getColor()); -// System.out.println(c.getShading()); -// System.out.println(c.getShape()); -// System.out.println(c.toString()); -// String a = "heyy"; -// System.out.println(a + c); -// System.out.println(c.isSet(d, e)); -// System.out.println("yeah!"); -// for (int i = -1; i<=2147483647; i++) { -// int j = i; -// j = (((j % 3)+3)%3)+1; -// if (j < 1 || j > 3) { -// System.out.println(i + " fuck"); -// } -// if(i==500000000){ -// System.out.println("booty thumper"); -// } -// if(i==1000000000){ -// System.out.println("jungle boogie"); -// } -// if(i==2000000000){ -// System.out.println("jungle booger"); -// } -// if(i==2007000000){ -// System.out.println("almost!"); -// } -// if(i==2100000000){ -// System.out.println("ALMOST!"); -// } -// if(i==2147483646){ -// System.out.println("THER WE ARE GOOD SHOW"); -// } -// } -// System.out.println("DONE"); - } -} \ No newline at end of file diff --git a/src/Game.java b/src/Game.java index 2470784..1d2ab74 100644 --- a/src/Game.java +++ b/src/Game.java @@ -1,48 +1,24 @@ public class Game{ - private Table t; + private Table t = new Table(); private Deck d; public Game(){ //begins with randomly generated deck of 12 cards + + //deleted:: Table t = new Table(); Deck d = new Deck(); for (int i = 0; i<12; i++){ - d.getNext(); + t.add(d.getNext()); } } public Game(String filename){ //loads specific deck - try { - String line; - BufferedReader infile = new BufferedReader(new FileReader(filename)); - int position = 0; - - while((line = infile.readLine()) != null) { - // Blank lines might contain white space, so trim it off - line = line.trim(); - - // ignore blank lines - if(line.length() == 0) - continue; - - // ignore comments - if(line.startsWith("#")) - continue; - - // a valid line contains 4 integers - StringTokenizer tokenizer = new StringTokenizer(line); - - int quantity = Integer.parseInt(tokenizer.nextToken()); - int color = Integer.parseInt(tokenizer.nextToken()); - int shading = Integer.parseInt(tokenizer.nextToken()); - int shape = Integer.parseInt(tokenizer.nextToken()); - - cards.add(new Card(quantity, color, shading, shape)); - nextCardIndex = 0; - } - } - catch(Exception e) { - throw new RuntimeException("Error while reading file: " + e.toString()); + + //deleted:: Table t = new Table(); + Deck d = new Deck(filename); + for (int i = 0; i<12; i++){ + d.getNext(); } } @@ -52,6 +28,7 @@ public int numSets(){ } public int numCards(){ + //returns number of cards on table which is 12 //or less if deck has lest than 12 cards return t.numCards(); diff --git a/src/GameTest.java b/src/GameTest.java index 3659c95..a7b8894 100644 --- a/src/GameTest.java +++ b/src/GameTest.java @@ -13,7 +13,13 @@ public class GameTest extends TestCase { * many "testSomething" methods in this class as you wish, and each * one will be called when running JUnit over this class.) */ - public void testX() { + public void testGame() { + Game g = new Game(); + assertEquals(g.numCards(), 12); + System.out.println(g.numSets()); + g.playRound(); + System.out.println(g.numSets()); } + } From acbda2cdea95110985b0683de3ed4c69734a6cfb Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Tue, 21 Apr 2015 21:11:25 -0400 Subject: [PATCH 34/47] Game and GameTest --- src/CardMain.java | 3 ++- src/Game.java | 60 +++++++++++++++++++++++++++++++---------------- src/GameTest.java | 22 ++++++++++++++--- 3 files changed, 61 insertions(+), 24 deletions(-) diff --git a/src/CardMain.java b/src/CardMain.java index 5a0a457..c64622d 100644 --- a/src/CardMain.java +++ b/src/CardMain.java @@ -1,11 +1,12 @@ public class CardMain{ public static void main(String[] args){ - Game g = new Game(); + Game g = new Game("81cards.txt"); System.out.println(g.numCards()); System.out.println(g.numSets()); g.playRound(); System.out.println(g.numSets()); + System.out.println(g.numCards()); } } diff --git a/src/Game.java b/src/Game.java index 1d2ab74..867f9f0 100644 --- a/src/Game.java +++ b/src/Game.java @@ -1,12 +1,13 @@ public class Game{ - private Table t = new Table(); private Deck d; + private Table t; public Game(){ //begins with randomly generated deck of 12 cards - //deleted:: Table t = new Table(); - Deck d = new Deck(); + d = new Deck(); + t = new Table(); + for (int i = 0; i<12; i++){ t.add(d.getNext()); } @@ -15,10 +16,15 @@ public Game(){ public Game(String filename){ //loads specific deck - //deleted:: Table t = new Table(); - Deck d = new Deck(filename); - for (int i = 0; i<12; i++){ - d.getNext(); + d = new Deck(filename); + t = new Table(); + + while (d.hasNext()){ + t.add(d.getNext()); + + if (t.numCards() == 12){ + return; + } } } @@ -62,17 +68,22 @@ public void playRound(){ // in this case cards are added like normal // and the table remains short a few cards - + int sets = t.numSets(); //1.) - if (t.numSets() == 0 && d.hasNext() == true){ + if (sets == 0 && d.hasNext() == true){ for (int i = 0; i < 3; i++){ + if (d.hasNext() == false){ + return; + } t.add(d.getNext()); } + return; } + //2.) - else if (t.numSets() > 0 && d.hasNext() == true){ + if (sets > 0 && d.hasNext() == true){ //call the number of cards in the begining to make it quicker int numCards = t.numCards(); //go through the table looking for the set @@ -86,18 +97,24 @@ else if (t.numSets() > 0 && d.hasNext() == true){ if (card1.isSet(card2,card3)) { t.removeSet(card1, card2, card3); - for (int p = 0; p < 3; p++){ + + for (int p = 0; t.numCards() < 12; p++){ + if (d.hasNext() == false){ + return; + } t.add(d.getNext()); - break; } + return; } } } - } + } + return; } + //3.) - else if (t.numCards() > 12 && t.numSets() > 0){ + if (t.numCards() > 12 && sets > 0){ //call the number of cards in the begining to make it quicker int numCards = t.numCards(); //go through the table looking for the set @@ -111,15 +128,16 @@ else if (t.numCards() > 12 && t.numSets() > 0){ if (card1.isSet(card2,card3)) { t.removeSet(card1, card2, card3); - break; + return; } } } } + return; } //4.) - else if (t.numSets() > 0 && d.hasNext() == false){ + if (sets > 0 && d.hasNext() == false){ //call the number of cards in the begining to make it quicker int numCards = t.numCards(); //go through the table looking for the set @@ -133,19 +151,21 @@ else if (t.numSets() > 0 && d.hasNext() == false){ if (card1.isSet(card2,card3)) { t.removeSet(card1, card2, card3); - break; + return; } } } } + return; } //5.) - else if (d.hasNext() == false && t.numSets() == 0){ - isGameOver(); + if (d.hasNext() == false && sets == 0){ + return; + //isGameOver(); } - //6.) may be a part of one of the previous + //6.) may work as of one of the previous } public boolean isGameOver(){ diff --git a/src/GameTest.java b/src/GameTest.java index a7b8894..2e9c484 100644 --- a/src/GameTest.java +++ b/src/GameTest.java @@ -13,12 +13,28 @@ public class GameTest extends TestCase { * many "testSomething" methods in this class as you wish, and each * one will be called when running JUnit over this class.) */ - public void testGame() { + public void test1RoundGame() { Game g = new Game(); + assertEquals(g.numCards(), 12); - System.out.println(g.numSets()); g.playRound(); - System.out.println(g.numSets()); + assertEquals(g.numCards(), 12); + } + + public void testWith81CardsDeck(){ + Game g = new Game("81cards.txt"); + + assertEquals(g.numCards(), 12); + g.playRound(); + assertEquals(g.numCards(), 12); + } + + public void testWith3CardsDeck(){ + Game g = new Game("3cards.txt"); + + assertEquals(g.numCards(), 3); + g.playRound(); + assertEquals(g.numCards(), 0); } From 2084a02355d599587ad1455eb43ba49d285a2b82 Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Wed, 22 Apr 2015 10:53:07 -0400 Subject: [PATCH 35/47] All files 4/22 --- src/.DS_Store | Bin 6148 -> 6148 bytes src/12cards0setsMilestone.dat | 13 +++ src/12cards14setsMilestone.dat | 12 +++ src/3cards0setsMilestone.dat | 12 +++ src/3cards1setMilestone.dat | 3 + src/Card.class | Bin 2318 -> 2330 bytes src/CardMain.class | Bin 0 -> 712 bytes src/CardMain.java~ | 14 +++ src/CardTest.class | Bin 3185 -> 3185 bytes src/Deck.class | Bin 2573 -> 2573 bytes src/DeckTest.class | Bin 837 -> 837 bytes src/Game.class | Bin 0 -> 2484 bytes src/Game.java~ | 172 +++++++++++++++++++++++++++++++++ src/GameTest.class | Bin 0 -> 1850 bytes src/GameTest.java | 69 ++++++++++++- src/GameTest.java~ | 41 ++++++++ src/Table.class | Bin 2444 -> 2444 bytes src/TableNode.class | Bin 647 -> 647 bytes src/TableNodeTest.class | Bin 0 -> 827 bytes src/TableTest.class | Bin 1874 -> 1874 bytes src/deckMilestone.dat | 12 +++ src/emptyDeckMilestone.dat | 1 + 22 files changed, 348 insertions(+), 1 deletion(-) create mode 100755 src/12cards0setsMilestone.dat create mode 100755 src/12cards14setsMilestone.dat create mode 100644 src/3cards0setsMilestone.dat create mode 100755 src/3cards1setMilestone.dat create mode 100644 src/CardMain.class create mode 100644 src/CardMain.java~ create mode 100644 src/Game.class create mode 100644 src/Game.java~ create mode 100644 src/GameTest.class create mode 100644 src/GameTest.java~ create mode 100644 src/TableNodeTest.class create mode 100755 src/deckMilestone.dat create mode 100755 src/emptyDeckMilestone.dat diff --git a/src/.DS_Store b/src/.DS_Store index 400b58de2610244adec07808117ed36ee67843f6..6e3d30217fe492122c352fa2f022776e4410eed1 100644 GIT binary patch delta 32 ocmZoMXfc@J&nUPtU^g?P;AS3{c&5#B*|HcX));MO=lIJH0Hvi09RL6T delta 65 zcmZoMXfc@J&nUDpU^g?P&}JT%cqU~|h9Cx421f=L245hp$B@gA;+d15oRpKF#K6EH S0K{iD$FNm0Zf58B%MSqgmk)^m diff --git a/src/12cards0setsMilestone.dat b/src/12cards0setsMilestone.dat new file mode 100755 index 0000000..dc7c2c6 --- /dev/null +++ b/src/12cards0setsMilestone.dat @@ -0,0 +1,13 @@ +# 12 cards with 0 sets +1 3 3 2 +3 3 2 2 +1 1 2 1 +1 2 3 3 +3 2 3 3 +1 3 1 3 +3 1 2 2 +2 2 3 2 +1 1 1 1 +3 2 1 1 +2 1 1 3 +2 2 1 3 diff --git a/src/12cards14setsMilestone.dat b/src/12cards14setsMilestone.dat new file mode 100755 index 0000000..1b3ea71 --- /dev/null +++ b/src/12cards14setsMilestone.dat @@ -0,0 +1,12 @@ +1 1 1 1 +1 1 1 2 +1 1 1 3 +1 1 2 1 +1 1 2 2 +1 1 2 3 +1 1 3 1 +1 1 3 2 +1 1 3 3 +1 2 1 1 +1 3 1 1 +1 2 1 2 diff --git a/src/3cards0setsMilestone.dat b/src/3cards0setsMilestone.dat new file mode 100644 index 0000000..b0a41dc --- /dev/null +++ b/src/3cards0setsMilestone.dat @@ -0,0 +1,12 @@ +# Lines starting with a # character are comments, and ignored +# Blank lines are also ignored, even if they contain whitespace + +# All other lines are expected to have 4 integers, separated by spaces +1 1 1 1 +1 1 1 2 +2 2 2 3 + +# A file does not need to contain all 81 cards + + + diff --git a/src/3cards1setMilestone.dat b/src/3cards1setMilestone.dat new file mode 100755 index 0000000..3fdd6d1 --- /dev/null +++ b/src/3cards1setMilestone.dat @@ -0,0 +1,3 @@ +1 1 1 1 +2 2 2 2 +3 3 3 3 diff --git a/src/Card.class b/src/Card.class index d98a2776f4b04c2e259ba49b07d33d8e127a305a..8f20a979003fce6c7fb23f8393b0c9f89f8a87d6 100644 GIT binary patch delta 51 zcmeAZnkB?>>ff$?3=9k=8##(N7^hCI=I{^~V_*e}6amQ+22qAm1_g#P25pA&$>%s6 E0C8LlcmMzZ delta 39 ucmbOw)F;Go>ff$?3=9lL8##(N7&|9db9iubF)#r|iWpcKN+#dpZ~y@D?h2Uz diff --git a/src/CardMain.class b/src/CardMain.class new file mode 100644 index 0000000000000000000000000000000000000000..c6450c2ddbd92f4d037f7699ab6154d4a9b1c69c GIT binary patch literal 712 zcmZuu+iuf95IvhXS=)6fq_o@%EjPC%F$DxjMZ8o3RdS(fP$k6ECb5DmUn<8&^qDV$ zhgJfK58$H^XA-J_R6p#_oSm6-&iL2w?>_-N!DAOQxTbO4#tj!WEIGJ|TM{k1Six$3uXJ9yZYS z@JJf%(`gFlrz+p}4x)aku;8C9{h!kA(Ws14ZY{5*VNxIG!7hE4bQ_tJ4(zN-g^7N- z-fg-bll@<(pbw=h;npmFTXv+`*NsZHIfsck+RLkKfMv+fm9GXR{&}8b7VuWQ8*3*} zU&qgLJey;X{uq0c0$f0gnS*&;BqGgUQ0F+{*$>p-x9TUb!f$A-AES8;J&9~a1e|F$ tt(ej+L34~njSUWOLh=>Z`~eQ05)~PX6Dlk)05cc1_lO`jU23806Mt^hX4Qo delta 17 YcmeAb=@sEP^>5cc1_lPBjU23806MP)g#Z8m diff --git a/src/DeckTest.class b/src/DeckTest.class index 37c8f7aced52b532f76fbd13c6707783678b74ca..f78e677c3b7b517017ea31e5cf720bf217bddce9 100644 GIT binary patch delta 17 ZcmX@gc9f0d)W2Q(7#J8#Hgec90{}pN1`GfI delta 17 ZcmX@gc9f0d)W2Q(7#J9gHgec90{}pD1_}TG diff --git a/src/Game.class b/src/Game.class new file mode 100644 index 0000000000000000000000000000000000000000..171d8c15d2b6fca12571057808b5d557fb45b3af GIT binary patch literal 2484 zcmc&$TWnNS6kX@ey>n-#w-3N6Ep4$>!D&I>vG|TW(2rXD9 z(#s~6n^>WsIu!iTWp=!436+e38QmCbPukS{^@&s>)2QH!RJSSUEj=B!LSZzKve)%@ zx7%sQP+?-UCmu_-#nK6J^cGcuaI5H**^%gz5G!Kc0-E2NiN(9t#(Et)vQP*|qB~=| zV{?+RROg)5OgfS3Tp|Gj+Y?DUMK=lY7Yh?BNjBBr-D+nTfE*buK)ofF?%+bOHyPWv zp{GB^1XZts5$F0mVIl@(;w;Sf<^?qB;%6rr_Yu$p(L#wnVZDC0opu6j;Zkc)e>!e2 zCo_hS-Pyv-!eo@tRqAMA5}qQglc0q#iY=_h8VgaZ6}u`6>#)#51kYKRA;WsS!gv;5 z#Rdzl*hnBjRw#Ou_4@XmcAUpEZpkebjU^%0qSMZ-v-i>_5UI{4>5Fx6D;RNgsj9gn z*5{gugX&)2gkw=89NL0e=tWOau zR7QH!8FB$bH<9F0lFX83V2`Ru&)`|o%8@Q}NSkza)_IXU((^e>ngN$V{zb}~Q!F_H z@QeiCa&0_(CAX0)ayC!+TTl8&{?@-bd$#&1<`!be0xy1j*$@^{<_YHMXHes7DEAMe z%3B$NJ|c#$>Kw7gBfdRS_6aUO^7>qCSk4AtV@0{qF^m%x`nFmzm;UM|%_uz7*cZ?^!X&mVmvHXvuCp<>lrSXkJeDH-upGYfl=PRwWwwvtfSt*KG=vhu5898Y{6E%fiAp> zJ(LdNEgZ!*oJ2d$B92S2@g26~dvxLk61YYEM_S*e{ZI6}L;t(z#jogB8uq9V_NhtO zuPSjs&BEKN76(-`-ceB;Qk(IvvT;~#=U$RFY1;0^5w#CT)q8kf9m5Ce6ppLU@Sz&P zN9r0rR@ZSt-NY&N0|wPE7*cn*cb7K5)Aj*ARS$7ivv5w!#|7ur+~*4`<$IM@q~S7V zqJ~nCd2OXUi(T?4zW|=6WHQHG0nM3&^hjKcHay*A}EQ=!V z-|H;_&5wEH=k~7ssC6>q@BXo471Q(&Y0gIW zkB)@MIyPmOxzC-+|FBa)1`GIal-uQ6IZHPz$=%aJc~_&zAA+G@^hwuqzhVkF17EUN ZUt+JmJg)ndco|kYwyKzbizsTS{S&ek%!L2| literal 0 HcmV?d00001 diff --git a/src/Game.java~ b/src/Game.java~ new file mode 100644 index 0000000..39037bf --- /dev/null +++ b/src/Game.java~ @@ -0,0 +1,172 @@ +public class Game{ + private Table t = new Table(); + private Deck d = new Deck(); + + public Game(){ + //begins with randomly generated deck of 12 cards + + //deleted:: Table t = new Table(); + Deck d = new Deck(); + for (int i = 0; i<12; i++){ + t.add(d.getNext()); + } + } + + public Game(String filename){ + //loads specific deck + + //deleted:: Table t = new Table(); + Deck d = new Deck(filename); + for (int i = 0; i<12; i++){ + d.getNext(); + } + } + + public int numSets(){ + //returns number of sets on the table + return t.numSets(); + } + + public int numCards(){ + + //returns number of cards on table which is 12 + //or less if deck has lest than 12 cards + return t.numCards(); + } + + public void playRound(){ + //used to advance game from one round to the next + // + //a round deals with removing one set + //and adding additional cards + // + //1.)when no sets on table but still cards in deck: + // this means just add 3 cards + //2.)most of the time: + // cards in deck and 12 on table containing 1+ sets + // in this situation we move from one round + // to the next by removing one set and adding 3 cards + // to the table from the deck + //3.)if a round starts with 12+ cards on table: + // (due to no sets) + // and theres is at least one set, + // then after removing a set we do not add cards + //4.)if there is at least one set but no cards left: + // we move to next round by just removing set + //5.)if no cards in deck or sets on table: + // game over + // + //6.)sometimes when you use custom decks: + // there may be only 1-2 cards remaining + // when you have to add cards to table + // in this case cards are added like normal + // and the table remains short a few cards + + int sets = t.numSets(); + + //1.) + if (sets == 0 && d.hasNext() == true){ + for (int i = 0; i < 3; i++){ + t.add(d.getNext()); + } + return; + } + + + //2.) + if (sets > 0 && d.hasNext() == true){ + //call the number of cards in the begining to make it quicker + int numCards = t.numCards(); + //go through the table looking for the set + for (int i=0; i 12 && sets > 0){ + //call the number of cards in the begining to make it quicker + int numCards = t.numCards(); + //go through the table looking for the set + for (int i=0; i 0 && d.hasNext() == false){ + //call the number of cards in the begining to make it quicker + int numCards = t.numCards(); + //go through the table looking for the set + for (int i=0; ik3H6#j0Syu5_8O;cJL#FmOm($c0$TL=`2SlUuei;_}?f;g|qYYF5BUtU0l z8OMbiXI#m`wQD!9v4}HnoN?idYd5alx^>|=e&@dYw3W%sz2~0uo%4O?o}2gUzb}6R zFoUHq4kH=FSQtJeWf>2nAE(5cFfl26N|q^E(h|#fIGSguyE${Utbl5^APckhJrS$_9`-=bfnXRU&@?L|}Ol>>t_)*QdpOT?0San{FS#4DG zmFrQjC`7D!-FDo?Pa0O47aT~etjG%pJt$j`_4pJ95;?iYRN1QTr1Gv)s_x7QCdgWO zUIg!`R2TNE4{b-+-IPL`o5>A~^64Gsn*{=3B@A*s!c&U767Se9)N>j>3~@EI(?pzh z!~@_cUgJsOSUb5uw2!`#AK|;Xi>}=G_wYv}FA$(%v=5!KgJcK#U{XyV^$hSg%yL3A z=#^^Hm{j*VW1?=PP52qQG%6#6vEVMueUzbS_d#xo2zR}}p^k=O1j!ahnCcM*)cg9b&Kf6C{2MF}%$}CrO*wLpahV z9B31cwg`PckdV^VQ{8;`0m6`wwXVG>BJ5}98r?(m>M2e~BHTla$Zm*FGP!rqy+p4~ zv}Q>|7w2y5b$0Mk;?Mcx{#J%qp=b}wie-3#Q1htAvELPnn)|V$QXp-t*1ON+Rc!&a zKpmHsb#)2p-upydARcITDuxHAVeE5vI*Lh-5jU8lDQI{SXn1b9G>Pk+&X9lM8v@2T zIn+!a}?E=u+`Vt(U0ZenN_#& o2D|cMTTS2utuE^P2XE5ylj#m0_%H&jJ;uI=^~dBSZ^ehie~KbfT>t<8 literal 0 HcmV?d00001 diff --git a/src/GameTest.java b/src/GameTest.java index 2e9c484..02f1b47 100644 --- a/src/GameTest.java +++ b/src/GameTest.java @@ -25,17 +25,84 @@ public void testWith81CardsDeck(){ Game g = new Game("81cards.txt"); assertEquals(g.numCards(), 12); + assertEquals(g.numSets(), 13); g.playRound(); assertEquals(g.numCards(), 12); + assertEquals(g.isGameOver(), false); } - public void testWith3CardsDeck(){ + public void test3cards1set(){ Game g = new Game("3cards.txt"); assertEquals(g.numCards(), 3); g.playRound(); assertEquals(g.numCards(), 0); } + + public void testSommerDecks(){ + Game g = new Game("3cards0setsMilestone.dat"); + + assertEquals(g.numCards(), 3); + assertEquals(g.numSets(), 0); + g.playRound(); + assertEquals(g.numCards(), 3); + assertEquals(g.isGameOver(), true); + + Game g1 = new Game("3cards1setMilestone.dat"); + + assertEquals(g1.numCards(), 3); + assertEquals(g1.numSets(), 1); + g1.playRound(); + assertEquals(g1.numCards(), 0); + assertEquals(g1.isGameOver(), true); + + Game g2 = new Game("12cards0setsMilestone.dat"); + + assertEquals(g2.numCards(), 12); + assertEquals(g2.numSets(), 0); + g2.playRound(); + assertEquals(g2.numCards(), 12); + assertEquals(g2.isGameOver(), true); + + Game g3 = new Game("12cards14setsMilestone.dat"); + + assertEquals(g3.numCards(), 12); + assertEquals(g3.numSets(), 14); + g3.playRound(); + assertEquals(g3.numCards(), 9); + assertEquals(g3.isGameOver(), false); + assertEquals(g3.numCards(), 9); + assertEquals(g3.numSets(), 8); + g3.playRound(); + assertEquals(g3.numCards(), 6); + assertEquals(g3.isGameOver(), false); + assertEquals(g3.numSets(), 1); + assertEquals(g3.isGameOver(), false); + g3.playRound(); + assertEquals(g3.numCards(), 3); + assertEquals(g3.numSets(), 0); + assertEquals(g3.isGameOver(), true); + assertEquals(g3.numCards(), 3); + + Game g4 = new Game("emptyDeckMilestone.dat"); + + assertEquals(g4.numCards(), 0); + assertEquals(g4.numSets(), 0); + g4.playRound(); + assertEquals(g4.numCards(), 0); + assertEquals(g4.isGameOver(), true); + + Game g5 = new Game("deckMilestone.dat"); + + assertEquals(g5.numCards(), 3); + assertEquals(g5.numSets(), 1); + g5.playRound(); + assertEquals(g5.numCards(), 0); + assertEquals(g5.isGameOver(), true); + + } + + } diff --git a/src/GameTest.java~ b/src/GameTest.java~ new file mode 100644 index 0000000..2e9c484 --- /dev/null +++ b/src/GameTest.java~ @@ -0,0 +1,41 @@ +import junit.framework.TestCase; + +/** + * A JUnit test case class. + * Every method starting with the word "test" will be called when running + * the test with JUnit. + */ +public class GameTest extends TestCase { + + /** + * A test method. + * (Replace "X" with a name describing the test. You may write as + * many "testSomething" methods in this class as you wish, and each + * one will be called when running JUnit over this class.) + */ + public void test1RoundGame() { + Game g = new Game(); + + assertEquals(g.numCards(), 12); + g.playRound(); + assertEquals(g.numCards(), 12); + } + + public void testWith81CardsDeck(){ + Game g = new Game("81cards.txt"); + + assertEquals(g.numCards(), 12); + g.playRound(); + assertEquals(g.numCards(), 12); + } + + public void testWith3CardsDeck(){ + Game g = new Game("3cards.txt"); + + assertEquals(g.numCards(), 3); + g.playRound(); + assertEquals(g.numCards(), 0); + } + + +} diff --git a/src/Table.class b/src/Table.class index 23de909f170e18a0ef0590499e13149c04be3b41..c0244988c750f1ae1b41154ca7f071acebfc05cb 100644 GIT binary patch delta 17 YcmeAX?h)oV^>5cc1_lO`jT|kU06TaF0RR91 delta 17 YcmeAX?h)oV^>5cc1_lPBjT|kU06T64{{R30 diff --git a/src/TableNode.class b/src/TableNode.class index b0193d1b40725c86f4982259aca2daf75693ad70..d0929be897e2e14eca64b59903f90cc23f5819e2 100644 GIT binary patch delta 17 YcmZo?ZD-{;^>5cc1_lO`jU4q%068NC&j0`b delta 17 YcmZo?ZD-{;^>5cc1_lPBjU4q%067^2%>V!Z diff --git a/src/TableNodeTest.class b/src/TableNodeTest.class new file mode 100644 index 0000000000000000000000000000000000000000..cd9402157cf4daa29869e19243d6fd909be5bca5 GIT binary patch literal 827 zcmZWnO>@#v6g>|T0%>S1egS@gUky+iZP7*B=|V-yI&gfiLkH zsYUPoP_pB=&C-q+Mtcg`i06`2Pq+m8H+2@=HYk} z^t~5;>|&`YjkX5vC)dI%*2Fl)1#c>3mRUm7sTva&w%}NJgvS=Pv14&=PiS?SERqWO z!Gr^G-UaTd_jw$AaD;BUA!lINuefAP8GG>Tl_G3*T8(TVf6H}Lw=-v3N28JeVr!9r%ecZw;p(#Z7xPl&I&&nt8rKZTmSCNW_{|(zw>E>` z7O+XMtId(>&S327^(oTo8#48RHiaosL6dNbl^V|rFIAZAu}&X3 diff --git a/src/deckMilestone.dat b/src/deckMilestone.dat new file mode 100755 index 0000000..a7f4bbf --- /dev/null +++ b/src/deckMilestone.dat @@ -0,0 +1,12 @@ +# Lines starting with a # character are comments, and ignored +# Blank lines are also ignored, even if they contain whitespace + +# All other lines are expected to have 4 integers, separated by spaces +1 1 1 1 +1 1 1 2 +1 1 1 3 + +# A file does not need to contain all 81 cards + + + diff --git a/src/emptyDeckMilestone.dat b/src/emptyDeckMilestone.dat new file mode 100755 index 0000000..fa71407 --- /dev/null +++ b/src/emptyDeckMilestone.dat @@ -0,0 +1 @@ +# Nothing here! \ No newline at end of file From 2353009674e8ee4d1fa2742cb7bc8e7120a7b78a Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Fri, 24 Apr 2015 17:46:28 -0400 Subject: [PATCH 36/47] Monte Carlo & Updated Classes 4/24 --- src/Card.java | 8 +++---- src/Deck.java | 4 ---- src/Game.java | 11 +-------- src/MonteCarlo.java | 55 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 18 deletions(-) mode change 100755 => 100644 src/Card.java create mode 100644 src/MonteCarlo.java diff --git a/src/Card.java b/src/Card.java old mode 100755 new mode 100644 index f0e00cc..c2ac76c --- a/src/Card.java +++ b/src/Card.java @@ -76,7 +76,7 @@ public String toString() { else if (quantity == 2) { quan = ("2"); } - else {// (quantity == 3) { + else { // (quantity == 3) quan = ("3"); } if (color == 1) { @@ -85,7 +85,7 @@ else if (quantity == 2) { else if (color == 2) { col = ("G"); //green } - else{ //(color == 3) { + else{ //(color == 3) col = ("P"); //purple } if (shading == 1) { @@ -94,7 +94,7 @@ else if (color == 2) { else if (shading == 2) { shad = ("T"); //striped/shaded } - else{// (shading == 3) { + else{ // (shading == 3) shad = ("S"); //solid/filled } if (shape == 1) { @@ -103,7 +103,7 @@ else if (shading == 2) { else if (shape == 2) { shap = ("D"); //diamond } - else{// (shading == 3) { + else{ // (shading == 3) shap = ("S"); //squiggle } String sequence = quan + col + shad + shap; diff --git a/src/Deck.java b/src/Deck.java index 4cf9ec0..1fb35be 100644 --- a/src/Deck.java +++ b/src/Deck.java @@ -6,7 +6,6 @@ public class Deck { - // Implement the rest of this class yourself private int nextCardIndex = 0; private ArrayList cards = new ArrayList(81); @@ -21,7 +20,6 @@ public Deck(){ } } } - Collections.shuffle(cards); } @@ -52,8 +50,6 @@ public Card getNext() { } public Deck(String filename) { - //file is named 3cards.txt - //cards = new ArrayList(81); try { String line; diff --git a/src/Game.java b/src/Game.java index 867f9f0..591d2fa 100644 --- a/src/Game.java +++ b/src/Game.java @@ -162,10 +162,8 @@ public void playRound(){ //5.) if (d.hasNext() == false && sets == 0){ return; - //isGameOver(); } - - //6.) may work as of one of the previous + } public boolean isGameOver(){ @@ -180,11 +178,4 @@ public boolean isGameOver(){ } } - - - -//end } - //notes: - //abstraction --- rely on methods of other classes - //// getCard from table and then isSet from card } \ No newline at end of file diff --git a/src/MonteCarlo.java b/src/MonteCarlo.java new file mode 100644 index 0000000..374dd62 --- /dev/null +++ b/src/MonteCarlo.java @@ -0,0 +1,55 @@ +public class MonteCarlo{ + public static void main(String[] args){ + + // used to answer our two questions + + //will run a large number of independent experiments + //then take average of experiments + //this number is an estimate of the quantity measured + //the more experiements run the better the estimate + + //first question: + //What is the average number of sets in a random collection of 12 cards from the deck? + //count how many sets in a group of 12 random cards from a deck + //each experiment should use a different deck + //to keep experiment independent + + //second question: + //What is the average number of cards left at the end of the game? + //one experiment is one game played with a random deck + //when gameover you count the number of cards on table + + //use a main class + + + //1st Question: + double avgNumberOfSets = 0; + int i = 0; + while(i<=1000000){ + Game g = new Game(); + avgNumberOfSets += g.numSets(); + i++; + } + System.out.println("The average Number of Sets in " + (i-1) + " sets of random cards is " + avgNumberOfSets/(i-1)); + + + //2nd question: + double avgNumberOfCards = 0; + int j = 0; + while(j<=1000000){ /// this takes about 9 minutes.. + Game g2 = new Game(); + while(g2.isGameOver() == false) { + g2.playRound(); + } + avgNumberOfCards += g2.numCards(); + j++; + } + System.out.println("The average Number of Cards left on the table at the end of a game after " + (j-1) + " games is " + avgNumberOfCards/(j-1)); + + + + + + //end of class + } +} \ No newline at end of file From 3878121fac383927a9b031d5d1a5ca197d86d926 Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Fri, 24 Apr 2015 19:34:23 -0400 Subject: [PATCH 37/47] All files --- src/Card.java~ | 122 ++++++++++++++++++++++++ src/CardTest.class | Bin 3185 -> 3508 bytes src/CardTest.java | 14 +++ src/CardTest.java~ | 179 +++++++++++++++++++++++++++++++++++ src/Deck.class | Bin 2573 -> 2573 bytes src/Deck.java~ | 93 ++++++++++++++++++ src/DeckTest.class | Bin 837 -> 965 bytes src/DeckTest.java | 5 + src/DeckTest.java~ | 43 +++++++++ src/EmptyDeck.text | 0 src/Game.class | Bin 2484 -> 2484 bytes src/Game.java~ | 44 ++++++--- src/MonteCarlo.class | Bin 0 -> 1436 bytes src/MonteCarlo.java~ | 2 + src/TableTestMilestone.class | 1 + 15 files changed, 490 insertions(+), 13 deletions(-) create mode 100755 src/Card.java~ mode change 100755 => 100644 src/CardTest.java create mode 100755 src/CardTest.java~ create mode 100644 src/Deck.java~ create mode 100644 src/DeckTest.java~ create mode 100644 src/EmptyDeck.text create mode 100644 src/MonteCarlo.class create mode 100644 src/MonteCarlo.java~ create mode 100644 src/TableTestMilestone.class diff --git a/src/Card.java~ b/src/Card.java~ new file mode 100755 index 0000000..f0e00cc --- /dev/null +++ b/src/Card.java~ @@ -0,0 +1,122 @@ +public class Card{ + + private int quantity; + private int color; + private int shading; + private int shape; + + private String quan; + private String col; + private String shad; + private String shap; + + public Card(int cardQuantity, int cardColor, int cardShading, int cardShape) { + if (cardQuantity < 1 || cardQuantity > 3) { + quantity = (((cardQuantity % 3) + 3) % 3) + 1; + } + else { + quantity = cardQuantity; + } + if (cardColor < 1 || cardColor > 3) { + color = (((cardColor % 3) + 3) % 3) + 1; + } + else { + color = cardColor; + } + if (cardShading < 1 || cardShading > 3) { + shading = (((cardShading % 3) + 3) % 3) + 1; + } + else { + shading = cardShading; + } + if (cardShape < 1 || cardShape > 3) { + shape = (((cardShape % 3) + 3) % 3) + 1; + } + else { + shape = cardShape; + } + } + + public int getQuantity() { + return quantity; + } + + public int getColor() { + return color; + } + + public int getShading() { + return shading; + } + + public int getShape() { + return shape; + } + + public boolean isSet(Card two, Card three) { + + int totalQuantity = getQuantity() + two.getQuantity() + three.getQuantity(); + int totalColor = getColor() + two.getColor() + three.getColor(); + int totalShading = getShading() + two.getShading() + three.getShading(); + int totalShape = getShape() + two.getShape() + three.getShape(); + + if (totalQuantity % 3 == 0 && totalColor % 3 == 0 && totalShading % 3 == 0 && totalShape % 3 == 0) { + return true; + } + else { + return false; + } + } + + public String toString() { + + if (quantity == 1) { + quan = ("1"); + } + else if (quantity == 2) { + quan = ("2"); + } + else {// (quantity == 3) { + quan = ("3"); + } + if (color == 1) { + col = ("R"); //red + } + else if (color == 2) { + col = ("G"); //green + } + else{ //(color == 3) { + col = ("P"); //purple + } + if (shading == 1) { + shad = ("O"); //empty + } + else if (shading == 2) { + shad = ("T"); //striped/shaded + } + else{// (shading == 3) { + shad = ("S"); //solid/filled + } + if (shape == 1) { + shap = ("O"); //oval + } + else if (shape == 2) { + shap = ("D"); //diamond + } + else{// (shading == 3) { + shap = ("S"); //squiggle + } + String sequence = quan + col + shad + shap; + return sequence; + } + + public boolean equals(Object obj) { + Card that = (Card)obj; + + return quantity == that.getQuantity() && + color == that.getColor() && + shading == that.getShading() && + shape == that.getShape(); + } + +} diff --git a/src/CardTest.class b/src/CardTest.class index 2bb71935ccef2bed8cefcd3800c46cf4b94e6c9e..0f339980e43cb52303072a0a9a080852d83c1421 100644 GIT binary patch delta 1092 zcmbW0yHgWU6vn@Oge;qN5NCAI2oa4ENHFs7fq?RUXhL`-AoyI!`aniUvcxhL{s(Ji zVdIR2HZp^NfH;=g+1Xmy**IhA7|+?G#GqfL7ep zQH?e)&gziS&eEadAUZiZ$8w&fi=|sb55Mcx(5IoFQv6{>6+PbB#LRf?MjlYO+bj84$+uHic8Z#dtih6)2F zW(~}Ns20*rh5UV5LYd`$UBcc_Y~IY8(FOC~t!QF)-kP)9>t`hBW+r1T+R4Qwi@2eg z`bi1CLT-TCwoprls-{x|<&db~0O=v8QrTBmOSv-I@r@iNHQd;PBM8z?!ckE>qHIdF zj;>C%aa99U(wCyjz%v{}9aVSZ4nh>k$kOEMDN-ogAQ(^8kHkoON*U{du?H^@b{TQp zMZ{%1CPt%R92bnA9`56HSt+BmkEqMwK2Ep{?xRUCngyfF%Zy*%e=+`dmX_ju^gExm zEOCa)cfx5EoG<0v%M*PkjFW;9^lcI2t8XgzcQ&uYz3wW`rl&ZYhb6N)RbbFGKadZ2 zs;N!L(<(h{P+}!&SxFQbn%~3$In7Q+O>%6L!6(li5zY HA3E~~Q7xlm delta 791 zcmbV}xi3Uf6vn^zW_j0m6e`Tv$M)=F-v(nD`!F-sPNFc8h=|akP)m3XjYguNl1xGn zJ%52eLZed|=e)V(H58ife)rsSfBEh`N$-2^{>$h66Mz;hdytP-4Q(E%XlLp0AP=4F zx>&kddRTe|f_&B|&@V8+r4a829s8+N$^rGFNMOiuKwN=gff0eQz^K5OhH(uO3fw)3 zjl_0P!ST_Dd8QQ1df`*x99-F2)#1gYjwwv*h+sy?EW0R6j3tga>THTeB78niJ`j!% z(b7B*ys3hSu07>C3#B%?+$*4z)o@N0I4Jx8s@;2d=pgLBkNMuTJ| zHD+vz-xzc(#G{q!hqwE^3zq2?f#mU)O?R`$aav{YlP-PU$U{VnRFH;Sn;e> zVDEcTdF@kA33-*4seZMkktHbmC^<~>e^*WSO{}|<5@~EQlqpc5NR29WQG+j=MEgMq&0%b8@=eoO|y?5`u%`86#W^Cx#`NTm0Ct+N~_#lIu3Lcu0`_fJ1HWy}zk2QX!EGJVy zrL?;KC2dfMh}vl@BaW4XY?FjY-=CUpnr7c5d7>2frbL=DIjR)-l~kiaotEgvv{}#* cNtX>hw)}Bmz>y(mrd))$$~zBcYNY?a09BbDkN^Mx diff --git a/src/Deck.java~ b/src/Deck.java~ new file mode 100644 index 0000000..4cf9ec0 --- /dev/null +++ b/src/Deck.java~ @@ -0,0 +1,93 @@ +import java.util.Collections; +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.StringTokenizer; +import java.util.ArrayList; + + +public class Deck { + // Implement the rest of this class yourself + private int nextCardIndex = 0; + private ArrayList cards = new ArrayList(81); + + public Deck(){ + for (int i=1; i<=3; i++) { + for (int j=1; j<=3; j++) { + for (int k=1; k<=3; k++) { + for (int m=1; m<=3; m++) { + Card card = new Card(i, j, k, m); + cards.add(card); + } + } + } + } + + Collections.shuffle(cards); + } + + public int getSize(){ + return cards.size(); + } + + public boolean hasNext() { + if (nextCardIndex < cards.size()) { + return true; + } + else { + return false; + } + } + + public Card getNext() { + //returns card + + if (hasNext() == true) { + nextCardIndex +=1; + return cards.get(nextCardIndex-1); + } + + else{ + return null; + } + } + + public Deck(String filename) { + //file is named 3cards.txt + //cards = new ArrayList(81); + + try { + String line; + BufferedReader infile = new BufferedReader(new FileReader(filename)); + int position = 0; + + while((line = infile.readLine()) != null) { + // Blank lines might contain white space, so trim it off + line = line.trim(); + + // ignore blank lines + if(line.length() == 0) + continue; + + // ignore comments + if(line.startsWith("#")) + continue; + + // a valid line contains 4 integers + StringTokenizer tokenizer = new StringTokenizer(line); + + int quantity = Integer.parseInt(tokenizer.nextToken()); + int color = Integer.parseInt(tokenizer.nextToken()); + int shading = Integer.parseInt(tokenizer.nextToken()); + int shape = Integer.parseInt(tokenizer.nextToken()); + + cards.add(new Card(quantity, color, shading, shape)); + nextCardIndex = 0; + } + } + catch(Exception e) { + throw new RuntimeException("Error while reading file: " + e.toString()); + } + } + + +} diff --git a/src/DeckTest.class b/src/DeckTest.class index f78e677c3b7b517017ea31e5cf720bf217bddce9..e5498fc7781c92acb69ad64ccf3202cc5c81776d 100644 GIT binary patch literal 965 zcmaKp+fEZv6o&uZ<1n297NG?TwBvN6|Mh@$m2IK`zvb*@w0Mwf=AI`SSDQX8_l5RYwF%VJvG%>F^<~mW&P^ zD;ieSWlh6+7#m@j0-+mr$98WC_|5ErKwzg^w*;ojcE{T5w+}66Umms?iIuxG**cJp zt?t8Mz&)~i0($w5Rcr2BJ+~wfb-C}hPuv$OC?M)I@dQj7DtWur+L2D3g~H}{k2Mun z)|&U_iPx9t?5UK+p-!)K`%cZeYb%oI$Sij(pGgA-qU0W!MaRZD_taIntbt8z8Murq z0+H+6HRU`==8&gPaU2oQMy&-B$9=v_{)r>o*7L5@%&YNsWRC!|W?4DsTe8#0S6s*L zG)n62!bh^VXPvsk-cV}sw{fV!>YOeW^(%B8_X$_08O}S zk6!x3+h1S3<9TzxH%A7VXQv}h^8^+!k7b_MaEX5{i2@cqpcJhP=Hk?-iHc*i>=139 zQ3JjoFv3_6->DPqF@k+Hge`cm6GPb0Us=EXmo>$QO4B_OJ literal 837 zcmaKq-)<5?6vn^V1$Nyow#ELzmbQScE>uejUYMXJ1~oCkCWfX)?xwKPEnCptMf(6g zhbG>5?Ts~>_y9hNzJZBYuwr7>f`&D< z*L3u?J7YwW$*bqov_Xb{cQ$Tl0djg5ZuczJJR2i zfv3L5!9;Z6g#uRdw%h6Nx?xloup`=AzTc2RmwUqFyvNyPtyo7*x)sSz|Gs<@=OHI^ zsAIM9A*(eU1s(UUrz)pUlW!f$XVS(LY;vlgz|^(vj;ga29Y<>CqK!*%Y?M&8v5Cvf zTbl?3%+pi?*~1b0t~?Ipk^6iY^eYO#Aww3NcbckF#g~I#r46DtPqdE$_dW%m3=pZ$0u4#T%Xa#Mud;;;7 zj)t>bQ*qG5G<_wd05h1S5R^Zsx&jENs3*GVvZMTI1mh zO}zQ}C3aO@XIz!i<5ESK^k+$z;W&pS%wdh*1{P4pBC5#77 12 && sets > 0){ //call the number of cards in the begining to make it quicker @@ -118,6 +133,7 @@ public class Game{ } } } + return; } //4.) @@ -140,14 +156,16 @@ public class Game{ } } } + return; } //5.) if (d.hasNext() == false && sets == 0){ - isGameOver(); + return; + //isGameOver(); } - //6.) may be a part of one of the previous + //6.) may work as of one of the previous } public boolean isGameOver(){ diff --git a/src/MonteCarlo.class b/src/MonteCarlo.class new file mode 100644 index 0000000000000000000000000000000000000000..69a433cb17478e305593cecdd8d5143025ed097e GIT binary patch literal 1436 zcmaJ>+in|G6kR7XopIc09PGMrnoAG2#3@Y-r3BKHP?EGwsFO5xh`2~dC-#Xu!JaYW zaik(7BvdK?z$*`ZK!D)Em8irA@W?;#1-v0jS!Z07K%-jnKIiP~+G}t7*S~-M1;8b2 zr*Q@)3z@~ME?!N;Ldl5N`f(AjySS8wi&6@2m~+;MH&b}aoO4E8PGcTdOu*YlEEw@l z3RhEj*TtfXB?0G(ANcWtfK{B@7O$w0k6Ck2C-gJQ6rpZj;8VhfiuOA%X?~Hl^QCjmnw1O2laVVL)2Ned_y%go%`w+ z8KI&&^W=^RAQrV>??Ktvt>~D3Vwqo`-&KLZBUS>a8S|dNsYpRTD^f|S$=q$^=3 zs_N^$X(w}tc*cPAFoXhu7*rmXam~eb4>zzPF!cW>7CU~UrXzvztvgz(eI2Q~mOY3v z+?58T^aJT(74I2wQ(#!Ojh5C(1+}m#s|Ks|+lg1%!y49IYdFY^K>M2=gPg3p1I+A1|c_x+lIAnoL9`?Dhv!|=E zfE#q0J<7QqhU`O^%H4LXn_Qc)L&tn?(tcRF#WBYmwpL9}*HNt&aR^KokJ*K%R8N>? z;AnAm>Y3){XPHxR*xNUO)5WJ9nLn3w@?X5{w`I^bxV-t}@N#$4e%q|b28W*fWIht; zZ#C52+hNDFnId7ySnxdZ{N#&u{@>U>aXy249iK?=hRuwZcET97&Umwdp;cWN{5mco8r0 z?8A4=IYAO_e9NpwqFGP!PEfOnPnf+(YG0x65S&M_Eiv{8GnV)Z85b8ae`1iq(@CnC Fe*m;CMOpv= literal 0 HcmV?d00001 diff --git a/src/MonteCarlo.java~ b/src/MonteCarlo.java~ new file mode 100644 index 0000000..99432ff --- /dev/null +++ b/src/MonteCarlo.java~ @@ -0,0 +1,2 @@ +public class MonteCarlo{ +} \ No newline at end of file diff --git a/src/TableTestMilestone.class b/src/TableTestMilestone.class new file mode 100644 index 0000000..7d1df88 --- /dev/null +++ b/src/TableTestMilestone.class @@ -0,0 +1 @@ +# emptydeckk \ No newline at end of file From d5cfa7db6a9ddd53de6147a15127d77921d20d6a Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Fri, 24 Apr 2015 19:36:35 -0400 Subject: [PATCH 38/47] Delete Card.java~ --- src/Card.java~ | 122 ------------------------------------------------- 1 file changed, 122 deletions(-) delete mode 100755 src/Card.java~ diff --git a/src/Card.java~ b/src/Card.java~ deleted file mode 100755 index f0e00cc..0000000 --- a/src/Card.java~ +++ /dev/null @@ -1,122 +0,0 @@ -public class Card{ - - private int quantity; - private int color; - private int shading; - private int shape; - - private String quan; - private String col; - private String shad; - private String shap; - - public Card(int cardQuantity, int cardColor, int cardShading, int cardShape) { - if (cardQuantity < 1 || cardQuantity > 3) { - quantity = (((cardQuantity % 3) + 3) % 3) + 1; - } - else { - quantity = cardQuantity; - } - if (cardColor < 1 || cardColor > 3) { - color = (((cardColor % 3) + 3) % 3) + 1; - } - else { - color = cardColor; - } - if (cardShading < 1 || cardShading > 3) { - shading = (((cardShading % 3) + 3) % 3) + 1; - } - else { - shading = cardShading; - } - if (cardShape < 1 || cardShape > 3) { - shape = (((cardShape % 3) + 3) % 3) + 1; - } - else { - shape = cardShape; - } - } - - public int getQuantity() { - return quantity; - } - - public int getColor() { - return color; - } - - public int getShading() { - return shading; - } - - public int getShape() { - return shape; - } - - public boolean isSet(Card two, Card three) { - - int totalQuantity = getQuantity() + two.getQuantity() + three.getQuantity(); - int totalColor = getColor() + two.getColor() + three.getColor(); - int totalShading = getShading() + two.getShading() + three.getShading(); - int totalShape = getShape() + two.getShape() + three.getShape(); - - if (totalQuantity % 3 == 0 && totalColor % 3 == 0 && totalShading % 3 == 0 && totalShape % 3 == 0) { - return true; - } - else { - return false; - } - } - - public String toString() { - - if (quantity == 1) { - quan = ("1"); - } - else if (quantity == 2) { - quan = ("2"); - } - else {// (quantity == 3) { - quan = ("3"); - } - if (color == 1) { - col = ("R"); //red - } - else if (color == 2) { - col = ("G"); //green - } - else{ //(color == 3) { - col = ("P"); //purple - } - if (shading == 1) { - shad = ("O"); //empty - } - else if (shading == 2) { - shad = ("T"); //striped/shaded - } - else{// (shading == 3) { - shad = ("S"); //solid/filled - } - if (shape == 1) { - shap = ("O"); //oval - } - else if (shape == 2) { - shap = ("D"); //diamond - } - else{// (shading == 3) { - shap = ("S"); //squiggle - } - String sequence = quan + col + shad + shap; - return sequence; - } - - public boolean equals(Object obj) { - Card that = (Card)obj; - - return quantity == that.getQuantity() && - color == that.getColor() && - shading == that.getShading() && - shape == that.getShape(); - } - -} From 2c80a5133858a5a0630475e4bc632a6b9de7ddb0 Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Fri, 24 Apr 2015 19:37:01 -0400 Subject: [PATCH 39/47] Delete CardMain.java~ --- src/CardMain.java~ | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/CardMain.java~ diff --git a/src/CardMain.java~ b/src/CardMain.java~ deleted file mode 100644 index 81eb13b..0000000 --- a/src/CardMain.java~ +++ /dev/null @@ -1,14 +0,0 @@ -public class CardMain{ - public static void main(String[] args){ - - Game g = new Game(); - System.out.println(g.numCards()); - System.out.println(g.numSets()); - g.playRound(); - System.out.println(g.numSets()); - System.out.println(g.numCards()); - } -} - - - From 5fc1719ee51d074945a900e268992378e61fd17d Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Fri, 24 Apr 2015 19:37:09 -0400 Subject: [PATCH 40/47] Delete CardTest.java~ --- src/CardTest.java~ | 179 --------------------------------------------- 1 file changed, 179 deletions(-) delete mode 100755 src/CardTest.java~ diff --git a/src/CardTest.java~ b/src/CardTest.java~ deleted file mode 100755 index bcca89c..0000000 --- a/src/CardTest.java~ +++ /dev/null @@ -1,179 +0,0 @@ -import junit.framework.TestCase; - -/** - * A JUnit test case class. - * Every method starting with the word "test" will be called when running - * the test with JUnit. - */ -public class CardTest extends TestCase { - - /** - * A test method. - * (Replace "X" with a name describing the test. You may write as - * many "testSomething" methods in this class as you wish, and each - * one will be called when running JUnit over this class.) - */ - public void test123() - { - //testing when everything is different - Card card1 = new Card(1, 1, 1, 1); - assertEquals(card1.getQuantity(), 1); - assertEquals(card1.getColor(), 1); - assertEquals(card1.getShading(), 1); - assertEquals(card1.getShape(), 1); - assertEquals(card1.toString(), "1ROO"); - Card card2 = new Card(2, 2, 2, 2); - assertEquals(card2.getQuantity(), 2); - assertEquals(card2.getColor(), 2); - assertEquals(card2.getShading(), 2); - assertEquals(card2.getShape(), 2); - assertEquals(card2.toString(), "2GTD"); - Card card3 = new Card(3, 3, 3, 3); - assertEquals(card3.getQuantity(), 3); - assertEquals(card3.getColor(), 3); - assertEquals(card3.getShading(), 3); - assertEquals(card3.getShape(), 3); - assertEquals(card3.toString(), "3PSS"); - assertEquals(card1.isSet(card2, card3), true); - } - public void testStupidNumbers() - { - //testing when all shading is different - Card negCard = new Card(-3, -33, -333, -3333); - assertEquals(negCard.getQuantity(), 1); - assertEquals(negCard.getColor(), 1); - assertEquals(negCard.getShading(), 1); - assertEquals(negCard.getShape(), 1); - assertEquals(negCard.toString(), "1ROO"); - Card lrgCard = new Card(2147483647, 172831, 7910, 457); - assertEquals(lrgCard.getQuantity(), 2); - assertEquals(lrgCard.getColor(), 2); - assertEquals(lrgCard.getShading(), 3); - assertEquals(lrgCard.getShape(), 2); - assertEquals(lrgCard.toString(), "2GSD"); - Card ranCard = new Card(24, 0, -2147483648, 2); - assertEquals(ranCard.getQuantity(), 1); - assertEquals(ranCard.getColor(), 1); - assertEquals(ranCard.getShading(), 2); - assertEquals(ranCard.getShape(), 2); - assertEquals(ranCard.toString(), "1RTD"); - assertEquals(negCard.isSet(lrgCard, ranCard), false); - } - - public void test3() - { - //testing when all the same - Card card4 = new Card(3, 3, 3, 3); - assertEquals(card4.getQuantity(), 3); - assertEquals(card4.getColor(), 3); - assertEquals(card4.getShading(), 3); - assertEquals(card4.getShape(), 3); - assertEquals(card4.toString(), "3PSS"); - Card card5 = new Card(3,3,3,3); - assertEquals(card5.getQuantity(), 3); - assertEquals(card5.getColor(), 3); - assertEquals(card5.getShading(), 3); - assertEquals(card5.getShape(), 3); - assertEquals(card5.toString(), "3PSS"); - Card card6 = new Card(3,3,3,3); - assertEquals(card6.getQuantity(), 3); - assertEquals(card6.getColor(), 3); - assertEquals(card6.getShading(), 3); - assertEquals(card6.getShape(), 3); - assertEquals(card6.toString(), "3PSS"); - assertEquals(card4.isSet(card5, card6), true); - } - - public void test2() - { - Card card1 = new Card(2, 2, 2, 2); - assertEquals(card1.getQuantity(), 2); - assertEquals(card1.getColor(), 2); - assertEquals(card1.getShading(), 2); - assertEquals(card1.getShape(), 2); - assertEquals(card1.toString(), "2GTD"); - Card card2 = new Card(2, 2, 2, 2); - assertEquals(card2.getQuantity(), 2); - assertEquals(card2.getColor(), 2); - assertEquals(card2.getShading(), 2); - assertEquals(card2.getShape(), 2); - assertEquals(card2.toString(), "2GTD"); - Card card3 = new Card(2, 2, 2, 2); - assertEquals(card3.getQuantity(), 2); - assertEquals(card3.getColor(), 2); - assertEquals(card3.getShading(), 2); - assertEquals(card3.getShape(), 2); - assertEquals(card3.toString(), "2GTD"); - assertEquals(card1.isSet(card2, card3), true); - } - - public void test1() - { - Card card1 = new Card(1, 1, 1, 1); - assertEquals(card1.getQuantity(), 1); - assertEquals(card1.getColor(), 1); - assertEquals(card1.getShading(), 1); - assertEquals(card1.getShape(), 1); - assertEquals(card1.toString(), "1ROO"); - Card card2 = new Card(1, 1, 1, 1); - assertEquals(card2.getQuantity(), 1); - assertEquals(card2.getColor(), 1); - assertEquals(card2.getShading(), 1); - assertEquals(card2.getShape(), 1); - assertEquals(card2.toString(), "1ROO"); - Card card3 = new Card(1, 1, 1, 1); - assertEquals(card3.getQuantity(), 1); - assertEquals(card3.getColor(), 1); - assertEquals(card3.getShading(), 1); - assertEquals(card3.getShape(), 1); - assertEquals(card3.toString(), "1ROO"); - assertEquals(card1.isSet(card2, card3), true); - } - - public void testAgainWheeee() - { - Card card1 = new Card(3, 3, 1, 2); - assertEquals(card1.getQuantity(), 3); - assertEquals(card1.getColor(), 3); - assertEquals(card1.getShading(), 1); - assertEquals(card1.getShape(), 2); - assertEquals(card1.toString(), "3POD"); - Card card2 = new Card(1, 2, 3, 3); - assertEquals(card2.getQuantity(), 1); - assertEquals(card2.getColor(), 2); - assertEquals(card2.getShading(), 3); - assertEquals(card2.getShape(), 3); - assertEquals(card2.toString(), "1GSS"); - Card card3 = new Card(2, 1, 2, 1); - assertEquals(card3.getQuantity(), 2); - assertEquals(card3.getColor(), 1); - assertEquals(card3.getShading(), 2); - assertEquals(card3.getShape(), 1); - assertEquals(card3.toString(), "2RTO"); - assertEquals(card1.isSet(card2, card3), true); - } - - public void testAgainAgain() - { - Card card1 = new Card(3, 3, 1, 23); - assertEquals(card1.getQuantity(), 3); - assertEquals(card1.getColor(), 3); - assertEquals(card1.getShading(), 1); - assertEquals(card1.getShape(), 3); - assertEquals(card1.toString(), "3POS"); - Card card2 = new Card(1, 2, 3, 3); - assertEquals(card2.getQuantity(), 1); - assertEquals(card2.getColor(), 2); - assertEquals(card2.getShading(), 3); - assertEquals(card2.getShape(), 3); - assertEquals(card2.toString(), "1GSS"); - Card card3 = new Card(2, 1, 2, 1); - assertEquals(card3.getQuantity(), 2); - assertEquals(card3.getColor(), 1); - assertEquals(card3.getShading(), 2); - assertEquals(card3.getShape(), 1); - assertEquals(card3.toString(), "2RTO"); - assertEquals(card1.isSet(card2, card3), false); - } - -} \ No newline at end of file From b007be54484467136cee4a405344bca56fcf70d2 Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Fri, 24 Apr 2015 19:37:19 -0400 Subject: [PATCH 41/47] Delete Deck.java~ --- src/Deck.java~ | 93 -------------------------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 src/Deck.java~ diff --git a/src/Deck.java~ b/src/Deck.java~ deleted file mode 100644 index 4cf9ec0..0000000 --- a/src/Deck.java~ +++ /dev/null @@ -1,93 +0,0 @@ -import java.util.Collections; -import java.io.BufferedReader; -import java.io.FileReader; -import java.util.StringTokenizer; -import java.util.ArrayList; - - -public class Deck { - // Implement the rest of this class yourself - private int nextCardIndex = 0; - private ArrayList cards = new ArrayList(81); - - public Deck(){ - for (int i=1; i<=3; i++) { - for (int j=1; j<=3; j++) { - for (int k=1; k<=3; k++) { - for (int m=1; m<=3; m++) { - Card card = new Card(i, j, k, m); - cards.add(card); - } - } - } - } - - Collections.shuffle(cards); - } - - public int getSize(){ - return cards.size(); - } - - public boolean hasNext() { - if (nextCardIndex < cards.size()) { - return true; - } - else { - return false; - } - } - - public Card getNext() { - //returns card - - if (hasNext() == true) { - nextCardIndex +=1; - return cards.get(nextCardIndex-1); - } - - else{ - return null; - } - } - - public Deck(String filename) { - //file is named 3cards.txt - //cards = new ArrayList(81); - - try { - String line; - BufferedReader infile = new BufferedReader(new FileReader(filename)); - int position = 0; - - while((line = infile.readLine()) != null) { - // Blank lines might contain white space, so trim it off - line = line.trim(); - - // ignore blank lines - if(line.length() == 0) - continue; - - // ignore comments - if(line.startsWith("#")) - continue; - - // a valid line contains 4 integers - StringTokenizer tokenizer = new StringTokenizer(line); - - int quantity = Integer.parseInt(tokenizer.nextToken()); - int color = Integer.parseInt(tokenizer.nextToken()); - int shading = Integer.parseInt(tokenizer.nextToken()); - int shape = Integer.parseInt(tokenizer.nextToken()); - - cards.add(new Card(quantity, color, shading, shape)); - nextCardIndex = 0; - } - } - catch(Exception e) { - throw new RuntimeException("Error while reading file: " + e.toString()); - } - } - - -} From 5e99ae4fc8cf550b108cf9a3d390a230df4d7684 Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Fri, 24 Apr 2015 19:37:28 -0400 Subject: [PATCH 42/47] Delete DeckTest.java~ --- src/DeckTest.java~ | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 src/DeckTest.java~ diff --git a/src/DeckTest.java~ b/src/DeckTest.java~ deleted file mode 100644 index 824a3b7..0000000 --- a/src/DeckTest.java~ +++ /dev/null @@ -1,43 +0,0 @@ -import junit.framework.TestCase; - -/** - * A JUnit test case class. - * Every method starting with the word "test" will be called when running - * the test with JUnit. - */ -public class DeckTest extends TestCase { - - /** - * A test method. - * (Replace "X" with a name describing the test. You may write as - * many "testSomething" methods in this class as you wish, and each - * one will be called when running JUnit over this class.) - */ - public void testEmptyDeck() { - Deck d = new Deck("EmptyDeck.txt"); - assertEquals(d.hasNext(), false); - } - - - public void testAllCards() { - Deck d = new Deck("81cards.txt"); - for (int i=0; i<81; i++) { - assertEquals(d.hasNext(), true); - d.getNext(); - } - d.getNext(); - assertEquals(d.hasNext(), false); - } - - public void test3Cards() { - Deck d = new Deck("3cards.txt"); - for (int i=0; i<3; i++) { - assertEquals(d.hasNext(), true); - d.getNext(); - } - d.getNext(); - assertEquals(d.hasNext(), false); - } - - -} From 8a57d4ca08bcd0ed804bb4b33015f0074b19137c Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Fri, 24 Apr 2015 19:37:37 -0400 Subject: [PATCH 43/47] Delete Game.java~ --- src/Game.java~ | 190 ------------------------------------------------- 1 file changed, 190 deletions(-) delete mode 100644 src/Game.java~ diff --git a/src/Game.java~ b/src/Game.java~ deleted file mode 100644 index 867f9f0..0000000 --- a/src/Game.java~ +++ /dev/null @@ -1,190 +0,0 @@ -public class Game{ - private Deck d; - private Table t; - - public Game(){ - //begins with randomly generated deck of 12 cards - - d = new Deck(); - t = new Table(); - - for (int i = 0; i<12; i++){ - t.add(d.getNext()); - } - } - - public Game(String filename){ - //loads specific deck - - d = new Deck(filename); - t = new Table(); - - while (d.hasNext()){ - t.add(d.getNext()); - - if (t.numCards() == 12){ - return; - } - } - } - - public int numSets(){ - //returns number of sets on the table - return t.numSets(); - } - - public int numCards(){ - - //returns number of cards on table which is 12 - //or less if deck has lest than 12 cards - return t.numCards(); - } - - public void playRound(){ - //used to advance game from one round to the next - // - //a round deals with removing one set - //and adding additional cards - // - //1.)when no sets on table but still cards in deck: - // this means just add 3 cards - //2.)most of the time: - // cards in deck and 12 on table containing 1+ sets - // in this situation we move from one round - // to the next by removing one set and adding 3 cards - // to the table from the deck - //3.)if a round starts with 12+ cards on table: - // (due to no sets) - // and theres is at least one set, - // then after removing a set we do not add cards - //4.)if there is at least one set but no cards left: - // we move to next round by just removing set - //5.)if no cards in deck or sets on table: - // game over - // - //6.)sometimes when you use custom decks: - // there may be only 1-2 cards remaining - // when you have to add cards to table - // in this case cards are added like normal - // and the table remains short a few cards - - int sets = t.numSets(); - - //1.) - if (sets == 0 && d.hasNext() == true){ - for (int i = 0; i < 3; i++){ - if (d.hasNext() == false){ - return; - } - t.add(d.getNext()); - } - return; - } - - - //2.) - if (sets > 0 && d.hasNext() == true){ - //call the number of cards in the begining to make it quicker - int numCards = t.numCards(); - //go through the table looking for the set - for (int i=0; i 12 && sets > 0){ - //call the number of cards in the begining to make it quicker - int numCards = t.numCards(); - //go through the table looking for the set - for (int i=0; i 0 && d.hasNext() == false){ - //call the number of cards in the begining to make it quicker - int numCards = t.numCards(); - //go through the table looking for the set - for (int i=0; i Date: Fri, 24 Apr 2015 19:38:05 -0400 Subject: [PATCH 44/47] Delete MonteCarlo.java~ --- src/MonteCarlo.java~ | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 src/MonteCarlo.java~ diff --git a/src/MonteCarlo.java~ b/src/MonteCarlo.java~ deleted file mode 100644 index 99432ff..0000000 --- a/src/MonteCarlo.java~ +++ /dev/null @@ -1,2 +0,0 @@ -public class MonteCarlo{ -} \ No newline at end of file From b6327b7f71bc11ab37fcb14ad07bdc2f8f160df8 Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Fri, 24 Apr 2015 19:38:11 -0400 Subject: [PATCH 45/47] Delete GameTest.java~ --- src/GameTest.java~ | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 src/GameTest.java~ diff --git a/src/GameTest.java~ b/src/GameTest.java~ deleted file mode 100644 index 2e9c484..0000000 --- a/src/GameTest.java~ +++ /dev/null @@ -1,41 +0,0 @@ -import junit.framework.TestCase; - -/** - * A JUnit test case class. - * Every method starting with the word "test" will be called when running - * the test with JUnit. - */ -public class GameTest extends TestCase { - - /** - * A test method. - * (Replace "X" with a name describing the test. You may write as - * many "testSomething" methods in this class as you wish, and each - * one will be called when running JUnit over this class.) - */ - public void test1RoundGame() { - Game g = new Game(); - - assertEquals(g.numCards(), 12); - g.playRound(); - assertEquals(g.numCards(), 12); - } - - public void testWith81CardsDeck(){ - Game g = new Game("81cards.txt"); - - assertEquals(g.numCards(), 12); - g.playRound(); - assertEquals(g.numCards(), 12); - } - - public void testWith3CardsDeck(){ - Game g = new Game("3cards.txt"); - - assertEquals(g.numCards(), 3); - g.playRound(); - assertEquals(g.numCards(), 0); - } - - -} From 423da4137cde334d5b9eb4b9fd3fc667b33d5d09 Mon Sep 17 00:00:00 2001 From: ChrisSheehan01 Date: Fri, 24 Apr 2015 19:38:16 -0400 Subject: [PATCH 46/47] Delete Table.java~ --- src/Table.java~ | 188 ------------------------------------------------ 1 file changed, 188 deletions(-) delete mode 100644 src/Table.java~ diff --git a/src/Table.java~ b/src/Table.java~ deleted file mode 100644 index 345e6d6..0000000 --- a/src/Table.java~ +++ /dev/null @@ -1,188 +0,0 @@ -public class Table{ - private TableNode head; - - public Table(){ - head = null; - } - - public void add(Card newCard){ - //new cards should be added to the front of the list - - TableNode newTableNode = new TableNode(newCard); - - // for an empty table - if (head == null) { - head = newTableNode; - } - - else { - newTableNode.setNext(head); - head = newTableNode; - } - } - - - public void removeSet(Card card1, Card card2, Card card3){ - //removes set from table - - //makes sure they're a set - if (card1.isSet(card2,card3) != true) { - return; - } - - //make sure the table isn't empty - if (head == null) { - return; - } - - //check if they're on the table and if they are assign them to variables - Card firstCard = null; - Card secondCard = null; - Card thirdCard = null; - - //temp traverses through the list - TableNode temp = head; - TableNode prev = head; - - //goes through list - while (temp != null) { - //check for first card - - //make instance of card class - - //This if statement is where the infinite loop occurs - if (card1.equals(temp.getCard())) { - firstCard = card1; - temp = temp.getNext(); - } - else if (card2.equals(temp.getCard())) { - secondCard = card2; - temp = temp.getNext(); - } - else if (card3.equals(temp.getCard())) { - thirdCard = card3; - temp = temp.getNext(); - } - else{ - temp = temp.getNext(); - } - } - - //if all cards are on table variables will equal cards given in parameter - if (card1.equals(firstCard) && card2.equals(secondCard) && card3.equals(thirdCard)) { - int i = 0; - while(i < 3) { - - //sets the temp back to the head - temp = head; - prev = head; - - //loop until end to remove cards - while (temp.getNext() != null && i < 3) { - //for removing card at head or in middle - if (card1.equals(temp.getCard()) || card2.equals(temp.getCard()) || card3.equals(temp.getCard())){ - if (temp == head){ - head = temp.getNext(); - prev = head; - temp = head; - i+=1; - } - else { - temp = temp.getNext(); - prev.setNext(temp); - i+=1; - } - } - else { - temp = temp.getNext(); - if (prev != head){ - prev=prev.getNext(); - } - } - } - - //for last card - if (temp.getNext()==null) { - if (card1.equals(temp.getCard()) || card2.equals(temp.getCard()) || card3.equals(temp.getCard())){ - prev.setNext(null); - i+=1; - } - //might not need to be here - else { - return; - } - } - } - } - //if cards are not on table the method ends - else { - return; - } - } - - - - public int numCards(){ - //returns number of cards on table - TableNode temp = head; - int i = 0; - if (head == null) { - return 0; - } - else{ - while (temp != null) { - i += 1; - temp = temp.getNext(); - } - return i; - } - } - - public Card getCard(int index){ - // parameter is the index although it will remove the (n-1)th card on the table - //returns card at given int - - TableNode temp = head; - if (temp == null) { - return null; - } - if (index == 0) { - return temp.getCard(); - } - else { // this may cause errors maybe change to j < index - for (int j = 0; j Date: Thu, 30 Apr 2015 22:00:40 -0400 Subject: [PATCH 47/47] MonteCarlo --- src/MonteCarlo.java | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/MonteCarlo.java b/src/MonteCarlo.java index 374dd62..4dfe154 100644 --- a/src/MonteCarlo.java +++ b/src/MonteCarlo.java @@ -22,34 +22,22 @@ public static void main(String[] args){ //use a main class - //1st Question: + //1st Question && 2nd Question: double avgNumberOfSets = 0; + double avgNumberOfCards = 0; int i = 0; - while(i<=1000000){ + while(i<=10000000){ Game g = new Game(); avgNumberOfSets += g.numSets(); + while(g.isGameOver() == false) { + g.playRound(); + } + avgNumberOfCards += g.numCards(); i++; } System.out.println("The average Number of Sets in " + (i-1) + " sets of random cards is " + avgNumberOfSets/(i-1)); - - - //2nd question: - double avgNumberOfCards = 0; - int j = 0; - while(j<=1000000){ /// this takes about 9 minutes.. - Game g2 = new Game(); - while(g2.isGameOver() == false) { - g2.playRound(); - } - avgNumberOfCards += g2.numCards(); - j++; - } - System.out.println("The average Number of Cards left on the table at the end of a game after " + (j-1) + " games is " + avgNumberOfCards/(j-1)); - - - + System.out.println("The average Number of Cards left on the table at the end of a game after " + (i-1) + " games is " + avgNumberOfCards/(i-1)); - //end of class } } \ No newline at end of file