Course:CPSC312-2017-TicTacToe Haskell

From UBC Wiki

TicTacToe Haskell

Authors: Johnson S, Will W, Eric C

What is the problem?

Implement tic tac toe (https://en.wikipedia.org/wiki/Tic-tac-toe) using Haskell. Our project will have one game mode: Player vs. AI. The player or computer must make a valid move indicated by integers 1-9, providing us with a new board, which is then checked with the multiple win conditions. When one of these win conditions is met, the result printed will be either "Player win", "Computer win", or "No winner". Play the game with start

What is the something extra?

In project one, our game was displayed through functions and having to retype game boards and queries which made it tedious to merely play the game. This time around, we have created a display screen so the player is able to see the current board. Import system.Random (randomRIO) was used in order to randomly generate a number between 1 and 9 (first checking if that integer is an empty panel) to determine the AI's move. However, the AI will always attempt to make winning moves as well as blocks off the player's first(using pattern matching). Overall, a lot smoother and with multiple printStrLn's which allow for a much more enjoyable user experience.

What did we learn from doing this?

Link to our game: https://github.com/willywwang/CPSC312-Project-2-Tic-Tac-Toe/blob/master/tictactoe.hs

At first, we tried to code something similar to our prolog project but had some difficulties switching between languages. However, we were able to learn key aspects and draw inspiration from different online resources such as youtube, hackage documentation, reddit, and stackexchange. For example, the use of importing packages such as system.Random and system.IO. It was difficult to understand at first but ended up being used quite often. Most of our project involves pattern matching. Although there are many cases, we believe that it was the simplest way to implement a game like this. It allows for very clear and concise code in which makes sense when read through.