Skip to content

Commit

Permalink
Bugfix/mcts (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
zarns authored Nov 16, 2024
1 parent 761b732 commit f2b016d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion ui/src/components/RightDrawer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $dark-divider: rgb(0 0 0 / 80%);

&.red { color: $red; }
&.blue { color: $blue; }
&.white { color: $blue; }
&.white { color: $white; }
&.orange { color: $orange; }

.player-color {
Expand Down
52 changes: 29 additions & 23 deletions ui/src/pages/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,38 @@ import { createGame } from "../utils/apiClient";

import "./HomePage.scss";

// Enum of Type of Game Mode
const GameMode = Object.freeze({
HUMAN_VS_CATANATRON: "HUMAN_VS_CATANATRON",
RANDOM_BOTS: "RANDOM_BOTS",
CATANATRON_BOTS: "CATANATRON_BOTS",
});

function getPlayers(gameMode, numPlayers) {
switch (gameMode) {
case GameMode.HUMAN_VS_CATANATRON:
const players = ["HUMAN"];
for (let i = 1; i < numPlayers; i++) {
players.push("CATANATRON");
}
return players;
case GameMode.RANDOM_BOTS:
return Array(numPlayers).fill("RANDOM");
case GameMode.CATANATRON_BOTS:
return Array(numPlayers).fill("CATANATRON");
default:
throw new Error("Invalid Game Mode");
}
}

export default function HomePage() {
const [loading, setLoading] = useState(false);
const [numPlayers, setNumPlayers] = useState(2);
const history = useHistory();

const handleCreateGame = async (getPlayers) => {
const handleCreateGame = async (gameMode) => {
setLoading(true);
const players = getPlayers(numPlayers);
const players = getPlayers(gameMode, numPlayers);
const gameId = await createGame(players);
setLoading(false);
history.push("/games/" + gameId);
Expand Down Expand Up @@ -50,39 +74,21 @@ export default function HomePage() {
<Button
variant="contained"
color="primary"
onClick={() => {
handleCreateGame((numPlayers) => {
const players = ["HUMAN"];
for (let i = 1; i < numPlayers; i++) {
players.push("CATANATRON");
}
return players;
});
}}
onClick={() => handleCreateGame(GameMode.HUMAN_VS_CATANATRON)}
>
Play against Catanatron
</Button>
<Button
variant="contained"
color="secondary"
onClick={() => {
handleCreateGame((numPlayers) => {
const players = Array(numPlayers).fill("RANDOM");
return players;
});
}}
onClick={() => handleCreateGame(GameMode.RANDOM_BOTS)}
>
Watch Random Bots
</Button>
<Button
variant="contained"
color="secondary"
onClick={() => {
handleCreateGame((numPlayers) => {
const players = Array(numPlayers).fill("CATANATRON");
return players;
});
}}
onClick={() => handleCreateGame(GameMode.CATANATRON_BOTS)}
>
Watch Catanatron
</Button>
Expand Down
9 changes: 4 additions & 5 deletions ui/src/pages/HomePage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,27 @@

.player-count-buttons {
.player-count-button {
width: 116px;
width: 130px;
height: 35px;
font-size: 1rem;
color: white !important;
margin: 0 4px;
transition: background-color 0.3s;
background-color: $dark-gray !important;

&:hover {
background-color: darken($dark-gray, 10%) !important;
}

&.selected {
background-color: #0d47a1 !important;
color: white !important;

&:hover {
background-color: darken(#0d47a1, 1%) !important;
}
}
}
}

}
}

0 comments on commit f2b016d

Please sign in to comment.