GameOptionsBuilder

Struct GameOptionsBuilder 

Source
pub struct GameOptionsBuilder {
    pub choice_atlantis: Option<&'static str>,
    pub choice_olympus: Option<&'static str>,
    pub atlantis_atlantis: Option<NumberPair>,
    pub atlantis_olympus: Option<NumberPair>,
    pub olympus_atlantis: Option<NumberPair>,
    pub olympus_olympus: Option<NumberPair>,
    /* private fields */
}
Expand description

A builder struct to create a GameOptions.

This struct is designed to encapsulate different ways of generating a new GameOptions struct. It is designed to be used in conjunction with the GameOptions struct.

The GameOptionsBuilder::new() method is used to create a new builder, which takes a builder_type argument. This argument is used to determine which variant of the builder is used. The builder_type argument can be one of the following:

Each of these variants has different fields that can be set and serve different purposes. The following table shows which fields should be set for each variant:

FieldRandomizedSeededCustomizedTypeDefault
min_valueYesNoYesu321
max_valueYesNoYesu3210
choice_atlantisYesYesYes&’static str“cooperate”
choice_olympusYesYesYes&’static str“defect”
atlantis_atlantisNoNoYesNumberPairNumberPair::new(4, 4)
atlantis_olympusNoNoYesNumberPairNumberPair::new(0, 5)
olympus_atlantisNoNoYesNumberPairNumberPair::new(5, 0)
olympus_olympusNoNoYesNumberPairNumberPair::new(3, 3)
seedNoYesNou64None

§Example

§RandomizedBuilder

This builder path takes in the lower bound and the upper bound for the scores that can be assigned to each option. It then generates a random score for each option within the given bounds.

use dilemma_tactix_lib::{
    GameOptionsBuilder as Builder,
    GameOptionsBuilderTypes as BuilderTypes,
    NumberPair,
};

let builder = Builder::new(BuilderTypes::Randomized);
let builder = builder.min_value(1);
let builder = builder?.max_value(10);
let builder = builder?.choice_atlantis("cooperate");
let builder = builder?.choice_olympus("defect");

let game_options = builder?.build();

§SeededBuilder

This builder path takes in the lower bound and the upper bound for the scores that can be assigned to each option. It also takes a seed value It then generates a random score for each option within the given bounds and the given seed.

use dilemma_tactix_lib::{
    GameOptionsBuilder as Builder,
    GameOptionsBuilderTypes as BuilderTypes,
};

let builder = Builder::new(BuilderTypes::Seeded);

§CustomizedBuilder

This builder allows you to set all the scores for each possible outcome individually. This allows for the most customization of the GameOptions struct.

use dilemma_tactix_lib::{
    GameOptionsBuilder as Builder,
    GameOptionsBuilderTypes as BuilderTypes,
    NumberPair,
};

let builder = Builder::new(BuilderTypes::Customized);
let builder = builder.choice_atlantis("cooperate");
let builder = builder?.choice_olympus("defect");
let builder = builder?.atlantis_atlantis(NumberPair::new(4, 4));
let builder = builder?.atlantis_olympus(NumberPair::new(0, 5));
let builder = builder?.olympus_atlantis(NumberPair::new(5, 0));
let builder = builder?.olympus_olympus(NumberPair::new(3, 3));

let game_options = builder?.build();

§Notes

I chose to use the Builder pattern here because it allows for easier manipulation of the GameOptions struct. I also used a State or Variant pattern here because it had the lowest complexity in terms of understanding the flow of options that need to be set.

§See Also

Fields§

§choice_atlantis: Option<&'static str>§choice_olympus: Option<&'static str>§atlantis_atlantis: Option<NumberPair>§atlantis_olympus: Option<NumberPair>§olympus_atlantis: Option<NumberPair>§olympus_olympus: Option<NumberPair>

Implementations§

Source§

impl GameOptionsBuilder

Source

pub const fn new(builder_type: GameOptionsBuilderTypes) -> Self

Creates a new GameOptionsBuilder struct.

This associated function creates a new GameOptionsBuilder struct with the given builder_type. The builder_type argument can be one of the following:

§Arguments
  • builder_type - The type of builder to create.
§Example
§RandomizedBuilder

This builder path takes in the lower bound and the upper bound for the scores that can be assigned to each option. It then generates a random score for each option within the given bounds.

use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Randomized);
§SeededBuilder

This builder path takes in the lower bound and the upper bound for the scores that can be assigned to each option. It also takes a seed value It then generates a random score for each option within the given bounds and the given seed.

use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Seeded);
§CustomizedBuilder

This builder allows you to set all the scores for each possible outcome individually. This allows for the most customization of the GameOptions struct.

use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Customized);
§Returns

A new GameOptionsBuilder struct with a given builder type.

§See Also
Source

