Question
Need Haskell programming Help. How to separate and label clusters ( 4 direction connected components) in a list of list number (2-d array) and replace
Need Haskell programming Help. How to separate and label clusters ( 4 direction connected components) in a list of list number (2-d array)
and replace all numbers in a specific cluster to 1 (I need to write this in haskell.)
(the way to label the clusters is like the flood fill, if it connects to their neighbor by up-down-left-right direction, they will be grouping in the same cluster. we go from top left to bottom right. Question 1: One Player, One Move The first part (onePlayerOneMove in the file csce322h0mework03part01.hs) will take in two (2) arguments (the game and a cluster) and returns one (1) value (the game that is the result of replacing the cluster with 1s). If the game has already been won, or the cluster does not exist, the game is unchanged. ( [44 ,43 ,42 ,41 ,40 ,38 ,36 ,35 ,34 ,32 ,31 ,30 ,29 ,27 ,25 ,24 ,22 ,17 ,8 ,4 ,2 ,1] , ["1321311223122" , "2221231113332" , "1331231113321" , "2222232111213" , "3311331312233" , "1112332213311" , "2233111131311" , "1212331133331" , "3113123223122" ] ) " Result " "1321311223122" "2221231113332" "1331231113321" "2222232111213" "3311331312233" "1112332213311" "2233111131311" "1212331133331" "3113123223111" "" Some haskell starter code: (csce322h0mework03part01.hs)
import Prelude import System.Environment ( getArgs ) import Data.List import Helpers
-- The main method that will be used for testing / comgand line access main = do args
-- YOUR CODE SHOULD COME AFTER THIS POINT onePlayerOneMove :: [[Char]] -> Int -> [[Char]] onePlayerOneMove game move = result
...................... (Helper.hs)
module Helpers ( readBattleFloodFile , printGame ) where
import Prelude import Data.Char import Data.List import Debug.Trace
readBattleFloodFile :: String -> IO ([Int],[[Char]]) readBattleFloodFile = readIO
printGame :: [[Char]] -> IO () printGame [] = do print "" printGame (ro:ros) = do print ro printGame ros
1 Instructions In this assignment, you will be required to write Haskell functions that simplify playing of the variation of Battleflood. 1.1 Data File Specification An example of properly formatted file is shown in Figure 1 The encodes a game and the clusters that are to be changed during every move. Clusters are formed by 4-direction connectivity (up, down, left, right) and numbered from top-left to bottom-right in the game. part 01 test01.bff C44, 43,42,41, 40, 38,36,35, 34, 32 31,30,29, 27 25,24, 22 17,8 4,2 1], 132 131 1223 122 222 1231 113332 133 1231 113321 222223211 1213 331 133 131 2233 111 23322133 11 2233111 1313 11" 12123311 3333 1. 31 13 123223 122" Figure 1: A properly formatted game encoding 1 Instructions In this assignment, you will be required to write Haskell functions that simplify playing of the variation of Battleflood. 1.1 Data File Specification An example of properly formatted file is shown in Figure 1 The encodes a game and the clusters that are to be changed during every move. Clusters are formed by 4-direction connectivity (up, down, left, right) and numbered from top-left to bottom-right in the game. part 01 test01.bff C44, 43,42,41, 40, 38,36,35, 34, 32 31,30,29, 27 25,24, 22 17,8 4,2 1], 132 131 1223 122 222 1231 113332 133 1231 113321 222223211 1213 331 133 131 2233 111 23322133 11 2233111 1313 11" 12123311 3333 1. 31 13 123223 122" Figure 1: A properly formatted game encoding
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started