MCPcopy Create free account
hub / github.com/StevenLyt/mapf-visualizer / requestSolution

Method requestSolution

src/LAMAPFVisualizer.jsx:130–234  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

128 }
129
130 async requestSolution(e) {
131 e.preventDefault();
132
133 if (this.state.agents.length === 0) {
134 this.setState({ isDialogOpen: true });
135 console.log("No agents");
136 return;
137 }
138
139 this.setState({ isPlanning: true });
140 // change agents to border
141 this.state.agents.forEach((agent) => {
142 var height = agent.height;
143 var width = agent.width;
144 var color = agent.color;
145 for (let i = agent.SR; i < agent.SR + height; i++) {
146 for (let j = agent.SC; j < agent.SC + width; j++) {
147 if (i === agent.SR) {
148 document.getElementById(`grid-${i}-${j}`).style.borderTop = `4px solid ${color}`;
149 }
150 if (i === agent.SR + height - 1) {
151 document.getElementById(`grid-${i}-${j}`).style.borderBottom = `4px solid ${color}`;
152 }
153 if (j === agent.SC) {
154 document.getElementById(`grid-${i}-${j}`).style.borderLeft = `4px solid ${color}`;
155 }
156 if (j === agent.SC + width - 1) {
157 document.getElementById(`grid-${i}-${j}`).style.borderRight = `4px solid ${color}`;
158 }
159 }
160 }
161 for (let i = agent.GR; i < agent.GR + height; i++) {
162 for (let j = agent.GC; j < agent.GC + width; j++) {
163 if (i === agent.GR) {
164 document.getElementById(`grid-${i}-${j}`).style.borderTop = `4px solid ${color}`;
165 }
166 if (i === agent.GR + height - 1) {
167 document.getElementById(`grid-${i}-${j}`).style.borderBottom = `4px solid ${color}`;
168 }
169 if (j === agent.GC) {
170 document.getElementById(`grid-${i}-${j}`).style.borderLeft = `4px solid ${color}`;
171 }
172 if (j === agent.GC + width - 1) {
173 document.getElementById(`grid-${i}-${j}`).style.borderRight = `4px solid ${color}`;
174 }
175 }
176 }
177 });
178
179 await new Promise((resolve) => setTimeout(resolve, 1000));
180
181 var walls = [];
182 var agents = [];
183 this.state.map.forEach((row, rowId) => {
184 row.forEach((grid, gridId) => {
185 if (grid.isWall) {
186 walls.push(this.linearizeLocation(rowId, gridId));
187 }

Callers 1

renderMethod · 0.95

Calls 2

linearizeLocationMethod · 0.95
playAnimationMethod · 0.95

Tested by

no test coverage detected