Skip to content

Commit

Permalink
IPVGO: Remove opponent from react state (#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
ficocelliguy authored Apr 24, 2024
1 parent f4fcb5c commit 0f23c95
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Go/ui/GoGameboardWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
// Destructure boardState to allow useMemo to trigger correctly
const traditional = Settings.GoTraditionalStyle;
const [showPriorMove, setShowPriorMove] = useState(false);
const [opponent, setOpponent] = useState<GoOpponent>(boardState.ai);
const [scoreOpen, setScoreOpen] = useState(false);
const [searchOpen, setSearchOpen] = useState(false);
const [waitingOnAI, setWaitingOnAI] = useState(false);
Expand Down Expand Up @@ -75,7 +74,7 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps

// Lock the board when it isn't the player's turn
const gameOver = boardState.previousPlayer === null;
const notYourTurn = boardState.previousPlayer === GoColor.black && opponent !== GoOpponent.none;
const notYourTurn = boardState.previousPlayer === GoColor.black && Go.currentGame.ai !== GoOpponent.none;
if (notYourTurn) {
SnackbarEvents.emit(`It is not your turn to play.`, ToastVariant.WARNING, 2000);
return;
Expand All @@ -94,7 +93,7 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
const didUpdateBoard = makeMove(boardState, x, y, currentPlayer);
if (didUpdateBoard) {
rerender();
opponent !== GoOpponent.none && takeAiTurn(boardState);
Go.currentGame.ai !== GoOpponent.none && takeAiTurn(boardState);
}
}

Expand All @@ -113,7 +112,7 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
}

setTimeout(() => {
opponent !== GoOpponent.none && takeAiTurn(boardState);
Go.currentGame.ai !== GoOpponent.none && takeAiTurn(boardState);
}, 100);
}

Expand All @@ -139,10 +138,9 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
setSearchOpen(true);
}

function resetState(newBoardSize = boardSize, newOpponent = opponent) {
function resetState(newBoardSize = boardSize, newOpponent = Go.currentGame.ai) {
setScoreOpen(false);
setSearchOpen(false);
setOpponent(newOpponent);
if (boardState.previousPlayer !== null && boardState.previousBoards.length) {
resetWinstreak(boardState.ai, false);
}
Expand Down Expand Up @@ -173,7 +171,8 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
const endGameAvailable = boardState.previousPlayer === GoColor.white && boardState.passCount;
const noLegalMoves =
boardState.previousPlayer === GoColor.white && !getAllValidMoves(boardState, GoColor.black).length;
const disablePassButton = opponent !== GoOpponent.none && boardState.previousPlayer === GoColor.black && waitingOnAI;
const disablePassButton =
Go.currentGame.ai !== GoOpponent.none && boardState.previousPlayer === GoColor.black && waitingOnAI;

const scoreBoxText = boardState.previousBoards.length
? `Score: Black: ${score[GoColor.black].sum} White: ${score[GoColor.white].sum}`
Expand Down Expand Up @@ -206,7 +205,7 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
onClose={() => setScoreOpen(false)}
newSubnet={() => newSubnet()}
finalScore={score}
opponent={opponent}
opponent={Go.currentGame.ai}
></GoScoreModal>
<div className={classes.boardFrame}>
{traditional ? (
Expand All @@ -219,8 +218,12 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
<Box className={`${classes.inlineFlexBox} ${classes.opponentTitle}`}>
<br />
<Typography variant={"h6"} className={classes.opponentLabel}>
{opponent !== GoOpponent.none ? "Subnet owner: " : ""}{" "}
{opponent === GoOpponent.w0r1d_d43m0n ? <CorruptableText content={opponent} spoiler={false} /> : opponent}
{Go.currentGame.ai !== GoOpponent.none ? "Subnet owner: " : ""}{" "}
{Go.currentGame.ai === GoOpponent.w0r1d_d43m0n ? (
<CorruptableText content={Go.currentGame.ai} spoiler={false} />
) : (
Go.currentGame.ai
)}
</Typography>
<br />
</Box>
Expand Down

0 comments on commit 0f23c95

Please sign in to comment.