-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
CardSampler
to separate files and use it in evaluation tests (#91
) * Refactor card_sampler include paths in benchmark files * Refactor to use `card_sampler::CardSampler` in tests * Refactor card_sampler implementation to separate header and source files
- Loading branch information
Showing
11 changed files
with
196 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
#include <array> | ||
#include <vector> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
namespace card_sampler { | ||
class CardSampler { | ||
std::array<int, 52> deck; | ||
|
||
public: | ||
CardSampler(void); | ||
std::vector<int> sample(int size); | ||
}; | ||
} // namespace card_sampler | ||
|
||
#ifdef __cplusplus | ||
} // closing brace for extern "C" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <phevaluator/card_sampler.h> | ||
#include <array> | ||
#include <chrono> | ||
#include <numeric> | ||
#include <random> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace card_sampler { | ||
static unsigned seed = | ||
std::chrono::system_clock::now().time_since_epoch().count(); | ||
static std::default_random_engine generator(seed); | ||
|
||
CardSampler::CardSampler(void) { | ||
std::iota(deck.begin(), deck.end(), 0); | ||
} | ||
|
||
std::vector<int> CardSampler::sample(int size) { | ||
std::vector<int> ret; | ||
int residual_cards = deck.size(); | ||
for (int i = 0; i < size; i++) { | ||
int target_index = generator() % residual_cards; | ||
int tail_index = residual_cards - 1; | ||
std::swap(deck[target_index], deck[tail_index]); | ||
ret.push_back(deck[tail_index]); | ||
residual_cards--; | ||
} | ||
return ret; | ||
} | ||
} // namespace card_sampler |
Oops, something went wrong.