-
Notifications
You must be signed in to change notification settings - Fork 0
BFS algorithm and path drawing added #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| const Route = ReactRouter.Route; | ||
| const Switch = ReactRouter.Switch; | ||
| const Game = require('./Game'); | ||
| const pathFind = require('../utils/BFS'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import findPath from '../utils/BFS';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I've been googling on the difference between require() and import and got into a wall of not understanding the difference between 'dynamic' and 'static' loading. And that's besides the fact that most places say that import is being transpiled by Babel to require() anyway because there is no native support yet... :/
-
Any chance for a link to clarify that difference between dynamic and static loading?
-
you marked only the
findPathto use withimport. Is there any reason not to useimporteverywhere instead of therequire()I've been using to for the other classes of the app? OrReactfor that matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- It's a complex topic and I can write you the basics in chat.
- I only commented in this PR on changes, not on everything. If I'd comment on everything, we'd never finish. Gotta limit the scope, otherwise it's unmanageable. You should use
importeverywhere you can.
|
|
||
| console.log('creating board') | ||
| console.log('path?'); | ||
| console.log(pathFind); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't one console.log enough?
|
|
||
| handleClickOnBoard(x, y) { | ||
| console.log('trying to update state'); | ||
| const board = this.state.board; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use destructuring, everywhere: const { board, } = this.state;
| this.updateEndLocation(x, y); | ||
| } else { | ||
| const tempBoard = this.state.board; | ||
| const tempBoard = board.map((row) =>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't name things "temp". Even life is temporary, we all know that. Even "new" is better than "temp".
Name your mapping functions. This helps debugging and stack traces. Naming things in general helps you write better code.
| } else { | ||
| const tempBoard = this.state.board; | ||
| const tempBoard = board.map((row) =>{ | ||
| return row.map((cell)=>Object.assign({}, cell)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shorter:
return row.map(cell => ({ ...cell, }));But why clone the cell at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because I want to make changes to state only from this.setState(), and since board is a nested array of objects, if i make a change to the cell's content it will change the state without invoking the setState function.
| } | ||
| } | ||
| } | ||
| return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return isInField(point) && isAllowedStep(point) && !hasBeenVisited(point);| return legal; | ||
| } | ||
|
|
||
| // the BFS algorithm that searches for a path between the 'start' and 'end' points |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A link to an explanation is better
| } | ||
|
|
||
| // the BFS algorithm that searches for a path between the 'start' and 'end' points | ||
| // returns 'true' if a path was found and 'false' if not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant for a well named boolean function
|
|
||
| // the BFS algorithm that searches for a path between the 'start' and 'end' points | ||
| // returns 'true' if a path was found and 'false' if not | ||
| var pathExists = function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you copy/pasted if from somewhere, add a link.
|
|
||
| } | ||
|
|
||
| module.exports = pathFind; No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export default findPath
No description provided.