开发者

Using streams to find best way - Scheme

I'm relatively new to Scheme and I'm having a few problems with streams. I only know how to make a stream of natural numbers, nothing more complex. I thought maybe they'll be of use in this case. So, basically, I have this matrix:

[0 0 0 0 0 S 0 0] [0 0 0 0 x 0 x 0] [0 0 0 0 x 0 0 x] [0 0 0 x 0 0 0 x] [0 0 0 x 0 0 0 x] [0 0 x x 0 0 0 0] [0 0 D 0 0 0 0 0]

where x = accessible paths S = source D = destination

What I have 开发者_开发百科to do is get from S to D by traveling only horizontally, vertically and diagonally one square at a time on the accessible paths. Until now, I've only created a list of positions that contains the source's position, the accessible paths and the destination's position. Is there a way of choosing the correct path by using streams? And if that is too complex for me to understand, what other method do you suggest?


I don't think that streams contribute substantially to an understanding of this problem. What you have is a search problem--you're looking for a sequence of moves in a space of possibilities. I would encourage you to take a look at HtDP, section 28 for a look at a very similar problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