How I Practice Programming: Five Dice

Sdílet
Vložit
  • čas přidán 5. 06. 2021
  • In this unusual video, I describe how programming practice needn't be stale and boring if you take inspiration from everyday things you find interesting, and viewed through the eyes of a programmer. Specifically I look at the implementation of 5 Dice based games, like Yahtzee.
    Source: github.com/OneLoneCoder/Javid...
    Patreon: / javidx9
    CZcams: / javidx9
    / javidx9extra
    Discord: / discord
    Twitter: / javidx9
    Twitch: / javidx9
    GitHub: www.github.com/onelonecoder
    Homepage: www.onelonecoder.com
  • Věda a technologie

Komentáře • 259

  • @zachreitan3859
    @zachreitan3859 Před 3 lety +321

    I REALLY appreciate these sorts of coding videos where someone explains the logic and thought process behind the code they write. I feel like this kind of thing is very sorely lacking in a lot of programming tutorials. It's not so important that you know WHAT code to write as much as WHY you would write it in the first place.

    • @javidx9
      @javidx9  Před 3 lety +50

      There's a full video about containers and why/how to choose them prior to this one. The simple answer is, it genuinely doesn't matter in this instance.

    • @dutu000
      @dutu000 Před 3 lety

      YES! Me too!!!

    • @Briglair
      @Briglair Před 3 lety +4

      Exactly! You don't learn anything by someone just saying "do this, do that." You learn how to copy from a screen, not how to apply logic on your own. I love this channel

    • @_miyu
      @_miyu Před 3 lety +1

      @@Briglair I feel very similar with music. I used to play the Trumpet when I was young and all we did was play exactly what was on the sheet. Later I tried to pick up Guitar. After awhile I noticed I was just memorizing chords and playing back exact songs that I happened to like. That never really worked for me. Now I really found what I am good at, I love to code and I have the ability to think problems through and generate my own real solutions. It is certainly a pleasure to see videos like this one, that show you how reason your way through problems.

    • @johnneighbor9866
      @johnneighbor9866 Před 3 lety

      @@Briglair Yep, and then concluded with, "and that's how you do x" and any viewer is just left there sitting like what did I waste 4 minutes watching, because in those, "type this, then this" there's no learning really promoted at all.
      Where Javid on the other hand, goes quickly but explains details as well, and being video, backtracking 10s is 100% a doable task.

  • @kadensharpin2156
    @kadensharpin2156 Před 3 lety +187

    "I don't like regular expressions because fundamentally I don't understand them"
    that hit close to home

    • @DFPercush
      @DFPercush Před 3 lety +38

      Regular expressions are like the vim text editor. Everyone who's devoted the time to learning it, swears by it. Everyone else is frustrated and annoyed by its existence.

    • @TotalImmort7l
      @TotalImmort7l Před 3 lety +4

      @@DFPercush Cannot agree more.

    • @zakkiedude132
      @zakkiedude132 Před 3 lety +3

      @@DFPercush particularly accurate because to really get the best out of vim you've really gotta learn how to :%s/regex/replacement/g

    • @ShadowRadiance
      @ShadowRadiance Před 3 lety +10

      There's a saying that "if you have a problem and solve it using a regular expression, you now have two problems."

    • @DFPercush
      @DFPercush Před 3 lety +1

      @@ShadowRadiance lol... only if you have to understand it later

  • @StuartLoria
    @StuartLoria Před 3 lety +40

    At college we used to say “Practice Only on the days you wake up”
    If you’re in a comma, bedridden or dead, you are excused.

  • @Backtrack3332
    @Backtrack3332 Před 3 lety +50

    How I do it:
    1. Search for some absurd idea on the internet or think of something actually useful :)
    2. Just do it
    3. Get frustrated, but also just do it
    4. Finish the project in an acceptable state

  • @JanKjeldsen
    @JanKjeldsen Před 3 lety +17

    Yatzy was the third program I wrote in high school in 1981. Programming language was Comal, a Basic derivative. The program worked but lacked structure. Learned the need for subroutines the hard way :) Did I forget to mention it was written on punch cards for a RC-7000 computer? It had 326 lines with no blank lines, why waste a card? On par with this C++ program, but mine had the computer play against you!

  • @salockingaming6246
    @salockingaming6246 Před 2 lety +9

    i really hope you don't stop making videos because I really love your calming pace and voice and I love using your olc engine

    • @javidx9
      @javidx9  Před 2 lety +3

      Thank you, no plans on stopping, will have a couple more this year I hope, but been on hiatus with my new family since summer.

  • @Nioub
    @Nioub Před 3 lety +25

    To detect the full house, you can encode it in "nnnmm" and "nnmmm", handling the m value exactly as the n value (but in a separate variable).

    • @whinebite
      @whinebite Před 3 lety +13

      Reading this under the effects of sleep depravation only made me imagine those as microwave sounds

  • @delgadogorn
    @delgadogorn Před 2 lety +1

    Your videos are amazing, very thorough and informative. I am only at the beginning stages of learning to program and understand very little but I still love how you explain the logic behind programming which most do not. You are one of the only few who inspire me to keep going. Keep up the great work!

  • @stephenelliott7071
    @stephenelliott7071 Před 3 lety +1

    An excellent video! I love breaking down a tricky problem and getting the program just running bug free (I call it the first hurdle). Then look to refine and refine the algorithm to make it more and more efficient - also more concise. Something you did particularly well here. Great stuff.

  • @wolverine9632
    @wolverine9632 Před 3 lety +1

    One of my proudest programming accomplishments was writing a full-featured single-player yahtzee game in BASIC on the Vtech PreComputer 1000.

  • @piratux2860
    @piratux2860 Před 3 lety +2

    What a lovely video. Simple, yet some parts have depth in it.

  • @danteculaciati1656
    @danteculaciati1656 Před 3 lety

    Love your videos man! Thanks for all your advice and the enthusiasm you put into them.

  • @ziolkovy
    @ziolkovy Před 3 lety +23

    @javidx Great video! (as always)
    One thing I noted:
    Maybe I do not know rules of game, but for me small straight pattern looks wrong - for instance 12234 don't match. Also five of a kind can be treated as full house, which shouldn't be possible.
    I think it is a good idea to set few dices sets manually for testing and then use random.

  • @Loleexer
    @Loleexer Před 3 lety

    You're a genius! I've got to learn how to optimise my code like that. It does happen sometimes that I write a neat little piece of code which does a lot, and I do get praised for it at work, but often times I rush to another tasks at hand without really thinking about what I wrote and of ways of making it better. Often times do I go back to my code only to realise how terrible it is at a first glance. Such inquisitive and robust optimisation will definitely take some time to learn, but the end result seems to be more than worth it! I'm glad I decided to watch this video.

  • @bryceschultz7215
    @bryceschultz7215 Před 3 lety +64

    At 33:35 you have a small straight but the pattern match doesn't find it because there are two fours keeping the straight from being consecutive.

    • @maurinavoni6925
      @maurinavoni6925 Před 3 lety

      .

    • @not-on-pizza
      @not-on-pizza Před 3 lety +12

      So I wasn't the only one yelling "BUG!" at the screen at 20:32, then!

    • @henrykkaufman1488
      @henrykkaufman1488 Před 3 lety +1

      @@not-on-pizza yep I'm on that very moment when he's explaining small straight pattern match and I'm looking in the comments to check if indeed I found a bug. But hey, everyone makes bugs, this will make me more forgiving towards myself.

    • @NillKitty
      @NillKitty Před 3 lety +3

      Yep 1-1-2-3-4 also wouldn't match those patterns.

    • @topfkopf666
      @topfkopf666 Před 3 lety

      @@NillKitty or double 2s or 3s. I was seriously annoyed by that flaw :p

  • @barellevy6030
    @barellevy6030 Před 3 lety +6

    Hey, great seeing you upload!
    How's things with the new addition to the family?
    Hope you are all in good health and adjusted as much as it's possible to adjust :-)

  • @l6e6i6n
    @l6e6i6n Před 3 lety

    Always enjoy your videos. Keep up the good work 👍

  • @d3r1n
    @d3r1n Před 3 lety +1

    Well I saw the discord status "Uploading a video" and came here. I love your videos so much as a kid who obsessed with computers and stuff you are my hero when it comes to programming

  • @DavidBauer38
    @DavidBauer38 Před 3 lety +1

    I was literally just thinking about doing a Yahtzee clone in Golang the other day! Looks like I need to get going! thanks for the inspiration, @javidx9!!!

  • @drummsnikk5073
    @drummsnikk5073 Před 3 lety

    Always a pleasure to watch your videos ❤️

  • @dieisonmarianofariasrocha7235

    Amazing video. It was 34 minutes of learning new things. Thank you so much for this video.

  • @onlywayisforward
    @onlywayisforward Před rokem

    Really great content dude!

  • @EzioOmer
    @EzioOmer Před 3 lety +1

    You could be the reason that fostered me to learn c++ i did not start c++ yet but i am thinking it currently . Love your videos !

  • @mailenolivera1523
    @mailenolivera1523 Před 2 lety

    I'm learning a lot from this video !! THANK YOU !

  • @petacrdi
    @petacrdi Před 2 lety

    Really insightful video! It is really nice seeing smart people writing code. Thanks!

  • @user-ns7rc4mp5b
    @user-ns7rc4mp5b Před 3 lety +4

    I have learned so many things through your videos. You are the kind of person I always wanted to be. Please continue to make more this kind of useful videos. I will be very, very grateful to you and hope you and your family will always be healthy!!!!

  • @Nuvhandra
    @Nuvhandra Před 3 lety

    Amazing, thank you again for a great video. "It's all about the journey rather than the end result", Cheers

  • @teucay7374
    @teucay7374 Před 3 lety

    As inspiring as always. Thanks for all!

  • @Bravo-oo9vd
    @Bravo-oo9vd Před 3 lety

    Really liked the the focus on expressing the logic as succinctly as possible. With this in mind, have you considered looking into some functional programming languages, eg. Haskell and maybe doing a video about them in the future? Imperative languages can be a bit verbose at times, and functional programming can be really "logic-dense", but things like monads, functors, applicatives, and all the other category theory jazz can be a little daunting at first. Would love to see something like this on your channel, even if it'd be only one or two videos.

  • @utkugokalp3179
    @utkugokalp3179 Před 3 lety +6

    Great idea to shoot a video about this, even the best need it sometimes

  • @ayo_trivedi
    @ayo_trivedi Před 3 lety +2

    You make awesome videos! I found your channel now and this is the best thing ever! You videos make me wonder if anyone need graphic engines like OpenGL or SFML.

  • @blinded6502
    @blinded6502 Před 3 lety

    That's one hell of a thumbnail, looks awesome!

  • @averbuchalex7
    @averbuchalex7 Před 2 lety

    very nice and informative video, learned a lot, thanks

  • @bradp213
    @bradp213 Před 3 lety

    I wish I knew about this channel when I was in college. Great video! Thanks

  • @MaksFam
    @MaksFam Před 3 lety

    Thank you for the awesome videos man!

  • @marcosdantas4258
    @marcosdantas4258 Před 2 lety

    i really love your videos javidx, thanks for the great content, i can see how computers have strong love for know values at compile time and he hate loops hahaha, on the last minutes of video you improves code quality by using vector and loops for computers aspects and aspects of FP libs and your fps drop 385 to 345 times, is incredible how things can be wrong if we adopt bad solutions for some cases, for me games is the more significant area to learn and improve your knowledge about computers and programming language.

  • @surters
    @surters Před 3 lety

    The good thing about videos like this is they show a different way of programming than I would have chosen.
    In this case my immediate thought would be the sum array of a counting sort would have given most of the matches and std::adjacent_difference might be usable for finding straights.

  • @ignabelitzky
    @ignabelitzky Před 3 lety +22

    "Generala" is the name in Argentina... such a nice game!

    • @nonchip
      @nonchip Před 3 lety +1

      to add to the language trivia: in germany we call it "Kniffel".

  • @trellend
    @trellend Před 3 lety +20

    You need a remove duplicates on your small/large straight before your test, and change your test pattern.

    • @joemaffei
      @joemaffei Před 3 lety +7

      I was just about to type this, as i noticed the 3 4 4 5 6 at the tail end of the video not registering as a small straight.

  • @alvfig
    @alvfig Před 3 lety

    Great content, thank you so much!

  • @leonm8906
    @leonm8906 Před 3 lety +14

    Hey, I did the same game in python as a coding exercise. It's called Kniffel here in germany.

  • @rethanon
    @rethanon Před 3 lety

    Loved the video, would be good to see how you implement the rule where a "turn" is actually 3 rolls, and on the first two rolls you can decide which dice to keep as you attempt to go for a particular goal (i.e. you don't roll all 5 dice every time)

  • @VincentGroenewold
    @VincentGroenewold Před 3 lety +1

    Absolutely love you sharing the process, this is so valuable. My big question, as a beginner, is... how long did it take you to come up with the other ways? Is this where, basically, the difference lies between experience and just being clever? :)

  • @esun411
    @esun411 Před 3 lety +1

    영상 항상 잘 보구 있습니다!

  • @Surf_Cat
    @Surf_Cat Před 3 lety +1

    Yahtzee is a nice choice when learning programming farmeworks/languages, it has a nice range of tasks. If you manage to decouple the logic (maybe iteratively) you can use it as a library to test gui or other stuff. I used this to figure out listboxes etc.. in gui frameworks, some 3d stuff and a lot of other new stuff when learning.

  • @greob
    @greob Před 3 lety

    Great video, thank you!

  • @antoruby
    @antoruby Před 3 lety

    A true game programmer: coding, refactoring for fitting the screen, and taking shortcuts in algorithms only with the power of manual testing! Sarcasm aside, very nice example and I like how you walk us through your design process.

  • @tibfulv
    @tibfulv Před 3 lety +1

    Basic regexes are really quite simple. You can do really complex things with them, but that's common in programming.
    The concept is quite similar to globbing. All words match themselves, '.' matches any character, '?' means zero or once, and '*' and '+' means repeated zero or more and once or more. If you need more fine-grained control, curly brackets controls repetitions, square brackets pattern matching. Also, you can match the beginning or end of the line with '^' and '$'. Anything more is implementation-dependent.
    In C, you compile a regex with regcomp() and match it with regexec(). In C++, things seem different. But the relevant funtions for both are in regex.h.
    www.geeksforgeeks.org/write-regular-expressions/
    www.geeksforgeeks.org/regular-expressions-in-c/
    www.softwaretestinghelp.com/regex-in-cpp/

  • @sigmundfreud4472
    @sigmundfreud4472 Před 3 lety

    Thanks for the video! It reminds me of when I was just starting out, I wrote some code to simulate the game “Left Right Center”. It’s completely a game of chance, except if you can choose your place in turn order. We had been playing it a lot (for money!) and I wanted to guess what the best place to start would be.
    Long story short, it seems the odds of winning increase the further in turn order you are, with great effect the fewer players there are. (With two players, Player 2 has a 70% win rate!)

  • @zach_attakk
    @zach_attakk Před 3 lety

    As a pedantic board gamer and coder, you have no idea how happy I am to hear the proper plurals for die/dice

  • @nokiaa3337
    @nokiaa3337 Před 3 lety

    I love you so much man , i dont know why really. You looks wonderful good and determined person maybe thats why RESPECT.

  • @tomvito
    @tomvito Před 3 lety

    Great video 👌🏻Thank you!

  • @iloveyourwcw9265
    @iloveyourwcw9265 Před 3 lety

    Great video ! : D

  • @TheSgrizli
    @TheSgrizli Před 3 lety +3

    Thank you bearded man for the knowledge.

  • @bestformspielt
    @bestformspielt Před 3 lety +3

    I would have sorted the input to the PatternMatch function inside the implementation. It is odd that a requirement of the function is that the input must be sorted beforehand. Not a common thing for an interface. :)

  • @jsflood
    @jsflood Před 3 lety

    One word. Awesome!

  • @abdulazizrakhimov7701
    @abdulazizrakhimov7701 Před 3 lety

    Hello Javid!) I missed you so much!) Please, I want you to release videos oftenly, because you make me to think like a geniusly boy!)🤗

  • @ernopakarinen9361
    @ernopakarinen9361 Před 3 lety

    Bit simliar as you :) My practice to learn new stuff has always been to take a new project and just start doing it in the new environment and/or new programming language you want to learn. I always learn best by doing things as I am not a scientist with a lot of background theory support (just a Bs.C). That is how I started back in 1982, I wanted to learn how a game was made, spend to do Basic interpreter stuff first with that comp and when I found new tools like Asm interpreter/compiler I went there and after a while to C :)
    But I think it's pretty much what you are doing here as well. Learn by doing, pick a project and find solutions for how to complete the challenges.
    It's "xanakig" from your Discord btw :P
    Good video yet again.

  • @jake_runs_the_world
    @jake_runs_the_world Před 3 lety

    Really useful video

  • @jimmynuggs5618
    @jimmynuggs5618 Před 3 lety

    Welcome back fella.

  • @felixmerz6229
    @felixmerz6229 Před 3 lety +1

    21:10 Missed an edge case there. 34566 is a possible roll for a small straight not covered by ?3456 or any other of the four patterns. Also true for rolls with duplicates that aren't at the beginning or end of the pattern.

  • @noblesavage149
    @noblesavage149 Před 3 lety

    Wow... I need something to get my teeth into as I've been losing the plot as a front end developer. Going to implement this in first one language and then use it as a base to learning other languages. Thanks dude!

  • @JaycenGiga
    @JaycenGiga Před 3 lety

    As others pointed out, there was a bug regarding the small straight rule. I think this comes from using a vector, which is a suboptimal data structure for the problem. As I see it, the most appropriate one would be a multiset which is also part of the standard library and so would not only be a perfect fit for the problem but also you would likely learn something new. Then, you could simply define a multisets for all the rules and do matches by checking for subsets, without using patterns.

  • @zettelkastendev3760
    @zettelkastendev3760 Před 3 lety

    thanks for this, I really struggle with coding right now

  • @urbaniuscee3657
    @urbaniuscee3657 Před 3 lety

    Nice video. Always good to see std::algorithm and std::numeric used in a creative fasion.
    One remark though:
    Wouldn't it be beneficial to immediately return false if one step of the pattern matching fails, instead of using a bool to save to current matching status. That would reduce the amount of variables on the stack, and the algorithm would terminate faster, if the pattern is not matched, which will be the most frequent case?

  • @prinnydadnope5768
    @prinnydadnope5768 Před 3 lety

    The small straight isn't limited to 4 values :
    1234?, ?2345, 2345?, ?3456 would work if all dice had different values, but fails if a value is shared.
    The earliest example is 11234, the ? is in the first spot.
    Or even 12234, where the ? is the in second or third spot.
    Great video overall, thank you for making this.
    People often underestimate "little projets", but it's by doing projects of all sizes that you progress, not just big ones.

  • @julienderiviere4907
    @julienderiviere4907 Před 3 lety

    Yahtzee was the first game I implemented 20 years ago... in Basic :p I should do it again in C++

  • @fabiogaluppo2635
    @fabiogaluppo2635 Před 3 lety

    Nice video! Let me ask you: Why not implements set contains in terms of find instead of count?

  • @TrollingAround
    @TrollingAround Před 3 lety +5

    Pattern matching - Small straight, you missed a pattern for 11234 (?1234) and 34566 (3456?). Good vid, thanks got my brain thinking :)

    • @not-on-pizza
      @not-on-pizza Před 3 lety +3

      Actually more than that, because you also need to account for Small Straights where one of the middle values is repeated.

    • @TrollingAround
      @TrollingAround Před 3 lety +1

      @@not-on-pizza - Of course! so also 12234, 12334, 23345, 23445, 34456 and 34556 - did I miss any?

    • @FiddlesMcGee
      @FiddlesMcGee Před 3 lety

      @@TrollingAround I believe there are 16 possibilities for a small straight, which I think can be covered using these 8 patterns...
      {
      "?1234", // *1* 1234
      "12?34", // 12 *2* 34 or 12 *3* 34
      "1234?", // 1234 *4* or 1234 *5* or 1234 *6*
      "2?345", // 2 *2* 345 or 2 *3* 345
      "234?5", // 234 *4* 5 or 234 *5* 5
      "?3456", // *1* 3456 or *2* 3456 or *3* 3456
      "34?56", // 34 *4* 56 or 34 *5* 56
      "3456?" // 3456 *6*
      }

    • @puncherinokripperino2500
      @puncherinokripperino2500 Před 3 lety

      i think hardcoding each pattern was a mistake, coding the logic would be much cleaner, and he could practice std::unique in patterns of N consecutives

  • @srpskihayk
    @srpskihayk Před 3 lety

    Some 40 years ago, I did this in BASIC on a Radio Shack Color Computer, and later on a Color Computer 2 using Extended BASIC. I see the methods have changed just a tad. (that is a joke). Great work!

  • @megaxlrful
    @megaxlrful Před 2 lety

    I will probably never forget my first time playing yahtzee. I barely understood the rules, and my first roll was a yahtzee with fives. Talk about beginners luck.

  • @DarkVigoole
    @DarkVigoole Před 3 lety +1

    Nice video. Do ?1234 pattern will be matched for small straight ?

  • @my_temporary_name
    @my_temporary_name Před 3 lety

    Oh, so this is how it's called in English! Very nice kata. Btw, having a pair and two pairs is good for game balance because you often end up with just pairs when trying to throw something more difficult.

  • @GonziHere
    @GonziHere Před 3 lety

    Spot drawing - great insight into the development of an algorithm (and the value of not using the first and fastest solution) But the result is harder to expand to say 7,8 and 9 values (it uses "hacks" that work only inthis exact scenario, its the opposize of robust).
    But again, great video especially for junior programmers who dont understand these continuous improvements (or the prototyping value of the first code) That was just a nitpick :)

    • @DFPercush
      @DFPercush Před 3 lety

      My first thought beyond the "brute force" method was to use truth tables and Karnaugh maps, but that involves breaking the value into bits first. I wouldn't have noticed that symmetry the way he did it, and the code he ended up with is probably faster. But my way would have been branchless, sometimes that matters (not here tho). The only other dot-face thing I can think of that has more than 6 values would be dominos. I wonder what that would look like... but as you said, it's a very constrained problem here, and why solve problems that you don't have to. :P

  • @jaredbowen827
    @jaredbowen827 Před 3 lety +2

    This is the simplest program you've done. I've done this to my TI-89 Calculator YEARS ago. It's a good way to learn how to code in SEVERAL coding Languages.

  • @JT-ky6ov
    @JT-ky6ov Před 3 lety +1

    Please tag @everyone in the Discord when the any day now @34:11 has finally come

  • @ErtosAcc
    @ErtosAcc Před 3 lety

    17 minutes in and I'm losing focus. Rewatching later. I can recognize a great video despite not knowing anything about C++, and this is one of them. Provides a refreshing view on programming.

  • @ross9263
    @ross9263 Před 3 lety

    Sometimes the most entertaining and engaging videos are ones about personal growth of a topic the viewer and creator are both interested in. Take a golf youtuber I watch: golf sidekick, almost always makes videos about a game he played that day and his thoughts throughout the match. his videos are about his own personal growth as a golfer.

  • @glizzdawiz
    @glizzdawiz Před 3 lety +6

    I've been wanting to do this with DnD scoring, dice and experience calculation.

    • @casperes0912
      @casperes0912 Před 3 lety +1

      DnD Beyond has an API you can hook into to get character sheet info if you want :)

    • @glizzdawiz
      @glizzdawiz Před 2 lety

      @@casperes0912 cool thank you

  • @classiccroissant3231
    @classiccroissant3231 Před 3 lety

    Thanks for all your updates. How is the family situation?
    Wondering: there is a "onelonecoder" reddit, is it you?

    • @ShadowRadiance
      @ShadowRadiance Před 3 lety

      That reddit is him, yes - one look at that pretty mug, and you cannot doubt it!

  • @not-on-pizza
    @not-on-pizza Před 3 lety

    About the "quick and dirty" way of reducing a string character to a digit at 23:40... I'm not sure about C++, but the C standard library guarantees that this is correct _only_ for the digits '0' to '9'. It does not guarantee it for any other part of the character encoding.

  • @inspisiavideos8542
    @inspisiavideos8542 Před 3 lety

    Hi! I have a question but I think it's more like an advise. I got a paid internship at a company that protects data for hospitals. The internship first day introduction day (last week) I was told by HR and some senior employees that I will be rotating first doing QA Engineering job (testing apps from the developers, watching out for bugs, zoom meetings and scrum). Then I'll be rotating to write code in Java. HR later gave me a Powerpoint presentation and one of the slides had info about all the job positions people can apply to and get a bonus by bringing in a new recruit. But the HR lady said it does not apply to interns. During my first week I have done nothing but trainings and explanations of the platforms. I feel like it's a lot for a team. So, the question is if with all this, do you think if I ask them if I could stay permanently there or to have my stay there extended. If so, at what point I should ask? My full time internship ends ending August. My concern is that I did the decision of quitting my previous job as an Assistant for nurses in order to have this opportunity. Just in case I signed up for algoexpert and train coding problems so I can be prepare and start applying to jobs at other companies. But, I'm concerned about this because I have 3 months before my income ends. Please let me know.

  • @Michmanjuga
    @Michmanjuga Před 3 lety

    9:38 The std::set actually has the method "find" which will return an iterator to the searched element if such an element exists otherwise std::set::end() will be returned.
    So you may write something like:
    auto faces = std::set{ 2, 3, 4, 5, 6 };
    if (faces.find(nFace) != faces.end()) {
    // ... your logic
    }

  • @mikael5743
    @mikael5743 Před 3 lety

    Thanks

  • @insoYT
    @insoYT Před 3 lety

    Probably ten out of ten times I'd have gone with RegExp and never looked back 😂 But I must admit that I liked to watch that little puzzling. RegExp sometimes feels annoyingly repetitive work without able to just copy&paste old solution. However I feel like with RegExp this logic would have been more readable. I believe I'd have also chosen "if(yyy && xx)" over "if((nnn?? && ???nn) || (nn??? && ??nnn))" for formatting. 👍 Programming would be boring without challenging our approaches 🤓 Great video, thanks!

  • @THE16THPHANTOM
    @THE16THPHANTOM Před 3 lety +1

    mkay, this is the way of my thought process as well, so i'm on a good track. minus the clever pattern recognition in code, i can never get all of that in one session. i only get to that point by repeated re-reading my code and discovering the efficient way by accident.

  • @39Kohm
    @39Kohm Před 3 lety

    spotted the Vimto immediately :D

  • @ZordidMuc
    @ZordidMuc Před 3 lety

    I think there's a problem with the patterns for small straights. 1234? for example can only match to 12345 (a large straight also) or 12346 - but what if I have 12234? Which pattern should match that?

  • @nathanalgren288
    @nathanalgren288 Před 2 lety

    Yahtzee kinda reminds me of a Video Poker program I did a while back (interestingly, also in C++). One way I understand the game is basically Poker with dice instead of cards!

  • @erichamion
    @erichamion Před 3 lety

    I haven't gotten to the end, so this may be fixed before the end of the video. "11234" would be a valid small straight, but there's no "?1234" pattern to match it. The same happens if there are two sixes: "34566" needs a "3456?" pattern.

  • @alexandrevolts7513
    @alexandrevolts7513 Před 3 lety

    Wow that's crazy how we do not see the same thing facing the same problem. I coded a Yams last week (Typescript), yeah what a nice coincidence.
    Concerning the pattern part, I used something like a OOP-oriented way, which is a totally different approach. Basically I just had a class for every possible combination inheriting from a common class "AYamsCombination", and every child class has a common function that I overwrite and that contains the algorithm to "solve" one combination, taking an array of number (the dices) as parameter, and returning the score if it was a valid combination, or -1 if it was a wrong one.
    Then I store all my classes in an array and loop over them to compute the scores of a given combination.
    To don't have redundant code I created a "YamsTools" class which contains three functions: hasNDicesOrMore(int[ ] dices, int n), hasSequence(int[ ] dices, int sequenceSize), countDices(int[ ] dices, int dice), which makes that generally every function that is supposed to check a combination doesn't exceed three or four lines.

    • @Reintjuu
      @Reintjuu Před 3 lety

      That's what I was thinking. Why is he not taking an OOP approach?

  • @orbisanimation6150
    @orbisanimation6150 Před 3 lety

    I really love your videos I wish i can write c++ as you :D

  • @electronicapentrutoti
    @electronicapentrutoti Před 3 lety +1

    Hey, Javidx9.
    I have a question: Is it possible to create a game such as games that you created with olcConsoleGameEngine, but without olcConsoleGameEngine library, because on my Visual Studio 2019 it doesn't work, and if it's possible to create games without it, can you please make some tutorials?
    By the way, I like your content and your high quality videos.👍

    • @javidx9
      @javidx9  Před 3 lety +1

      Thanks. The CGE was replaced with the modern olcPixelGameEngine, it does the same thing and is mostly compatible with the videos. You need a library of some description since C++ has no built in awareness of graphics.

    • @electronicapentrutoti
      @electronicapentrutoti Před 3 lety +1

      @@javidx9 Ok, thank you 👍😉

  • @fplancke3336
    @fplancke3336 Před 3 lety

    Have you thought of adding a letter m to patterns that works like n but independently? This way the full house pattern set would be simplified to nnmmm | nnnmm.

  • @stevefalcigno2092
    @stevefalcigno2092 Před 3 lety +2

    Very nice! One thing, at 33:39 the values 3,4,4,5,6 should give us a small straight (I think).

  • @justinlangley8972
    @justinlangley8972 Před 3 lety

    I like regular expressions, but only for things where it's implementation stays simple, which is rare. If you can solve it algorithmically, do that instead because other people who read your code will thank you for sparing them if they struggle with regex. Regex is also hard to debug, and requires you to diagram it as a finite state machine (it's how regex works) to figure out where the issue lies. So anyhow, if you want to learn regex you'll want to study finite state machines, and when you build regex yourself you'll want to use a website like regexr (not a fan of it being actions riot based) or some other website. There also exists websites that turn regex into a graph of the finite state machine they represent. Hope this information is helpful for someone who would like to learn regex, but ultimately I don't think it's a critical skill to learn. However, if you come across it in your line of work, you'll at least know what it is and possibly how to dissect it, and then implement a better solution. There are circumstances where a good regex implementation can have a time complexity as good as an algorithmic implementation, and sometimes better if the implementation is poor. I really like the lambda implementation in this video, it's an elegant way to do it.

  • @justcallmenoah5743
    @justcallmenoah5743 Před 3 lety +1

    Yeah, the pattern matching is cool, but the implementation here is prone to bugs. I once made Yahtzee in c++ in college and I found the best way to calculate score, was to have an array of six integers that contain the count of each die value you have. It's much easier to determine your scores that way!

    • @Roomsaver
      @Roomsaver Před rokem

      Good idea! I like that implementation

  • @framegrace1
    @framegrace1 Před 3 lety

    I use the same approach. Start with most trivial implementations and the algorithm patterns appear like magic...

  • @Cesar-ey7wu
    @Cesar-ey7wu Před 3 lety

    Yahtzee's core gameplay is evaluating probabilities (which can be surprisingly counter intuitive).

  • @alexstone691
    @alexstone691 Před 3 lety +1

    24:00 why don't you just return false if any of the conditions don't match? Aren't you looping unnecessarily if first dice don't match a rule