-getPos :: !Coord !.PegBoard -> Maybe Position
-getPos {x,y} b = if (valid b) Nothing (Just (b.[y].[x]))
-where
- valid b = y<0 || x<0 || y >= size b || x >= size b.[0] || b.[y].[x] == Inv
-
-move :: !PegBoard !Move -> Maybe PegBoard
-move b {c=cc=:{x=tx,y=ty}, d}
-# sc=:{x=sx,y=sy} = transform cc d
-# fc=:{x=fx,y=fy} = transform sc d
-= case getPos fc b of
- Just Peg = case getPos sc b of
- Just Peg = case getPos cc b of
- Just Emp = Just {{{c\\c<-:r}\\r<-:b} & [fy,fx]=Emp, [sy,sx]=Emp, [ty,tx]=Peg}
- _ = Nothing
- _ = Nothing
- _ = Nothing
-where
- transform :: !Coord !Direction -> Coord
- transform c=:{x,y} d = case d of
- N = {c & y=y+1}
- S = {c & y=y-1}
- W = {c & x=x+1}
- E = {c & x=x-1}
-
-getCoords :: (Char -> Bool) !PegBoard -> [Coord]
-getCoords f b = [{x=x,y=y}\\r<-:b & y<-[0..] , c<-:r & x<-[0..] | f c]
-
-printPegBoard :: !PegBoard -> String
-printPegBoard b = join "\n" (["\n":[r\\r <-: b]] ++ ["\n"])
-