Skip to content

Commit

Permalink
CPUの打つ手をゆっくりにする
Browse files Browse the repository at this point in the history
  • Loading branch information
ia7ck committed Apr 28, 2024
1 parent c780852 commit 4b6f915
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions app/abc349_e/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ export default function ABC349_E() {
...state.grid[p],
player: player === "first" ? "second" : "first",
};
setState({ step: "play", grid: newGrid });
if (rest < state.grid.length) {
setState({ step: "play", grid: newGrid });
} else {
// CPU first turn
setTimeout(() => {
setState({ step: "play", grid: newGrid });
}, 200);
}
}
}
}
Expand All @@ -108,17 +115,9 @@ export default function ABC349_E() {
// step: "input" -> "play"
const handleStartButtonClick = () => {
if (state.step === "input") {
const newGrid = string9ToOwner9(state.grid);
if (newGrid !== null) {
if (player === "second") {
// CPU first
const p = choosePosition(newGrid);
newGrid[p] = { ...newGrid[p], player: "first" };
}
setState({
step: "play",
grid: newGrid,
});
const grid = string9ToOwner9(state.grid);
if (grid !== null) {
setState({ step: "play", grid });
}
}
};
Expand Down Expand Up @@ -361,6 +360,9 @@ function GridButton({
"grid place-items-center h-20 w-20 border-l last:border-r border-gray-400",
grid[index].player === "first" && "bg-rose-100",
grid[index].player === "second" && "bg-indigo-100",
grid[index].player !== null &&
grid[index].player !== player &&
"transition-colors duration-500",
grid[index].player === null &&
isYourTurn &&
(player === "first"
Expand Down

0 comments on commit 4b6f915

Please sign in to comment.