From 1f7307612571a6a4331f6faf517412da58e7e90f Mon Sep 17 00:00:00 2001 From: zhiyang7 Date: Thu, 30 Dec 2021 16:52:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A2=84=E6=B5=8B=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/locales/en/translation.json | 1 + src/locales/zh/translation.json | 1 + src/view/PvEView/PvEDoudizhuDemoView.js | 28 +++++++++++++++++++------ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 2b0f37b..a9d1094 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -8,6 +8,7 @@ "doudizhu": { "ai_hand_faceup": "AI Hand Face-Up", + "ai_prediction": "AI Prediction", "play_as_landlord": "Play As Landlord", "play_as_peasant": "Play As Peasant", "landlord_up": "Landlord Up", diff --git a/src/locales/zh/translation.json b/src/locales/zh/translation.json index 5f5d542..a32ba82 100644 --- a/src/locales/zh/translation.json +++ b/src/locales/zh/translation.json @@ -8,6 +8,7 @@ "doudizhu": { "ai_hand_faceup": "显示AI手牌", + "ai_prediction": "显示AI预测", "play_as_landlord": "扮演地主", "play_as_peasant": "扮演农民", "landlord_up": "地主上家", diff --git a/src/view/PvEView/PvEDoudizhuDemoView.js b/src/view/PvEView/PvEDoudizhuDemoView.js index 9435f8c..28d3dd1 100644 --- a/src/view/PvEView/PvEDoudizhuDemoView.js +++ b/src/view/PvEView/PvEDoudizhuDemoView.js @@ -356,7 +356,7 @@ function PvEDoudizhuDemoView() { } }; - const requestApiPlay = async () => { + const requestApiPlay = async (eval_only) => { // gather information for api request const player_position = playerInfo[gameState.currentPlayer].douzeroPlayerPosition; const player_hand_cards = cardArr2DouzeroFormat(gameState.hands[gameState.currentPlayer].slice().reverse()); @@ -444,13 +444,17 @@ function PvEDoudizhuDemoView() { }; const apiRes = await axios.post(`${douzeroDemoUrl}/legal`, qs.stringify(requestBody)); if (apiRes.data.legal_action === '') { - proceedNextTurn([]); + if(!eval_only) { + proceedNextTurn([]); + } setPredictionRes({ prediction: [['', t('doudizhu.only_choice')]], hands: gameState.hands[gameState.currentPlayer].slice(), }); } else if (apiRes.data.legal_action.split(',').length === 1) { - proceedNextTurn(apiRes.data.legal_action.split('')); + if(!eval_only) { + proceedNextTurn(apiRes.data.legal_action.split('')); + } setPredictionRes({ prediction: [[apiRes.data.legal_action, t('doudizhu.only_choice')]], hands: gameState.hands[gameState.currentPlayer].slice(), @@ -493,7 +497,9 @@ function PvEDoudizhuDemoView() { } } } - proceedNextTurn(bestAction.split('')); + if(!eval_only) { + proceedNextTurn(bestAction.split('')); + } } } catch (err) { Message({ @@ -715,7 +721,9 @@ function PvEDoudizhuDemoView() { if (gameState.currentPlayer !== null && syncGameStatus === 'playing') { // if current player is not user, request for API player if (gameState.currentPlayer !== mainPlayerId) { - requestApiPlay(); + requestApiPlay(false); + } else if (!hidePredictionArea) { + requestApiPlay(true); } else { setPredictionRes({ prediction: [], hands: [] }); } @@ -1056,10 +1064,18 @@ function PvEDoudizhuDemoView() { style={{ textAlign: 'center', height: '100%', display: 'inline-block' }} className="switch-control" control={ - + } label={t('doudizhu.ai_hand_faceup')} /> + + } + label={t('doudizhu.ai_prediction')} + />