Skip to content

Commit

Permalink
logs and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
BurbachGabriel committed Nov 2, 2024
1 parent cbd8db1 commit 579224b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug ChessBot Server",
"runtimeExecutable": "nodemon",
"program": "${workspaceFolder}/src/server/main.ts",
"restart": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"env": {
"NODE_ENV": ""
}
}
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"workspaces": ["src/client", "src/server"],
"scripts": {
"dev": "nodemon src/server/main.ts",
"debug": "nodemon --inspect src/server/main.ts",
"start": "NODE_ENV=production ts-node ./src/server/main.ts",
"build": "vite build",
"docs:build": "typedoc",
Expand Down
15 changes: 14 additions & 1 deletion src/server/robot/path-materializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,22 @@ export function materializePath(move: Move): Command {
const mainPiece = robotManager.getRobotAtIndices(
GridIndices.squareToGrid(move.from),
);

console.log(
"robot indices are: ",
GridIndices.squareToGrid(move.to),
);
robotManager.updateRobot(
mainPiece.id,
GridIndices.squareToGrid(move.to),
);

console.log(
"captured robot indices are: ",
Math.floor(robotManager.getRobot(capturePiece).position.x),
),
" ,",
Math.floor(robotManager.getRobot(capturePiece).position.x);
robotManager.updateRobot(
capturePiece,
robotManager.getRobot(capturePiece).homeIndices,
Expand All @@ -549,7 +561,8 @@ export function materializePath(move: Move): Command {
const mainPiece = robotManager.getRobotAtIndices(
GridIndices.squareToGrid(move.from),
);


console.log("robot indices are: ", GridIndices.squareToGrid(move.to));
robotManager.updateRobot(
mainPiece.id,
GridIndices.squareToGrid(move.to),
Expand Down
10 changes: 7 additions & 3 deletions src/server/robot/robot-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,21 @@ export class RobotManager {
* Throws if no robot is found.
*/
getRobotAtIndices(indices: GridIndices): Robot {
const robotId = this.indicesToIds.get(JSON.stringify(indices))
const robotId = this.indicesToIds.get(JSON.stringify(indices));
if (robotId === undefined) {
throw new Error("Failed to find robot at position " + indices);
}
return this.getRobot(robotId);
}

updateRobot(robotId: string, indices: GridIndices) {
if (this.indicesToIds.has(JSON.stringify(indices))) {
this.indicesToIds.delete(JSON.stringify(indices));
// if (this.indicesToIds.has(JSON.stringify(indices))) {
// this.indicesToIds.delete(JSON.stringify(indices));
// }
for (const [i, r] of this.indicesToIds.entries()) {
if (robotId === r) this.indicesToIds.delete(i);
}
this.indicesToIds.set(JSON.stringify(indices), robotId);
console.log("new indices are: ", indices);
}
}

0 comments on commit 579224b

Please sign in to comment.