@w1nd251 I would love to see it too. Yes agree for sure can be done in a recursive manner, but I wanted to focus on the iterative approach at the time of creating this video.
I call this function once before checking if I did not click on the bomb and everything works perfectly. Try catch for "array out of bound exception"@@eduriseworld
@@eduriseworld i created board 10x10 with 90 bombs and had duplicate. I think that reveal function could be written much faster, look :D const Reveal = (grid, x, y, mapSize, nonMineCount) => { if(grid[x][y].value === 0) { for(let i=-1; i = 0 && x < mapSize && y >= 0 && y < mapSize){ return true; } else{ return false; } } export default Reveal;
10:23 createboard
18:31 createboard (full)
24:42 designing Cell component
50:50 reveal.js
Too many code in reveal.js. Simply use recursive function that will spread from clicked square to all the directions till the bombs
You have 150 lines of code, it can be done in 30
@w1nd251 that is interesting to see.
Have you done it so far?
@w1nd251 I would love to see it too. Yes agree for sure can be done in a recursive manner, but I wanted to focus on the iterative approach at the time of creating this video.
const mark = (board: Square[][], x: number, y: number) => {
try{
if(board[x][y].revealed === true){
return;
}
if(board[x][y].value === 0){
board[x][y].revealed = true;
}
if(board[x][y].value !== 0 && board[x][y].value !== -1){
board[x][y].revealed = true;
return;
}
// top row
mark(board, x - 1, y - 1)
mark(board, x - 1, y)
mark(board, x - 1, y + 1)
//left and right
mark(board, x, y - 1)
mark(board, x, y + 1)
// bottom row
mark(board, x + 1, y - 1)
mark(board, x + 1, y)
mark(board, x + 1, y + 1)
return board;
} catch (e){
return;
}
}@@eduriseworld
I call this function once before checking if I did not click on the bomb and everything works perfectly. Try catch for "array out of bound exception"@@eduriseworld
great turorial, are you sure that generate Bomb cant generate duplicate coords?
Yes 100% positive, the logic is in createBoard.js. Can you tell why it won't generate duplicate coords based on the code?
@@eduriseworld i created board 10x10 with 90 bombs and had duplicate. I think that reveal function could be written much faster, look :D
const Reveal = (grid, x, y, mapSize, nonMineCount) => {
if(grid[x][y].value === 0)
{
for(let i=-1; i = 0 && x < mapSize && y >= 0 && y < mapSize){
return true;
}
else{
return false;
}
}
export default Reveal;
@@kacper6107 let me check that.
Thank you, nice video!
Wait what! 🤯
8th