From 0dde408d01a2e4391a0a50535824891d55015bb2 Mon Sep 17 00:00:00 2001 From: emilybache Date: Fri, 12 Oct 2012 15:58:55 +0200 Subject: [PATCH] C++ version of Yahtzee Kata by Jon Jagger. Taken from http://cyber-dojo.com/?id=57FFF6CEE2 --- Yahtzee/cpp/makefile | 6 + Yahtzee/cpp/run.tests | Bin 0 -> 24820 bytes Yahtzee/cpp/yahtzee.cpp | 251 ++++++++++++++++++++++++++++++++++ Yahtzee/cpp/yahtzee.hpp | 33 +++++ Yahtzee/cpp/yahtzee.tests.cpp | 153 +++++++++++++++++++++ 5 files changed, 443 insertions(+) create mode 100644 Yahtzee/cpp/makefile create mode 100755 Yahtzee/cpp/run.tests create mode 100644 Yahtzee/cpp/yahtzee.cpp create mode 100644 Yahtzee/cpp/yahtzee.hpp create mode 100644 Yahtzee/cpp/yahtzee.tests.cpp diff --git a/Yahtzee/cpp/makefile b/Yahtzee/cpp/makefile new file mode 100644 index 00000000..29429df5 --- /dev/null +++ b/Yahtzee/cpp/makefile @@ -0,0 +1,6 @@ +run.tests.output : run.tests + ./run.tests + +run.tests : *.cpp + g++ -Wall -Werror -O *.cpp -o run.tests + diff --git a/Yahtzee/cpp/run.tests b/Yahtzee/cpp/run.tests new file mode 100755 index 0000000000000000000000000000000000000000..7f78da1fc3afbaf3b70df68ef0c7528c1873b89b GIT binary patch literal 24820 zcmeHP4|G)3nZIvl2%`ojC@QwKq$-*yhD^dhphjn41|~H^B!~#o$1qGtx|2+pKOu0i z8$045jbmx0UDsM=x2?pi?zX01***czI*SRdG93z z@N`elo-;S+y?ej=`@Zjf_q%`IefPf1YiIs=b|hnpm9Y*BV{A08G&0t)&mqOwHMsn^ zRJG1C+qcL!Z!YB;gJL9yq)1OY3Q*PgzJ>FREL`4g%wv*cY9&9s(L;1Jv!7a>|#YS4>S*wrs|VkSq$V`qmdP`OKl58 z(Ou4^uS95J%x&s-TE2``bwxzijR)x~fjsr&agv{CeLbnajglBes@f7(W2>8&MZ#)p zJU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x``D@XCSMJYz7ppG#bdbIsK`qqeOZC}qVX>EURj-<7HzWX&??)OC`t?m0g zC~0l~k3KUa{n|d@(~{Qq1Ai!KZC{YSaw7g#xj#r}5=3kJgvTVU?H8Vvw6H z+dsTs(wpQy=0r(r`7f;afPOpOExsd^JZj?adSayzzp5Q_{=v864psNct&BQ`-^$ z{nrTmdP#pu(p8dvLeh6h`smeye}$x9m--%*v{%~qq@>@M{M#gbGyWHg>^UImLsI{H zl3w%~fm`8wvTv-!$4Yva#7iYTTH@1*hCj9QfLRIa&Z<*-g0;BwWCVB&>JF@y8H_=a<=x2m{ z*8XiKdY7QH`VN`!H%+t~)%M_;fomqNS-587^5d$(^#xpa;G%ybpzki`;PT?~;kpag zTwDllH*OcJr({n}B>G<=GwWg5O06`9kr z->ed?#)A!NITEvL=g#ods%nkOmqfE?&eZ)pb2wDR%sJD@bBk(q>U>oy{}o(S6_B&i zSo~nzX!Bs)SkXcFApe*-sx&^P^&pT$7J1d*pRPV8SC?1{A)_AWR00}oomR{*1`JBDTZad0WqxT z^~hA1LLbD+wWtBoE%^2M)67d~1881x>p{HaiB-NS(^%n|6+>}VaJS@MZtx4&gWiKw z?KMfv72 + +int Yahtzee::Chance(int d1, int d2, int d3, int d4, int d5) +{ + int total = 0; + total += d1; + total += d2; + total += d3; + total += d4; + total += d5; + return total; +} + + +int Yahtzee::yahtzee(int dice[]) +{ + int counts[6] = {0,0,0,0,0,0}; + for (int i = 0; i != 5; i++) + counts[dice[i]-1]++; + for (int i = 0; i != 6; i++) + if (counts[i] == 5) + return 50; + return 0; +} + +int Yahtzee::Ones(int d1, int d2, int d3, int d4, int d5) { + int sum = 0; + if (d1 == 1) sum++; + if (d2 == 1) sum++; + if (d3 == 1) sum++; + if (d4 == 1) sum++; + if (d5 == 1) + sum++; + + return sum; +} + +int Yahtzee::Twos(int d1, int d2, int d3, int d4, int d5) { + int sum = 0; + if (d1 == 2) sum += 2; + if (d2 == 2) sum += 2; + if (d3 == 2) sum += 2; + if (d4 == 2) sum += 2; + if (d5 == 2) sum += 2; + return sum; +} + + +int Yahtzee::Threes(int d1, int d2, int d3, int d4, int d5) { + int s; + s = 0; + if (d1 == 3) s += 3; + if (d2 == 3) s += 3; + if (d3 == 3) s += 3; + if (d4 == 3) s += 3; + if (d5 == 3) s += 3; + return s; +} + +Yahtzee::Yahtzee() +{ +} + +Yahtzee::Yahtzee(int d1, int d2, int d3, int d4, int _5) +{ + dice = new int[5]; + dice[0] = d1; + dice[1] = d2; + dice[2] = d3; + dice[3] = d4; + dice[4] = _5; +} + +int Yahtzee::Fours() +{ + int sum; + sum = 0; + for (int at = 0; at != 5; at++) { + if (dice[at] == 4) { + sum += 4; + } + } + return sum; +} + + +int Yahtzee::Fives() +{ + int s = 0; + int i; + for (i = 0; i < 5; i++) + if (dice[i] == 5) + s = s + 5; + return s; +} + +int Yahtzee::sixes() +{ + int sum = 0; + for (int at = 0; at < 5; at++) + if (dice[at] == 6) + sum = sum + 6; + return sum; +} + +int Yahtzee::ScorePair(int d1, int d2, int d3, int d4, int d5) +{ + int counts[6] = {0,0,0,0,0,0}; + counts[d1-1]++; + counts[d2-1]++; + counts[d3-1]++; + counts[d4-1]++; + counts[d5-1]++; + int at; + for (at = 0; at != 6; at++) + if (counts[6-at-1] == 2) + return (6-at)*2; + return 0; +} + +int Yahtzee::TwoPair(int d1, int d2, int d3, int d4, int d5) +{ + int counts[6] = {0}; + counts[d1-1]++; + counts[d2-1]++; + counts[d3-1]++; + counts[d4-1]++; + counts[d5-1]++; + int n = 0; + int score = 0; + for (int i = 0; i < 6; i += 1) + if (counts[6-i-1] == 2) { + n++; + score += (6-i); + } + if (n == 2) + return score * 2; + else + return 0; +} + +int Yahtzee::FourOfAKind(int _1, int _2, int d3, int d4, int d5) +{ + int * tallies; + tallies = new int[6]; + tallies[0] = tallies[1] = tallies[2] = 0; + tallies[3] = tallies[4] = tallies[5] = 0; + tallies[_1-1]++; + tallies[_2-1]++; + tallies[d3-1]++; + tallies[d4-1]++; + tallies[d5-1]++; + for (int i = 0; i < 6; i++) + if (tallies[i] == 4) + return (i+1) * 4; + return 0; +} + +int Yahtzee::ThreeOfAKind(int d1, int d2, int d3, int d4, int d5) +{ + int * t; + t = new int[6]; + t[0] = t[1] = t[2] = 0; + t[3] = t[4] = t[5] = 0; + t[d1-1]++; + t[d2-1]++; + t[d3-1]++; + t[d4-1]++; + t[d5-1]++; + for (int i = 0; i < 6; i++) + if (t[i] == 3) + return (i+1) * 3; + return 0; +} + + +int Yahtzee::SmallStraight(int d1, int d2, int d3, int d4, int d5) +{ + int* tallies =new int[6]; + memset(tallies, 0, sizeof(int)*6); + tallies[d1-1] += 1; + tallies[d2-1] += 1; + tallies[d3-1] += 1; + tallies[d4-1] += 1; + tallies[d5-1] += 1; + if (tallies[0] == 1 && + tallies[1] == 1 && + tallies[2] == 1 && + tallies[3] == 1 && + tallies[4] == 1) + return 15; + return 0; +} + +int Yahtzee::LargeStraight(int d1, int d2, int d3, int d4, int d5) +{ + int* tallies = new int[6]; + memset(tallies, 0, sizeof(*tallies)*6); + tallies[d1-1] += 1; + tallies[d2-1] += 1; + tallies[d3-1] += 1; + tallies[d4-1] += 1; + tallies[d5-1] += 1; + if (tallies[1] == 1 && + tallies[2] == 1 && + tallies[3] == 1 && + tallies[4] == 1 + && tallies[5] == 1) + return 20; + return 0; +} + + +int Yahtzee::FullHouse(int d1, int d2, int d3, int d4, int d5) +{ + int* tallies; + bool _2 = false; + int i; + int _2_at = 0; + bool _3 = false; + int _3_at = 0; + + + + + tallies = new int[6]; + memset(tallies, 0, sizeof(int)*6); + tallies[d1-1] += 1; + tallies[d2-1] += 1; + tallies[d3-1] += 1; + tallies[d4-1] += 1; + tallies[d5-1] += 1; + + for (i = 0; i != 6; i += 1) + if (tallies[i] == 2) { + _2 = true; + _2_at = i+1; + } + + for (i = 0; i != 6; i += 1) + if (tallies[i] == 3) { + _3 = true; + _3_at = i+1; + } + + if (_2 && _3) + return _2_at * 2 + _3_at * 3; + else + return 0; +} diff --git a/Yahtzee/cpp/yahtzee.hpp b/Yahtzee/cpp/yahtzee.hpp new file mode 100644 index 00000000..c79dce48 --- /dev/null +++ b/Yahtzee/cpp/yahtzee.hpp @@ -0,0 +1,33 @@ +#ifndef YAHTZEE_INCLUDED +#define YATHZEE_INCLUDED + +class Yahtzee +{ +public: + + static int Chance(int d1, int d2, int d3, int d4, int d5); + static int yahtzee(int dice[]); + static int Ones(int d1, int d2, int d3, int d4, int d5); + static int Twos(int d1, int d2, int d3, int d4, int d5); + static int Threes(int d1, int d2, int d3, int d4, int d5); + +protected: + int * dice; +public: + Yahtzee(); + Yahtzee(int d1, int d2, int d3, int d4, int _5); + int Fours(); + int Fives(); + int sixes(); + int ScorePair(int d1, int d2, int d3, int d4, int d5); + static int TwoPair(int d1, int d2, int d3, int d4, int d5); + static int FourOfAKind(int _1, int _2, int d3, int d4, int d5); + static int ThreeOfAKind(int d1, int d2, int d3, int d4, int d5); + + static int SmallStraight(int d1, int d2, int d3, int d4, int d5); + static int LargeStraight(int d1, int d2, int d3, int d4, int d5); + static int FullHouse(int d1, int d2, int d3, int d4, int d5); + +}; + +#endif \ No newline at end of file diff --git a/Yahtzee/cpp/yahtzee.tests.cpp b/Yahtzee/cpp/yahtzee.tests.cpp new file mode 100644 index 00000000..42878ea9 --- /dev/null +++ b/Yahtzee/cpp/yahtzee.tests.cpp @@ -0,0 +1,153 @@ +#include "yahtzee.hpp" +#include +#include + +static void Chance_scores_sum_of_all_dice(void) +{ + int expected = 15; + int actual = Yahtzee().Chance(2,3,4,5,1); + assert(expected == actual); + assert(16 == Yahtzee().Chance(3,3,4,5,1)); +} + +static int * ints(int a, int b, int c, int d, int e) +{ + int * r = new int[5]; + r[0] = a; + r[1] = b; + r[2] = c; + r[3] = d; + r[4] = e; + return r; +} + +static void Yahtzee_scores_50(void) +{ + int expected = 50; + int actual = Yahtzee().yahtzee(ints(4,4,4,4,4)); + assert(expected == actual); + assert(50 == Yahtzee().yahtzee(ints(6,6,6,6,6))); + assert(0 == Yahtzee().yahtzee(ints(6,6,6,6,3))); +} + +static void Test_1s() +{ + assert(Yahtzee().Ones(1,2,3,4,5) == 1); + assert(2 == Yahtzee().Ones(1,2,1,4,5)); + assert(0 == Yahtzee().Ones(6,2,2,4,5)); + assert(4 == Yahtzee().Ones(1,2,1,1,1)); +} + +static void test_2s() +{ + assert(4 == Yahtzee().Twos(1,2,3,2,6)); + assert(10 == Yahtzee().Twos(2,2,2,2,2)); +} + +static void test_threes() +{ + assert(6 == Yahtzee().Threes(1,2,3,2,3)); + assert(12 == Yahtzee().Threes(2,3,3,3,3)); +} + +static void fours_test() +{ + assert(12 == (new Yahtzee(4,4,4,5,5))->Fours()); + assert(8 == (new Yahtzee(4,4,5,5,5))->Fours()); + assert(4 == (*new Yahtzee(4,5,5,5,5)).Fours()); +} + +static void fives() { + assert(10 == (new Yahtzee(4,4,4,5,5))->Fives()); + assert(15 == Yahtzee(4,4,5,5,5).Fives()); + assert(20 == Yahtzee(4,5,5,5,5).Fives()); +} + +static void sixes_test() +{ + assert(0 == Yahtzee(4,4,4,5,5).sixes()); + assert(6 == Yahtzee(4,4,6,5,5).sixes()); + assert(18 == Yahtzee(6,5,6,6,5).sixes()); +} + +static void one_pair() +{ + assert(6 == Yahtzee().ScorePair(3,4,3,5,6)); + assert(10 == Yahtzee().ScorePair(5,3,3,3,5)); + assert(12 == Yahtzee().ScorePair(5,3,6,6,5)); +} + +static void two_Pair() +{ + assert(16 == Yahtzee().TwoPair(3,3,5,4,5)); + assert(0 == Yahtzee().TwoPair(3,3,5,5,5)); +} + +static void three_of_a_kind() +{ + assert(9 == Yahtzee().ThreeOfAKind(3,3,3,4,5)); + assert(15 == Yahtzee().ThreeOfAKind(5,3,5,4,5)); + assert(0 == Yahtzee::ThreeOfAKind(3,3,3,3,5)); +} + +static void four_of_a_knd() +{ + assert(12 == Yahtzee::FourOfAKind(3,3,3,3,5)); + assert(20 == Yahtzee::FourOfAKind(5,5,5,4,5)); + assert(0 == Yahtzee::FourOfAKind(3,3,3,3,3)); +} + +static void smallStraight() +{ + assert(15 == Yahtzee::SmallStraight(1,2,3,4,5)); + assert(15 == Yahtzee::SmallStraight(2,3,4,5,1)); + assert(0 == Yahtzee().SmallStraight(1,2,2,4,5)); +} + +static void largeStraight() +{ + assert(20 == Yahtzee::LargeStraight(6,2,3,4,5)); + assert(20 == Yahtzee().LargeStraight(2,3,4,5,6)); + assert(0== Yahtzee::LargeStraight(1,2,2,4,5)); +} + + +static void fullHouse() +{ + assert(18 == Yahtzee().FullHouse(6,2,2,2,6)); + assert(0 == Yahtzee().FullHouse(2,3,4,5,6)); +} + +typedef void test(); + +static test * tests[ ] = +{ + Chance_scores_sum_of_all_dice, + Yahtzee_scores_50, + Test_1s, + test_2s, + test_threes, + fours_test, + fives, + sixes_test, + one_pair, + two_Pair, + three_of_a_kind, + four_of_a_knd, + smallStraight, + largeStraight, + fullHouse, + static_cast(0), +}; + +int main() +{ + size_t at = 0; + while (tests[at]) + { + tests[at++](); + std::cout << '.'; + } + std::cout << std::endl << at << " tests passed" << std::endl; + return 0; +} \ No newline at end of file