# Course:CPSC312-2017-Crusher

## Crusher

Authors: Simon, Jingru, Yun Meng

### What is the problem?

State the general problem. If applicable, tell us what information you will use, e.g., a link to some web site that provides the information you used. What will you do?

The problem is if the logical programming language haskell can be used to implement a game. We will address this problem by implementing and creating the Crusher game as outlined in the starter file.

### What is the something extra?

What is the in-depth aspect you will do? If the problem is related to some other group's project, tell us how they fit together. If in doubt, include the information.

We will provide the next best board for a player given the current board taking advantage of heuristics, in this respect incorporating some form of AI into project.

### What did we learn from doing this?

(This should be written after you have done the work.) What is the bottom-line? Is logic programming suitable for (part-of) the task? Make sure you include the evidence for your claims. By the process of implementing the game crusher in haskell, we learned a few different things. A deeper understanding of Data and Type constructs was gained, as well as how to apply them in context of our project. Additionally, we learned how to create search trees ,while also furthering our experience with recursive functions and higher order functions such as foldr and filter. Difficulty in testing was an issue as we did not use any testing platforms and many of our functions required large inputs to test properly. We found logical programming through the haskell language, for the most part, suitable for the task of implementing the crusher game. This included implementing functions for creating the board, evaluating the board and operations based on heuristics such as finding the next best board in a search tree. This is justified by sample code and output shown below:

You can run the program by calling the function crusher which returns the list of boards with the new current board first in the list followed by all the old boards seen in the game. The 4 parameters are: 1. A list starting with the most recent board followed by the history of all boards seen in the game 2. 'W' or 'B' representing the player the program is 3. An integer representing the depth of the search tree 4. An integer representing the dimensions of the board

• Crusher> crusher ["W------------BB-BBB","----W--------BB-BBB","-W-----------BB-BBB"] 'W' 2 3

["W------------BB-BBB","W------------BB-BBB","----W--------BB-BBB","-W-----------BB-BBB"]

Another example is the function generateNewStates which returns the list of next possible boards given the possible slides, jumps and history of boards it has already seen It takes 6 parameters which are: 1. Board - A board representing the most recent board 2. History - A list of board representing the all boards already seen 3. Grid - representing the coordinate grid of the game 4. Slides - all possible slides for the given grid 5. Jumps - all possible jumps for the given grid 6. Player - W or B representing the player the program is

• Crusher> generateNewStates board0 [] grid0 slides0 jumps0 W

[[W,W,W,D,W,D,D,D,D,D,W,D,D,B,B,D,B,B,B],[W,W,W,D,W,D,D,D,D,W,D,D,D,B,B,D,B,B,B],[W,W,W,D,W,D,W,D,D,D,D,D,D,B,B,D,B,B,B],[W,W,W,W,W,D,D,D,D,D,D,D,D,B,B,D,B,B,B],[W,W,W,D,D,W,D,D,D,W,D,D,D,B,B,D,B,B,B],[W,W,W,D,D,W,D,D,W,D,D,D,D,B,B,D,B,B,B],[W,W,W,W,D,W,D,D,D,D,D,D,D,B,B,D,B,B,B],[W,W,W,D,D,W,W,D,D,D,D,D,D,B,B,D,B,B,B],[W,W,D,D,W,W,W,D,D,D,D,D,D,B,B,D,B,B,B],[W,W,D,D,W,W,D,D,D,W,D,D,D,B,B,D,B,B,B],[W,D,W,D,W,W,D,D,W,D,D,D,D,B,B,D,B,B,B],[W,D,W,D,W,W,D,D,D,D,W,D,D,B,B,D,B,B,B],[D,W,W,W,W,W,D,D,D,D,D,D,D,B,B,D,B,B,B],[D,W,W,D,W,W,D,D,D,W,D,D,D,B,B,D,B,B,B]]