1- #include <stdio.h>
2- #include <stdlib.h>
31#include <assert.h>
4- #include <string.h>
52#include <phevaluator/phevaluator.h>
63#include <phevaluator/rank.h>
4+ #include <stdio.h>
5+ #include <stdlib.h>
6+ #include <string.h>
77
88/*
99 * This C code is a demonstration of how to calculate the card id, which will
1010 * be used as the parameter in the evaluator. It also shows how to use the
1111 * return value to determine which hand is the stronger one.
1212 */
13- int main ()
14- {
15- /*
16- * In this example we use a scenario in the game Texas Holdem:
17- * Community cards: 9c 4c 4s 9d 4h (both players share these cards)
18- * Player 1: Qc 6c
19- * Player 2: 2c 9h
20- *
21- * Both players have full houses, but player 1 has only a four full house
22- * while player 2 has a nine full house.
13+ int main () {
14+ /*
15+ * In this example we use a scenario in the game Texas Holdem:
16+ * Community cards: 9c 4c 4s 9d 4h (both players share these cards)
17+ * Player 1: Qc 6c
18+ * Player 2: 2c 9h
2319 *
24- * The result is player 2 has a stronger hand than player 1.
25- */
20+ * Both players have full houses, but player 1 has only a four full house
21+ * while player 2 has a nine full house.
22+ *
23+ * The result is player 2 has a stronger hand than player 1.
24+ */
2625
2726 /*
2827 * To calculate the value of each card, we can either use the Card Id
@@ -36,36 +35,36 @@ int main()
3635 * And the suits are:
3736 * club = 0, diamond = 1, heart = 2, spade = 3
3837 */
39- // Community cards
40- int a = 7 * 4 + 0 ; // 9c
41- int b = 2 * 4 + 0 ; // 4c
42- int c = 2 * 4 + 3 ; // 4s
43- int d = 7 * 4 + 1 ; // 9d
44- int e = 2 * 4 + 2 ; // 4h
38+ // Community cards
39+ int a = 7 * 4 + 0 ; // 9c
40+ int b = 2 * 4 + 0 ; // 4c
41+ int c = 2 * 4 + 3 ; // 4s
42+ int d = 7 * 4 + 1 ; // 9d
43+ int e = 2 * 4 + 2 ; // 4h
4544
46- // Player 1
47- int f = 10 * 4 + 0 ; // Qc
48- int g = 4 * 4 + 0 ; // 6c
45+ // Player 1
46+ int f = 10 * 4 + 0 ; // Qc
47+ int g = 4 * 4 + 0 ; // 6c
4948
50- // Player 2
51- int h = 0 * 4 + 0 ; // 2c
52- int i = 7 * 4 + 2 ; // 9h
49+ // Player 2
50+ int h = 0 * 4 + 0 ; // 2c
51+ int i = 7 * 4 + 2 ; // 9h
5352
54- // Evaluating the hand of player 1
55- int rank1 = evaluate_7cards (a , b , c , d , e , f , g );
56- // Evaluating the hand of player 2
57- int rank2 = evaluate_7cards (a , b , c , d , e , h , i );
53+ // Evaluating the hand of player 1
54+ int rank1 = evaluate_7cards (a , b , c , d , e , f , g );
55+ // Evaluating the hand of player 2
56+ int rank2 = evaluate_7cards (a , b , c , d , e , h , i );
5857
5958 assert (rank1 == 292 );
6059 assert (rank2 == 236 );
6160
62- printf ("The rank of the hand in player 1 is %d\n" , rank1 ); // expected 292
63- printf ("The rank of the hand in player 2 is %d\n" , rank2 ); // expected 236
64- printf ("Player 2 has a stronger hand\n" );
61+ printf ("The rank of the hand in player 1 is %d\n" , rank1 ); // expected 292
62+ printf ("The rank of the hand in player 2 is %d\n" , rank2 ); // expected 236
63+ printf ("Player 2 has a stronger hand\n" );
6564
66- // Since the return value of the hand in player 2 is less than player 1,
67- // it's considered to be a higher rank and stronger hand.
68- // So player 2 beats player 1.
65+ // Since the return value of the hand in player 2 is less than player 1,
66+ // it's considered to be a higher rank and stronger hand.
67+ // So player 2 beats player 1.
6968
7069 enum rank_category category = get_rank_category (rank2 );
7170 assert (category == FULL_HOUSE );
@@ -78,10 +77,10 @@ int main()
7877 assert (strcmp (rank_description , "Nines Full over Fours" ) == 0 );
7978
8079 const char * rank_sample_hand = describe_sample_hand (rank2 );
81- printf ("The best hand from player 2 is %s %s\n" ,
82- rank_sample_hand , is_flush (rank2 ) ? "flush" : "" );
80+ printf ("The best hand from player 2 is %s %s\n" , rank_sample_hand ,
81+ is_flush (rank2 ) ? "flush" : "" );
8382 assert (strcmp (rank_sample_hand , "99944" ) == 0 );
8483 assert (!is_flush (rank2 ));
8584
86- return 0 ;
85+ return 0 ;
8786}
0 commit comments