tag:blogger.com,1999:blog-21500237.post660368421399436938..comments2023-04-29T04:08:32.247-04:00Comments on Praise, Curse, and Recurse: The Polar Game in Haskell, Day 4Paul R. Pottshttp://www.blogger.com/profile/04401509483200614806noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-21500237.post-40041059040643886982013-06-29T11:32:59.110-04:002013-06-29T11:32:59.110-04:00Hi Roland,
Yeah, it has occurred to me that if I&...Hi Roland,<br /><br />Yeah, it has occurred to me that if I'm actually using lists where I can detect the end case, there isn't really a need for the Edge tile. I could just delete it entirely. It is a hold-over from the Objective-C version where I use it as a flag to avoid dereferencing array elements past the bounds.<br /><br />Thanks for the simplification of next_ppos -- that's a good idea.<br /><br />It also occurred to me as I ate dinner last night that I can use a fold on a list of moves to collect up the updated boards. I don't think in the fully functional mind-set yet. But that should be easy to implement -- I'll do that for next time, which should allow me to get the rest of the boards up and running quickly and validate all the cases.Paul R. Pottshttps://www.blogger.com/profile/04401509483200614806noreply@blogger.comtag:blogger.com,1999:blog-21500237.post-61552247438832968642013-06-29T10:49:57.681-04:002013-06-29T10:49:57.681-04:00Hi Paul,
next_ppos could be written as:
next_ppo...Hi Paul,<br /><br />next_ppos could be written as:<br /><br />next_ppos :: Pos -> Dir -> Pos<br />next_ppos pos dir = Pos (posY pos + fst step) (posX pos + snd step)<br /> where <br /> step = delta dir<br /> delta East = (0, 1)<br /> delta South = (1, 0)<br /> delta West = (0, -1)<br /> delta North = (-1, 0)<br /><br />So you split the adding from the direction stuff.<br /><br />Regards<br /> R.<br /><br />PS: You have to add some blanks in front of the 6 last lines ...Rolandhttps://www.blogger.com/profile/01178864369662094911noreply@blogger.comtag:blogger.com,1999:blog-21500237.post-25819126434095549572013-06-29T10:08:44.467-04:002013-06-29T10:08:44.467-04:00Hi Paul,
I like your post about this Plar game.
S...Hi Paul,<br /><br />I like your post about this Plar game.<br />Some remarks about Edge.<br />1.) I suggest to factor out " ++ [Edge] from the view function as:<br />view :: Board -> Pos -> Dir -> [Tile]<br />view board pos dir = (view' board pos dir) ++ [Edge]<br /> where<br /> view' board pos East = ( drop ( posX pos + 1 ) $ ... <br />2.) Do you really want to add the Edge tile every time you construct a slice? An alternative would be to have an addEdge function, that adds all the edges to a board after you create it with get_initial_board.<br />3.) Do you really need the Edge tile? If the penguine sees an empt list of tiles, it's at the edge of his nice small world. You could avoid all the runtime errors like<br /> collide [] = error "traverse empty list!" or<br /> step [] = error "step: empty list!"<br />If you have no runtime errors, the chances that your program fails are much smaller!<br /><br />Thanks and regards<br /> RolandRolandhttps://www.blogger.com/profile/01178864369662094911noreply@blogger.com