Course:CPSC312-2023/Snakes And Ladders

From UBC Wiki

Snakes ๐Ÿ and Ladders ๐Ÿชœ

Authors: Sarah Ibrahim, Kevin Wong

What is the problem?

Our implementation of the snakes and ladders board game using Haskell accompanied by a GUI developed using Gloss.

Our goal is to implement a version of the board game Snakes and Ladders. Our implementation will involve two players competing against each other to reach the finish first.

What is the something extra?

We will be implementing a GUI to create a visualization of the actual board game and the progress of the players. The board will also show each player what number has been rolled by the die on their turn.

What did we learn from doing this?

We learned quite a lot from working on this project!

Firstly, the implementation of this project provided us with plenty of experience programming in Haskell, which helped get us comfortable with its use and syntax. By extensively coding in Haskell we were also able to develop a greater appreciation for functional programming.

One concept of Haskell that particularly stood out to us were list comprehension and pattern matching! List comprehension was extremely helpful in the development of our GUI component; our entire grid was actually created using it! It also allowed us to seamlessly iterate over lists and update the game and player states based on their current position on the game grid.

Having developed the ability to keep track of player position in the grid, pattern matching helped us check if a player has won the game, and if so render a screen announcing them as the winner of the game!

In addition, the top-bottom planning stage of this project helped us think about how big, daunting functions can be achieved by breaking down their functionality into smaller, simpler components. For example, the thought of keeping track of player movement and the state of the game in general seemed quite complicated. So we broke these concepts down:

  • Our PlayerState Consists stored data about:
    • Whose turn it was
    • Player 1's current position on the grid
    • Player 2's current position on the grid
    • The number resulting from a die roll during a player's turn.
      An example of the screen declaring the winner of the game.
  • Our GameState stored the following data:
    • The game grid as an array of Boolean pairs storing the presence of the players with each game state.
    • Whether the game is over or is continuing.


Finally, it was really rewarding to be able to develop a game that we can be proud of using a functional language. As well, developing the GUI using Gloss was a huge learning experience. Having considered the points above, we can safely say that Haskell was suitable for the task of developing this rendition of snakes and ladders.

Links

GitHub repository link.