From ffc0642f833bb745c2b3eee57b0c529ed14d7640 Mon Sep 17 00:00:00 2001 From: John Ferguson Date: Tue, 31 Mar 2015 17:42:46 -0400 Subject: [PATCH 1/6] SetProject Finished --- src/Card.java | 88 +++++++++++++++++++++++++++++++++++++++++++++++ src/CardTest.java | 44 ++++++++++++++++++++++++ 2 files changed, 132 insertions(+) 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..0547daf --- a/src/Card.java +++ b/src/Card.java @@ -1,6 +1,94 @@ public class Card { + private int quantity; + private int color; + private int shading; + private int shape; // Create the rest of this class yourself + public Card (int isQuant, int isCol, int isShad, int isShap) { + quantity = ((((isQuant % 3) + 3) % 3)); + color = ((((isCol % 3) + 3) % 3)); + shading = ((((isShad % 3) + 3) % 3)); + shape = ((((isShap % 3) + 3) % 3)); + } + + + public int getQuantity() { + + return quantity; + } + + public int getColor() { + + return color; + } + + public int getShading() { + + return shading; + } + + public int getShape() { + + return shape; + } + + public boolean isSet(Card cardX, Card cardY) { + if ((((quantity + cardX.getQuantity() + cardY.getQuantity()) % 3) == 0) && + (((color + cardX.getColor() + cardY.getColor()) % 3) == 0) && + (((shading + cardX.getShading() + cardY.getShading()) % 3) == 0) && + (((shape + cardX.getShape() + cardY.getShape()) % 3) == 0)) { + return true; + } + else { + return false; + } + + + } + + public String toString() { + String str = ""; + str += quantity; + if (color == 0) { + str += "R"; + } + + if (color == 1) { + str += "G"; + } + + if (color == 2) { + str += "P"; + } + + if (shading == 0) { + str += "O"; + } + + if (shading == 1) { + str += "T"; + } + + if (shading == 2) { + str += "S"; + } + + if (shape == 0) { + str += "O"; + } + + if (shape == 1) { + str += "D"; + } + + if (shape == 2) { + str += "S"; + } + return str; + + } + public boolean equals(Object obj) { Card that = (Card)obj; diff --git a/src/CardTest.java b/src/CardTest.java new file mode 100644 index 0000000..31ff63c --- /dev/null +++ b/src/CardTest.java @@ -0,0 +1,44 @@ +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 testCardWorks() { + Card c1 = new Card(0,1,2,1); + assertEquals("0GSD",c1.toString()); + + Card c2 = new Card(1,2,0,2); + assertEquals("1POS",c2.toString()); + + Card c3 = new Card(2,0,1,0); + assertEquals("2RTO",c3.toString()); + + + + + } + + public void testTruthSet() { + Card c1 = new Card(1,2,3,2); + Card c2 = new Card(2,3,1,3); + Card c3 = new Card(3,1,2,1); + assertEquals(true, c1.isSet(c2, c3)); + } + + public void testFalseSet() { + Card c1 = new Card(1,3,3,1); + Card c2 = new Card(3,3,3,3); + Card c3 = new Card(3,2,1,3); + assertEquals(false, c1.isSet(c2, c3)); +} +} From 285aa977683efc1a0734df50560f9c0eda910016 Mon Sep 17 00:00:00 2001 From: John Ferguson Date: Tue, 7 Apr 2015 17:39:08 -0400 Subject: [PATCH 2/6] Deck Part Done --- src/Deck.java | 35 +++++++++++++++++++++++++++++++++++ src/DeckTest.java | 34 ++++++++++++++++++++++++++++++++++ src/threeCards.dat | 3 +++ 3 files changed, 72 insertions(+) mode change 100755 => 100644 src/Deck.java create mode 100644 src/DeckTest.java create mode 100644 src/threeCards.dat diff --git a/src/Deck.java b/src/Deck.java old mode 100755 new mode 100644 index ab3a2a3..44ec0be --- a/src/Deck.java +++ b/src/Deck.java @@ -2,9 +2,44 @@ import java.io.FileReader; import java.util.StringTokenizer; import java.util.ArrayList; +import java.util.Collections; public class Deck { // Implement the rest of this class yourself + private ArrayList cards = new ArrayList(81); + private int nextCardIndex = 0; + + public Deck() { + for ( int i = 1; i <= 3; i++) { + for (int a = 1; a <= 3; a++) { + for (int b = 1; b <= 3; b++) { + for (int c = 1; c<=3; c++) { + Card card = new Card(i,a,b,c); + } + } + } + } + Collections.shuffle(cards); + } + + public boolean hasNext() { + if (nextCardIndex < cards.size()) { + return true; + } + else { + return false; + } + } + + public Card getNext() { + if (hasNext() == false) { + return null; + } + else { + nextCardIndex += 1; + return cards.get(nextCardIndex - 1); + } + } public Deck(String filename) { cards = new ArrayList(81); diff --git a/src/DeckTest.java b/src/DeckTest.java new file mode 100644 index 0000000..373e328 --- /dev/null +++ b/src/DeckTest.java @@ -0,0 +1,34 @@ +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 testDeckCard() { + Deck d = new Deck("threeCards.dat"); + Card c1 = new Card(0,1,2,1); + + assertEquals(true, d.getNext().equals(c1)); + assertEquals(true, d.hasNext()); + + Card c2 = new Card(1,2,0,2); + + assertEquals(true, d.getNext().equals(c2)); + assertEquals(true, d.hasNext()); + + Card c3 = new Card(2,0,1,0); + + assertEquals(true, d.getNext().equals(c3)); + assertEquals(false, d.hasNext()); + } + +} diff --git a/src/threeCards.dat b/src/threeCards.dat new file mode 100644 index 0000000..1862c8a --- /dev/null +++ b/src/threeCards.dat @@ -0,0 +1,3 @@ +0 1 2 1 +1 2 0 2 +2 0 1 0 \ No newline at end of file From 7d7652b08c41dfd3966c76303b24940069f68c1d Mon Sep 17 00:00:00 2001 From: John Ferguson Date: Thu, 9 Apr 2015 13:42:21 -0400 Subject: [PATCH 3/6] Modified card and deck --- src/Card.java | 34 +++++++++++++++++++++------------- src/CardTest.java | 12 ++++++------ src/DeckTest.java | 6 +++--- src/threeCards.dat | 6 +++--- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/Card.java b/src/Card.java index 0547daf..855421d 100644 --- a/src/Card.java +++ b/src/Card.java @@ -6,10 +6,18 @@ public class Card { // Create the rest of this class yourself public Card (int isQuant, int isCol, int isShad, int isShap) { - quantity = ((((isQuant % 3) + 3) % 3)); - color = ((((isCol % 3) + 3) % 3)); - shading = ((((isShad % 3) + 3) % 3)); - shape = ((((isShap % 3) + 3) % 3)); + quantity = fixValue(isQuant); + color = fixValue(isCol); + shading = fixValue(isShad); + shape = fixValue(isShap); + + } + + private int fixValue(int valueToFix) { + if (valueToFix < 1 || valueToFix > 3) + return (((valueToFix % 3) + 3) % 3) + 1; + else + return valueToFix; } @@ -50,39 +58,39 @@ public boolean isSet(Card cardX, Card cardY) { public String toString() { String str = ""; str += quantity; - if (color == 0) { + if (color == 1) { str += "R"; } - if (color == 1) { + if (color == 2) { str += "G"; } - if (color == 2) { + if (color == 3) { str += "P"; } - if (shading == 0) { + if (shading == 1) { str += "O"; } - if (shading == 1) { + if (shading == 2) { str += "T"; } - if (shading == 2) { + if (shading == 3) { str += "S"; } - if (shape == 0) { + if (shape == 1) { str += "O"; } - if (shape == 1) { + if (shape == 2) { str += "D"; } - if (shape == 2) { + if (shape == 3) { str += "S"; } return str; diff --git a/src/CardTest.java b/src/CardTest.java index 31ff63c..589c8c5 100644 --- a/src/CardTest.java +++ b/src/CardTest.java @@ -14,14 +14,14 @@ public class CardTest extends TestCase { * one will be called when running JUnit over this class.) */ public void testCardWorks() { - Card c1 = new Card(0,1,2,1); - assertEquals("0GSD",c1.toString()); + Card c1 = new Card(1,2,3,2); + assertEquals("1GSD",c1.toString()); - Card c2 = new Card(1,2,0,2); - assertEquals("1POS",c2.toString()); + Card c2 = new Card(2,3,1,3); + assertEquals("2POS",c2.toString()); - Card c3 = new Card(2,0,1,0); - assertEquals("2RTO",c3.toString()); + Card c3 = new Card(3,1,2,1); + assertEquals("3RTO",c3.toString()); diff --git a/src/DeckTest.java b/src/DeckTest.java index 373e328..cf37f0d 100644 --- a/src/DeckTest.java +++ b/src/DeckTest.java @@ -15,17 +15,17 @@ public class DeckTest extends TestCase { */ public void testDeckCard() { Deck d = new Deck("threeCards.dat"); - Card c1 = new Card(0,1,2,1); + Card c1 = new Card(1,2,3,2); assertEquals(true, d.getNext().equals(c1)); assertEquals(true, d.hasNext()); - Card c2 = new Card(1,2,0,2); + Card c2 = new Card(2,3,1,3); assertEquals(true, d.getNext().equals(c2)); assertEquals(true, d.hasNext()); - Card c3 = new Card(2,0,1,0); + Card c3 = new Card(3,1,2,1); assertEquals(true, d.getNext().equals(c3)); assertEquals(false, d.hasNext()); diff --git a/src/threeCards.dat b/src/threeCards.dat index 1862c8a..e7593df 100644 --- a/src/threeCards.dat +++ b/src/threeCards.dat @@ -1,3 +1,3 @@ -0 1 2 1 -1 2 0 2 -2 0 1 0 \ No newline at end of file +1 2 3 2 +2 3 1 3 +3 1 2 1 \ No newline at end of file From d3cd810b33b5a4acda295a7ea7a3421fa7bc2057 Mon Sep 17 00:00:00 2001 From: John Ferguson Date: Tue, 14 Apr 2015 20:03:32 -0400 Subject: [PATCH 4/6] Table and TableNode --- src/Table.java | 130 +++++++++++++++++++++++++++++++++++++++++ src/TableNode.java | 27 +++++++++ src/TableNodeTest.java | 35 +++++++++++ src/TableTest.java | 34 +++++++++++ 4 files changed, 226 insertions(+) create mode 100644 src/Table.java create mode 100644 src/TableNode.java create mode 100644 src/TableNodeTest.java create mode 100644 src/TableTest.java diff --git a/src/Table.java b/src/Table.java new file mode 100644 index 0000000..7e340b1 --- /dev/null +++ b/src/Table.java @@ -0,0 +1,130 @@ +public class Table { + private TableNode head; + + + public Table() { + head = null; + } + + public void add(Card card) { + TableNode node = new TableNode(card); + if (head == null) { + head = node; + } + else { + node.setNext(head); + head = node; + } + } + + public void removeSet(Card c1, Card c2 , Card c3) { + if (c1.isSet(c2,c3) == false) { + return; + } + TableNode temp = head; + Card removeC1 = null; + Card removeC2 = null; + Card removeC3 = null; + + while (temp != null) { + if (temp.getCard() == c1) { + removeC1 = c1; + } + if (temp.getCard() == c2) { + removeC2 = c2; + } + if (temp.getCard() == c3) { + removeC3 = c3; + } + + temp = temp.getNext(); + } + + if (removeC1 == c1 && removeC2 == c2 && removeC3 == c3) { + TableNode curr = head; + TableNode prev = null; + int prevNumCards = numCards(); + + while (curr != null) { + if (curr.getCard() == c1 || curr.getCard() == c2 || curr.getCard() == c3) { + if (curr == head) { + prev = head; + head = head.getNext(); + prev.setNext(null); + curr = head; + prev = null; + } + else { + prev.setNext(curr.getNext()); + curr.setNext(null); + } + } + if (numCards() == 0) { + return; + } + if (curr.getNext() == null && prev != null) { + curr = prev.getNext(); + } + if (prevNumCards == numCards()) { + prev = curr; + curr = curr.getNext(); + } + prevNumCards = numCards(); + } + } + return; + } + + public int numCards() { + TableNode temp = head; + int card = 0; + if (head == null) { + return 0; + } + else { + while (temp != null) { + temp = temp.getNext(); + card += 1; + } + return card; + + + } + } + + public Card getCard(int index) { + TableNode temp = head; + if (temp == null) { + return null; + } + for (int d = 0; d < index; d++) { + temp = temp.getNext(); + if (temp == null) { + return null; + } + } + return temp.getCard(); + + + } + + public int numSets() { + int isSet = 0; + int numCards = numCards(); + for (int a = 0; a < numCards - 2; a++) { + for (int b = 1; b < numCards - 1; b++) { + for (int c = 2; c < numCards; c++) { + + Card card1 = getCard(a); + Card card2 = getCard(b); + Card card3 = getCard(c); + + if (card1.isSet(card2,card3)) { + isSet += 1; + } + } + } + } + return isSet; + } +} \ No newline at end of file diff --git a/src/TableNode.java b/src/TableNode.java new file mode 100644 index 0000000..92520c3 --- /dev/null +++ b/src/TableNode.java @@ -0,0 +1,27 @@ +public class TableNode { + private Card card; + private TableNode next; + + public TableNode(Card c1) { + + card = c1; + next = null; + + } + + public void setNext(TableNode node) { + + next = node; + + } + + public TableNode getNext() { + + return next; + + } + + public Card getCard() { + return card; + } +} \ No newline at end of file diff --git a/src/TableNodeTest.java b/src/TableNodeTest.java new file mode 100644 index 0000000..320cdb9 --- /dev/null +++ b/src/TableNodeTest.java @@ -0,0 +1,35 @@ +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 TableNodeTest 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 testTableNodeCards() { + Card c1 = new Card(1, 2, 3, 2); + TableNode n1 = new TableNode(c1); + assertEquals(null, n1.getNext()); + assertEquals(c1, n1.getCard()); + + Card c2 = new Card(2, 3, 1, 3); + TableNode n2 = new TableNode(c2); + assertEquals(null, n2.getNext()); + assertEquals(c2, n2.getCard()); + + Card c3 = new Card(1, 3, 2, 3); + TableNode n3 = new TableNode(c3); + assertEquals(null, n3.getNext()); + assertEquals(c3, n3.getCard()); + + + } + +} diff --git a/src/TableTest.java b/src/TableTest.java new file mode 100644 index 0000000..063dfff --- /dev/null +++ b/src/TableTest.java @@ -0,0 +1,34 @@ +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 TableTest 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 testTable() { + Table t = new Table(); + + Card c1 = new Card(1,2,3,2); + t.add(c1); + + Card c2 = new Card(2,3,1,3); + t.add(c2); + + Card c3 = new Card(1,3,2,3); + t.add(c3); + + assertEquals(3, t.numCards()); + assertEquals(true, t.getCard(0).equals(c3)); + assertEquals(true, t.getCard(1).equals(c2)); + assertEquals(true, t.getCard(2).equals(c1)); + } + +} From 40175ad811c2f78de4b02364d785ccf6d86dc6bd Mon Sep 17 00:00:00 2001 From: John Ferguson Date: Thu, 23 Apr 2015 16:29:29 -0400 Subject: [PATCH 5/6] modified but not finished game --- src/Card.java | 10 ++-- src/Game.java | 99 ++++++++++++++++++++++++++++++ src/GameTest.java | 24 ++++++++ src/Table.java | 149 ++++++++++++++++++++++++---------------------- 4 files changed, 207 insertions(+), 75 deletions(-) create mode 100644 src/Game.java create mode 100644 src/GameTest.java diff --git a/src/Card.java b/src/Card.java index 855421d..a7ed9ed 100644 --- a/src/Card.java +++ b/src/Card.java @@ -41,11 +41,11 @@ public int getShape() { return shape; } - public boolean isSet(Card cardX, Card cardY) { - if ((((quantity + cardX.getQuantity() + cardY.getQuantity()) % 3) == 0) && - (((color + cardX.getColor() + cardY.getColor()) % 3) == 0) && - (((shading + cardX.getShading() + cardY.getShading()) % 3) == 0) && - (((shape + cardX.getShape() + cardY.getShape()) % 3) == 0)) { + public boolean isSet(Card c1, Card c2) { + if ((((quantity + c1.getQuantity() + c2.getQuantity()) % 3) == 0) && + (((color + c1.getColor() + c2.getColor()) % 3) == 0) && + (((shading + c1.getShading() + c2.getShading()) % 3) == 0) && + (((shape + c1.getShape() + c2.getShape()) % 3) == 0)) { return true; } else { diff --git a/src/Game.java b/src/Game.java new file mode 100644 index 0000000..88877b7 --- /dev/null +++ b/src/Game.java @@ -0,0 +1,99 @@ +public class Game { + private Table t; + private Deck d; + + public Game() { + + d = new Deck(); + t = new Table(); + + for (int i = 0; i < 12; i++) { + t.add(d.getNext()); + } + } + + public Game(String cardGame) { + + t = new Table(); + d = new Deck(cardGame); + for (int i = 0; i < 12; i++) { + if(d.hasNext() == true) { + t.add(d.getNext()); + } + } + } + + public int numSets() { + + return t.numSets(); + + } + + public int numCards() { + + return t.numCards(); + + } + + public void playRound() { + //worked with Hailey Kester on the playRound in lab + + if (t.numSets() == 0 && d.hasNext() == true) { + for (int i = 0; i < 3; i++) { + if(d.hasNext() == true) { + t.add(d.getNext()); + } + } + return; + } + + if (t.numSets() > 0) { + for (int a = 0; a < t.numCards() - 2; a++) { + for (int b = a + 1; b < t.numCards() - 1; b++) { + for (int c = b + 1; c < t.numCards(); c++) { + Card c1 = t.getCard(a); + Card c2 = t.getCard(b); + Card c3 = t.getCard(c); + + if (c1.isSet(c2,c3)) { + t.removeSet(c1, c2, c3); + if (t.numCards() < 12 && d.hasNext()) { + for (int i = 0; i < 3; i++) { + if(d.hasNext() == true) { + t.add(d.getNext()); + } + return; + } + } + } + } + } + } + } + } + + + + + + + + + + + + public boolean isGameOver() { + + if (d.hasNext() == false && t.numSets() == 0) { + return true; + } + + else { + return false; + } + } +} + + + + \ No newline at end of file diff --git a/src/GameTest.java b/src/GameTest.java new file mode 100644 index 0000000..f26dfe5 --- /dev/null +++ b/src/GameTest.java @@ -0,0 +1,24 @@ +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 testGameRound() { + + Game g1 = new Game(); + assertEquals(g1.numCards(), 12); + g1.playRound(); + + } + +} diff --git a/src/Table.java b/src/Table.java index 7e340b1..0079c60 100644 --- a/src/Table.java +++ b/src/Table.java @@ -1,13 +1,15 @@ public class Table { private TableNode head; - + private int isLength; public Table() { head = null; + isLength = 0; } public void add(Card card) { TableNode node = new TableNode(card); + isLength += 1; if (head == null) { head = node; } @@ -17,62 +19,69 @@ public void add(Card card) { } } - public void removeSet(Card c1, Card c2 , Card c3) { - if (c1.isSet(c2,c3) == false) { - return; - } + private boolean onTable(Card card) { + //got help from Hailey Kester in lab TableNode temp = head; - Card removeC1 = null; - Card removeC2 = null; - Card removeC3 = null; - while (temp != null) { - if (temp.getCard() == c1) { - removeC1 = c1; - } - if (temp.getCard() == c2) { - removeC2 = c2; + if (temp.getCard().equals(card)) { + return true; } - if (temp.getCard() == c3) { - removeC3 = c3; - } - temp = temp.getNext(); } - - if (removeC1 == c1 && removeC2 == c2 && removeC3 == c3) { - TableNode curr = head; - TableNode prev = null; - int prevNumCards = numCards(); - - while (curr != null) { - if (curr.getCard() == c1 || curr.getCard() == c2 || curr.getCard() == c3) { - if (curr == head) { - prev = head; - head = head.getNext(); - prev.setNext(null); - curr = head; - prev = null; - } - else { - prev.setNext(curr.getNext()); - curr.setNext(null); - } - } - if (numCards() == 0) { - return; - } - if (curr.getNext() == null && prev != null) { - curr = prev.getNext(); - } - if (prevNumCards == numCards()) { - prev = curr; - curr = curr.getNext(); - } - prevNumCards = numCards(); + return false; + } + + private void removeCard(Card card) { + //help from hailey kester in lab + TableNode temp = findTemp(card); + isLength -= 1; + if (temp == null) { + head = head.getNext(); + } + else { + TableNode john = temp.getNext(); + temp.setNext(john.getNext()); + } + } + + private TableNode findTemp(Card card) { + //help from hailey kester in lab + TableNode temp = null; + TableNode john = head; + while (john != null) { + Card johnCard = john.getCard(); + if (johnCard.equals(card)) { + return temp; } + temp = john; + john = john.getNext(); + } + return null; + } + + + public void removeSet(Card c1, Card c2 , Card c3) { + //got help from Hailey Kester in lab + TableNode temp = head; + TableNode john = null; + + if (!c1.isSet(c2, c3)) { + return; + } + if(!onTable(c1)) { + return; + } + if(!onTable(c2)) { + return; + } + if(!onTable(c3)) { + return; } - return; + removeCard(c1); + removeCard(c2); + removeCard(c3); + + } public int numCards() { @@ -94,37 +103,37 @@ public int numCards() { public Card getCard(int index) { TableNode temp = head; - if (temp == null) { + if (index >= isLength || temp == null) { return null; } - for (int d = 0; d < index; d++) { - temp = temp.getNext(); - if (temp == null) { - return null; - } - } - return temp.getCard(); + if (index == 0) { + return temp.getCard(); + } + else { + for (int i = 0; i < index; i++) { + temp = temp.getNext(); + } + return temp.getCard(); + } } public int numSets() { - int isSet = 0; - int numCards = numCards(); - for (int a = 0; a < numCards - 2; a++) { - for (int b = 1; b < numCards - 1; b++) { - for (int c = 2; c < numCards; c++) { - - Card card1 = getCard(a); - Card card2 = getCard(b); - Card card3 = getCard(c); + int theSet = 0; + for (int a = 0; a < isLength - 2; a++) { + for (int b = a + 1; b < isLength - 1; b++) { + for (int c = b + 1; c < isLength; c++) { + Card c1 = getCard(a); + Card c2 = getCard(b); + Card c3 = getCard(c); - if (card1.isSet(card2,card3)) { - isSet += 1; + if(c1.isSet(c2, c3)) { + theSet += 1; } } } } - return isSet; + return theSet; } } \ No newline at end of file From d17ad1f21c1e2a18f4aec39a0c733b871670a201 Mon Sep 17 00:00:00 2001 From: John Ferguson Date: Wed, 29 Apr 2015 10:07:43 -0400 Subject: [PATCH 6/6] Monte Carlo Simulation Done --- src/MonteCarloSimulation.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/MonteCarloSimulation.java diff --git a/src/MonteCarloSimulation.java b/src/MonteCarloSimulation.java new file mode 100644 index 0000000..a470350 --- /dev/null +++ b/src/MonteCarloSimulation.java @@ -0,0 +1,26 @@ +public class MonteCarloSimulation { + + public static void main(String[] args) { + + double avgSets = 0; + int a = 0; + while (a <= 1000001) { + Game g1 = new Game(); + avgSets += g1.numSets(); + } + System.out.println("Avg # of sets is " + avgSets); + + double avgCards = 0; + int b = 0; + while (b <= 100001) { + Game g2 = new Game(); + while(g2.isGameOver() == false) { + g2.playRound(); + } + avgCards += g2.numCards(); + a++; + } + System.out.println("Avg # of cards is " + avgCards); + } +} + \ No newline at end of file