Authors: George Yu, Elton Kok, Stephen Li
What is the problem?
Battleship is a fun game to play with your friends. But what if all your friends are busy? Our Battleship game introduces an AI to play with you, and a two player mode!
What is the something extra?
Our plan is to build a battleship game with opponents of varying difficulties. Randomness will be introduced in both the initializing of the computer's ships as well as it's decision-making process. We have also implemented a GUI for the game in two player mode using the Haskell Gloss library.
What did we learn from doing this?
Creating a program/game with Haskell involves very little actual coding. Programming in Haskell is more about defining data types and type signatures for functions since much more thought has to go into the typing of the program. Figuring out how to type the State was a learning experience as we had to figure out not only what data is needed for people to play the game but also for the computer to make decisions.
Learning to use different Haskell libraries was challenging at first, but straightforward after we realized that looking at the type definition of each function tells the developer exactly how to use the function. This reinforced our understand of how important type definitions are in a functional programming language like Haskell.
Working with random is much more cumbersome in Haskell than in other languages as the randomness comes from a seed which must be generating in a I/O function and hence there you cannot invoke a function that generates a random element in a pure function.
In this game we worked around that by adapting our pure functions to be I/O functions and also by calculating our own seed.
Overall, Haskell is well equipped to create a turn-based board game. Haskell's strong typing makes code more robust to changes and allows for easier debugging. As mentioned earlier Haskell's efficiency (in terms of lines of code) and the absence of side-effects makes for better readability.