diff --git a/Cribbage/cribbage.log b/Cribbage/cribbage.log index bbca90486b9cbda7dfd8c71c2596fddc88b571b5..aa5c683897821af5648fa8f30f02c93924490e2b 100644 --- a/Cribbage/cribbage.log +++ b/Cribbage/cribbage.log @@ -1,24 +1,33 @@ -seed,55510 +seed,30006 cribbage.RandomPlayer,P0 cribbage.RandomPlayer,P1 -deal,P0,[2C,2H,7C,QC,QD,KH] -deal,P1,[AD,AH,TD,JS,QH,KC] -discard,P0,[2C,QC] -discard,P1,[JS,KC] -starter,8H - - -show,P0,8H+[2H,7C,QD,KH] -score,P0,2,2,fifteen,[7C,8H] -show,P1,8H+[AD,AH,TD,QH] -score,P1,2,2,pair2,[AD,AH] -show,P1,8H+[2C,JS,QC,KC] -score,P1,5,3,run3,[JS,QC,KC] - - -show,P0,8H+[2H,7C,QD,KH] -score,P0,2,2,fifteen,[7C,8H] -show,P1,8H+[AD,AH,TD,QH] -score,P1,7,2,pair2,[AD,AH] -show,P1,8H+[2C,JS,QC,KC] -score,P1,10,3,run3,[JS,QC,KC] +deal,P0,[AH,3H,4D,4S,7D,8C] +deal,P1,[AS,3S,6S,9S,TS,JS] +discard,P0,[3H,7D] +discard,P1,[3S,9S] +starter,3D +play,P0,4,4D +play,P1,10,6S +play,P0,14,4S +play,P1,15,AS +score,P1,2,2,fifteen +play,P0,23,8C +score,P0,1,1,go +play,P0,24,AH +score,P0,2,1,go +score,P0,3,1,go +play,P1,10,JS +score,P1,3,1,go +play,P1,20,TS +score,P1,4,1,go +show,P0,3D+[AH,4D,4S,8C] +score,P0,5,2,fifteen,[3D,4D,8C] +score,P0,5,2,fifteen,[3D,4S,8C] +score,P0,9,2,pair2,[4D,4S] +show,P1,3D+[AS,6S,TS,JS] +score,P1,8,4,flush4,[AS,6S,TS,JS] +show,P1,3D+[3H,3S,7D,9S] +score,P1,10,2,fifteen,[3H,3S,9S] +score,P1,10,2,fifteen,[3D,3H,9S] +score,P1,10,2,fifteen,[3D,3S,9S] +score,P1,20,6,pair3,[3D,3H,3S] diff --git a/Cribbage/cribbage.properties b/Cribbage/cribbage.properties index 07cd098a1569820f205ce904b49647c4169e77ce..fba8e4a48c76d2488bd03f688b01f865c06b3902 100644 --- a/Cribbage/cribbage.properties +++ b/Cribbage/cribbage.properties @@ -1,7 +1,7 @@ -Seed=55510 +#Seed=55510 #Seed=12345 #Seed=1248 -#Seed=30006 +Seed=30006 #Animate=true Animate=false #Player0=cribbage.HumanPlayer diff --git a/Cribbage/out/production/Cribbage/cribbage/Cribbage.class b/Cribbage/out/production/Cribbage/cribbage/Cribbage.class index 8cecbea403ee3f3cb6c9e6a242f396b09e7cd981..741a399389144ae4f656afaf3367d4e2d2a1f342 100644 Binary files a/Cribbage/out/production/Cribbage/cribbage/Cribbage.class and b/Cribbage/out/production/Cribbage/cribbage/Cribbage.class differ diff --git a/Cribbage/out/production/Cribbage/cribbage/CribbageHandCards.class b/Cribbage/out/production/Cribbage/cribbage/CribbageHandCards.class index 26e29fc6065d3e179572e4dcf322f321f479036d..2685c46cb8a8e8dc8f7683a34cba780e8f9fd284 100644 Binary files a/Cribbage/out/production/Cribbage/cribbage/CribbageHandCards.class and b/Cribbage/out/production/Cribbage/cribbage/CribbageHandCards.class differ diff --git a/Cribbage/out/production/Cribbage/cribbage/Fifteens.class b/Cribbage/out/production/Cribbage/cribbage/Fifteens.class deleted file mode 100644 index dc654828575dfd346092433ff70c2b8058cf86b5..0000000000000000000000000000000000000000 Binary files a/Cribbage/out/production/Cribbage/cribbage/Fifteens.class and /dev/null differ diff --git a/Cribbage/out/production/Cribbage/cribbage/Flush.class b/Cribbage/out/production/Cribbage/cribbage/Flush.class deleted file mode 100644 index f94ad1b49f6bbbf5a1b422e3a1dc7f7fcff16793..0000000000000000000000000000000000000000 Binary files a/Cribbage/out/production/Cribbage/cribbage/Flush.class and /dev/null differ diff --git a/Cribbage/out/production/Cribbage/cribbage/HandCards.class b/Cribbage/out/production/Cribbage/cribbage/HandCards.class index 5cbf91854a3e1cbf19341e8987edf611c35daa00..5b6b497d0cbcce41d378e0b957030a1f0fed3c90 100644 Binary files a/Cribbage/out/production/Cribbage/cribbage/HandCards.class and b/Cribbage/out/production/Cribbage/cribbage/HandCards.class differ diff --git a/Cribbage/out/production/Cribbage/cribbage/Jack.class b/Cribbage/out/production/Cribbage/cribbage/Jack.class deleted file mode 100644 index abe4dad483fb43696ebb2227a7304174a698edab..0000000000000000000000000000000000000000 Binary files a/Cribbage/out/production/Cribbage/cribbage/Jack.class and /dev/null differ diff --git a/Cribbage/out/production/Cribbage/cribbage/Pairs.class b/Cribbage/out/production/Cribbage/cribbage/Pairs.class deleted file mode 100644 index ac63c6a5a98e123e9be0b2e588ac15b23c4d70dc..0000000000000000000000000000000000000000 Binary files a/Cribbage/out/production/Cribbage/cribbage/Pairs.class and /dev/null differ diff --git a/Cribbage/out/production/Cribbage/cribbage/Rule.class b/Cribbage/out/production/Cribbage/cribbage/Rule.class index 2b5ad62c54a6cb39677de9f54535ddc50493be74..9fb1a004c3430dffa7a9108b62d08e40f4709523 100644 Binary files a/Cribbage/out/production/Cribbage/cribbage/Rule.class and b/Cribbage/out/production/Cribbage/cribbage/Rule.class differ diff --git a/Cribbage/out/production/Cribbage/cribbage/Runs.class b/Cribbage/out/production/Cribbage/cribbage/Runs.class deleted file mode 100644 index 1a0733a9f6dfc7184a93b5e90f3937cd2001d164..0000000000000000000000000000000000000000 Binary files a/Cribbage/out/production/Cribbage/cribbage/Runs.class and /dev/null differ diff --git a/Cribbage/out/production/Cribbage/cribbage/playPairs.class b/Cribbage/out/production/Cribbage/cribbage/playPairs.class new file mode 100644 index 0000000000000000000000000000000000000000..ed9de86dc8ac3de09d1aa5bc68c9ff3ff44ceb70 Binary files /dev/null and b/Cribbage/out/production/Cribbage/cribbage/playPairs.class differ diff --git a/Cribbage/out/production/Cribbage/cribbage/playRuns.class b/Cribbage/out/production/Cribbage/cribbage/playRuns.class new file mode 100644 index 0000000000000000000000000000000000000000..bb9088bcc8bdd041445206300219e1b5b050958b Binary files /dev/null and b/Cribbage/out/production/Cribbage/cribbage/playRuns.class differ diff --git a/Cribbage/out/production/Cribbage/cribbage/playTotal.class b/Cribbage/out/production/Cribbage/cribbage/playTotal.class new file mode 100644 index 0000000000000000000000000000000000000000..05921179683373afdd89e7e8e879a1344742b4cf Binary files /dev/null and b/Cribbage/out/production/Cribbage/cribbage/playTotal.class differ diff --git a/Cribbage/out/production/Cribbage/cribbage/showFifteens.class b/Cribbage/out/production/Cribbage/cribbage/showFifteens.class new file mode 100644 index 0000000000000000000000000000000000000000..65b8f4eb479fd0030081c0fcb7b691abcf22e2b6 Binary files /dev/null and b/Cribbage/out/production/Cribbage/cribbage/showFifteens.class differ diff --git a/Cribbage/out/production/Cribbage/cribbage/showFlush.class b/Cribbage/out/production/Cribbage/cribbage/showFlush.class new file mode 100644 index 0000000000000000000000000000000000000000..9f3cd6aa18548eca94216bd935b882d9633a51fa Binary files /dev/null and b/Cribbage/out/production/Cribbage/cribbage/showFlush.class differ diff --git a/Cribbage/out/production/Cribbage/cribbage/showJack.class b/Cribbage/out/production/Cribbage/cribbage/showJack.class new file mode 100644 index 0000000000000000000000000000000000000000..69b8780bf16d8fe63e4b3bec29ee77592d605600 Binary files /dev/null and b/Cribbage/out/production/Cribbage/cribbage/showJack.class differ diff --git a/Cribbage/out/production/Cribbage/cribbage/showPairs.class b/Cribbage/out/production/Cribbage/cribbage/showPairs.class new file mode 100644 index 0000000000000000000000000000000000000000..fb4ec174417c7ae2bac7ba05e85e4938c1c0b8d3 Binary files /dev/null and b/Cribbage/out/production/Cribbage/cribbage/showPairs.class differ diff --git a/Cribbage/out/production/Cribbage/cribbage/showRuns.class b/Cribbage/out/production/Cribbage/cribbage/showRuns.class new file mode 100644 index 0000000000000000000000000000000000000000..0a22c29b69bf2cd6f4709936ad8d4ce735286f4e Binary files /dev/null and b/Cribbage/out/production/Cribbage/cribbage/showRuns.class differ diff --git a/Cribbage/src/cribbage/Cribbage.java b/Cribbage/src/cribbage/Cribbage.java index bc3d9cd54f21da60a704fd6d6530a08bff741ba1..522a7faf719d57c5c5b1aba3b3be48d0aab412f0 100644 --- a/Cribbage/src/cribbage/Cribbage.java +++ b/Cribbage/src/cribbage/Cribbage.java @@ -272,6 +272,7 @@ private void play() { } else { s.lastPlayer = currentPlayer; // last Player to play a card in this segment transfer(nextCard, s.segment); + log.writeLog(String.format("play,P%d,%d,%s", currentPlayer, total((s.segment)), canonical(nextCard))); if (total(s.segment) == thirtyone) { // lastPlayer gets 2 points for a 31 s.newSegment = true; @@ -282,7 +283,41 @@ private void play() { currentPlayer = (currentPlayer+1) % 2; } } + // both players have no cards + if ((players[0].emptyHand() && players[1].emptyHand())) { + s.go = true; + } + } + + // copy cards of segment + Hand sCopy = new Hand(deck); + for (Card c : s.segment.getCardList()){ + sCopy.insert(c.clone(), false); + } + + // initialize + HandCards segmentCards = new CribbageHandCards(); + modifyPlay(segmentCards); + + //set player + if (s.lastPlayer == 0){ + segmentCards.setPlayer(0); + segmentCards.setScore(scores[0]); + } else { + segmentCards.setPlayer(1); + segmentCards.setScore(scores[1]); + } + //check go + if (s.go){ + segmentCards.sendHandCards(sCopy, starter, deck); + } else { + Hand empty = new Hand(deck); + segmentCards.sendHandCards(sCopy, empty, deck); } + //scoring + scores[s.lastPlayer] = segmentCards.scoreHandCards(); + updateScore(s.lastPlayer); + if (s.newSegment) { segments.add(s.segment); s.reset(segments); @@ -295,35 +330,40 @@ void showHandsCrib() { log.writeLog(String.format("show,P0,%s+%s", canonical(starter.getLast()), canonical(handsCopy[0]))); HandCards p0HandCards = new CribbageHandCards(); p0HandCards.setPlayer(0); - modifySubject(p0HandCards); - p0HandCards.sendHandCards(handsCopy[0], starter); - scores[0] += p0HandCards.scoreHandCards(); + p0HandCards.setScore(scores[0]); + modifyShow(p0HandCards); + p0HandCards.sendHandCards(handsCopy[0], starter, deck); + scores[0] = p0HandCards.scoreHandCards(); updateScore(0); // score player 1 (dealer) log.writeLog(String.format("show,P1,%s+%s", canonical(starter.getLast()), canonical(handsCopy[1]))); HandCards p1HandCards = new CribbageHandCards(); p1HandCards.setPlayer(1); - modifySubject(p1HandCards); - p1HandCards.sendHandCards(handsCopy[1], starter); + p1HandCards.setScore(scores[1]); + modifyShow(p1HandCards); + p1HandCards.sendHandCards(handsCopy[1], starter, deck); p1HandCards.scoreHandCards(); // score crib (for dealer) log.writeLog(String.format("show,P1,%s+%s", canonical(starter.getLast()), canonical(crib))); - p1HandCards.sendHandCards(crib, starter); - scores[1] += p1HandCards.scoreHandCards(); + p1HandCards.sendHandCards(crib, starter, deck); + scores[1] = p1HandCards.scoreHandCards(); updateScore(1); } -void modifySubject(HandCards playersHandCards){ - Rule fifteens = new Fifteens(); - Rule runs = new Runs(); - Rule pairs = new Pairs(); - Rule flush = new Flush(); - Rule jack = new Jack(); - playersHandCards.addRule(fifteens); - playersHandCards.addRule(runs); - playersHandCards.addRule(pairs); - playersHandCards.addRule(flush); - playersHandCards.addRule(jack); +void modifyShow(HandCards playersHandCards){ + playersHandCards.addRule(new showFifteens()); + playersHandCards.addRule(new showRuns()); + playersHandCards.addRule(new showPairs()); + playersHandCards.addRule(new showFlush()); + playersHandCards.addRule(new showJack()); +} + +void modifyPlay(HandCards playersHandCards){ + Rule playsss = new playTotal(); + + playersHandCards.addRule(new playTotal()); + playersHandCards.addRule(new playRuns()); + playersHandCards.addRule(new playPairs()); } public Cribbage() diff --git a/Cribbage/src/cribbage/CribbageHandCards.java b/Cribbage/src/cribbage/CribbageHandCards.java index e8e6301fa7d16dfa6e6ec9539fbecbaf0c3017be..d499e56a8dd219d56926ed3b85930bec72d1374c 100644 --- a/Cribbage/src/cribbage/CribbageHandCards.java +++ b/Cribbage/src/cribbage/CribbageHandCards.java @@ -1,5 +1,6 @@ package cribbage; +import ch.aplu.jcardgame.Deck; import ch.aplu.jcardgame.Hand; import java.util.ArrayList; @@ -26,10 +27,13 @@ public class CribbageHandCards implements HandCards{ } @Override - public void sendHandCards(Hand hand, Hand starter){ - rules.forEach((rule) -> rule.receiveHandCards(hand, starter)); + public void sendHandCards(Hand hand, Hand starter, Deck deck){ + rules.forEach((rule) -> rule.receiveHandCards(hand, starter, deck)); } + @Override + public void setScore(int score){this.score = score;} + @Override public void setPlayer(int player){ this.player = player; diff --git a/Cribbage/src/cribbage/HandCards.java b/Cribbage/src/cribbage/HandCards.java index 31360d387a07900521c3ec7fe56b12e6c2fd6e36..c4da2f582eed465c2007b7207df59a362c33d2c7 100644 --- a/Cribbage/src/cribbage/HandCards.java +++ b/Cribbage/src/cribbage/HandCards.java @@ -1,5 +1,6 @@ package cribbage; +import ch.aplu.jcardgame.Deck; import ch.aplu.jcardgame.Hand; public interface HandCards { @@ -8,9 +9,11 @@ public interface HandCards { void removeRule(Rule rule); - void sendHandCards(Hand hand, Hand starter); + void sendHandCards(Hand hand, Hand starter, Deck deck); void setPlayer(int player); + void setScore(int score); + int scoreHandCards(); } diff --git a/Cribbage/src/cribbage/Rule.java b/Cribbage/src/cribbage/Rule.java index e6dffca7e9993a6b7f0dde707e8013018b04e36a..faf805631832223724b6c07142cd3de1cf609f3f 100644 --- a/Cribbage/src/cribbage/Rule.java +++ b/Cribbage/src/cribbage/Rule.java @@ -1,13 +1,13 @@ package cribbage; +import ch.aplu.jcardgame.Deck; import ch.aplu.jcardgame.Hand; -import cribbage.IPlayer; -import cribbage.LogGenerator; public interface Rule { LogGenerator log = LogGenerator.getLog(); - void receiveHandCards(Hand hand, Hand starter); + void receiveHandCards(Hand hand, Hand starter, Deck deck); + int calculateScore(int playerId, int currentScore); } diff --git a/Cribbage/src/cribbage/playPairs.java b/Cribbage/src/cribbage/playPairs.java new file mode 100644 index 0000000000000000000000000000000000000000..f2fdac1db169dcc421d93a83e0e1e3da776fa037 --- /dev/null +++ b/Cribbage/src/cribbage/playPairs.java @@ -0,0 +1,56 @@ +package cribbage; + +import ch.aplu.jcardgame.Card; +import ch.aplu.jcardgame.Deck; +import ch.aplu.jcardgame.Hand; + +public class playPairs implements Rule{ + + Hand hand; + + public playPairs(){} + + @Override + public void receiveHandCards(Hand hand, Hand starter, Deck deck){ + this.hand = new Hand(deck); + for (Card c : hand.getCardList()){ + this.hand.insert(c.clone(), false); + } + } + + @Override + public int calculateScore(int playerId, int currentScore){ + int score = 0; + int len; + + while ((len = hand.getNumberOfCards()) > 0){ + Hand[] pairs; + if (len == 4){ + pairs = hand.extractQuads(); + if (pairs.length != 0) { + score += 12; + break; + } + } else if (len == 3){ + pairs = hand.extractTrips(); + if (pairs.length != 0){ + score += 6; + break; + } + } else if (len == 2){ + pairs = hand.extractPairs(); + if (pairs.length != 0){ + score += 2; + break; + } + } + hand.removeFirst(false); + } + if (score != 0){ + log.writeLog(String.format("score,P%d,%d,%d,pair%d", playerId, currentScore + score, score, len)); + } + + return score; + } + +} diff --git a/Cribbage/src/cribbage/playRuns.java b/Cribbage/src/cribbage/playRuns.java new file mode 100644 index 0000000000000000000000000000000000000000..32068fabac4c6dbf9f72da4b8a996b2431b065cc --- /dev/null +++ b/Cribbage/src/cribbage/playRuns.java @@ -0,0 +1,38 @@ +package cribbage; + +import ch.aplu.jcardgame.Card; +import ch.aplu.jcardgame.Deck; +import ch.aplu.jcardgame.Hand; + +public class playRuns implements Rule{ + + Hand hand = new Hand(null); + + public playRuns(){} + + @Override + public void receiveHandCards(Hand hand, Hand starter, Deck deck){ + this.hand = new Hand(deck); + for (Card c : hand.getCardList()){ + this.hand.insert(c.clone(), false); + } + } + + @Override + public int calculateScore(int playerId, int currentScore){ + + int score = 0; + int len; + + while ((len = hand.getNumberOfCards()) > 0){ + Hand[] runs = hand.extractSequences(len); + if (runs.length != 0){ + score += len; + log.writeLog(String.format("score,P%d,%d,%d,run%d", playerId, currentScore + score, score, len)); + break; + } + hand.removeFirst(false); + } + return score; + } +} diff --git a/Cribbage/src/cribbage/playTotal.java b/Cribbage/src/cribbage/playTotal.java new file mode 100644 index 0000000000000000000000000000000000000000..f1816987d811e974ca87db8074c92b2b061615eb --- /dev/null +++ b/Cribbage/src/cribbage/playTotal.java @@ -0,0 +1,53 @@ +package cribbage; + +import ch.aplu.jcardgame.Card; +import ch.aplu.jcardgame.Deck; +import ch.aplu.jcardgame.Hand; + +public class playTotal implements Rule{ + + Hand hand = new Hand(null); + Hand starter; + boolean go = false; + final int fifteen = 15; + final int thirtyone = 31; + + public playTotal(){} + + @Override + public void receiveHandCards(Hand hand, Hand starter, Deck deck){ + this.hand = new Hand(deck); + for (Card c : hand.getCardList()){ + this.hand.insert(c.clone(), false); + } + this.starter = starter; + setGo(); + } + + private void setGo(){ + if (starter.getNumberOfCards() == 1){ + go = true; + } + } + + @Override + public int calculateScore(int playerId, int currentScore){ + int score = 0; + + int total = Cribbage.cribbage.total(hand); + + if (total == fifteen){ + score += 2; + log.writeLog(String.format("score,P%d,%d,%d,fifteen", playerId, currentScore + score, score)); + } else if (total == thirtyone){ + score += 2; + log.writeLog(String.format("score,P%d,%d,%d,thirtyone", playerId, currentScore + score, score)); + } else if (go){ + score += 1; + log.writeLog(String.format("score,P%d,%d,%d,go", playerId, currentScore + score, score)); + go = false; + } + + return score; + } +} diff --git a/Cribbage/src/cribbage/Fifteens.java b/Cribbage/src/cribbage/showFifteens.java similarity index 81% rename from Cribbage/src/cribbage/Fifteens.java rename to Cribbage/src/cribbage/showFifteens.java index 3efe55ca05ddbd744d9c90f3f9eeec0e59f86a1c..41f839af751721686467d80eacfde25acace9aa6 100644 --- a/Cribbage/src/cribbage/Fifteens.java +++ b/Cribbage/src/cribbage/showFifteens.java @@ -1,19 +1,23 @@ package cribbage; import ch.aplu.jcardgame.Card; +import ch.aplu.jcardgame.Deck; import ch.aplu.jcardgame.Hand; import java.util.ArrayList; -public class Fifteens implements Rule{ +public class showFifteens implements Rule{ - Hand hand; + Hand hand = new Hand(null); - public Fifteens(){} + public showFifteens(){} @Override - public void receiveHandCards(Hand hand, Hand starter){ - this.hand = hand; + public void receiveHandCards(Hand hand, Hand starter, Deck deck){ + this.hand = new Hand(deck); + for (Card c : hand.getCardList()){ + this.hand.insert(c.clone(), false); + } this.hand.insert(starter, false); } diff --git a/Cribbage/src/cribbage/Flush.java b/Cribbage/src/cribbage/showFlush.java similarity index 69% rename from Cribbage/src/cribbage/Flush.java rename to Cribbage/src/cribbage/showFlush.java index 9e764c0f2f69d17694644965e35e5af146ec6fbe..1212eff4678845694023ffccbcba0f1a44b64a33 100644 --- a/Cribbage/src/cribbage/Flush.java +++ b/Cribbage/src/cribbage/showFlush.java @@ -1,18 +1,22 @@ package cribbage; import ch.aplu.jcardgame.Card; +import ch.aplu.jcardgame.Deck; import ch.aplu.jcardgame.Hand; -public class Flush implements Rule{ +public class showFlush implements Rule{ - Hand hand; + Hand hand = new Hand(null); Card starter; - public Flush(){} + public showFlush(){} @Override - public void receiveHandCards(Hand hand, Hand starter){ - this.hand = hand; + public void receiveHandCards(Hand hand, Hand starter, Deck deck){ + this.hand = new Hand(deck); + for (Card c : hand.getCardList()){ + this.hand.insert(c.clone(), false); + } this.starter = starter.get(0); } diff --git a/Cribbage/src/cribbage/Jack.java b/Cribbage/src/cribbage/showJack.java similarity index 67% rename from Cribbage/src/cribbage/Jack.java rename to Cribbage/src/cribbage/showJack.java index d088bed4c31d065ebd971d5432295c89816ed22e..60afe24fdc4d67744adb7e0800c26c636191c2c8 100644 --- a/Cribbage/src/cribbage/Jack.java +++ b/Cribbage/src/cribbage/showJack.java @@ -1,19 +1,23 @@ package cribbage; import ch.aplu.jcardgame.Card; +import ch.aplu.jcardgame.Deck; import ch.aplu.jcardgame.Hand; -public class Jack implements Rule{ +public class showJack implements Rule{ - Hand hand; + Hand hand = new Hand(null); Card starter; - public Jack(){} + public showJack(){} @Override - public void receiveHandCards(Hand hand, Hand starter){ - this.hand = hand; + public void receiveHandCards(Hand hand, Hand starter, Deck deck){ + this.hand = new Hand(deck); + for (Card c : hand.getCardList()){ + this.hand.insert(c.clone(), false); + } this.starter = starter.get(0); } diff --git a/Cribbage/src/cribbage/Pairs.java b/Cribbage/src/cribbage/showPairs.java similarity index 73% rename from Cribbage/src/cribbage/Pairs.java rename to Cribbage/src/cribbage/showPairs.java index c27727b4d6865e585644a244bc3e546ae8b47d32..63f6444b87a6841106b6ca96e1a373862c338946 100644 --- a/Cribbage/src/cribbage/Pairs.java +++ b/Cribbage/src/cribbage/showPairs.java @@ -1,17 +1,22 @@ package cribbage; +import ch.aplu.jcardgame.Card; +import ch.aplu.jcardgame.Deck; import ch.aplu.jcardgame.Hand; -public class Pairs implements Rule{ +public class showPairs implements Rule{ - Hand hand; + Hand hand = new Hand(null); - public Pairs(){} + public showPairs(){} @Override - public void receiveHandCards(Hand hand, Hand starter){ - this.hand = hand; + public void receiveHandCards(Hand hand, Hand starter, Deck deck){ + this.hand = new Hand(deck); + for (Card c : hand.getCardList()){ + this.hand.insert(c.clone(), false); + } this.hand.insert(starter, false); } diff --git a/Cribbage/src/cribbage/Runs.java b/Cribbage/src/cribbage/showRuns.java similarity index 63% rename from Cribbage/src/cribbage/Runs.java rename to Cribbage/src/cribbage/showRuns.java index b8d3efd647c45a7ccaabb79930a7d5e6a9ce8847..16ae0f6163a153dab20139d9b029c9a73d837ad2 100644 --- a/Cribbage/src/cribbage/Runs.java +++ b/Cribbage/src/cribbage/showRuns.java @@ -1,16 +1,21 @@ package cribbage; +import ch.aplu.jcardgame.Card; +import ch.aplu.jcardgame.Deck; import ch.aplu.jcardgame.Hand; -public class Runs implements Rule{ +public class showRuns implements Rule{ - Hand hand; + Hand hand = new Hand(null); - public Runs(){} + public showRuns(){} @Override - public void receiveHandCards(Hand hand, Hand starter){ - this.hand = hand; + public void receiveHandCards(Hand hand, Hand starter, Deck deck){ + this.hand = new Hand(deck); + for (Card c : hand.getCardList()){ + this.hand.insert(c.clone(), false); + } this.hand.insert(starter, false); }