From f76b84af7a27856b6908d488726368628e63e495 Mon Sep 17 00:00:00 2001 From: Songyi Huang Date: Sun, 25 Apr 2021 22:59:22 -0700 Subject: [PATCH] fix bug in three landlord card; show three landlord card in right side --- src/assets/gameview.scss | 12 +++- src/view/PvEView/PvEDoudizhuDemoView.js | 75 +++++++++++++++++++++---- 2 files changed, 75 insertions(+), 12 deletions(-) diff --git a/src/assets/gameview.scss b/src/assets/gameview.scss index c660bb9..9f5c190 100644 --- a/src/assets/gameview.scss +++ b/src/assets/gameview.scss @@ -103,7 +103,8 @@ } .MuiFormControlLabel-label { - display: table-cell; + text-align: center; + height: 51px; line-height: 51px; vertical-align: middle; } @@ -143,6 +144,15 @@ width: 100%; height: calc(100% - 72px); + &.with-three-landlord-cards { + height: calc(100% - 200px); + .probability-item { + .playing { + height: 109px; + } + } + } + .probability-item { display: table-row; diff --git a/src/view/PvEView/PvEDoudizhuDemoView.js b/src/view/PvEView/PvEDoudizhuDemoView.js index ca5a6f9..50d72b6 100644 --- a/src/view/PvEView/PvEDoudizhuDemoView.js +++ b/src/view/PvEView/PvEDoudizhuDemoView.js @@ -30,7 +30,8 @@ import { douzeroDemoUrl } from '../../utils/config'; const shuffledDoudizhuDeck = shuffleArray(fullDoudizhuDeck.slice()); -const threeLandlordCards = shuffleArray(sortDoudizhuCards(shuffledDoudizhuDeck.slice(0, 3))); +let threeLandlordCards = shuffleArray(sortDoudizhuCards(shuffledDoudizhuDeck.slice(0, 3))); +const originalThreeLandlordCards = threeLandlordCards.slice(); const initConsiderationTime = 30000; const considerationTimeDeduction = 1000; @@ -43,9 +44,9 @@ let initHands = [ shuffledDoudizhuDeck.slice(20, 37), shuffledDoudizhuDeck.slice(37, 54), ]; + console.log('init hands', initHands); console.log('three landlord card', threeLandlordCards); -console.log('player info', playerInfo); let gameStateTimeout = null; @@ -92,6 +93,25 @@ function PvEDoudizhuDemoView() { } const proceedNextTurn = async (playingCard, rankOnly = true) => { + // take played three landlord card out + if (playerInfo[gameState.currentPlayer].role === 'landlord' && threeLandlordCards.length > 0) { + let playingCardCopy; + if (rankOnly) playingCardCopy = playingCard.slice(); + else + playingCardCopy = playingCard.map((card) => { + const { rank } = card2SuiteAndRank(card); + return rank; + }); + threeLandlordCards = threeLandlordCards.filter((card) => { + const { rank } = card2SuiteAndRank(card); + const idx = playingCardCopy.indexOf(rank); + if (idx >= 0) { + playingCardCopy.splice(idx, 1); + return false; + } else return true; + }); + } + // if next player is user, get legal actions if ((gameState.currentPlayer + 1) % 3 === mainPlayerId) { const player_hand_cards = cardArr2DouzeroFormat(gameState.hands[mainPlayerId].slice().reverse()); @@ -574,7 +594,7 @@ function PvEDoudizhuDemoView() { )} {predictionRes.prediction.length > idx ? ( -
+
{`Expected Score: ${predictionRes.prediction[idx][1]}`}
) : ( @@ -636,11 +656,44 @@ function PvEDoudizhuDemoView() { -
+ {playerInfo.length > 0 && gameState.currentPlayer !== null ? ( +
+ + Three Landlord Cards + +
+ {sortDoudizhuCards(originalThreeLandlordCards, true).map((card) => { + const [rankClass, suitClass, rankText, suitText] = translateCardData(card); + return ( +
+ {rankText} + {suitText} +
+ ); + })} +
+
+ ) : ( +
+ Waiting... +
+ )} + +
{playerInfo.length > 0 && gameState.currentPlayer !== null ? ( - Current Player: {gameState.currentPlayer} -
+ Current Player: {gameState.currentPlayer} |{' '} {playerInfo[gameState.currentPlayer].role}
) : ( @@ -648,7 +701,7 @@ function PvEDoudizhuDemoView() { )}
-
+
{computeProbabilityItem(0)}
{computeProbabilityItem(1)}
{computeProbabilityItem(2)}
@@ -662,8 +715,8 @@ function PvEDoudizhuDemoView() { } label="Show Rival Cards" /> @@ -675,8 +728,8 @@ function PvEDoudizhuDemoView() { }