探索 Trax 游戏:从基础规则到功能实现
1. Trax 游戏基础概念
在 Trax 游戏里,有几个关键概念和操作需要掌握。首先是方向移动,定义了向不同方向移动坐标的函数:
north c = {c & row = c.row-1}
south c = {c & row = c.row+1}
west c = {c & col = c.col-1}
east c = {c & col = c.col+1}
go North = north
go South = south
go West = west
go East = east
同时,还需要了解 Trax 的一些属性,如当前瓷砖数量、坐标的最小和最大值、占用的列数和行数,以及在某个坐标处能找到的瓷砖:
nr_of_tiles :: !Trax -> Int
nr_of_tiles trax = length trax.tiles
bounds :: !Trax -> (!(!Int,!Int), !(!Int,!Int))
bounds trax
| nr_of_tiles trax > 0 = ((minList cols,maxList cols), (minList rows,maxList rows))
| otherwise = abort "bounds␣applied␣to␣empty␣set␣of␣tiles.\n"
where coords = map fst trax.tiles
cols = map col coords
rows = map
超级会员免费看
订阅专栏 解锁全文
8999

被折叠的 条评论
为什么被折叠?



