Coding Challenge #71: Minesweeper

Поделиться
HTML-код
  • Опубликовано: 18 ноя 2024

Комментарии • 527

  • @AnimilesYT
    @AnimilesYT 6 лет назад +206

    When starting a new game and clicking on a random tile: To bee or not to bee. That's the question

    • @Bunny99s
      @Bunny99s 6 лет назад +27

      Actually the real minesweeper will always make the first clicked cell an empty cell. So it fills the grid when clicking the first cell. Otherwise the hard mode would be so frustrating as the chance to click a mine / bee / bomb on first pick is so high.

    • @alexi1182
      @alexi1182 4 года назад +3

      I'm gonna ask you to get out

    • @Yazan_Majdalawi
      @Yazan_Majdalawi 2 месяца назад

      Love this

  • @David-vo1rl
    @David-vo1rl 7 лет назад +212

    One tip for the mouse-click: instead of checking every cell if it contains the mouse when clicked, do simple math: floor(mousex / cellwidth) -> this will return the x-index of the cell clicked. Do the same for mousey. For example - if cell width is 50 and you click on 75th pixel it's floor(75 / 50) which is 1 (x index of the cell). :)

    • @David-vo1rl
      @David-vo1rl 7 лет назад +27

      Oh and btw I didn't watch the video yet and I also forgot that you record live so if you changed it later don't mind this comment :)

    • @TheCodingTrain
      @TheCodingTrain  7 лет назад +65

      Great point!

    • @narkocat
      @narkocat 7 лет назад +1

      Nice advice! Thanks!

    • @skylerockspecial
      @skylerockspecial 7 лет назад +2

      David was looking through the comments to see if someone noticed, looping through all cells to check if it was clicked...

    • @drewchie
      @drewchie 7 лет назад

      i️ dont speak code please translate

  • @ELHAUKEZ
    @ELHAUKEZ 7 лет назад +52

    even if I had a mean day and feel somehow bad watching dan makes me giggle and getting a smile back. he's more human than most of people i know + I dig his coding :) didn't we all wanted a teacher like him

    • @TheCodingTrain
      @TheCodingTrain  7 лет назад +13

      Thanks for the nice feedback!

    • @MrCmon113
      @MrCmon113 6 лет назад +1

      Every human is equally a human.

  • @reimarpb
    @reimarpb 6 лет назад +149

    17:14 "We don't have too much farther to go"
    **video is 53 minutes long**

    • @ashish2628
      @ashish2628 5 лет назад +6

      came looking for this comment at 17:14 haha

    • @ridlr9299
      @ridlr9299 4 года назад +1

      just came down here to say the same thing lol

    • @LaviArzi
      @LaviArzi 4 года назад

      Same, one year later

  • @Amayakase
    @Amayakase 7 лет назад +12

    While I never code in JavaScript, I'm still learning alot here. My preferred language is Lua, and since JS and Lua are very alike, it's easy to watch these tutorials while coding in Lua. Thanks!

  • @juneru2
    @juneru2 Год назад +8

    As someone trying to learn JS just to make a simple game, these challenge videos are perfect! I wasn't aware of p5.js, and it helps make programming much simpler in JavaScript, kinda like how LOVE2D and PICO-8 do for Lua.

  • @Manticore_007
    @Manticore_007 Год назад +6

    I'm beginning to sound like a suckup, but boy, you're entertaining to watch coding. Very cool to see this iconic game under the hood. Very satisfying to see it begin to work more and more as we know it!

  • @FromRootsToRadicals_INTP
    @FromRootsToRadicals_INTP Год назад +3

    Dude, your my fav channel for coding i have come across. This would be my channel if i dod RUclips. Your delivery, topics and interactions. Senior lead dev at 38 and started at 11. For real, one of my top 5 fav channels of all time. Thanks!

  • @nathanjohnson9715
    @nathanjohnson9715 2 года назад +9

    minesweeper was actually the very first large-(ish) thing I every programmed. It was for a BASIC class in high school (and no I'm really not that old, it was an outdated class even then). I used a three dimensional array, which actually worked really well for a language like BASIC, which doesn't have objects that can have properties, but each x,y location could have the different properties it needed (revealed/not, mine/not, physical representation) on one of the "layers" on the z axis. It was a fun project.

  • @ArnoldsKtm
    @ArnoldsKtm 7 лет назад +89

    This one was amazing to watch. That flood fill function was satisfying.
    I think the bee generation should be after the first click so it never hits a bee on the first try!

    • @TheCodingTrain
      @TheCodingTrain  7 лет назад +23

      Yes, I really should have done this!

    • @Chayat0freak
      @Chayat0freak 7 лет назад +7

      The Coding Train that's how real minesweeper does it

    • @trouncerrredits
      @trouncerrredits 2 года назад +1

      i defined a function that took a random generated 'firstclick', excluded it and the surrounding squares from the potential mine locations, then randomly filled the remaining squares with a set number of mines.

  • @fedos
    @fedos 3 года назад +2

    I love watching these where you're figuring it out in real time, and record yourself making the same mistakes that all programmers make, more than videos where the programmer is showing what they did and editing out the things like forgetting to return a value or typing [i][i] instead of [i][j].

  • @dualappsgamer
    @dualappsgamer 5 лет назад +25

    17:15 "we don't have too much further to go"
    *length of video*: 53:45

  • @ga_per
    @ga_per 4 года назад +4

    I've just programmed a minesweeper in python and I came to YT to see how other people made it, and now I'm watching you coding it in javascript, which is a language that I don't know, but it's funny how the logics behind our both projects are similar, even the dilema about the neighbor (I came across the same problem with the loop)

  • @FromRootsToRadicals_INTP
    @FromRootsToRadicals_INTP Год назад +1

    Man making learning new stuff fun again. Thanks and not just coding but thought prep.

  • @Bromon655
    @Bromon655 Год назад +3

    Keeps such a fluid train of thought and debugs with ease. I can only hope that one day I can train my mind to operate the same.

  • @naut_nigel
    @naut_nigel 7 лет назад +36

    "You reveal yourself! No YOU REVEAL YOURSELF!"
    Omg I have fallen in love with you.

  • @chrisalvarez5405
    @chrisalvarez5405 6 лет назад +2

    This video saved me, I was trying to made it in C++ for a school proyect and I couldn't find the way to do the recursive part until I found this video. Thank you very much!

  • @mauriceslegtenhorst1651
    @mauriceslegtenhorst1651 6 лет назад +1

    You are the most fun way to learn coding. Thank you for your free and fun videos

  • @malik641
    @malik641 7 лет назад +64

    Infinite looping stack overflow easily explained at 46:26
    "Hey, neighbor, reveal yourself."
    "No, YOU reveal yourself!"
    This guy's hilarious. The best is when he gets a bit frazzled by something. Entertaining for the full hour. I love it. You rock!

    • @brocklebeau3007
      @brocklebeau3007 2 года назад +1

      All I could think of was the spiderman meme; you! No You! NO YOU!

  • @Superslayen151
    @Superslayen151 7 лет назад +69

    Can you do Tetris for the next challenge? I'm brand new to code. I love your channel and I'm learning a lot from it! Thanks!

    • @TheCodingTrain
      @TheCodingTrain  7 лет назад +41

      I've been getting this request a lot, will consider it!

    • @lardosian
      @lardosian 6 лет назад

      You will find a github project where a guy has made it with React..

    • @AlgyCuber
      @AlgyCuber 5 лет назад

      i might try

  • @o0DraastiK
    @o0DraastiK 7 лет назад +3

    I've attempted to learn programming for the last 14 years. I'm finally at the point where I can at the very least understand what a line of code I'm typing is doing. I hope one day I will have knowledge like his in whatever language I'm proficient in.

  • @ekarademir
    @ekarademir 7 лет назад +3

    I've written my own sweeper game months ago after I saw and inspired by your channel. It's very entertaining to see the similarity of problems you've encountered. I was curious to see how you solved them one by one.

  • @SteveCirelli
    @SteveCirelli Год назад +3

    Such good ideas for coding challenges. Thanks for the inspiration!

  • @Bolt6265
    @Bolt6265 7 лет назад +10

    Im not sure if anyone has already pointed it out, not that i can immediately see, but splice totally does return the spliced items. The reason it didnt work is because splice returns a new array that contains the item(s), so only splicing one item would mean youd need to just access the first element in the array before looking for your choice index stuff.
    So itd look something more like var i = choice[0][0]; var j = choice[0][1];
    Keep up the good work and sorry if someone has already said it!

    • @TheCodingTrain
      @TheCodingTrain  7 лет назад +4

      Oh, thank you for this excellent correction!

  • @JannisAdmek
    @JannisAdmek 6 лет назад +3

    this is so entertaining that Im gonna show parts to people who aren't into coding!

  • @lucaspetersen5074
    @lucaspetersen5074 6 лет назад +3

    I don't undestand most of this 'cause I only code in Python (and pretty basic stuff lol), but I love to see your excitement making these videos. Love the channel :D

  • @Kaixo
    @Kaixo 7 лет назад +3

    In the three/ four weeks that I've been learning Javascript, i'd have never thought I'd make super mario in the fourth week... My programming teacher will get a heart attack if I show this to him... All thanks to the wonderful videos on this channel!! Keep up the amazing work :D
    My teacher showed me a mario project of someone who was a grade higher than me, and now, four weeks later, he will not believe what he's seeing xD can't wait to see his reaction tomorrow xD

  • @renatomonroy9309
    @renatomonroy9309 7 лет назад +2

    thanks for your time Dan you are a great teacher , I coded this in pygame just using the same logic, it was really easy once you know the syntax, keep up this videos of classic games

  • @ノラ-h3q
    @ノラ-h3q 7 лет назад +169

    I want that transparent cap D:

    • @aryamankejriwal5959
      @aryamankejriwal5959 7 лет назад +3

      ngai noriko forget the cap, I want the whiteboard paint! A huge white board!

    • @loxiurasitz6248
      @loxiurasitz6248 6 лет назад

      That transparent hair is also very cool.

  • @parley5101
    @parley5101 6 лет назад +2

    This is great! What's funny is that I made this game before I even saw this video and it is actually pretty similar to yours.
    Also, there is this game called MasterMind (it is a board game) but I would really like it if it was put on a screen.

  • @MichaelJones-wb5dx
    @MichaelJones-wb5dx 7 лет назад +1

    This was great to watch! I'm quite new to JavaScript so couldn't follow all of it, but I'm sure when I watch this video again in a month or two this'll make more sense! I enjoyed the energetic way this was presented and you have yourself a new subscriber :)

  • @json_bourne3812
    @json_bourne3812 2 года назад +1

    Just came across this video, decided to do it myself before watching - took roughly the same time! Had a lot of fun, going to watch you do it now 😉

  • @periklisrips4355
    @periklisrips4355 7 лет назад +2

    I'd like to let you know that this was one of your greatest videos.!! Keep it up!!!

  • @hqs9585
    @hqs9585 7 лет назад +2

    Awesome series of tutorials! Great speaker and great attitude, a 10+

  • @hychhayrith
    @hychhayrith 6 лет назад +1

    thanks sir for your nice code with all js and a very attracting reaction when you code. I really love the way you fix error and your creativeness.

  • @ResanChea
    @ResanChea 5 лет назад

    I tried to fix my problem while making the check neighbors things for like an hour and was unsuccessful, and you just figured it out on the fly, it's just amazing, I'm only watching to the part I haven't done or tried but failed at doing

  • @charliejulietdavies8715
    @charliejulietdavies8715 7 лет назад +1

    i was inspired when i first watched this video to try it myself, but since you went with the bees theme i tried to make beesweeper with hexagonal tiles. it's working now but it was a NIGHTMARE to get that grid behaving itself

  • @staticvoidsolutions4998
    @staticvoidsolutions4998 2 года назад +3

    Following in this vein, the old classic, Battleship, would be interesting to implement as well.

  • @mariohernandez6590
    @mariohernandez6590 7 лет назад +3

    You could turn the (x,y) coordinate into a string and map it to a cell object. This way you can use a Map data structure to check the click much faster!

  • @tehfatcoder667
    @tehfatcoder667 5 лет назад +1

    That checkNeighbors function helped me make chess Game thank you so much.

    • @jamiedonaldson794
      @jamiedonaldson794 4 года назад

      Nice when I was programming chess I used it too.

  • @BenjaminUliana
    @BenjaminUliana 6 лет назад +2

    So awesome a channel. You are like the Bob Ross of coding!

  • @logic_xxmobxx9636
    @logic_xxmobxx9636 5 лет назад +1

    I coded this myself and added a concept of shield to the game.. looked online to see how others coded the game. Was not disappointed

  • @gqoniefh
    @gqoniefh 7 лет назад +1

    Just sub'd your channel. Glad I found it.
    Why it's good for me:
    Coding has always been a curiosity of mine.
    My experience with coding = 1%
    I can learn and progress quickly through your channel.
    Thanks!

  • @happylittlemonk
    @happylittlemonk 2 года назад +2

    at 20:50 line 38, you should return and exit the loop once you found the cell. It is more efficient

  • @Tracks777
    @Tracks777 7 лет назад +15

    I enjoyed your video :) Keep it up!

  • @darkridge
    @darkridge 7 лет назад +20

    A one... two-- A one... two... three... four...
    Half a bee, philosophically,
    Must, ipso facto, half not be.
    But half the bee has got to be
    Vis a vis, its entity. D'you see?
    But can a bee be said to be
    Or not to be an entire bee
    When half the bee is not a bee
    Due to some ancient injury?
    Singing...
    La dee dee, one two three,
    Eric the half a bee.
    A B C D E F G,
    Eric the half a bee.
    Is this wretched demi-bee,
    Half-asleep upon my knee,
    Some freak from a menagerie?
    No! It's Eric the half a bee!
    Fiddle de dum, Fiddle de dee,
    Eric the half a bee.
    Ho ho ho, tee hee hee,
    Eric the half a bee.
    I love this hive, employee-ee,
    Bisected accidentally,
    One summer afternoon by me,
    I love him carnally.
    He loves him carnally,
    Semi-carnally.
    The end.

  • @mohitbhatia1994h
    @mohitbhatia1994h 4 года назад

    never seen someone so happy while fixing the bugs

  • @veltedingel
    @veltedingel 2 года назад

    I love to listen to this in the background while i try to code the same in c#

  • @AdriGomezD
    @AdriGomezD 7 лет назад +1

    Best programming teacher ever💪

  • @samanthacrothers7088
    @samanthacrothers7088 7 лет назад +1

    I love how you do the what it does and then decide how it does it. I hit a road block in programming because I would always write the object and then write functions about that object and then implement those functions if and when it was needed. But to think of telling the object what needs done like ball.bounce and then write the function for bounce is a ton easier to think about in your mind. No judging people i'm self taught. Only wish I have is that you would show us some regualar javascript without the p5 thing.

  • @Tracks777
    @Tracks777 7 лет назад +6

    Awesome video,Keep it up!

  • @maoryatskan6346
    @maoryatskan6346 5 лет назад +1

    I like the idea that you make mistake on purpose so students will learn, but in my opinion you should also educate to read the docs like in the scenario of the "splice" function.
    Keep up we love your content.

  • @AndrewBlechinger
    @AndrewBlechinger 2 года назад +3

    I thought this was going to be about solving it efficiently (turns out Minesweeper is NP-complete!) but this is interesting too.

  • @AnimilesYT
    @AnimilesYT 6 лет назад +1

    Random programming thought:
    let's take this loop: for (int count = 0; count < size; count++)
    let's compact it: for (int c = 0; c < s; c++)
    And there you have it. The language C++
    And which character do we get when we combine the ++ together? A # of course. Because C# is an evolved form of C++.
    Therefore, C# is another way of writing 'count++'

  • @tilmanahlers2095
    @tilmanahlers2095 6 лет назад

    You are a great presenter & entertainer! Well done!
    There is just one little thing I would change
    instead of writing
    if( sth === true){
    if(sthElse === true){
    //do sth
    }
    }
    one could write:
    if(sth === wrong){
    return; //in the loop continue;
    }
    if(sthElse === wrong){
    return; //in the loop continue;
    }
    //do sth.
    The advantage of the second approach is that there isn't so much nested coding. But how I have said: Great Job!

  • @phos4us
    @phos4us 5 лет назад +2

    I'm two years late to the party, but I made my own Minesweeper using python and the pygame module. Inspiration :)

  • @jollyyeholiver1578
    @jollyyeholiver1578 6 лет назад +10

    Should add a function that always returns empty cell for first pick.

    • @RickMeasham
      @RickMeasham 4 года назад

      I think this is how the original works. It only does the population after the first click

  • @seancpp
    @seancpp 4 года назад +3

    It’s every programmers last words:
    “Okay we’re most of the way there!”

  • @doubledeltas
    @doubledeltas 6 лет назад +22

    0:47 Actually, in the most of Minesweepers, mines are created when you first click.

    • @ArnoldsKtm
      @ArnoldsKtm 4 года назад +2

      @Hex96 what...

    • @misterhiker
      @misterhiker 4 года назад +1

      @@ArnoldsKtm , 구본웅
      is partially correct. The mines are created before you click, however if you click on a square that contains a mine on your first click, the program changes this to a non mine square.

    • @eballeste
      @eballeste 2 года назад

      not sure what the mechanics are but definitely first click will never be a bomb

  • @TheNewGreenIsBlue
    @TheNewGreenIsBlue 2 года назад

    @46:45 If I'm correct, Flood fill shouldn't fill NON-adjacent cells (diagonal cells). You COULD still do a loop, but do them as two loops separately for each plane... looping through x, and then through y. (x-1, y), (x,y), (x+1,y) and then (x,y-1),(x,y),(x,y+1)

  • @porwater95
    @porwater95 7 лет назад +3

    Daniel, I LOVE YOUR VIDEOS! I have learned so much from your videos. Thanks!! Do you have a playlist about object oriented programming? I want to learn that properly.

    • @TheCodingTrain
      @TheCodingTrain  7 лет назад +2

      Yes, here is one for Java / Processing:
      ruclips.net/video/YcbcfkLzgvs/видео.html
      I also discuss this in the foundations of JS a bit:
      ruclips.net/video/8j0UDiN7my4/видео.html
      And more on prototype:
      ruclips.net/video/hS_WqkyUah8/видео.html

    • @porwater95
      @porwater95 7 лет назад

      Thanks, I'll look into them!!

  • @MrHumanwarrior
    @MrHumanwarrior 6 лет назад

    Love your energy.

  • @aitorperez6105
    @aitorperez6105 6 лет назад +1

    "I don't know what's going to happen next, but I'm just gonna get started" Mr. Shiffman

  • @chromosoze
    @chromosoze 6 лет назад

    instead of creating a prototype function to check where the mouse is pressed, i just took the offset of the mouse on the canvas, divided it by the width of the grid, and rounded it down. Then, I used that number to get the specified square.

  • @indigoUanP
    @indigoUanP 2 года назад

    it's comedic how even after watching someone MAKE minesweeper, i still have no idea how it works

  • @selimcalskan9442
    @selimcalskan9442 4 года назад +1

    46:20 no need to check whether it is a bee because if the value of the cell is zero, that means that cell already has no bees around.

  • @spicybaguette7706
    @spicybaguette7706 6 лет назад

    those bees you've drawn on the whiteboard look more like baguettes, but really short ones

  • @hurnaumkaushik1055
    @hurnaumkaushik1055 6 лет назад

    Thank you so much for that little tip on the floodfill( ) error

  • @davidm.johnston8994
    @davidm.johnston8994 7 лет назад +2

    Hey man, I really like your channel, and although I always liked coding in general, this is what got me into actually opening an IDE again and code some stuff.
    I'm a student in CGI and as so I need to get myself more familiar with python, so I thought I could make some fun projects and games to do so.
    So much question is : I really enjoy your "challenge" format and was wondering if you would care to try and do a coding challenge in python. Maybe using pygame, or some other library... Or maybe from scratch (I don't know if this is feasible).

  • @fraxinellla
    @fraxinellla 7 лет назад +2

    1:20 I love that transition...

  • @gizmosandgadgets5751
    @gizmosandgadgets5751 2 года назад +1

    very nice, but I beelieve that one of the caveats of minesweeper is that the generated map must start with a zero on first click (so long as that's possible)

  • @erikgratz5539
    @erikgratz5539 5 лет назад +3

    also, you could avoid the whole Options array by subtracting 1 from your loop iterator every time a cell already has a bee in it. Much cleaner.

    • @ryan-heath
      @ryan-heath 5 лет назад

      Erik Gratz huh, I don’t follow it, care to explain?

    • @erikgratz5539
      @erikgratz5539 5 лет назад +1

      @@ryan-heath Sure!
      In the loop designed to designate random cells as having a bee in them, add a conditional that checks if the cell is already a bee, and subtract 1 from the iterator variable. For example:
      for (let n = 0; n < totalBees; n++){
      [select a random cell]
      if( [cell is already a bee] ){
      n = n-1;
      }else{
      [make the cell a bee]
      }
      }
      My syntax isnt perfect because I dont remember this video perfectly, but thats the basic idea. You can change and effect the iterator (the variable declared in the for loop) inside the for loop, and by subtracting one from it when the randomly selected cell has already been touched by the loop, you ensure that the exact number of bees will be set, and no less.

    • @ryan-heath
      @ryan-heath 5 лет назад +1

      Erik Gratz ah I see, but that loop might run forever (theoretically).
      Think about when you have a 10x10 grid and want to select 90 random bees. The chance you pick an already occupied cell, becomes almost 1.

    • @erikgratz5539
      @erikgratz5539 5 лет назад

      @@ryan-heath I think you're solving a nonexisttent problem with that one. Even on a 10x10 grid where you are selecting 99 bees, the system can run that loop ten million times a second. Even if the odds of finding an empty cell are incredibly small, this will always find it in 1-3 seconds of real time at most. For a truly infinite loop you would have to request more bombs than spaces, which should have its own error logic anyway. In conclusion, in the real world, its a nonissue, so I wouldn't spend time solving it.

    • @ryan-heath
      @ryan-heath 5 лет назад +2

      Erik Gratz 1-3 secs is an awful lot of time in CPU land 😬
      I’d rather don’t spent cpu cycles for nothing, when there is a simple solution to get the task accomplished.
      It might be an overkill for this simple app, yes, but it’s classic to randomly select items from a set in O(N) time.

  • @ElTrabajo88
    @ElTrabajo88 4 года назад

    The David Copperfield of JS. Awesome!

  • @limeondisguise3114
    @limeondisguise3114 5 лет назад +2

    "We don't have much farther to go"
    He says, 35% of the way into the video

  • @oFoxo1
    @oFoxo1 7 лет назад +9

    46:46 check this frame there is a mistake in the flood fill function! the cell on the bottom left from where you clicked shouldn't be revealed..that's something tricky to achieve tho :/

    • @TheCodingTrain
      @TheCodingTrain  7 лет назад

      Oh! I'll take a look. . .

    • @alex95sang52
      @alex95sang52 7 лет назад +4

      Instead of revealing the 8 neighbors, you only reveal the 4 direct neighbors. I think this fix would work

    • @thfreakinacage
      @thfreakinacage 7 лет назад

      I guess you could add a check which makes sure the Abs() of the two offsets are not equal?
      This I believe would only then call the function on neighbours where one of the offsets is 0 (ie: above, below, left, right).

    • @thfreakinacage
      @thfreakinacage 7 лет назад +2

      I tried my own idea above and it sort of worked, but I realised a problem. If a diagonal is a number then it SHOULD be revealed. Only when a diagonal is empty (0 neighbors) should it be skipped in the flood fill.
      So instead, I tried this:
      if (abs(xoff) != abs(yoff) || (abs(xoff) == abs(yoff) && neighbor.neighborCount > 0)) {
      if (!neighbor.mine && !neighbor.revealed) {
      neighbor.reveal();
      }
      }
      There might be a nicer way to add my extra if statement, but I'm basically saying "If the offsets are not equal (IE: Above, below, left, right) then reveal, or if they are not equal but the diagonal neighbor has more than 0 neighbors, reveal it".
      From a quick test it seems to be behaving correctly, but if anybody spots a problem, please let me know :D

    • @jonasnicolaysen8019
      @jonasnicolaysen8019 4 года назад +1

      i understand that this is late.
      but the reveal in that frame is correct as far as I know mines....beesweeper

  • @flameofthephoenix8395
    @flameofthephoenix8395 8 месяцев назад

    0:37 Nice! To make things a little more visually interesting you could have each cell that's not a bee contain eight honeycombs then instead of a number of how many bees are nearby you just fill in honeycombs with honey for each cell nearby.

  • @shilpakhadela8856
    @shilpakhadela8856 2 месяца назад

    Bro is 50 and his coding skills are still so much more superior to mine. Respect ❤️🗿🗿
    Love your vids ❤️❤️

  • @VictorZamanian
    @VictorZamanian 2 года назад

    Yeah "new Array(cols)" doesn't give the array a certain number of elements to start. It just gives you a new array with a length of "cols", but all the elements are empty (not null or undefined, but empty). It merely sets the "length" property.

  • @reading-with-dad7
    @reading-with-dad7 4 месяца назад

    This guy is great!

  • @camelcase9225
    @camelcase9225 7 лет назад +1

    It's cool you're attaching a class' methods to the prototype now, but maybe it's time to just move into ES6's arrow functions ^^

  • @ethankwan6786
    @ethankwan6786 3 года назад +1

    17:11 Dan: We're really moving along here!
    Me: *looks at timeline*

  • @adud6764
    @adud6764 7 лет назад +1

    I take issue with the mousePressed() function at 20:13.
    Wouldnt it be better to get both mouse positions (relative to the grid) divide them by the width and use the resulting double (rounded down to an integer) as the index for the array? This should work, right?
    Suppose a mouse click at x=110 and y=90 with a cell width of 50.
    That would be :
    i(x) = 110/50 = 2. ... => 2
    i(y) = 90/50 = 1, ... => 1
    array[2][1]
    That should scale better with a larger grid as it cuts down on calculations.

  • @Skwiggs
    @Skwiggs 6 лет назад

    A super easy way to get the count of neighbouring bees on a cells would simply be to +=1 each neighbouring's cell count when placing a bee. That way you don't need to go through the array twice

  • @ZickPranks
    @ZickPranks 7 лет назад

    Would love to see you code a roulette table!

  • @mullen1116
    @mullen1116 7 лет назад +1

    I like the video but I can't help but think it would be more efficient if you took the x and y coordinates of the mouse press and used a function to map those coordinates to a cell in the grid instead of iterating through the whole 2D array each time. Just a thought! Cheers

  • @mathistenberken1188
    @mathistenberken1188 7 лет назад

    OMG I love ur vids, nice inspirations for my allday stuff...

    • @TheCodingTrain
      @TheCodingTrain  7 лет назад +1

      Thank you!

    • @mathistenberken1188
      @mathistenberken1188 7 лет назад

      I don't know whether you did before, but if not, you could do Flipper in one of the next coding challenges to have a more challenging project

  • @Rumplestiltzchen
    @Rumplestiltzchen 2 года назад

    I love these videos

  • @AlexVasiluta
    @AlexVasiluta 7 лет назад +3

    can you do Tetris? It should be fun to see you implement the 7-bag randomizer, insta-lock or ghost piece

    • @AlexVasiluta
      @AlexVasiluta 7 лет назад +4

      sent a request on the github page

  • @danielhegedus8354
    @danielhegedus8354 2 года назад

    When i click on a video my mind just instantly goes:
    "👏now what i👏 need to 👏 do"

  • @oooSIDEooo
    @oooSIDEooo 7 лет назад

    Says now we do not need to go much further at 17:17 but the video is still 53:45 minutes! Good time management bro ^^

  • @MrPhantomdc
    @MrPhantomdc 4 года назад

    Great job man )

  • @tomburris8380
    @tomburris8380 7 лет назад +17

    +The Coding Train, next time you do a coding challenge in js can you use the ES6 class syntax please? It's so nice and would make me warm and fuzzy inside! :)

    • @redhen
      @redhen 7 лет назад +6

      Tom Burris The 'I forgot to super() ' song would be inevitable, and fantastic.

    • @TheCodingTrain
      @TheCodingTrain  7 лет назад +7

      HAHA

    • @TheCodingTrain
      @TheCodingTrain  7 лет назад +7

      I'm thinking about when to make the transition, perhaps sometime this summer.

    • @seanmahmud584
      @seanmahmud584 7 лет назад

      Hey what software do you use to code?

    • @mattgeek49
      @mattgeek49 7 лет назад

      Tom Burris you have a big mistake, when you floodfill it floodfills the diagonals, you should disable them because in the original it doesn't reveal trough diagonals

  • @toastyPredicament
    @toastyPredicament 2 года назад

    thank you now back to where I was an hour ago.

  • @simonmellberg3869
    @simonmellberg3869 Год назад

    I think the flood reveal in this program reveals over diagonals. Which I don't think is in the original game. Nonetheless a very entertaining video. Thank you!

  • @williamgaze1262
    @williamgaze1262 7 лет назад

    This is awesome subscribed.

  • @kevnar
    @kevnar 6 лет назад +3

    Don't worry about copyright violations, Daniel Shiffman. I don't think your singing is good enough to trigger RUclips's flagging bot.

  • @brookestephen
    @brookestephen Год назад +1

    why not use key:value pairs, with row and column in the key like key = "0.4". Then you only need space in your data structure for those cells with content, and there's no duplicate cells. You can use the same data structure no matter how many dimensions you have. You could use the Composite Design Pattern, in which the Number square and the Bomb square are sub-classes of Cell. They'll have the same state and execute functions, but different implementations. You can make Cell abstract so it can't be instantiated.

    • @brookestephen
      @brookestephen Год назад

      You can identify each cell by the same key: "0.4" is row zero column four!

  • @marco_gallone
    @marco_gallone 4 года назад

    The floodfill algorithm should terminate in purely x or y directions (not diagonals), simple refactor - exclude corners from neighbour check.

  • @hummmmmmmmus
    @hummmmmmmmus 4 года назад +1

    5:30 this is how I did the snake challenge... granted i was going to feed the array to a neural network but still, it was needlessly memory intensive

  • @dukestt
    @dukestt 7 лет назад +10

    the mouse pressed function can detect which button was pressed which is very useful. it is a nightmare in VB

    • @yourspanishstories
      @yourspanishstories 7 лет назад

      dukestt well, in vb it's easy to implement that too, if you meant visual basic

    • @purpleice2343
      @purpleice2343 7 лет назад +1

      VB is a nightmare.

    • @dukestt
      @dukestt 6 лет назад

      I was talking about the whole thing not just the mouse click. but thanks anyway.