Trait Game

Source
pub trait Game<const P: usize>:
    Clone
    + Sized
    + Send
    + Sync {
    type Move: Move;
    type Utility: Utility;
    type State: State;
    type View: State;

    // Required method
    fn state_view(
        &self,
        state: &Self::State,
        player: PlayerIndex<P>,
    ) -> Self::View;

    // Provided method
    fn num_players(&self) -> usize { ... }
}
Expand description

A root trait that all games implement.

This trait primarily serves two purposes:

  • It specifies the trait requirements of all game types via its supertraits.
  • It defines a set of associated types, common to all games, which simplifies type signatures elsewhere.

Additionally, for games with hidden information, it defines the relationship between the primary game state and the view of that state available to each player.

§Future work

There are two improvements planned for this trait, pending the stabilization of certain Rust features:

  • The const generic parameter P will be replaced by an associated constant when this Rust issue is resolved, allowing associated constants to be used in const generics. This will simplify many type signatures throughout the library.

  • The associated type View will default to the associated type State, and the state_view method will default to simply return the state unchanged, when associated type defaults are stabilized, allowing implementers to skip specifying these for the common case of perfect-information games.

Required Associated Types§

Source

type Move: Move

The type of moves played by players in this game.

Source

type Utility: Utility

The type of utility values awarded to each player at the end of the game.

Source

type State: State

The type of intermediate game state used during the execution of the game.

Source

type View: State

The type of the view of the intermediate game state presented to players.

This may differ from State to support hidden information, that is, aspects of the game state that are not visible to players while making strategic decisions.

Required Methods§

Source

fn state_view(&self, state: &Self::State, player: PlayerIndex<P>) -> Self::View

Produce a view of the game state for the given player.

For perfect-information games, this should return the original state unchanged.

Provided Methods§

Source

fn num_players(&self) -> usize

The number of players this game is for.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<G: Playable<P> + 'static, const P: usize> Game<P> for Repeated<G, P>

Source§

type Move = <G as Game<P>>::Move

Source§

type Utility = <G as Game<P>>::Utility

Source§

type State = RepeatedState<G, P>

Source§

type View = RepeatedState<G, P>

Source§

impl<M: Move, U: Utility, const P: usize> Game<P> for Normal<M, U, P>

Source§

impl<M: Move, U: Utility, const P: usize> Game<P> for Simultaneous<M, U, P>

Source§

impl<S: State, M: Move, U: Utility, O: Outcome<M, U, P>, const P: usize> Game<P> for GameTree<S, M, U, O, P>

Source§

type Move = M

Source§

type Utility = U

Source§

type State = S

Source§

type View = S