Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions .yarn/patches/react-chessboard-npm-4.7.3-53276f9bfb.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
diff --git a/dist/index.esm.js b/dist/index.esm.js
index 3267047874ff62812505a97c7a96d3fae7a8e220..0992869f2bc525d938ad60815cd0630895a02bac 100644
--- a/dist/index.esm.js
+++ b/dist/index.esm.js
@@ -69,9 +69,9 @@ const WHITE_COLUMN_VALUES = {
c: 2,
d: 3,
e: 4,
- f: 5,
- g: 6,
- h: 7,
+ f: 0,
+ g: 1,
+ h: 2,
};
const BLACK_COLUMN_VALUES = {
a: 7,
@@ -83,8 +83,8 @@ const BLACK_COLUMN_VALUES = {
g: 1,
h: 0,
};
-const WHITE_ROWS = [7, 6, 5, 4, 3, 2, 1, 0];
-const BLACK_ROWS = [0, 1, 2, 3, 4, 5, 6, 7];
+const WHITE_ROWS = [2, 1, 0];
+const BLACK_ROWS = [0, 1, 2];

// https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces
// By en:User:Cburnett - Own work
@@ -778,19 +778,19 @@ function Notation({ row, col }) {
const whiteColor = customLightSquareStyle.backgroundColor;
const blackColor = customDarkSquareStyle.backgroundColor;
const isRow = col === 0;
- const isColumn = row === 7;
+ const isColumn = row === 2;
const isBottomLeftSquare = isRow && isColumn;
function getRow() {
- return boardOrientation === "white" ? 8 - row : row + 1;
+ return boardOrientation === "white" ? 3 - row : row + 1;
}
function getColumn() {
return boardOrientation === "black" ? COLUMNS[7 - col] : COLUMNS[col];
}
function renderBottomLeft() {
- return (jsxs(Fragment, { children: [jsx("div", Object.assign({ style: Object.assign(Object.assign({ zIndex: 3, position: "absolute" }, { color: whiteColor }), numericStyle(boardWidth, customNotationStyle)) }, { children: getRow() })), jsx("div", Object.assign({ style: Object.assign(Object.assign({ zIndex: 3, position: "absolute" }, { color: whiteColor }), alphaStyle(boardWidth, customNotationStyle)) }, { children: getColumn() }))] }));
+ return (jsxs(Fragment, { children: [jsx("div", Object.assign({ style: Object.assign(Object.assign({ zIndex: 3, position: "absolute" }, { color: blackColor }), numericStyle(boardWidth, customNotationStyle)) }, { children: getRow() })), jsx("div", Object.assign({ style: Object.assign(Object.assign({ zIndex: 3, position: "absolute" }, { color: blackColor }), alphaStyle(boardWidth, customNotationStyle)) }, { children: getColumn() }))] }));
}
function renderLetters() {
- return (jsx("div", Object.assign({ style: Object.assign(Object.assign({ userSelect: "none", zIndex: 3, position: "absolute" }, { color: col % 2 !== 0 ? blackColor : whiteColor }), alphaStyle(boardWidth, customNotationStyle)) }, { children: getColumn() })));
+ return (jsx("div", Object.assign({ style: Object.assign(Object.assign({ userSelect: "none", zIndex: 3, position: "absolute" }, { color: col % 2 === 0 ? blackColor : whiteColor }), alphaStyle(boardWidth, customNotationStyle)) }, { children: getColumn() })));
}
function renderNumbers() {
return (jsx("div", Object.assign({ style: Object.assign(Object.assign({ userSelect: "none", zIndex: 3, position: "absolute" }, (boardOrientation === "black"
@@ -4844,15 +4844,15 @@ function Squares() {
});
return result;
}, [premoves]);
- return (jsx("div", Object.assign({ "data-boardid": id }, { children: [...Array(8)].map((_, r) => {
+ return (jsx("div", Object.assign({ "data-boardid": id }, { children: [...Array(3)].map((_, r) => {
return (jsx("div", Object.assign({ style: {
display: "flex",
flexWrap: "nowrap",
width: boardWidth,
- } }, { children: [...Array(8)].map((_, c) => {
+ } }, { children: [...Array(3)].map((_, c) => {
const square = boardOrientation === "black"
- ? (COLUMNS[7 - c] + (r + 1))
- : (COLUMNS[c] + (8 - r));
+ ? (COLUMNS[2 - c] + (r + 2))
+ : (COLUMNS[c] + (4 - r));
const squareColor = c % 2 === r % 2 ? "white" : "black";
const squareHasPremove = premoves.find((p) => p.sourceSq === square || p.targetSq === square);
const squareHasPremoveTarget = premovesHistory
diff --git a/dist/index.js b/dist/index.js
index a55a978e1a9de9b7eb3ec174177fc60186384931..fddcb4cc3fdd5ff2697ab748afc24bf4a58da8fb 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -30,7 +30,7 @@ function __rest(s, e) {
return t;
}

-const COLUMNS = "abcdefgh".split("");
+const COLUMNS = "abc".split("");
const START_POSITION_OBJECT = {
a8: "bR",
b8: "bN",
@@ -69,24 +69,14 @@ const WHITE_COLUMN_VALUES = {
a: 0,
b: 1,
c: 2,
- d: 3,
- e: 4,
- f: 5,
- g: 6,
- h: 7,
};
const BLACK_COLUMN_VALUES = {
- a: 7,
- b: 6,
- c: 5,
- d: 4,
- e: 3,
- f: 2,
- g: 1,
- h: 0,
+ a: 2,
+ b: 1,
+ c: 0,
};
-const WHITE_ROWS = [7, 6, 5, 4, 3, 2, 1, 0];
-const BLACK_ROWS = [0, 1, 2, 3, 4, 5, 6, 7];
+const WHITE_ROWS = [2, 1, 0];
+const BLACK_ROWS = [0, 1, 2];

// https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces
// By en:User:Cburnett - Own work
@@ -4846,15 +4836,15 @@ function Squares() {
});
return result;
}, [premoves]);
- return (jsxRuntime.jsx("div", Object.assign({ "data-boardid": id }, { children: [...Array(8)].map((_, r) => {
+ return (jsxRuntime.jsx("div", Object.assign({ "data-boardid": id }, { children: [...Array(3)].map((_, r) => {
return (jsxRuntime.jsx("div", Object.assign({ style: {
display: "flex",
flexWrap: "nowrap",
width: boardWidth,
- } }, { children: [...Array(8)].map((_, c) => {
+ } }, { children: [...Array(3)].map((_, c) => {
const square = boardOrientation === "black"
- ? (COLUMNS[7 - c] + (r + 1))
- : (COLUMNS[c] + (8 - r));
+ ? (COLUMNS[2 - c] + (r + 1))
+ : (COLUMNS[c] + (3 - r));
const squareColor = c % 2 === r % 2 ? "white" : "black";
const squareHasPremove = premoves.find((p) => p.sourceSq === square || p.targetSq === square);
const squareHasPremoveTarget = premovesHistory
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "utd-chess-bots",
"private": true,
"version": "0.0.0",
"workspaces": ["src/client", "src/server"],
"workspaces": [
"src/client",
"src/server"
],
"scripts": {
"dev": "ts-node src/server/main.ts",
"devup": "nodemon src/server/main.ts",
Expand Down Expand Up @@ -44,5 +47,5 @@
"optionalDependencies": {
"bufferutil": "^4.0.8"
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
"packageManager": "yarn@4.13.0"
}
2 changes: 1 addition & 1 deletion src/client/chessboard/chessboard-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function ChessboardWrapper(props: ChessboardWrapperProps): JSX.Element {
<Chessboard
// set up the board
boardOrientation={side === Side.WHITE ? "white" : "black"}
boardWidth={width}
boardWidth={width*2}
position={chess.fen}
// do a promotion check
onPromotionCheck={(from: Square, to: Square) => {
Expand Down
5 changes: 4 additions & 1 deletion src/client/game/game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function Game(): JSX.Element {
setGameInterruptedReason(gameState.gameEndReason);
}
return gameState;
})
});
},
false,
);
Expand All @@ -132,6 +132,8 @@ export function Game(): JSX.Element {
);
// go to /home if error
} else if (isError) {
console.log(isError);
console.log("error");
return <Navigate to="/home" />;
}

Expand Down Expand Up @@ -184,6 +186,7 @@ export function Game(): JSX.Element {
(move: Move): void => {
setChess(chess.copy(move));
sendMessage(new MoveMessage(move));
window.location.reload();
}
: () => {}; //send a do-nothing function if game is paused

Expand Down
2 changes: 1 addition & 1 deletion src/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"interactjs": "^1.10.27",
"motion": "^12.6.0",
"react": "^18.2.0",
"react-chessboard": "^4.5.0",
"react-chessboard": "patch:react-chessboard@npm%3A4.7.3#~/.yarn/patches/react-chessboard-npm-4.7.3-53276f9bfb.patch",
"react-dom": "^18.2.0",
"react-joystick-component": "^6.2.1",
"react-router-dom": "^6.21.3",
Expand Down
6 changes: 5 additions & 1 deletion src/client/setup/setup-game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ export function SetupGame(props: SetupGameProps) {
side: selectedSide,
difficulty: difficulty.toString(),
});
} else {
} else if (props.gameType === GameType.HUMAN){
promise = post("/start-human-game", {
side: selectedSide,
});
} else{
promise = post("/start-hexapawn-game", {
side: selectedSide,
});
}
promise.then(() => {
navigate("/game");
Expand Down
14 changes: 12 additions & 2 deletions src/client/setup/setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enum SetupType {
COMPUTER = "computer",
HUMAN = "human",
PUZZLE = "puzzle",
HEXAPAWN = "hexapawn",
}

/**
Expand Down Expand Up @@ -60,13 +61,14 @@ export function Setup(): JSX.Element {
: null}
{(
setupType === SetupType.COMPUTER ||
setupType === SetupType.HUMAN
setupType === SetupType.HUMAN ||
setupType === SetupType.HEXAPAWN
) ?
<SetupGame
gameType={
setupType === SetupType.COMPUTER ?
GameType.COMPUTER
: GameType.HUMAN
: setupType === SetupType.HUMAN ? GameType.HUMAN : GameType.HEXAPAWN
}
/>
: null}
Expand Down Expand Up @@ -132,6 +134,14 @@ function SetupMain(props: SetupMainProps) {
onClick={() => props.onPageChange(SetupType.PUZZLE)}
className={buttonColor()}
/>
<Button
large
text="Hexapawn"
rightIcon="arrow-right"
intent="primary"
onClick={() => props.onPageChange(SetupType.HEXAPAWN)}
className={buttonColor()}
/>
<ThemeButtons />
</>
);
Expand Down
1 change: 1 addition & 0 deletions src/common/client-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export enum Difficulty {
export enum GameType {
COMPUTER = "computer",
HUMAN = "human",
HEXAPAWN = "hexapawn",
}
66 changes: 63 additions & 3 deletions src/server/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from "./managers";
import {
ComputerGameManager,
HexapawnGameManager,
HumanGameManager,
PuzzleGameManager,
} from "./game-manager";
Expand Down Expand Up @@ -70,6 +71,7 @@ import {
setAllRobotsToDefaultPositions,
unpauseGame,
} from "./pauseHandler";
import { type Square } from "chess.js";

/**
* Helper function to move all robots from their home positions to their default positions
Expand Down Expand Up @@ -354,9 +356,9 @@ apiRouter.get("/game-state", (req, res) => {
return res.status(400).send({ message: "No game is currently active" });
}
const clientType = clientManager.getClientType(req.cookies.id);
return res.send({
gameManager.getGameState(clientType),
});
return res.send(
gameManager.getGameState(clientType)
);
});

/**
Expand Down Expand Up @@ -428,6 +430,64 @@ apiRouter.post("/start-human-game", async (req, res) => {
return res.send({ message: "success" });
});

/**
* start hexapawn game endpoint
*
* creates a new human game engine based on the request's side
*
* returns a success message
*/
apiRouter.post("/start-hexapawn-game", async (req, res) => {
canReloadQueue = true;
const side = req.query.side as Side;

// Convert puzzle.robotDefaultPositions from Record<string, string> to Map<string, GridIndices>
const defaultPositionsMap = new Map<string, GridIndices>();
for (const [robotId, startSquare] of Object.entries({
"robot-1": "a2",
"robot-2": "b2",
"robot-3": "c2",
"robot-4": "a4",
"robot-5": "b4",
"robot-6": "c4",
})) {
const robot = robotManager.getRobot(robotId);
if (robot) {
// Convert square string to GridIndices using squareToGrid
const gridIndices = GridIndices.squareToGrid(startSquare as Square);
defaultPositionsMap.set(robotId, gridIndices);
console.log(
`Robot ${robotId} will move to square ${startSquare} (${gridIndices.toString()})`,
);
} else {
return res.status(400).send({
message:
"Missing robot " +
robotId +
" which is required to start the puzzle, because it is included in the puzzle's robotDefaultPositions map.",
});
}
}

// Execute the movement command with the converted positions
await setupDefaultRobotPositions(
!START_ROBOTS_AT_DEFAULT,
defaultPositionsMap,
);

// create a new human game manager
setGameManager(
new HexapawnGameManager(
new ChessEngine(),
socketManager,
side,
clientManager,
false,
),
);
return res.send({ message: "success" });
});

apiRouter.post("/start-puzzle-game", async (req, res) => {
//get puzzle components
const puzzle = JSON.parse(req.query.puzzle as string) as PuzzleComponents;
Expand Down
Loading
Loading