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

Method requestSolution

src/MAPFVisualizer.jsx:140–217  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

138 }
139
140 async requestSolution(e) {
141 e.preventDefault();
142
143 if (this.state.agents.length === 0) {
144 this.setState({ isDialogOpen: true });
145 return;
146 }
147
148 if (this.state.goalToAdd) return;
149
150 this.setState({ isPlanning: true });
151
152 // change agents to border
153 this.state.agents.forEach((agent) => {
154 var color = agent.color;
155 document.getElementById(`grid-${agent.SR}-${agent.SC}`).style.border = `4px solid ${color}`;
156 document.getElementById(`grid-${agent.GR}-${agent.GC}`).style.border = `4px solid ${color}`;
157 });
158
159 // delay 1s before showing animation
160 await new Promise((resolve) => setTimeout(resolve, 1000));
161
162 var walls = [];
163 var agents = [];
164 this.state.map.forEach((row, rowId) => {
165 row.forEach((grid, gridId) => {
166 if (grid.isWall) {
167 walls.push(this.linearizeLocation(rowId, gridId));
168 }
169 });
170 });
171 this.state.agents.forEach((agent) => {
172 agents.push({
173 startLoc: this.linearizeLocation(agent.SR, agent.SC),
174 goalLoc: this.linearizeLocation(agent.GR, agent.GC),
175 });
176 });
177
178 var data = { row: this.state.numRow, col: this.state.numCol, walls: walls, agents: agents };
179 let options = this.state.options;
180 for (let key in options) {
181 data[key] =
182 typeof options[key].options[0] === "number"
183 ? options[key].value
184 : options[key].options[options[key].value];
185 }
186 const req = {
187 method: "POST",
188 headers: {
189 // Accept: "application/json",
190 "Content-Type": "application/json",
191 },
192 // mode: 'no-cors',
193 // credentials: 'include',
194 body: JSON.stringify(data),
195 // url: `http://localhost:8080`
196 };
197 // fetch("http://52.53.223.36:8080/"+ this.state.name, req)

Callers 1

renderMethod · 0.95

Calls 2

linearizeLocationMethod · 0.95
playAnimationMethod · 0.95

Tested by

no test coverage detected