FP Homework 1 extension
1 - Chess position
Implement the function move
which has 2 arguments of the type Result
(position A and position B). Function result type is Bool
, It is True
if it is possible with one chess piece move get from position A to B, false
otherwise.
move :: Result-> Result -> Bool
2 - Ticktacktoe
Implement the function winner
which has 2 arguments, the same description of a play-filed as before. It will return Bool
indicating that one of the players have more then 4 pieces in a row, column or diagonally.
winner:: (Int,Int) -> [(Int,Int)] -> Bool
3 - Maze
Implement the function length
which has 2 arguments. First argument is a list of strings representing a maze row by row from top to bottom ('*' - wall, ' ' - empty square, 's' - starting position). At the beginning we are at position 's'. Second argument is a position in the maze. Find the length of a shortest path from start to this position.
length :: Result -> (Int,Int) -> Int
sampleInput = ["*********",
"*s* * *",
"* * * * *",
"* * * * *",
"* * *",
"******* *",
" *",
"*********"]
4 - Minesweeper
Implement the function makeMove
which has 2 argument. First is Result
. It will be a result from the function minesweeper
.
Second argument will be pair (row,column)
, it will represent a position where player 'clicked'. The result will be a playground where just a part of the play-ground will be visible. The character .
detonates a hidden field (initially all fields are hidden). If player clicked in a mine, you can output the input. If he clicked on a number different then zero, just the number will be visible. If it is a zero, then the whole consecutive area of zeroes along with bordering numbers will be visible.
minesweeper :: Result -> Result
sampleInput = ["1110000",
"1*11110",
"1122*10",
"001*221",
"233211*",
"***2011",
"*8*3000",
"***2000"]
Prelude>pp(makeMove sampleInput (0,7))
..10000
..11110
.....10
.....21
.......
.......
.......
.......
5 - Ships
Implement the function checkOverlap
which has 2 arguments. First is a pair (columns, rows)
which defines size of the playground. Second argument is a list of list containing coordinates of squares taken by ships. Each of the inner lists represents one ship. Ship is defined as a set of coordinates (column, row)
, where column is given using small English alphabet. You can consider that the size of play-field will be smaller then 25x25. Output Bool
indicating that the game description is valid. It is valid when no ships overlap or touch each other.
checkOverlap:: -> (Int, Int) -> [[(Char, Int)]] -> Bool