()
| 344 | } |
| 345 | |
| 346 | addAgentToMap() { |
| 347 | const color = randomColor({ luminosity: "light" }); |
| 348 | var newMap = structuredClone(this.state.map); |
| 349 | for (let i = this.state.addedSRow; i < this.state.addedSRow + this.state.addedHeight; i++) { |
| 350 | for (let j = this.state.addedSCol; j < this.state.addedSCol + this.state.addedWidth; j++) { |
| 351 | if (newMap[i][j].agent !== -1 || newMap[i][j].isWall) { |
| 352 | this.setState({ isError: true }, () => this.showSnackbar(color)); |
| 353 | return; |
| 354 | } |
| 355 | newMap[i][j].agent = this.state.numAgents + 1; |
| 356 | newMap[i][j].isStart = true; |
| 357 | newMap[i][j].color = color; |
| 358 | } |
| 359 | } |
| 360 | for (let i = this.state.addedGRow; i < this.state.addedGRow + this.state.addedHeight; i++) { |
| 361 | for (let j = this.state.addedGCol; j < this.state.addedGCol + this.state.addedWidth; j++) { |
| 362 | if (newMap[i][j].agent !== -1 || newMap[i][j].isWall) { |
| 363 | this.setState({ isError: true }, () => this.showSnackbar(color)); |
| 364 | return; |
| 365 | } |
| 366 | newMap[i][j].agent = this.state.numAgents + 1; |
| 367 | newMap[i][j].isGoal = true; |
| 368 | newMap[i][j].color = color; |
| 369 | } |
| 370 | } |
| 371 | this.setState({ map: newMap }, () => this.showSnackbar(color)); |
| 372 | } |
| 373 | |
| 374 | handleAddAgentByClick() { |
| 375 | var color = randomColor({ luminosity: "light" }); |
no test coverage detected