pub fn min_value(self, min_value: u32) -> Result<Self, BuilderError>

Sets the minimum value for the GameOptions.

This function sets the minimum value for the GameOptions struct that is being built. This function is only valid for the GameOptionsBuilderTypes::Randomized and the GameOptionsBuilderTypes::Seeded variants of the GameOptionsBuilder struct.

§Arguments
  • min_value - The minimum value for the GameOptions.
§Example
§RandomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Randomized)
        .min_value(1);
assert!(game_options_builder.is_ok());
§SeededBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Seeded).min_value(1);

assert!(game_options_builder.is_ok());
§CustomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Customized)
        .min_value(1);

assert!(game_options_builder.is_err());
§Errors

This function will return an error if the builder_type is GameOptionsBuilderTypes::Customized.

§Returns

The GameOptionsBuilder struct with the min_value field set.

§See Also
Source

pub fn max_value(self, max_value: u32) -> Result<Self, BuilderError>

Sets the maximum value for the GameOptions.

This function sets the maximum value for the GameOptions struct that is being built. This function is only valid for the GameOptionsBuilderTypes::Randomized and the GameOptionsBuilderTypes::Seeded variants of the GameOptionsBuilder struct.

§Arguments
  • max_value - The maximum value for the GameOptions.
§Example
§RandomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Randomized)
        .max_value(10);
assert!(game_options_builder.is_ok());
§SeededBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Seeded).max_value(10);

assert!(game_options_builder.is_ok());
§CustomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Customized)
        .max_value(10);

assert!(game_options_builder.is_err());
§Errors

This function will return an error if the builder_type is GameOptionsBuilderTypes::Customized.

§Returns

The GameOptionsBuilder struct with the max_value field set.

§See Also
Source

pub fn choice_atlantis( self, choice_atlantis: &'static str, ) -> Result<Self, BuilderError>

Sets the first choice available to players in GameOptions.

This function sets the first choice available to players in GameOptions. This function is valid for all variants of the GameOptionsBuilder struct.

§Arguments
  • choice_atlantis - The first choice available to players in GameOptions.
§Example
§RandomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Randomized)
        .choice_atlantis("cooperate");

let game_options = game_options_builder.unwrap().build();
§SeededBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};
use rand::SeedableRng;

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Seeded)
        .choice_atlantis("cooperate");

let game_options = game_options_builder.unwrap().build();
§CustomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Customized)
        .choice_atlantis("cooperate");

let game_options = game_options_builder.unwrap().build();
§Errors

This function will return an error if the choice_atlantis argument is empty.

§Returns

The GameOptionsBuilder struct with the choice_atlantis field set.

§See Also
Source

pub fn choice_olympus( self, choice_olympus: &'static str, ) -> Result<Self, BuilderError>

Sets the second choice available to players in GameOptions.

This function sets the second choice available to players in GameOptions. This function is valid for all variants of the GameOptionsBuilder struct.

§Arguments
  • choice_olympus - The second choice available to players in GameOptions.
§Example
§RandomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Randomized)
        .choice_olympus("defect");

let game_options = game_options_builder.unwrap().build();
§SeededBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Seeded)
        .choice_olympus("defect");

let game_options = game_options_builder.unwrap().build();
§CustomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Customized)
        .choice_olympus("defect");

let game_options = game_options_builder.unwrap().build();
§Errors

This function will return an error if the choice_olympus argument is empty.

§Returns

The GameOptionsBuilder struct with the choice_olympus field set.

§See Also
Source

pub fn atlantis_atlantis( self, atlantis_atlantis: NumberPair, ) -> Result<Self, BuilderError>

Sets the score for the case when both players (Aleph and Beth) choose the first (Atlantis) choice.

This function sets the score for the case when both players choose the first (Atlantis) choice. This function is only valid for the GameOptionsBuilderTypes::Customized variant of the GameOptionsBuilder struct.

§Arguments
  • atlantis_atlantis - The score to set.
§Example
§RandomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
    NumberPair,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Randomized)
        .atlantis_atlantis(NumberPair::new(4, 4));
§SeededBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
    NumberPair,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Seeded)
        .atlantis_atlantis(NumberPair::new(4, 4));
§CustomizedBuilder
use dilemma_tactix_lib::{
   GameOptionsBuilder,
  GameOptionsBuilderTypes,
   NumberPair,
};

let game_options_builder =
   GameOptionsBuilder::new(GameOptionsBuilderTypes::Customized)
      .atlantis_atlantis(NumberPair::new(4, 4));


let game_options = game_options_builder.unwrap().build();
§Errors

This function will return an error if the builder_type is GameOptionsBuilderTypes::Randomized or GameOptionsBuilderTypes::Seeded.

§Returns

The GameOptionsBuilder struct with the atlantis_atlantis field set.

§See Also
Source

