I am trying to make a card game that two players show there cards and the one with the highest rank wins and takes the card.(War Card Game). The trouble i am having is running the whole game, to see the final result of who the winner is. I have made the code that can do one round of the game:
type ComparisonRule = Card -> Card -> Bool
type RoundRule = ([Card],[Card]) -> ([Card],[Card])
standardComparison :: ComparisonRule
standardComparison (Card r1 _) (Card r2 _)
| r1 > r2 = True
|otherwise = False
roundWithoutWar :: ComparisonRule -> RoundRule
roundWithoutWar f (x:xs,y:ys)
|f x y = (xs ++ [x] ++ [y],ys)
|f y x = (xs,ys ++ [y] ++ [x])
|otherwise = (xs,ys)
I use
standardRound :: RoundRule
standardRound = roundWithoutWar standardComparison
to run one round of the game.
I am trying to make a full game function that would run the rounds in recursion until someone wins(the winner is the person with the most cards):
fullGame :: RoundRule -> ([Card],[Card]) -> [([Card],[Card])]
fullGame r ([],[]) = [([],[])]
fullGame r ([],y:ys) = [([],y:ys)]
fullGame r (x:xs,[]) = [(x:xs,[])]
fullGame r (x:xs,y:ys) = (x:xs,y:ys) : fullGame ( r (x:xs,y:ys))
"r" being the single round function (StandardRound) However, i get an error when i try to run the full game function
War_Project_2.hs:138:46:
Couldn't match expected type ‘[([Card], [Card])]’
with actual type ‘([Card], [Card]) -> [([Card], [Card])]’
Probable cause: ‘fullGame’ is applied to too few arguments
In the second argument of ‘(:)’, namely
‘fullGame (r (x : xs, y : ys))’
In the expression: (x : xs, y : ys) : fullGame (r (x : xs, y : ys))
War_Project_2.hs:138:57:
Couldn't match type ‘([Card], [Card])’
with ‘([Card], [Card]) -> ([Card], [Card])’
Expected type: RoundRule
Actual type: ([Card], [Card])
Possible cause: ‘r’ is applied to too many arguments
In the first argument of ‘fullGame’, namely ‘(r (x : xs, y : ys))’
In the second argument of ‘(:)’, namely
‘fullGame (r (x : xs, y : ys))’
The point free function i tried to write to run the fullgame is:
simpleFullGame ::([Card],[Card]) -> [([Card],[Card])]
simpleFullGame = fullGame simpleRound
fullGame ( r (x:xs,y:ys))should befullGame r ( r (x:xs,y:ys))