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

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

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

  • @leonardciupei8018
    @leonardciupei8018 Год назад +2

    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 11 месяцев назад +1

      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 8 месяцев назад +1

      @@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 :)

  • @0xCAFEF00D
    @0xCAFEF00D 6 лет назад +40

    I found this very helpful for understanding functional programming.

  • @zark4711
    @zark4711 4 года назад +9

    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.

  • @AnnVoronova-r5b
    @AnnVoronova-r5b 3 года назад +2

    Чувак, от души спасибо за видео! Пишем с подругой сейчас игру "Морской бой" на 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!

  • @patrickdc683
    @patrickdc683 6 лет назад +14

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

    • @Tsoding
      @Tsoding  6 лет назад +12

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

  • @franeklubi
    @franeklubi 5 лет назад +5

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

  • @Antinumeric
    @Antinumeric 7 лет назад +33

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

    • @Tsoding
      @Tsoding  7 лет назад +31

      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. :)

  • @florianfromm3265
    @florianfromm3265 7 лет назад +8

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

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

    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.

  • @ferdinaldopelembe
    @ferdinaldopelembe Год назад +2

    12:10 BIG LOL here 😂😂😂

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

    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 года назад +1

      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.

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

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

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

    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

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

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

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

    This was amazing I loved it!

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

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

  • @EmanAhmed-mg5vm
    @EmanAhmed-mg5vm 3 года назад

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

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

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

    • @Tsoding
      @Tsoding  6 лет назад +9

      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 3 года назад

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

  • @mlady.y
    @mlady.y 4 года назад +2

    Thank you 😍, you help me a lot

  • @funmath3835
    @funmath3835 3 года назад

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

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

    Thanks for this video! It help me a lot 👌

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

    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.

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

    Where tf is part 1 lol

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

    excellent video. well done

  • @top_cat26
    @top_cat26 6 лет назад +14

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

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

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

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

    muy bueno , gracias¡¡¡

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

    hack in Haskell every day.

  • @anzo.p
    @anzo.p 5 лет назад +1

    Beautiful

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

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

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

    how do I run this on Mac?

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

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

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

    Cabal is not installing

    • @Bratjuuc
      @Bratjuuc 3 года назад

      Stack is better

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

    very fast

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

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

  • @JohnnyRicha
    @JohnnyRicha 5 лет назад +4

    Would be great see an Object Oriented implementation.

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

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

  • @zerocoll20
    @zerocoll20 3 года назад

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