Skip to content

Commit

Permalink
fix flatten
Browse files Browse the repository at this point in the history
  • Loading branch information
shumbo committed Oct 16, 2024
1 parent a5f3c7e commit df5c39b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
29 changes: 13 additions & 16 deletions chorus_lib/examples/cardgame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ struct Player2;
#[derive(ChoreographyLocation)]
struct Player3;

fn read_i32() -> i32 {
let mut input = String::new();
std::io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
input.trim().parse::<i32>().expect("Failed to parse input")
}

struct Game<
Players: LocationSet
+ Subset<HCons<Dealer, Players>, PlayersSubsetAll>
Expand Down Expand Up @@ -73,11 +81,7 @@ impl<
{
let card1 = op.locally(Dealer, |_| {
println!("Enter the first card for {:?}", Q::name());
let mut input = String::new();
std::io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
input.trim().parse::<i32>().expect("Failed to parse input")
read_i32()
});
op.comm(Dealer, Q::new(), &card1)
}
Expand Down Expand Up @@ -202,11 +206,8 @@ impl<
if choice {
let card2 = op.locally(Dealer, |_| {
println!("Player {:?} wants another card", Player::name());
let mut input = String::new();
std::io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
input.trim().parse::<i32>().expect("Failed to parse input")
println!("Enter the second card for {:?}", Player::name());
read_i32()
});
let card2 = op.comm(Dealer, Player::new(), &card2);
op.locally(Player::new(), |un| {
Expand Down Expand Up @@ -235,11 +236,7 @@ impl<
);
let tbl_card = op.locally(Dealer, |_| {
println!("Enter a single card for everyone ");
let mut input = String::new();
std::io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
input.trim().parse::<i32>().expect("Failed to parse input")
read_i32()
});
let table_card = op.broadcast(Dealer, tbl_card);

Expand All @@ -264,7 +261,7 @@ impl<
hand2.push(self.table_card);
println!("Final hands: {:?}", hand2);
let sum: i32 = hand2.iter().sum();
println!("My win result: {}", sum > 19);
println!("My win result: {}", sum % 21 > 19);
return ();
})
}
Expand Down
2 changes: 1 addition & 1 deletion chorus_lib/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ where
where
LS1: Subset<LS2, LS1SubsetLS2>,
{
let value = self.value.unwrap().value;
let value = self.value.map(|x| x.value).flatten();
MultiplyLocated {
value,
phantom: PhantomData,
Expand Down

0 comments on commit df5c39b

Please sign in to comment.