From 579224b1858f95cebf28111b4a388636966b26e0 Mon Sep 17 00:00:00 2001 From: Gabriel Burbach Date: Sat, 2 Nov 2024 00:20:54 -0500 Subject: [PATCH] logs and updates --- .vscode/launch.json | 21 +++++++++++++++++++++ package.json | 1 + src/server/robot/path-materializer.ts | 15 ++++++++++++++- src/server/robot/robot-manager.ts | 10 +++++++--- 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..79e3d4b0 --- /dev/null +++ b/.vscode/launch.json @@ -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": "" + } + } + ] +} \ No newline at end of file diff --git a/package.json b/package.json index 55e6ccfc..2d85cdf5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/server/robot/path-materializer.ts b/src/server/robot/path-materializer.ts index 85fe7d2a..8f042d91 100644 --- a/src/server/robot/path-materializer.ts +++ b/src/server/robot/path-materializer.ts @@ -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, @@ -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), diff --git a/src/server/robot/robot-manager.ts b/src/server/robot/robot-manager.ts index 6ed26371..0dc12936 100644 --- a/src/server/robot/robot-manager.ts +++ b/src/server/robot/robot-manager.ts @@ -48,7 +48,7 @@ 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); } @@ -56,9 +56,13 @@ export class RobotManager { } 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); } }