module MoveGenerator where
- Custom data structure which is a tuple structure that contains a position (Position row column)
data Position = Position cfw_row : Int, column : Int deriving (Show)
- Generate all possible states for current board and player
- Questoin 1
preparednessQuotient i s c pn pa d n =
(top pa s c) / (bottom pn d n i)
top pa s c = 8 * (pa * (s + c)
bottom pn d n i = 3 * (pn * (d + n + i)
- Question 2
kungPaoFactor r dm ds n c ft ff s =
(term1 dm ds n) + (term2 r c ft ff s)
term1 dm
- Part A
- recursion, keep summing up all the 1/n + 1/(n-1) + 1/(n-2) + . + 0 <- when n = 0, it counts as 0
- harmonic 5 = 1/5 + 1/4 + 1/3 + 1/2 + 1 + 0
harmonic : Int -> Float
harmonic n
| n <= 0 = 0 - Protect against when user input a value less than 0
- available coin types 1,2,5,10,20,50,100
- =
- list comprehension approach
- if the n is 0, we simply just return [] since it doesnt require any change
- if the n is not 0, grab the first list returned from the helper function
change : Int -> [Int]
chang
- Question 1
- param matching:
- kungPaoFactor r dm ds n c ft ff s -> k
- this is done by separate the formula into budget related and food related function
kungPaoFactor : Int -> Float -> Float -> Int -> Int -> Int -> Int -> Int -> Float
kungPaoFactor r
- PegPuzzle.hs
- Written by Kurt Eislet
- NOTE THAT THE COMMENTING DONE BELOW IS NOT HOW WE WANT YOU TO
- COMMENT YOUR PROGRAMS. THINK OF THESE OVERLY WORDY COMMENTS
- AS A MINI-LECTURE ABOUT HOW THIS PROGRAM WORKS, NOT AS AN
- EXAMPLE OF CONCISE DOCUMEN
module MinMax where
import MoveScoring
import MoveGenerator
- Custom data structure which is an n-ary tree representation of possible moves; contains the current board and list of children states
data BoardTree = BoardTree cfw_currBoard : [String], childr
LISTS
- Haskell requires homogenous lists; excepts for Int and Floats
LIST PROCESSING
Counting number of ints in an array
mylenInt : [Int] -> Int
mylenInt inlist
|null inlist = 0
|otherwise = 1 + (mylenInt (tail inlist)
Counting number of letters in a s
data Color = R | G | B | W | Y | O deriving (Eq, Show)
type Face = (Color, Color, Color, Color)
type State = (Face, Face, Face, Face, Face, Face)
data Move = Fwd | Rgt | Bck | Lft | Up | Dwn deriving (Eq, Show)
type Path = ([Move], State)
type Frontier =
module MoveScoring where
import MoveGenerator
- Calculates score for the currPlayer on the board; Score is 100 if the currPlayer has won and -100 if the currPlayer has lost
boardEval_a4s7 : [String] -> Char -> Char -> Char -> Float
boardEval_a4s7 board pl
square : Int -> Int
square n = n ^ 2
mypi : Float
mypi = 3.14
rev : [a] -> [a]
rev l
| null l = l
| otherwise = revhelp l []
revhelp : [a] -> [a] -> [a]
revhelp l a
| null l = a
| otherwise = revhelp (tail l) ([head l] + a)
len : [a] -> Int
len l