Solved–Assignment 03 –Solution

$30.00 $19.00

Instructions In this assignment, you will be required to write Haskell functions that simplify navigating an elaborate maze. 1.1 Data File Speci cation An example of properly formatted le is shown in Figure 1. part01test01.emf ( ll ul rr uu l ” , [ x x x x x x x x x x ”…

You’ll get a: . zip file solution

 

 

Description

5/5 – (1 vote)
  • Instructions

In this assignment, you will be required to write Haskell functions that simplify navigating an elaborate maze.

1.1 Data File Speci cation

An example of properly formatted le is shown in Figure 1.

part01test01.emf

(

  • ll ul rr uu l ” ,

[

  • x x x x x x x x x x ” ,

  • xxx – – – – -1 x ” ,

  • xx – -x – – – – x ” , “x – – -x – – xxx ” , “x -x -x – xx – x ” , “x -x – – – – – – x ” , “x – – – – – xx – x ” , “x – – xg – -x – x ” ,

  • xx -x – – – – – x ” ,

  • x x x x x x x x x x “

]

)

Figure 1: A properly formatted maze encoding

  • One Player, One Move

The rst part (onePlayerOneMove in the le csce322homeWork03part01.hs) will take in two

  1. arguments (the maze and a move) and returns one (1) value (the maze that is the result of Player 1 making the given move) . If the maze has already been solved, or the direction of the move is immediately blocked, the maze is unchanged. Otherwise, like the JavaScript assignment, the player keeps moving until the goal is reached, they reach a dead end (where the only open

1

move is \backwards”), or they occupy a spot with more options than just moving \forward” and \backward”.

(

  • ll ul rr uu l ” ,

[

  • x x x x x x x x x x ” ,

  • xxx – – – – -1 x ” ,

  • xx – -x – – – – x ” , “x – – -x – – xxx ” , “x -x -x – xx – x ” , “x -x – – – – – – x ” , “x – – – – – xx – x ” , “x – – xg – -x – x ” ,

  • xx -x – – – – – x ” ,

  • x x x x x x x x x x “

]

)

Figure 2: Before onePlayerOneMove

” Result “

” x x x x x x x x x x “

” xxx – – – -1 – x “

” xx – -x – – – – x “

“x – – -x – – xxx “

“x -x -x – xx – x “

“x -x – – – – – – x “

“x – – – – – xx – x “

“x – – xg – -x – x “

” xx -x – – – – – x “

” x x x x x x x x x x “

“”

Figure 3: After onePlayerOneMove

  • One Player, Many Moves

The second part (onePlayerManyMoves in the le csce322homeWork03part02.hs) will take in two

  1. arguments (the maze and a list of moves) and returns one (1) value (the maze that is the result of Player 1 making all of the give moves). If the maze has already been solved the maze is unchanged. If the direction of a move is immediately blocked, the maze is unchanged for that move.

Page 2

(

  • r l l l d l r d l r d u l ” ,

[

  • x x x x x x x x x x x x x x x ” , “x – xxx – – -x – – – xxx ” , “x – – xx -x -x -x – xxx ” ,

  • xx – -x – – – – – – -x – x ” ,

  • xxxgxxxx -x -x – – x ” , “x -x -x – -x – – xx – xx ” , “x -x – – – – – – – – – – xx ” , “x – – x1xx -x – -x – – x ” , “x – – – – – – – xx -x – xx ” ,

  • x x x x x x x x x x x x x x x “

]

)

Figure 4: Before onePlayerManyMoves

” Result “

” x x x x x x x x x x x x x x x “

“x – xxx – – –

x – – –

xxx “

“x – –

xx -x -x -x – xxx “

” xx –

-x – – –

—-

x – x “

” xxx1xxxx -x -x – – x “

“x -x -x – -x – – xx – xx “

“x -x – – – – – – – – – – xx “

“x – -x – xx -x – -x – – x “

“x – – – – – – – xx -x – xx “

” x x x x x x x x x x x x x x x “

“”

Figure 5: After onePlayerManyMoves

  • Many Players , One Move

The third part (manyPlayersOneMove in the le csce322homeWork03part03.hs) will take in two

  1. arguments (the maze and a move) and returns one (1) value (the maze that is the result of Player 1 making the given move). If the maze has already been solved, or the direction of the move is immediately blocked, the maze is unchanged. This di ers from the rst part in that there may be more than 1 player in the maze.

Page 3

(

  • lr ” ,

[

  • x x x x x x x x x x x x ” , “x – – – – – – -x – – x ” , “x -x -x -x – – – – x ” , “x – – -3 – -x – – xx ” ,

  • xx – – – – xxx – – x ” ,

  • xx – xxx -2 – x – x ” ,

  • xx – – – – -x – – – x ” ,

  • xxx – – xxxxx – x ” , “x -x – – -1 – xx – x ” , “x – xx – xxxxx – x ” , “x -g – – -x – – – – x ” ,

  • x x x x x x x x x x x x “

]

)

Figure 6: Before manyPlayersOneMove

” Result “

” x x x x x x x x x x x x “

“x – – –

—-

x –

– x “

“x -x -x -x –

– –

– x “

“x – – –

3 – -x

– –

xx “

” xx – –

– – xxx –

– x “

” xx – xxx -2

– x – x “

” xx – –

– – -x

– –

– x “

” xxx – – xxxxx – x “

“x -x -1 – – – xx – x “

“x – xx – xxxxx – x “

“x -g – – -x – – – – x “

” x x x x x x x x x x x x “

“”

Figure 7: After manyPlayersOneMove

  • Many Players , Many Moves

The fourth part (manyPlayersManyMoves in the le csce322homeWork03part04.hs) will take in two (2) arguments (the maze and a list of moves) and returns one (1) value (the maze that is the result of Player 1 making the rst move, Player 2 making the second. . . ). If the maze has already been solved, or the direction of the move is immediately blocked, the maze is unchanged and the next player makes the next move.

Page 4

(

  • d ” ,

[

  • x x x x x x x x x x x x x ” ,

  • xx -x – -x – – – -1 x ” ,

  • xx – – – – – – -x – – x ” , “x -2 – x – -x -x – xx ” , “x -x – xxx – -x – – x ” , “x – -4 – – -x – -x – x ” ,

  • xxx3 – xx – -x – – x ” , “x – – – – – – -x – – – x ” ,

  • xg – – – – – -x – xxx ” ,

  • x x x x x x x x x x x x x “

]

)

Figure 8: Before manyPlayersManyMoves

” Result “

” x x x x x x x x x x x x x “

” xx -x – -x – – – – – x “

” xx – – – – – – – x1 – x “

“x -2 – x – -x -x – xx “

“x -x – xxx

– -x

– – x “

“x – –

4—

x – –

x – x “

” xxx3 – xx

– -x

– – x “

“x – –

—-

-x –

– – x “

” xg – – – – –

-x – xxx “

” x x x x x x x x x x x x x “

“”

Figure 9: After manyPlayersManyMoves

  • Naming Conventions

Your les should follow the naming convention of

csce322homeWork03part01.hs, csce322homeWork03part02.hs, csce322homeWork03part03.hs, and csce322homeWork03part04.hs.

6.1 Helpers.hs

A le named Helpers.hs has been provided with the functionality to read the .emf les into matrices. If a modi ed Helpers.hs le is not included with your submission, the default will be used in its place.

Page 5

  • webgrader Note

Submissions will be tested with ghc. cse.unl.edu is currently running version 7:10:3 of ghc. If you would like to test things o ine, you can load a le in ghci with the command :l filename.hs and run the main method on a given le with the command :main “/path/to/inputfile.bff”

8

Point Allocation

Component

Points

csce322homeWork03part01.hs

Compilation

10

Test Cases

1 10

Total

20

csce322homeWork03part02.hs

Compilation

10

Test Cases

1 10

Total

20

csce322homeWork03part03.hs

Compilation

10

Test Cases

1 20

Total

30

csce322homeWork03part04.hs

Compilation

10

Test Cases

1 20

Total

30

Total

100

9

External Resources

Learn Haskell Fast and Hard

Learn You a Haskell for Great Good!

Red Bean Software

Functional Programming Fundamentals The Haskell Cheatsheet

Page 6