添加预测功能切换
This commit is contained in:
parent
d3ed86d212
commit
1f73076125
|
@ -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",
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
"doudizhu": {
|
||||
"ai_hand_faceup": "显示AI手牌",
|
||||
"ai_prediction": "显示AI预测",
|
||||
"play_as_landlord": "扮演地主",
|
||||
"play_as_peasant": "扮演农民",
|
||||
"landlord_up": "地主上家",
|
||||
|
|
|
@ -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 === '') {
|
||||
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) {
|
||||
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,8 +497,10 @@ function PvEDoudizhuDemoView() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if(!eval_only) {
|
||||
proceedNextTurn(bestAction.split(''));
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
Message({
|
||||
message: 'Error receiving prediction result, please try refresh the page',
|
||||
|
@ -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={
|
||||
<Switch checked={!hidePredictionArea} onChange={toggleHidePredictionArea} />
|
||||
<Switch checked={!hideRivalHand} onChange={setHideRivalHand(!hideRivalHand)} />
|
||||
}
|
||||
label={t('doudizhu.ai_hand_faceup')}
|
||||
/>
|
||||
<FormControlLabel
|
||||
style={{ textAlign: 'center', height: '100%', display: 'inline-block' }}
|
||||
className="switch-control"
|
||||
control={
|
||||
<Switch checked={!hidePredictionArea} onChange={setHidePredictionArea(!hidePredictionArea)} />
|
||||
}
|
||||
label={t('doudizhu.ai_prediction')}
|
||||
/>
|
||||
</FormGroup>
|
||||
</Layout.Col>
|
||||
<Layout.Col span="1" style={{ height: '100%', width: '1px' }}>
|
||||
|
|
Loading…
Reference in New Issue