Skip to content

Commit 1bc79a2

Browse files
authored
Format C and C++ files with pre-commit hooks including clang-format (#97)
1 parent 8de95ab commit 1bc79a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+60972
-74736
lines changed

cpp/benchmark/benchmark.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "benchmark/benchmark.h"
2+
23
#include "phevaluator/card_sampler.h"
34
#include "phevaluator/phevaluator.h"
45

cpp/examples/c_example.c

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
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
}

cpp/examples/cpp_example.cc

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
#include <phevaluator/phevaluator.h>
2-
#include <iostream>
2+
33
#include <cassert>
4+
#include <iostream>
45

5-
int main()
6-
{
7-
/*
8-
* This demonstrated scenario is the same as the one shown in example 1.
9-
* Community cards: 9c 4c 4s 9d 4h (both players share these cards)
10-
* Player 1: Qc 6c
11-
* Player 2: 2c 9h
12-
*/
13-
phevaluator::Rank rank1 = phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "Qc", "6c");
14-
phevaluator::Rank rank2 = phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "2c", "9h");
6+
int main() {
7+
/*
8+
* This demonstrated scenario is the same as the one shown in example 1.
9+
* Community cards: 9c 4c 4s 9d 4h (both players share these cards)
10+
* Player 1: Qc 6c
11+
* Player 2: 2c 9h
12+
*/
13+
phevaluator::Rank rank1 =
14+
phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "Qc", "6c");
15+
phevaluator::Rank rank2 =
16+
phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "2c", "9h");
1517

16-
// expected 292
18+
// expected 292
1719
assert(rank1.value() == 292);
18-
std::cout << "The rank of the hand in player 1 is " << rank1.value() << std::endl;
19-
// expected 236
20+
std::cout << "The rank of the hand in player 1 is " << rank1.value()
21+
<< std::endl;
22+
// expected 236
2023
assert(rank2.value() == 236);
21-
std::cout << "The rank of the hand in player 2 is " << rank2.value() << std::endl;
24+
std::cout << "The rank of the hand in player 2 is " << rank2.value()
25+
<< std::endl;
2226

2327
assert(rank1 < rank2);
2428
std::cout << "Player 2 has a stronger hand" << std::endl;
@@ -28,10 +32,11 @@ int main()
2832
std::cout << "Player 2 has a " << rank2.describeCategory() << std::endl;
2933

3034
assert(rank2.describeRank() == "Nines Full over Fours");
31-
std::cout << "More specifically, player 2 has a " << rank2.describeRank() << std::endl;
35+
std::cout << "More specifically, player 2 has a " << rank2.describeRank()
36+
<< std::endl;
3237

3338
assert(rank2.describeSampleHand() == "99944");
3439
assert(!rank2.isFlush());
35-
std::cout << "The best hand from player 2 is " << rank2.describeSampleHand() <<
36-
(rank2.isFlush() ? " in flush" : "") << std::endl;
40+
std::cout << "The best hand from player 2 is " << rank2.describeSampleHand()
41+
<< (rank2.isFlush() ? " in flush" : "") << std::endl;
3742
}
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <phevaluator/phevaluator.h>
2-
#include <iostream>
2+
33
#include <cassert>
4+
#include <iostream>
45

56
/*
67
* This example uses library pheval5.
@@ -11,17 +12,22 @@
1112
* and follow `examples/cpp_example.cc`.
1213
*/
1314

14-
int main()
15-
{
16-
phevaluator::Rank rank1 = phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h");
17-
phevaluator::Rank rank2 = phevaluator::EvaluateCards("8c", "7c", "6s", "5d", "4s");
15+
int main() {
16+
phevaluator::Rank rank1 =
17+
phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h");
18+
phevaluator::Rank rank2 =
19+
phevaluator::EvaluateCards("8c", "7c", "6s", "5d", "4s");
1820

1921
assert(rank1.value() == 292);
20-
std::cout << "The rank of the hand in player 1 is " << rank1.value() << std::endl;
22+
std::cout << "The rank of the hand in player 1 is " << rank1.value()
23+
<< std::endl;
2124

2225
assert(rank2.value() == 1606);
23-
std::cout << "The rank of the hand in player 2 is " << rank2.value() << std::endl;
26+
std::cout << "The rank of the hand in player 2 is " << rank2.value()
27+
<< std::endl;
2428

2529
assert(rank1.value() < rank2.value());
26-
std::cout << "Due to rank1.value() < rank2.value(), player 1 has a stronger hand" << std::endl;
30+
std::cout
31+
<< "Due to rank1.value() < rank2.value(), player 1 has a stronger hand"
32+
<< std::endl;
2733
}
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <phevaluator/phevaluator.h>
2-
#include <iostream>
2+
33
#include <cassert>
4+
#include <iostream>
45

56
/*
67
* This example uses library pheval6.
@@ -11,17 +12,22 @@
1112
* and follow `examples/cpp_example.cc`.
1213
*/
1314

14-
int main()
15-
{
16-
phevaluator::Rank rank1 = phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "7d");
17-
phevaluator::Rank rank2 = phevaluator::EvaluateCards("8c", "7c", "6s", "5d", "4s", "2s");
15+
int main() {
16+
phevaluator::Rank rank1 =
17+
phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "7d");
18+
phevaluator::Rank rank2 =
19+
phevaluator::EvaluateCards("8c", "7c", "6s", "5d", "4s", "2s");
1820

1921
assert(rank1.value() == 292);
20-
std::cout << "The rank of the hand in player 1 is " << rank1.value() << std::endl;
22+
std::cout << "The rank of the hand in player 1 is " << rank1.value()
23+
<< std::endl;
2124

2225
assert(rank2.value() == 1606);
23-
std::cout << "The rank of the hand in player 2 is " << rank2.value() << std::endl;
26+
std::cout << "The rank of the hand in player 2 is " << rank2.value()
27+
<< std::endl;
2428

2529
assert(rank1.value() < rank2.value());
26-
std::cout << "Due to rank1.value() < rank2.value(), player 1 has a stronger hand" << std::endl;
30+
std::cout
31+
<< "Due to rank1.value() < rank2.value(), player 1 has a stronger hand"
32+
<< std::endl;
2733
}
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <phevaluator/phevaluator.h>
2-
#include <iostream>
2+
33
#include <cassert>
4+
#include <iostream>
45

