| 358 | } |
| 359 | |
| 360 | handleMouseDown(row, col) { |
| 361 | if (this.state.toDelete) { |
| 362 | let agentToDelete = this.state.map[row][col].agent; |
| 363 | let agents = this.state.agents; |
| 364 | agents.splice(agentToDelete - 1, 1); |
| 365 | let map = this.state.map; |
| 366 | for (let i = 0; i < map.length; i++) { |
| 367 | for (let j = 0; j < map[i].length; j++) { |
| 368 | if (!map[i][j].isWall) { |
| 369 | map[i][j].isStart = false; |
| 370 | map[i][j].isGoal = false; |
| 371 | map[i][j].agent = -1; |
| 372 | map[i][j].color = ""; |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | for (let i = 0; i < agents.length; i++) { |
| 377 | let agent = agents[i]; |
| 378 | map[agent.SR][agent.SC].isStart = true; |
| 379 | map[agent.SR][agent.SC].agent = i + 1; |
| 380 | map[agent.SR][agent.SC].color = agent.color; |
| 381 | map[agent.GR][agent.GC].isGoal = true; |
| 382 | map[agent.GR][agent.GC].agent = i + 1; |
| 383 | map[agent.GR][agent.GC].color = agent.color; |
| 384 | } |
| 385 | this.setState({ map: map, agents: agents, numAgents: agents.length, toDelete: false }); |
| 386 | } else if (this.state.startToAdd) { |
| 387 | if (!this.state.map[row][col].isWall && this.state.map[row][col].agent === -1) { |
| 388 | var map = this.state.map; |
| 389 | map[row][col].agent = this.state.numAgents + 1; |
| 390 | map[row][col].isStart = true; |
| 391 | map[row][col].color = this.state.colorToAdd; |
| 392 | this.setState({ |
| 393 | startToAdd: false, |
| 394 | goalToAdd: true, |
| 395 | addedSRowClick: row, |
| 396 | addedSColClick: col, |
| 397 | map: map, |
| 398 | }); |
| 399 | } |
| 400 | } else if (this.state.goalToAdd) { |
| 401 | if (!this.state.map[row][col].isWall && this.state.map[row][col].agent === -1) { |
| 402 | var map = this.state.map; |
| 403 | map[row][col].agent = this.state.numAgents + 1; |
| 404 | map[row][col].isGoal = true; |
| 405 | map[row][col].color = this.state.colorToAdd; |
| 406 | this.setState({ |
| 407 | goalToAdd: false, |
| 408 | addedSRowClick: null, |
| 409 | addedSColClick: null, |
| 410 | colorToAdd: "", |
| 411 | numAgents: this.state.numAgents + 1, |
| 412 | map: map, |
| 413 | agents: [ |
| 414 | ...this.state.agents, |
| 415 | { |
| 416 | SR: this.state.addedSRowClick, |
| 417 | SC: this.state.addedSColClick, |