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