添加预测功能切换
This commit is contained in:
parent
d3ed86d212
commit
1f73076125
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
"doudizhu": {
|
"doudizhu": {
|
||||||
"ai_hand_faceup": "AI Hand Face-Up",
|
"ai_hand_faceup": "AI Hand Face-Up",
|
||||||
|
"ai_prediction": "AI Prediction",
|
||||||
"play_as_landlord": "Play As Landlord",
|
"play_as_landlord": "Play As Landlord",
|
||||||
"play_as_peasant": "Play As Peasant",
|
"play_as_peasant": "Play As Peasant",
|
||||||
"landlord_up": "Landlord Up",
|
"landlord_up": "Landlord Up",
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
"doudizhu": {
|
"doudizhu": {
|
||||||
"ai_hand_faceup": "显示AI手牌",
|
"ai_hand_faceup": "显示AI手牌",
|
||||||
|
"ai_prediction": "显示AI预测",
|
||||||
"play_as_landlord": "扮演地主",
|
"play_as_landlord": "扮演地主",
|
||||||
"play_as_peasant": "扮演农民",
|
"play_as_peasant": "扮演农民",
|
||||||
"landlord_up": "地主上家",
|
"landlord_up": "地主上家",
|
||||||
|
|
|
@ -356,7 +356,7 @@ function PvEDoudizhuDemoView() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const requestApiPlay = async () => {
|
const requestApiPlay = async (eval_only) => {
|
||||||
// gather information for api request
|
// gather information for api request
|
||||||
const player_position = playerInfo[gameState.currentPlayer].douzeroPlayerPosition;
|
const player_position = playerInfo[gameState.currentPlayer].douzeroPlayerPosition;
|
||||||
const player_hand_cards = cardArr2DouzeroFormat(gameState.hands[gameState.currentPlayer].slice().reverse());
|
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));
|
const apiRes = await axios.post(`${douzeroDemoUrl}/legal`, qs.stringify(requestBody));
|
||||||
if (apiRes.data.legal_action === '') {
|
if (apiRes.data.legal_action === '') {
|
||||||
proceedNextTurn([]);
|
if(!eval_only) {
|
||||||
|
proceedNextTurn([]);
|
||||||
|
}
|
||||||
setPredictionRes({
|
setPredictionRes({
|
||||||
prediction: [['', t('doudizhu.only_choice')]],
|
prediction: [['', t('doudizhu.only_choice')]],
|
||||||
hands: gameState.hands[gameState.currentPlayer].slice(),
|
hands: gameState.hands[gameState.currentPlayer].slice(),
|
||||||
});
|
});
|
||||||
} else if (apiRes.data.legal_action.split(',').length === 1) {
|
} 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({
|
setPredictionRes({
|
||||||
prediction: [[apiRes.data.legal_action, t('doudizhu.only_choice')]],
|
prediction: [[apiRes.data.legal_action, t('doudizhu.only_choice')]],
|
||||||
hands: gameState.hands[gameState.currentPlayer].slice(),
|
hands: gameState.hands[gameState.currentPlayer].slice(),
|
||||||
|
@ -493,7 +497,9 @@ function PvEDoudizhuDemoView() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
proceedNextTurn(bestAction.split(''));
|
if(!eval_only) {
|
||||||
|
proceedNextTurn(bestAction.split(''));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Message({
|
Message({
|
||||||
|
@ -715,7 +721,9 @@ function PvEDoudizhuDemoView() {
|
||||||
if (gameState.currentPlayer !== null && syncGameStatus === 'playing') {
|
if (gameState.currentPlayer !== null && syncGameStatus === 'playing') {
|
||||||
// if current player is not user, request for API player
|
// if current player is not user, request for API player
|
||||||
if (gameState.currentPlayer !== mainPlayerId) {
|
if (gameState.currentPlayer !== mainPlayerId) {
|
||||||
requestApiPlay();
|
requestApiPlay(false);
|
||||||
|
} else if (!hidePredictionArea) {
|
||||||
|
requestApiPlay(true);
|
||||||
} else {
|
} else {
|
||||||
setPredictionRes({ prediction: [], hands: [] });
|
setPredictionRes({ prediction: [], hands: [] });
|
||||||
}
|
}
|
||||||
|
@ -1056,10 +1064,18 @@ function PvEDoudizhuDemoView() {
|
||||||
style={{ textAlign: 'center', height: '100%', display: 'inline-block' }}
|
style={{ textAlign: 'center', height: '100%', display: 'inline-block' }}
|
||||||
className="switch-control"
|
className="switch-control"
|
||||||
control={
|
control={
|
||||||
<Switch checked={!hidePredictionArea} onChange={toggleHidePredictionArea} />
|
<Switch checked={!hideRivalHand} onChange={setHideRivalHand(!hideRivalHand)} />
|
||||||
}
|
}
|
||||||
label={t('doudizhu.ai_hand_faceup')}
|
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>
|
</FormGroup>
|
||||||
</Layout.Col>
|
</Layout.Col>
|
||||||
<Layout.Col span="1" style={{ height: '100%', width: '1px' }}>
|
<Layout.Col span="1" style={{ height: '100%', width: '1px' }}>
|
||||||
|
|
Loading…
Reference in New Issue