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 typeState
, and thestate_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§
Required Methods§
Sourcefn state_view(&self, state: &Self::State, player: PlayerIndex<P>) -> Self::View
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§
Sourcefn num_players(&self) -> usize
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.