[Part 2] Tic-tac-toe Game in Haskell -- Procedural vs Functional

Ғылым және технология

Source Code: github.com/tsoding/profun
Waste Your Money: / tsoding

Пікірлер: 51

  • @0xCAFEF00D
    @0xCAFEF00D6 жыл бұрын

    I found this very helpful for understanding functional programming.

  • @zark4711
    @zark47114 жыл бұрын

    Juggling with indices is often tedious and might sometimes lead to off by one errors. If the board was a static 3x3, I would define a [[Cell]] containing all rows (horizontal, vertical, diagonal) and use functions like ‘all’ and ‘any’ to determine the winning and endgame states. For dynamic size boards this structure can be calculated by (assuming board :: [[Cell]]): let tBoard = transpose board in diagonal board : diagonal tBoard : (board ++ tBoard) where diagnonal ((x:_):rest)) = x : diagonal (map (drop 1) rest), diagonal _ = []. Again, if it was a static 3x3 board, I would just list all “rows” once.

  • @franeklubi
    @franeklubi5 жыл бұрын

    Fuck man, this is all i needed, not some boring tutorial stating the basics, this

  • @florianfromm3265
    @florianfromm32656 жыл бұрын

    Finally :) Just in for this great functional stuff ! Btw. would love to see Boids in Haskell (with Gloss :)).

  • @ferdinaldocoding
    @ferdinaldocoding6 ай бұрын

    12:10 BIG LOL here 😂😂😂

  • @user-dn5ol9wc2u
    @user-dn5ol9wc2u3 жыл бұрын

    Чувак, от души спасибо за видео! Пишем с подругой сейчас игру "Морской бой" на haskell, и твое видео нам очень помогло. Ждем с нетерпением ждем следующих роликов! Dude, thanks for the video! We are now writing a game "Sea Battle" on haskell with a friend, and your video helped us a lot. We are looking forward to the next videos!

  • @leonardciupei8018
    @leonardciupei80187 ай бұрын

    Hello! I just finished making this game, it was my first ever experience building and running a program! Your video was super helpful and I learned a lot, not just about Haskell but also using Emacs. Thank you very much for this tutorial! :)

  • @samuraijosh1595

    @samuraijosh1595

    6 ай бұрын

    Did you do this in haskell? Amazing!! I made a small hangman game in haskell recently. And OMG I loved it. Haskell makes it so that i can just take one look at a function and the function will speak for itself about what it's doing. Next try to build a snake game with haskell hehe.

  • @leonardciupei8018

    @leonardciupei8018

    3 ай бұрын

    @@samuraijosh1595 Yes I did :) it was a really good experience with programming in general. I also did the Hangman game hehe. Right now I'm trying to develop a personal application through Haskell, wish me luck! P.S. I might try the snake in the future :)

  • @patrickdc683
    @patrickdc6836 жыл бұрын

    The logic in the playerwon function could be made a lot easier by pattern matching the 3x3 board.

  • @Tsoding

    @Tsoding

    6 жыл бұрын

    Sure! Feel free to submit a pull request with a fix: github.com/tsoding/profun :)

  • @zark4711
    @zark47114 жыл бұрын

    I would calculate the state running/ended, which player won or if it is a tie and whose player‘s move it is (assuming x always starts) from the board. This takes some (in this case little) computational power and trades it for more guaranteed consistency of the data structure.

  • @Antinumeric
    @Antinumeric6 жыл бұрын

    I feel like Gloss is doing a bit more heavy lifting compared to SDL in the C version.

  • @Tsoding

    @Tsoding

    6 жыл бұрын

    Yep, that's true. With gloss we don't have to organize the event loop as we did in the procedural example. But that actually enables us with making ~99% of the code pure functional. Notice how there is no a single `do` in the entire code base and the only place we use the `IO` type is in the `main` function. :)

  • @mehdisaffar
    @mehdisaffar4 жыл бұрын

    This was amazing I loved it!

  • @stro3277
    @stro32772 жыл бұрын

    i just finished learning python.... this is like 20 steps above my paygrade

  • @mlady.y
    @mlady.y3 жыл бұрын

    Thank you 😍, you help me a lot

  • @AlejoCP00
    @AlejoCP00 Жыл бұрын

    Thanks for this video! It help me a lot 👌

  • @scottlim5597
    @scottlim55973 жыл бұрын

    excellent video. well done

  • @luisalejandrohernandezmaya254
    @luisalejandrohernandezmaya2544 жыл бұрын

    Excuse me. What is the double diagonal meaning at 11:21 ?

  • @electricimpulsetoprogramming
    @electricimpulsetoprogramming Жыл бұрын

    could you write an article talking the differences about each one of them and what you think. i get bored too easy by watching videos

  • @EmanAhmed-mg5vm
    @EmanAhmed-mg5vm2 жыл бұрын

    how can i get the external modules to be added to the haskell file?

  • @Ahelhot
    @Ahelhot4 жыл бұрын

    Ok. but what about performance? if immutable structs copies data in memory after each call, how to draw assassin's creed in 60 fps?)

  • @neolight1010

    @neolight1010

    2 жыл бұрын

    I think Persistent Data Structures that solves that issue. But yeah, Haskell programs are not as fast as C or other low-level languages, but it gets pretty close.

  • @braydenmarshall808
    @braydenmarshall8084 жыл бұрын

    help-me-im-trapped-in-the-basement

  • @top_cat26
    @top_cat266 жыл бұрын

    muy bueno , gracias¡¡¡

  • @zdeezy420
    @zdeezy4206 жыл бұрын

    This really cool I wanna know how big of a game can u make on Haskell? Like COD and fortnite?

  • @Tsoding

    @Tsoding

    6 жыл бұрын

    Not sure about COD, but Quake 3 is quite possible lambdacube3d.com/

  • @beauteetmusculation8191

    @beauteetmusculation8191

    3 жыл бұрын

    @@Tsoding This lambdacube3d website and project is awesome. Such a shame this is not used anywhere. :-(

  • @scriptocreator

    @scriptocreator

    2 жыл бұрын

    @@Tsoding _Oh, why did I, Russian guy, go to the Net…_

  • @funmath3835
    @funmath38352 жыл бұрын

    so its better to follow haskell or is it good to c one

  • @anzo.p
    @anzo.p4 жыл бұрын

    Beautiful

  • @madbad1310
    @madbad13103 жыл бұрын

    Я ошибаюсь, или правильно чувствую русский акцент (хоть и не сильный)?

  • @AdamSchelenbergCom
    @AdamSchelenbergCom5 жыл бұрын

    hack in Haskell every day.

  • @top_cat26
    @top_cat266 жыл бұрын

    Please....web scraping in Haskell....Gracias...gracias

  • @tuckertcs
    @tuckertcs Жыл бұрын

    Where tf is part 1 lol

  • @Yetipfote
    @Yetipfote4 жыл бұрын

    fine. Now heavily parallelize it to 12 cores :))

  • @cepi24
    @cepi248 ай бұрын

    Sir, we are waiting for part 3, object-oriented version. Great job

  • @alexanderskusnov5119
    @alexanderskusnov5119 Жыл бұрын

    А где сравнение? Пустое видео.

  • @xiaoruchen6435
    @xiaoruchen64352 жыл бұрын

    how do I run this on Mac?

  • @joe_hoeller_chicago
    @joe_hoeller_chicago4 жыл бұрын

    Cabal is not installing

  • @Bratjuuc

    @Bratjuuc

    3 жыл бұрын

    Stack is better

  • @jacobscrackers98
    @jacobscrackers984 жыл бұрын

    At 13:10 the procedural and functional results don't look the same: the functional image has a border showing at the bottom and right side of the screen.

  • @alexanderskusnov5119
    @alexanderskusnov5119 Жыл бұрын

    very fast

  • @JohnnyRicha
    @JohnnyRicha5 жыл бұрын

    Would be great see an Object Oriented implementation.

  • @ruffianeo3418

    @ruffianeo3418

    3 жыл бұрын

    but then REAL OOP - as in CLOS or Smalltalk :)

  • @jony1710
    @jony17106 жыл бұрын

    Nope, still don't understand Haskell. Much prefer the ML dialects. ;)

  • @Tsoding

    @Tsoding

    6 жыл бұрын

    Dude, same

  • @zerocoll20
    @zerocoll203 жыл бұрын

    Your skill is amazing but you have a bad taste for environment colors.

Келесі