Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 685ee30

Browse files
fixing the weighted algorithms execution and its styles
1 parent f5af74e commit 685ee30

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

‎src/Components/GridLayoutComponent.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,12 @@ class GridLayout extends Component {
175175
document.getElementById(`node-${row}-${col}`).className = 'end';
176176
}
177177
if (st) {
178-
if (!node.iswall&&!node.isweight&&!node.strt && !node.end) {
178+
if (!node.strt && !node.end)
179179
document.getElementById(`node-${row}-${col}`).className = '';
180-
}
180+
if(node.isweight)
181+
document.getElementById(`node-${row}-${col}`).className += ' node-weight ';
182+
if(node.iswall)
183+
document.getElementById(`node-${row}-${col}`).className += 'node-wall';
181184
} else {
182185
if (!node.iswall && !node.strt && !node.end) {
183186
document.getElementById(`node-${row}-${col}`).className = '';
@@ -187,7 +190,7 @@ class GridLayout extends Component {
187190
}
188191
}
189192

190-
generateNewGridWithPreviousWalls() {
193+
generateNewGridWithPreviousWalls(st) {
191194
const b = [];
192195
for (let row = 0; row < 23; row++) {
193196
const currRow = [];
@@ -205,8 +208,8 @@ class GridLayout extends Component {
205208
aDis: 0,
206209
aEndDis: 0,
207210
isVisited: node.iswall ? node.isVisited : false,
208-
isweight: false,
209-
cost: 0,
211+
isweight: st ? node.isweight :false,
212+
cost: st ? node.cost : 0,
210213
previousNode: null,
211214
iswall: node.iswall
212215
};
@@ -267,7 +270,7 @@ class GridLayout extends Component {
267270
const ran = Math.floor(Math.random() * 5 + 1);
268271
const box = this.state.boxes;
269272

270-
273+
console.log(ran);
271274
const node = box[row][col];
272275

273276
const val = {
@@ -301,14 +304,15 @@ class GridLayout extends Component {
301304

302305
if (num === 1) {
303306
return false
304-
} else {
305-
for (let i = 2; i < this.prime; i++) {
307+
} else
308+
{
309+
for (let i = 2; i < this.prime ; i++) {
306310
if (num % i === 0) {
307-
return false
311+
return false;
308312
}
309313
}
310314
}
311-
return true
315+
return true;
312316
}
313317

314318
even(num) {
@@ -339,6 +343,7 @@ class GridLayout extends Component {
339343
this.setState({
340344
boxes: val
341345
})
346+
console.log(val+" in random weight");
342347
}
343348

344349

@@ -372,8 +377,8 @@ class GridLayout extends Component {
372377

373378
}
374379

375-
clearGridForNewAlgo() {
376-
let val = this.generateNewGridWithPreviousWalls();
380+
clearGridForNewAlgo(st) {
381+
let val = this.generateNewGridWithPreviousWalls(st);
377382
this.setState({
378383
boxes: val
379384
})
@@ -510,7 +515,7 @@ class GridLayout extends Component {
510515
visualizeDijkstra() {
511516
if (this.state.boxes !== []) {
512517
this.clearStyles(true);
513-
this.clearGridForNewAlgo();
518+
this.clearGridForNewAlgo(true);
514519
}
515520

516521

@@ -600,7 +605,7 @@ class GridLayout extends Component {
600605
visuaizeGBFS() {
601606
if (this.state.boxes !== []) {
602607
this.clearStyles(true);
603-
this.clearGridForNewAlgo();
608+
this.clearGridForNewAlgo(true);
604609
}
605610
console.log('Started gbfs');
606611
const { boxes } = this.state;
@@ -616,7 +621,7 @@ class GridLayout extends Component {
616621
visualizeaSearch() {
617622
if (this.state.boxes !== []) {
618623
this.clearStyles(true);
619-
this.clearGridForNewAlgo();
624+
this.clearGridForNewAlgo(true);
620625
}
621626

622627
const { boxes } = this.state;
@@ -786,7 +791,7 @@ class GridLayout extends Component {
786791
} >
787792
</Header>
788793

789-
<div id = "display" > </div>
794+
<div id = "display" >
790795

791796

792797
<div className = "grid-container" > {
@@ -800,7 +805,7 @@ class GridLayout extends Component {
800805
<GridBlock chng = {{ start: this.state.start, func: this.change.bind(this)}}
801806
row = { pos }
802807
col = { pos2 }
803-
key = { `${pos}-${pos2}` }
808+
key = { `${pos}-${pos2}` }z
804809
start = { c.strt }
805810
end = { c.end }
806811
startnode = { this.state.start }
@@ -810,6 +815,7 @@ class GridLayout extends Component {
810815
mouseIsPressed = { this.state.isMousePressed }
811816
iswall = { c.iswall }
812817
weight = { c.isweight }
818+
cost = {c.cost}
813819

814820
onMouseDown = {
815821
(row, col) => this.handleMouseDown(row, col)
@@ -829,6 +835,7 @@ class GridLayout extends Component {
829835
);})
830836
} </div>
831837
</div>
838+
</div>
832839
)}
833840
}
834841

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /