Hello!

One of the students in my class came upon this weird error.. I don't understand
why it appears, but it appears to be a problem with the hugs parser.  The error
is "INTERNAL ERROR: parseInput".  Here is the script:

regards,
Brian


{--------------------------------------------------------------------------------------
   Project A
   Anthony Jose Moretti
   108076
   Computer Fundamentals A (141)
---------------------------------------------------------------------------------------}
{- The function playable essentially checks whether a game of Mastermind has the right
   amount of columns and colours to make it interesting and manageable and thus a 
playable
   game. -}

-- s = the size of the board, ie number of columns
-- c = the number of colours to be used in the game

playable :: Int -> Int -> Bool
playable s c
        |(3 <= s) && (s <= 6) && (3 <= c) && (c <= (s+2)) == True = True
        |otherwise = False

---------------------------------------------------------------------------------------

{- The function code is meant to select at random the colour code for that game by 
using a
   code of numbers (the same length as the number of colours required) generated 
randomly
   to pick the colours for that game. -}

type Colour = String
type Row = [Colour]

-- pc = permitable colours specified for that game
-- c  = the number code the computer has selected to choose the colour code for that 
game

code :: [Colour] -> [Int] -> Row
code pc c = [pc!!(a-1) | a <- c]

---------------------------------------------------------------------------------------

{- The function validguess checks the validity of the player's guess by checking if it 
has
   the correct amount of colours and that all the colours are permitted - as in they 
have
   been used in the code to be guessed. -}

-- s  = size of board (number of columns)
-- pc = permitable colours
-- g  = the player's guess

validguess :: Int -> [Colour] -> Row -> Bool
validguess s pc g
        | (and [x `elem` pc | x <- g] == True) && ((length g) == s) = True
        | otherwise = False

---------------------------------------------------------------------------------------

{- The function wild-codes creates a number of possible guesses when a guess is 
submitted     with one or more wildcards in it that are used to produce valid colours 
in their spots,    a number of possibilities is most usually created. -} 

wild_codes :: [Colour] -> Row -> [Row]
wild_codes colour guess = check colour [guess]

check :: [String] -> [Row] -> [Row]
check colour [] = []
check colour (guess:restguess)
        |"WILD" `elem` guess = check colour ((wildr2 colour guess) ++ restguess)
        |otherwise = guess:check colour restguess

        where
        wildreplacement1 :: Row -> String -> Row
        wildreplacement1 (guest:restguess) nc
                |guess == "WILD" = nc:restguess
                |otherwise = guess:wildreplacement1 restguess nc

        wildr2 :: Row -> Row -> [Row]
        wildr2 colourlist guess = [wildreplacement1 guess colour | colour <- 
colourlist]

Reply via email to