pub fn atlantis_olympus( self, atlantis_olympus: NumberPair, ) -> Result<Self, BuilderError>

Sets the score for the case when Player Aleph chooses the first (Atlantis) choice and Player Beth chooses the second (Olympus) choice.

This function sets the score for the case when Player Aleph chooses the first (Atlantis) choice and Player Beth chooses the second (Olympus) choice. This function is only valid for the GameOptionsBuilderTypes::Customized variant of the GameOptionsBuilder struct.

§Arguments
  • atlantis_olympus - The score to set.
§Example
§RandomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
    NumberPair,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Randomized)
        .atlantis_olympus(NumberPair::new(0, 5));
§SeededBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
    NumberPair,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Seeded)
        .atlantis_olympus(NumberPair::new(0, 5));
§CustomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
    NumberPair,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Customized)
        .atlantis_olympus(NumberPair::new(0, 5));

let game_options = game_options_builder.unwrap().build();
§Errors

This function will return an error if the builder_type is GameOptionsBuilderTypes::Randomized or GameOptionsBuilderTypes::Seeded.

§Returns

The GameOptionsBuilder struct with the atlantis_olympus field set.

§See Also
Source

pub fn olympus_atlantis( self, olympus_atlantis: NumberPair, ) -> Result<Self, BuilderError>

Sets the score for the case when Player Aleph chooses the second choice and Player Beth chooses the first choice.

This function sets the score for the case when Player Aleph chooses the second (Olympus) choice and Player Beth chooses the first (Atlantis) choice. This function is only valid for the GameOptionsBuilderTypes::Customized variant of the GameOptionsBuilder struct.

§Arguments
  • olympus_atlantis - The score to set.
§Example
§RandomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
    NumberPair,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Randomized)
        .olympus_atlantis(NumberPair::new(5, 0));
§SeededBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
    NumberPair,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Seeded)
        .olympus_atlantis(NumberPair::new(5, 0));
§CustomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
    NumberPair,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Customized)
        .olympus_atlantis(NumberPair::new(5, 0));


let game_options = game_options_builder.unwrap().build();
§Errors

This function will return an error if the builder_type is GameOptionsBuilderTypes::Randomized or GameOptionsBuilderTypes::Seeded.

§Returns

The GameOptionsBuilder struct with the olympus_atlantis field set.

§See Also
Source

pub fn olympus_olympus( self, olympus_olympus: NumberPair, ) -> Result<Self, BuilderError>

Sets the score for the case when both players (Aleph and Beth) choose the second (Olympus) choice.

This function sets the score for the case when both players choose the second (Olympus) choice. This function is only valid for the GameOptionsBuilderTypes::Customized variant of the GameOptionsBuilder struct.

§Arguments
  • olympus_olympus - The score to set.
§Example
§RandomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
    NumberPair,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Randomized)
        .olympus_olympus(NumberPair::new(3, 3));
§SeededBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
    NumberPair,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Seeded)
        .olympus_olympus(NumberPair::new(3, 3));
§CustomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
    NumberPair,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Customized)
        .olympus_olympus(NumberPair::new(3, 3));


let game_options = game_options_builder.unwrap().build();
§Errors

This function will return an error if the builder_type is GameOptionsBuilderTypes::Randomized or GameOptionsBuilderTypes::Seeded.

§Returns

The GameOptionsBuilder struct with the olympus_olympus field set.

§See Also
Source

pub fn seed(self, seed: u64) -> Result<Self, BuilderError>

Sets the seed for the GameOptions.

This function sets the seed for the GameOptions struct that is being built. This function is only valid for the GameOptionsBuilderTypes::Seeded variant of the GameOptionsBuilder struct.

§Arguments
  • seed - The seed for the GameOptions.
§Example
§RandomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Randomized)
        .seed(123456789);
§SeededBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Seeded)
        .seed(123456789);
§CustomizedBuilder
use dilemma_tactix_lib::{
    GameOptionsBuilder,
    GameOptionsBuilderTypes,
};

let game_options_builder =
    GameOptionsBuilder::new(GameOptionsBuilderTypes::Customized)
        .seed(123456789);
§Errors

This function will return an error if the builder_type is GameOptionsBuilderTypes::Randomized or GameOptionsBuilderTypes::Customized.

§Returns

The GameOptionsBuilder struct with the seed field set.

§See Also
Source

pub fn build(self) -> GameOptions

Trait Implementations§

Source§

impl Clone for GameOptionsBuilder

Source§

fn clone(&self) -> GameOptionsBuilder

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 GameOptionsBuilder

Source§

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

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

impl PartialEq for GameOptionsBuilder

Source§

fn eq(&self, other: &GameOptionsBuilder) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for GameOptionsBuilder

Source§

impl Eq for GameOptionsBuilder

Source§

impl StructuralPartialEq for GameOptionsBuilder

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