-transform (x, y) d = case d of
- N = (x, y-1)
- S = (x, y+1)
- W = (x-1, y)
- E = (x+1, y)
-
-getPos :: Coord -> StateT PegBoard Maybe Position
-getPos c=:(x, y) = getState >>= \b->if (valid b c)
- fail (pure b.[y].[x])
-
-valid :: PegBoard Coord -> Bool
-valid b (x, y) = y<0 || x<0 || y >= size b || x >= size b.[0] || b.[y].[x] == Inv
-
-fail :: StateT PegBoard Maybe a
-fail = StateT \s->Nothing
-
-applyMove :: Move PegBoard -> Maybe PegBoard
-applyMove (c=:(fx, fy), d) b = Nothing
-//# sc=:(sx, sy) = transform c d
-//# tc=:(tx, ty) = transform sc d
-//= liftM3 tuple3 (getPos c b) (getPos sc b) (getPos tc b)
-// >>= \f->case f of
-// (Peg, Peg, Emp) = Nothing//Just {b & [fx,fy]=Emp, [sx,sy]=Emp, [tx,ty]=Peg}
-// _ = Nothing
+transform (x, y) d = case d of N = (x, y+1); S = (x, y-1); W = (x+1, y); E = (x-1, y)
+
+getPos :: Coord -> Solver Position
+getPos c=:(x, y) = get >>= \b->if (valid b) empty (pure b.[y].[x])
+where
+ valid b = y<0 || x<0 || y >= size b || x >= size b.[0] || b.[y].[x] == Inv
+
+applyMove :: Move -> Solver ()
+applyMove (tc=:(tx, ty), d)
+# sc=:(sx, sy) = transform tc d
+# fc=:(fx, fy) = transform sc d
+= get >>= \b->liftM3 tuple3 (getPos fc) (getPos sc) (getPos tc) >>= \f->case f of
+ (Peg, Peg, Emp)
+ # b = {{{c\\c<-:r}\\r<-:b} & [fy,fx]=Emp, [sy,sx]=Emp, [ty,tx]=Peg}
+ = tell [b] >>| put b
+ _ = empty