Skip to content

Commit

Permalink
Format C files with clang-format (LLVM style), delete trailing whites…
Browse files Browse the repository at this point in the history
…pace, fix line endings, and add final newline
  • Loading branch information
azriel1rf committed May 2, 2024
1 parent 9157517 commit 88c2ab0
Show file tree
Hide file tree
Showing 59 changed files with 60,930 additions and 74,715 deletions.
12 changes: 6 additions & 6 deletions cpp/benchmark/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using namespace phevaluator;

static void EvaluateAllFiveCards(benchmark::State& state) {
static void EvaluateAllFiveCards(benchmark::State &state) {
for (auto _ : state) {
for (int a = 0; a < 48; a++) {
for (int b = a + 1; b < 49; b++) {
Expand All @@ -21,7 +21,7 @@ static void EvaluateAllFiveCards(benchmark::State& state) {
}
BENCHMARK(EvaluateAllFiveCards);

static void EvaluateAllSixCards(benchmark::State& state) {
static void EvaluateAllSixCards(benchmark::State &state) {
for (auto _ : state) {
for (int a = 0; a < 47; a++) {
for (int b = a + 1; b < 48; b++) {
Expand All @@ -40,7 +40,7 @@ static void EvaluateAllSixCards(benchmark::State& state) {
}
BENCHMARK(EvaluateAllSixCards);

static void EvaluateAllSevenCards(benchmark::State& state) {
static void EvaluateAllSevenCards(benchmark::State &state) {
for (auto _ : state) {
for (int a = 0; a < 46; a++) {
for (int b = a + 1; b < 47; b++) {
Expand All @@ -63,7 +63,7 @@ BENCHMARK(EvaluateAllSevenCards);

const int SIZE = 100;

static void EvaluateRandomFiveCards(benchmark::State& state) {
static void EvaluateRandomFiveCards(benchmark::State &state) {
std::vector<std::vector<int>> hands;
card_sampler::CardSampler cs{};
for (int i = 0; i < SIZE; i++) {
Expand All @@ -78,7 +78,7 @@ static void EvaluateRandomFiveCards(benchmark::State& state) {
}
BENCHMARK(EvaluateRandomFiveCards);

static void EvaluateRandomSixCards(benchmark::State& state) {
static void EvaluateRandomSixCards(benchmark::State &state) {
std::vector<std::vector<int>> hands;
card_sampler::CardSampler cs{};

Expand All @@ -95,7 +95,7 @@ static void EvaluateRandomSixCards(benchmark::State& state) {
}
BENCHMARK(EvaluateRandomSixCards);

static void EvaluateRandomSevenCards(benchmark::State& state) {
static void EvaluateRandomSevenCards(benchmark::State &state) {
std::vector<std::vector<int>> hands;
card_sampler::CardSampler cs{};

Expand Down
2 changes: 1 addition & 1 deletion cpp/benchmark/benchmark_plo4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using namespace phevaluator;

const int SIZE = 100;

static void EvaluateRandomPlo4Cards(benchmark::State& state) {
static void EvaluateRandomPlo4Cards(benchmark::State &state) {
std::vector<std::vector<int>> hands;
card_sampler::CardSampler cs{};

Expand Down
2 changes: 1 addition & 1 deletion cpp/benchmark/benchmark_plo5.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using namespace phevaluator;

const int SIZE = 100;

static void EvaluateRandomPlo5Cards(benchmark::State& state) {
static void EvaluateRandomPlo5Cards(benchmark::State &state) {
std::vector<std::vector<int>> hands;
card_sampler::CardSampler cs{};

Expand Down
2 changes: 1 addition & 1 deletion cpp/benchmark/benchmark_plo6.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using namespace phevaluator;

const int SIZE = 100;

static void EvaluateRandomPlo6Cards(benchmark::State& state) {
static void EvaluateRandomPlo6Cards(benchmark::State &state) {
std::vector<std::vector<int>> hands;
card_sampler::CardSampler cs{};

Expand Down
85 changes: 42 additions & 43 deletions cpp/examples/c_example.c
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <phevaluator/phevaluator.h>
#include <phevaluator/rank.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*
* This C code is a demonstration of how to calculate the card id, which will
* be used as the parameter in the evaluator. It also shows how to use the
* return value to determine which hand is the stronger one.
*/
int main()
{
/*
* In this example we use a scenario in the game Texas Holdem:
* Community cards: 9c 4c 4s 9d 4h (both players share these cards)
* Player 1: Qc 6c
* Player 2: 2c 9h
*
* Both players have full houses, but player 1 has only a four full house
* while player 2 has a nine full house.
int main() {
/*
* In this example we use a scenario in the game Texas Holdem:
* Community cards: 9c 4c 4s 9d 4h (both players share these cards)
* Player 1: Qc 6c
* Player 2: 2c 9h
*
* The result is player 2 has a stronger hand than player 1.
*/
* Both players have full houses, but player 1 has only a four full house
* while player 2 has a nine full house.
*
* The result is player 2 has a stronger hand than player 1.
*/

/*
* To calculate the value of each card, we can either use the Card Id
Expand All @@ -36,52 +35,52 @@ int main()
* And the suits are:
* club = 0, diamond = 1, heart = 2, spade = 3
*/
// Community cards
int a = 7 * 4 + 0; // 9c
int b = 2 * 4 + 0; // 4c
int c = 2 * 4 + 3; // 4s
int d = 7 * 4 + 1; // 9d
int e = 2 * 4 + 2; // 4h
// Community cards
int a = 7 * 4 + 0; // 9c
int b = 2 * 4 + 0; // 4c
int c = 2 * 4 + 3; // 4s
int d = 7 * 4 + 1; // 9d
int e = 2 * 4 + 2; // 4h

// Player 1
int f = 10 * 4 + 0; // Qc
int g = 4 * 4 + 0; // 6c
// Player 1
int f = 10 * 4 + 0; // Qc
int g = 4 * 4 + 0; // 6c

// Player 2
int h = 0 * 4 + 0; // 2c
int i = 7 * 4 + 2; // 9h
// Player 2
int h = 0 * 4 + 0; // 2c
int i = 7 * 4 + 2; // 9h

// Evaluating the hand of player 1
int rank1 = evaluate_7cards(a, b, c, d, e, f, g);
// Evaluating the hand of player 2
int rank2 = evaluate_7cards(a, b, c, d, e, h, i);
// Evaluating the hand of player 1
int rank1 = evaluate_7cards(a, b, c, d, e, f, g);
// Evaluating the hand of player 2
int rank2 = evaluate_7cards(a, b, c, d, e, h, i);

assert(rank1 == 292);
assert(rank2 == 236);

printf("The rank of the hand in player 1 is %d\n", rank1); // expected 292
printf("The rank of the hand in player 2 is %d\n", rank2); // expected 236
printf("Player 2 has a stronger hand\n");
printf("The rank of the hand in player 1 is %d\n", rank1); // expected 292
printf("The rank of the hand in player 2 is %d\n", rank2); // expected 236
printf("Player 2 has a stronger hand\n");

// Since the return value of the hand in player 2 is less than player 1,
// it's considered to be a higher rank and stronger hand.
// So player 2 beats player 1.
// Since the return value of the hand in player 2 is less than player 1,
// it's considered to be a higher rank and stronger hand.
// So player 2 beats player 1.

enum rank_category category = get_rank_category(rank2);
assert(category == FULL_HOUSE);
const char* rank_category_description = describe_rank_category(category);
const char *rank_category_description = describe_rank_category(category);
assert(strcmp(rank_category_description, "Full House") == 0);
printf("Player 2 has a %s\n", rank_category_description);

const char* rank_description = describe_rank(rank2);
const char *rank_description = describe_rank(rank2);
printf("More specifically, player 2 has a %s\n", rank_description);
assert(strcmp(rank_description, "Nines Full over Fours") == 0);

const char* rank_sample_hand = describe_sample_hand(rank2);
printf("The best hand from player 2 is %s %s\n",
rank_sample_hand, is_flush(rank2) ? "flush": "");
const char *rank_sample_hand = describe_sample_hand(rank2);
printf("The best hand from player 2 is %s %s\n", rank_sample_hand,
is_flush(rank2) ? "flush" : "");
assert(strcmp(rank_sample_hand, "99944") == 0);
assert(!is_flush(rank2));

return 0;
return 0;
}
42 changes: 23 additions & 19 deletions cpp/examples/cpp_example.cc
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
#include <phevaluator/phevaluator.h>
#include <iostream>
#include <cassert>
#include <iostream>
#include <phevaluator/phevaluator.h>

int main()
{
/*
* This demonstrated scenario is the same as the one shown in example 1.
* Community cards: 9c 4c 4s 9d 4h (both players share these cards)
* Player 1: Qc 6c
* Player 2: 2c 9h
*/
phevaluator::Rank rank1 = phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "Qc", "6c");
phevaluator::Rank rank2 = phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "2c", "9h");
int main() {
/*
* This demonstrated scenario is the same as the one shown in example 1.
* Community cards: 9c 4c 4s 9d 4h (both players share these cards)
* Player 1: Qc 6c
* Player 2: 2c 9h
*/
phevaluator::Rank rank1 =
phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "Qc", "6c");
phevaluator::Rank rank2 =
phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "2c", "9h");

// expected 292
// expected 292
assert(rank1.value() == 292);
std::cout << "The rank of the hand in player 1 is " << rank1.value() << std::endl;
// expected 236
std::cout << "The rank of the hand in player 1 is " << rank1.value()
<< std::endl;
// expected 236
assert(rank2.value() == 236);
std::cout << "The rank of the hand in player 2 is " << rank2.value() << std::endl;
std::cout << "The rank of the hand in player 2 is " << rank2.value()
<< std::endl;

assert(rank1 < rank2);
std::cout << "Player 2 has a stronger hand" << std::endl;
Expand All @@ -28,10 +31,11 @@ int main()
std::cout << "Player 2 has a " << rank2.describeCategory() << std::endl;

assert(rank2.describeRank() == "Nines Full over Fours");
std::cout << "More specifically, player 2 has a " << rank2.describeRank() << std::endl;
std::cout << "More specifically, player 2 has a " << rank2.describeRank()
<< std::endl;

assert(rank2.describeSampleHand() == "99944");
assert(!rank2.isFlush());
std::cout << "The best hand from player 2 is " << rank2.describeSampleHand() <<
(rank2.isFlush() ? " in flush" : "") << std::endl;
std::cout << "The best hand from player 2 is " << rank2.describeSampleHand()
<< (rank2.isFlush() ? " in flush" : "") << std::endl;
}
23 changes: 14 additions & 9 deletions cpp/examples/evaluator5_standalone_example.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <phevaluator/phevaluator.h>
#include <iostream>
#include <cassert>
#include <iostream>
#include <phevaluator/phevaluator.h>

/*
* This example uses library pheval5.
Expand All @@ -11,17 +11,22 @@
* and follow `examples/cpp_example.cc`.
*/

int main()
{
phevaluator::Rank rank1 = phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h");
phevaluator::Rank rank2 = phevaluator::EvaluateCards("8c", "7c", "6s", "5d", "4s");
int main() {
phevaluator::Rank rank1 =
phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h");
phevaluator::Rank rank2 =
phevaluator::EvaluateCards("8c", "7c", "6s", "5d", "4s");

assert(rank1.value() == 292);
std::cout << "The rank of the hand in player 1 is " << rank1.value() << std::endl;
std::cout << "The rank of the hand in player 1 is " << rank1.value()
<< std::endl;

assert(rank2.value() == 1606);
std::cout << "The rank of the hand in player 2 is " << rank2.value() << std::endl;
std::cout << "The rank of the hand in player 2 is " << rank2.value()
<< std::endl;

assert(rank1.value() < rank2.value());
std::cout << "Due to rank1.value() < rank2.value(), player 1 has a stronger hand" << std::endl;
std::cout
<< "Due to rank1.value() < rank2.value(), player 1 has a stronger hand"
<< std::endl;
}
23 changes: 14 additions & 9 deletions cpp/examples/evaluator6_standalone_example.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <phevaluator/phevaluator.h>
#include <iostream>
#include <cassert>
#include <iostream>
#include <phevaluator/phevaluator.h>

/*
* This example uses library pheval6.
Expand All @@ -11,17 +11,22 @@
* and follow `examples/cpp_example.cc`.
*/

int main()
{
phevaluator::Rank rank1 = phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "7d");
phevaluator::Rank rank2 = phevaluator::EvaluateCards("8c", "7c", "6s", "5d", "4s", "2s");
int main() {
phevaluator::Rank rank1 =
phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "7d");
phevaluator::Rank rank2 =
phevaluator::EvaluateCards("8c", "7c", "6s", "5d", "4s", "2s");

assert(rank1.value() == 292);
std::cout << "The rank of the hand in player 1 is " << rank1.value() << std::endl;
std::cout << "The rank of the hand in player 1 is " << rank1.value()
<< std::endl;

assert(rank2.value() == 1606);
std::cout << "The rank of the hand in player 2 is " << rank2.value() << std::endl;
std::cout << "The rank of the hand in player 2 is " << rank2.value()
<< std::endl;

assert(rank1.value() < rank2.value());
std::cout << "Due to rank1.value() < rank2.value(), player 1 has a stronger hand" << std::endl;
std::cout
<< "Due to rank1.value() < rank2.value(), player 1 has a stronger hand"
<< std::endl;
}
27 changes: 16 additions & 11 deletions cpp/examples/evaluator7_standalone_example.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <phevaluator/phevaluator.h>
#include <iostream>
#include <cassert>
#include <iostream>
#include <phevaluator/phevaluator.h>

/*
* This example uses library pheval7.
Expand All @@ -11,18 +11,23 @@
* and follow `examples/cpp_example.cc`.
*/

int main()
{
phevaluator::Rank rank1 = phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "Qc", "6c");
phevaluator::Rank rank2 = phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "2c", "9h");
int main() {
phevaluator::Rank rank1 =
phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "Qc", "6c");
phevaluator::Rank rank2 =
phevaluator::EvaluateCards("9c", "4c", "4s", "9d", "4h", "2c", "9h");

// expected 292
// expected 292
assert(rank1.value() == 292);
std::cout << "The rank of the hand in player 1 is " << rank1.value() << std::endl;
// expected 236
std::cout << "The rank of the hand in player 1 is " << rank1.value()
<< std::endl;
// expected 236
assert(rank2.value() == 236);
std::cout << "The rank of the hand in player 2 is " << rank2.value() << std::endl;
std::cout << "The rank of the hand in player 2 is " << rank2.value()
<< std::endl;

assert(rank2.value() < rank1.value());
std::cout << "Due to rank2.value() < rank1.value(), player 2 has a better hand" << std::endl;
std::cout
<< "Due to rank2.value() < rank1.value(), player 2 has a better hand"
<< std::endl;
}
Loading

0 comments on commit 88c2ab0

Please sign in to comment.