pub struct ChoiceNameOptions {}Expand description
A data struct that holds the names of the choices.
This is a simple data struct that is used to internally store the names of choice pairs that can be given for a single game.
The names are taken from the Universal Paperclips game, and are used to make the game more interesting.
The names are stored as const array of tuples, which can be accessed
using the get_choice_pair function.
The struct also provides a way to get a random pair of names. This can be
done using the get_random_pair
function.
The complete list of available options can be found in the table below.
§Examples
§Get a specific pair
use dilemma_tactix_lib::ChoiceNameOptions;
let (choice_atlantis, choice_olympus) =
ChoiceNameOptions::get_choice_pair(0);
assert_eq!(choice_atlantis, "cooperate");
assert_eq!(choice_olympus, "defect");§Get a random pair
use dilemma_tactix_lib::ChoiceNameOptions;
let (choice_atlantis, choice_olympus) =
ChoiceNameOptions::get_random_pair();§Notes
The names are taken from the Universal Paperclips minigame.
I have also decided to make a static array that can be stored in the binary itself to make it easier to distribute the game. This means that the names are not configurable, and are the same for every game.
For this reason, you would usually want to use the get_random_pair
function, as it will return a random pair of names.
§Available Options
| Index | Choice Atlantis | Choice Olympus |
|---|---|---|
| 0 | cooperate | defect |
| 1 | swerve | straight |
| 2 | macro | micro |
| 3 | fight | back_down |
| 4 | bet | fold |
| 5 | raise_price | lower_price |
| 6 | opera | football |
| 7 | go | stay |
| 8 | heads | tails |
| 9 | particle | wave |
| 10 | discrete | continuous |
| 11 | peace | war |
| 12 | search | evaluate |
| 13 | lead | follow |
| 14 | accept | reject |
| 15 | accept | deny |
| 16 | attack | decay |
§See Also
Implementations§
impl ChoiceNameOptions
The ChoiceNameOptions struct represents a collection of choice pairs.
This struct provides methods to retrieve specific choice pairs, as well as random choice pairs. It also exposes the choice pairs as arrays and provides methods to retrieve the individual choices from each pair.
Source§impl ChoiceNameOptions
impl ChoiceNameOptions
Sourcepub const fn get_choice_pair(n: usize) -> (&'static str, &'static str)
pub const fn get_choice_pair(n: usize) -> (&'static str, &'static str)
Get a specific choice pair.
This function returns a specific choice pair, based on the index provided. The index must be less than the length of the array.
§Arguments
n- The index of the choice pair to return.
§Examples
use dilemma_tactix_lib::ChoiceNameOptions as CNO;
let (choice_atlantis, choice_olympus) = CNO::get_choice_pair(0);
assert_eq!(choice_atlantis, "cooperate");
assert_eq!(choice_olympus, "defect");§Returns
A tuple containing the two choices.
§Panics
This function will panic if the index is greater than the length of the array.
§See Also
Sourcepub fn get_random_pair() -> (&'static str, &'static str)
pub fn get_random_pair() -> (&'static str, &'static str)
Get a random choice pair.
This function returns a random choice pair, based on the length of the array.
§Examples
use dilemma_tactix_lib::ChoiceNameOptions as CNO;
let (choice_atlantis, choice_olympus) = CNO::get_random_pair();
§Returns
A tuple containing the two choices.
§See Also
§Notes
This function uses the rand crate to generate a random number.
The random number is generated using the ChaCha12Rng
§See Also
Sourcepub const fn choice_pairs() -> [(&'static str, &'static str); 17]
pub const fn choice_pairs() -> [(&'static str, &'static str); 17]
Returns the choice name options pair list.
This function is a const fn, which means it is evaluated at
compile time. It returns the CHOICE_PAIRS array, which is a list
of tuples representing choice name options.
Each tuple in the array contains two &'static str elements, where the
first element is the name of the Atlantis choice and the second element
is the name of the Olympus choice.
§Examples
use dilemma_tactix_lib::ChoiceNameOptions as CNO;
let pairs = CNO::choice_pairs();
assert_eq!(pairs[0], ("cooperate", "defect"));§Returns
This function returns an array of 17 tuples, where each tuple contains
two &'static str elements representing the name of the Atlantis choice
and the name of the Olympus choice.
Sourcepub const fn choice_pairs_length() -> usize
pub const fn choice_pairs_length() -> usize
Returns the length of the choice name options pair list.
This function is a const fn, which means it is evaluated at
compile time. It returns the length of the CHOICE_PAIRS array,
which represents the number of choice name option pairs available.
§Examples
use dilemma_tactix_lib::ChoiceNameOptions as CNO;
assert_eq!(CNO::choice_pairs_length(), 17);§Returns
This function returns a usize which represents the length of the
CHOICE_PAIRS array.
Sourcepub fn choice_atlantis_options() -> [&'static str; 17]
pub fn choice_atlantis_options() -> [&'static str; 17]
Returns the array of the first choice in each pair.
This function maps over the CHOICE_PAIRS array and returns a new array
containing the first element (the Atlantis choice) of each tuple.
§Examples
use dilemma_tactix_lib::ChoiceNameOptions as CNO;
let atlantis_options = CNO::choice_atlantis_options();
assert_eq!(atlantis_options[0], "cooperate");§Returns
This function returns an array of 17 &'static str elements, where each
element is the first item (Atlantis choice) of the corresponding tuple
in the CHOICE_PAIRS array.
Sourcepub fn choice_olympus_options() -> [&'static str; 17]
pub fn choice_olympus_options() -> [&'static str; 17]
Returns the array of the second choice in each pair.
This function maps over the CHOICE_PAIRS array and returns a new array
containing the second element (the Olympus choice) of each tuple.
§Examples
use dilemma_tactix_lib::ChoiceNameOptions as CNO;
let olympus_options = CNO::choice_olympus_options();
assert_eq!(olympus_options[0], "defect");§Returns
This function returns an array of 17 &'static str elements, where each
element is the second item (Olympus choice) of the corresponding tuple
in the CHOICE_PAIRS array.
Trait Implementations§
Source§impl Clone for ChoiceNameOptions
impl Clone for ChoiceNameOptions
Source§fn clone(&self) -> ChoiceNameOptions
fn clone(&self) -> ChoiceNameOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more