ChoiceNameOptions

Struct ChoiceNameOptions 

Source
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

IndexChoice AtlantisChoice Olympus
0cooperatedefect
1swervestraight
2macromicro
3fightback_down
4betfold
5raise_pricelower_price
6operafootball
7gostay
8headstails
9particlewave
10discretecontinuous
11peacewar
12searchevaluate
13leadfollow
14acceptreject
15acceptdeny
16attackdecay

§See Also

Implementations§

Source§

impl ChoiceNameOptions

This impl block contains no items.

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

Source

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
Source

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
Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> ChoiceNameOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ChoiceNameOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for ChoiceNameOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V