summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-12-22 20:35:49 -0500
committerKjetil Orbekk <kj@orbekk.com>2022-12-22 20:36:35 -0500
commit573749cb2055d9e3e6897f73d6879773d738faee (patch)
tree84238c93441bdef3e097b82ce37348d8c7c766ee
parent93faa3894907508933a43173d829b15fd32cbc44 (diff)
Add playing view showing declarer and dummy hands
-rw-r--r--protocol/src/bridge_engine.rs19
-rw-r--r--protocol/src/simple_bots.rs6
-rw-r--r--webapp/src/components/table.rs34
3 files changed, 55 insertions, 4 deletions
diff --git a/protocol/src/bridge_engine.rs b/protocol/src/bridge_engine.rs
index bfc2a93..293b205 100644
--- a/protocol/src/bridge_engine.rs
+++ b/protocol/src/bridge_engine.rs
@@ -187,6 +187,11 @@ impl DealInPlay {
self.in_progress.current_player()
}
+ pub fn is_dummy_visible(&self) -> bool {
+ !self.tricks_played.is_empty()
+ || !self.in_progress.trick.cards_played.is_empty()
+ }
+
pub fn play(
mut self: Self,
card: Card,
@@ -835,11 +840,23 @@ impl PlayStatePlayerView {
play_state: &PlayState,
player_position: Player,
) -> Self {
+ let dummy = if play_state.playing_deal.is_dummy_visible() {
+ Some(
+ play_state
+ .contract
+ .declarer
+ .many_next(2)
+ .get_cards(&play_state.playing_deal.deal)
+ .clone(),
+ )
+ } else {
+ None
+ };
Self {
player_position,
bidding: play_state.bidding.clone(),
contract: play_state.contract,
- dummy: None,
+ dummy,
declarer_tricks: 0,
hand: player_position
.get_cards(&play_state.playing_deal.deal)
diff --git a/protocol/src/simple_bots.rs b/protocol/src/simple_bots.rs
index 501f1f4..8965254 100644
--- a/protocol/src/simple_bots.rs
+++ b/protocol/src/simple_bots.rs
@@ -67,6 +67,9 @@ mod tests {
let south_state =
PlayStatePlayerView::from_play_state(&play_state, Player::South);
+ assert!(!play_state.playing_deal.is_dummy_visible());
+ assert!(south_state.dummy.is_none());
+
let card1 = (RandomPlayingBot {}).play(&south_state).await;
info!("South state: {south_state:#?}");
@@ -79,6 +82,9 @@ mod tests {
let west_state =
PlayStatePlayerView::from_play_state(&play_state, Player::West);
+ assert!(play_state.playing_deal.is_dummy_visible());
+ assert!(west_state.dummy.is_some());
+
let card2 = (RandomPlayingBot {}).play(&west_state).await;
info!("West state: {west_state:#?}");
diff --git a/webapp/src/components/table.rs b/webapp/src/components/table.rs
index 78a5f91..ab95e10 100644
--- a/webapp/src/components/table.rs
+++ b/webapp/src/components/table.rs
@@ -88,9 +88,8 @@ pub fn online_table(props: &OnlineTableProps) -> Html {
let center = match &*table_state {
Some(GameStatePlayerView::Bidding(bidding)) =>
bidding_view(bidding, on_bid),
- Some(GameStatePlayerView::Playing(playing)) => html! {
- {"Need to implement this"}
- },
+ Some(GameStatePlayerView::Playing(playing)) =>
+ playing_view(playing),
None => html! { <p>{"Loading table"}</p> },
};
@@ -100,7 +99,9 @@ pub fn online_table(props: &OnlineTableProps) -> Html {
<button onclick={leave_table}>
{ "Leave table" }
</button>
+ <div class="game-layout">
{ center }
+ </div>
</>
}
}
@@ -129,3 +130,30 @@ pub fn bidding_view(
</>
}
}
+
+pub fn playing_view(
+ playing: &PlayStatePlayerView)
+ -> Html {
+ let on_card_clicked = Callback::from(|card| {});
+ // Dummy is assumed to be north for now.
+ let dummy = match &playing.dummy {
+ Some(hand) => html! {
+ <Hand cards={hand.clone()} on_card_clicked={on_card_clicked.clone()}/>
+ },
+ None => html! {<p>{"Dummy is not visible yet"}</p>},
+ };
+ html! {
+ <>
+ <div class="center">
+ <p>{format!("It is {:?} to play", playing.current_player())}</p>
+ <p>{format!("Current trick: {:?}", playing.current_trick)}</p>
+ </div>
+ <div class="hand north">
+ { dummy }
+ </div>
+ <div class="hand south">
+ <Hand cards={playing.hand.clone()} on_card_clicked={on_card_clicked.clone()} />
+ </div>
+ </>
+ }
+}