-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add matchup type and cartesian product tournament
- Loading branch information
Showing
6 changed files
with
88 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::{Game, PerPlayer, Player, Strategy}; | ||
use std::sync::Arc; | ||
|
||
/// A collection of players ready to play a game. | ||
#[derive(Clone)] | ||
pub struct Matchup<G: Game<P>, const P: usize> { | ||
players: PerPlayer<Arc<Player<G, P>>, P>, | ||
} | ||
|
||
impl<G: Game<P>, const P: usize> Matchup<G, P> { | ||
/// Construct a new matchup. | ||
pub fn new(players: PerPlayer<Arc<Player<G, P>>, P>) -> Self { | ||
Matchup { players } | ||
} | ||
|
||
/// Construct a new matchup from an array of players. | ||
pub fn from_players(players: [Player<G, P>; P]) -> Self { | ||
Matchup::new(PerPlayer::new(players.map(Arc::new))) | ||
} | ||
|
||
/// Get the players in this matchup. | ||
pub fn players(&self) -> &PerPlayer<Arc<Player<G, P>>, P> { | ||
&self.players | ||
} | ||
|
||
/// Get the names of all players in this matchup. | ||
pub fn names(&self) -> PerPlayer<String, P> { | ||
self.players.map(|player| player.name().to_owned()) | ||
} | ||
|
||
/// Get fresh copies of each player's strategy for playing the game. | ||
pub fn strategies(&self) -> PerPlayer<Strategy<G::View, G::Move, P>, P> { | ||
self.players.map(|player| player.new_strategy()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters