Skip to content

Commit

Permalink
Added blanket implementations for utility traits
Browse files Browse the repository at this point in the history
  • Loading branch information
ishirgarg committed Apr 12, 2024
1 parent cee7a44 commit b9d31ba
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/game/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,29 @@ where
G: SimpleSum<N>,
{
fn utility(&self, state: State) -> [Utility; N] {
todo!()
SimpleSum::utility(self, state).map(|x| x as Utility)
}
}

impl<G> SimpleSum<2> for G
where
G: ClassicGame,
G: ClassicGame + Extensive<2>,
{
fn utility(&self, state: State) -> [SimpleUtility; 2] {
todo!()
let player_utility = ClassicGame::utility(self, state);
let other_player_utility = match player_utility {
SimpleUtility::WIN => SimpleUtility::LOSE,
SimpleUtility::LOSE => SimpleUtility::WIN,
SimpleUtility::TIE => SimpleUtility::TIE,
SimpleUtility::DRAW => SimpleUtility::DRAW,
};

if Extensive::turn(self, state) == 0 {
[player_utility, other_player_utility]
}
else {
[other_player_utility, player_utility]
}
}
}

Expand All @@ -368,6 +381,6 @@ where
G: ClassicPuzzle,
{
fn utility(&self, state: State) -> [SimpleUtility; 1] {
todo!()
[ClassicPuzzle::utility(self, state)]
}
}

0 comments on commit b9d31ba

Please sign in to comment.