56
/*
67
* This example uses library pheval7.
@@ -11,18 +12,23 @@
1112
* and follow `examples/cpp_example.cc`.
1213
*/
1314

14-
int main()
15-
{
16-
phevaluator::Rank rank1 = phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "Qc", "6c");
17-
phevaluator::Rank rank2 = phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "2c", "9h");
15+
int main() {
16+
phevaluator::Rank rank1 =
17+
phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "Qc", "6c");
18+
phevaluator::Rank rank2 =
19+
phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "2c", "9h");
1820

19-
// expected 292
21+
// expected 292
2022
assert(rank1.value() == 292);
21-
std::cout << "The rank of the hand in player 1 is " << rank1.value() << std::endl;
22-
// expected 236
23+
std::cout << "The rank of the hand in player 1 is " << rank1.value()
24+
<< std::endl;
25+
// expected 236
2326
assert(rank2.value() == 236);
24-
std::cout << "The rank of the hand in player 2 is " << rank2.value() << std::endl;
27+
std::cout << "The rank of the hand in player 2 is " << rank2.value()
28+
<< std::endl;
2529

2630
assert(rank2.value() < rank1.value());
27-
std::cout << "Due to rank2.value() < rank1.value(), player 2 has a better hand" << std::endl;
31+
std::cout
32+
<< "Due to rank2.value() < rank1.value(), player 2 has a better hand"
33+
<< std::endl;
2834
}

cpp/examples/omaha_example.cc

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
1-
#include <iostream>
21
#include <phevaluator/phevaluator.h>
32
#include <phevaluator/rank.h>
3+
44
#include <cassert>
5+
#include <iostream>
56

67
/*
78
* This example is mostly the same as plo4_example.cc
8-
* In this example, we call EvaluateOmahaCards, which is exactly the same as EvaluatePlo4Cards
9+
* In this example, we call EvaluateOmahaCards, which is exactly the same as
10+
* EvaluatePlo4Cards
911
*/
10-
int main()
11-
{
12+
int main() {
1213
/*
1314
* Community cards: 4c 5c 6c 7s 8s
1415
* Player 1: 2c 9c As Kd
1516
* Player 2: 6s 9s Ts Js
1617
*/
17-
phevaluator::Rank rank1 =
18-
phevaluator::EvaluateOmahaCards("4c", "5c", "6c", "7s", "8s", // community cards
19-
"2c", "9c", "As", "Kd"); // player hole cards
20-
phevaluator::Rank rank2 =
21-
phevaluator::EvaluateOmahaCards("4c", "5c", "6c", "7s", "8s", // community cards
22-
"6s", "9s", "Ts", "Js"); // player hole cards
18+
phevaluator::Rank rank1 = phevaluator::EvaluateOmahaCards(
19+
"4c", "5c", "6c", "7s", "8s", // community cards
20+
"2c", "9c", "As", "Kd"); // player hole cards
21+
phevaluator::Rank rank2 = phevaluator::EvaluateOmahaCards(
22+
"4c", "5c", "6c", "7s", "8s", // community cards
23+
"6s", "9s", "Ts", "Js"); // player hole cards
2324

2425
/*
25-
* It seems that Player 2 can make a straight-flush, but that's not true. Because each
26-
* player can only select 3 cards from the community cards and 2 cards from his own hole
27-
* cards, so Player 2 cannot get a straight-flush in this example.
26+
* It seems that Player 2 can make a straight-flush, but that's not true.
27+
* Because each player can only select 3 cards from the community cards and 2
28+
* cards from his own hole cards, so Player 2 cannot get a straight-flush in
29+
* this example.
2830
*
29-
* Therefore the result is, Player 1 can make a 9-high flush in clubs, and Player 2 can
30-
* only make a 10-high straight.
31+
* Therefore the result is, Player 1 can make a 9-high flush in clubs, and
32+
* Player 2 can only make a 10-high straight.
3133
*/
3234
assert(rank1.value() == 1578);
3335
std::cout << "Player 1 has:" << std::endl;
@@ -43,5 +45,5 @@ int main()
4345
std::cout << rank2.describeRank() << std::endl;
4446
std::cout << rank2.describeSampleHand() << std::endl;
4547

46-
return 0;
48+
return 0;
4749
}

0 commit comments

Comments
 (0)