even more baking ahead of time

This commit is contained in:
Logan McGrath 2021-10-07 07:11:53 -07:00
parent 6854b850fe
commit 3dd86d3c38

View File

@ -25,8 +25,7 @@ move = do
if topDiscA >= topDiscC
then return Nothing
else do
popPegA
pushPegC $ fromJust topDiscA
pushPegC =<< popPegA
Just <$> makeMove "a" "c"
{------------------------------------------------------------------------------}
@ -106,10 +105,13 @@ makeMove from to = do
putPegs pegs {pegsMoves = move' : pegsMoves pegs}
return move'
popPegA :: (Monad m) => PegStep m ()
popPegA :: (Monad m) => PegStep m Disc
popPegA = do
peg <- getPegA
putPegA $ peg {pegDiscs = init $ pegDiscs peg}
let disc = last $ pegDiscs peg
rest = init $ pegDiscs peg
putPegA $ peg {pegDiscs = rest}
return disc
pushPegC :: (Monad m) => Disc -> PegStep m ()
pushPegC disc = do