software-engineering-amsterdam / ST2018_WG_7

0 stars 0 forks source link

Lab 5 #3

Open BertLisser opened 5 years ago

BertLisser commented 5 years ago

Exercise 2. Good but refactoring can be more complete. In many more places it is possible to replace Constraints by [Position]

type Node = (Sudoku,[Position])
prune :: (Row,Column,Value)
      -> [Position] -> [Position]
constraints :: Sudoku -> [Position]

Exercise 3

minimalSudoku :: Node -> Bool
minimalSudoku node = not $ any uniqueSol (parents node)

must become

minimalSudoku :: Node -> Bool
minimalSudoku node = (not $ any uniqueSol (parents node)) &&  (uniqueSol node)

Exercise 4

checkEmptyBlockSudoku :: Int -> IO ()
checkEmptyBlockSudoku n = do [r] <- rsolveNs [emptyN]
                             showNode r
                             xs <- shuffleBlocks
                             -- xs <- blocksToEmpty n
                             let xs' = take n xs
                             let r' = cleanBlocks r xs'
                             if uniqueSol r' then do
                                s  <- genProblem r'
                                showNode s
                             else checkEmptyBlockSudoku n

better

checkEmptyBlockSudoku :: Int -> IO ()
checkEmptyBlockSudoku n = do [r] <- rsolveNs [emptyN]
                             showNode r
                             xs <- shuffleBlocks
                             -- xs <- blocksToEmpty n
                             let xs' = take n xs
                             let r' = cleanBlocks r xs'
                             s  <- genProblem r'
                             if uniqueSol s then do             
                                showNode s
                             else checkEmptyBlockSudoku n

In the old way you will miss possible unique solutions.

njtromp commented 5 years ago

Could you please elaborate on how you envision the refactoring of Constraint? Given our types

type Position = (Row,Column)
type Constrnt = [[Position]] -- Mind the missing 'ai' in the spelling as this is copied from the assignment

the refactoring of type Constraint = (Row,Column,[Value]) would lead to type Constraint = (Position,[Value]) which would lead to

type Node = (Sudoku,[(Position,[Value])])

which is different then the suggested refactoring in the issue!

type Node = (Sudoku,[Position])

The list of values is missing in this case.

BertLisser commented 5 years ago

You don't need this because you can always call freeAtPos for getting [Value]. But I admitted this is expensive. But missed a remark like that it is ugly to have to similar types Constraint and Constrnt. It looks as if the refactoring task is not finished.