【发布时间】:2015-03-06 10:49:44
【问题描述】:
对于家庭作业,我必须(除其他外)在 Oz 中创建一个棋盘。
我对这种语言相当陌生,但我想这样做:
declare
fun {MakeTile Col Row}
if Col==1 then
if {And (Row=<10) (Row>=2)} then N in
N = {MakeTile 1 Row+1}|{MakeTile 1 Row-1}|{MakeTile 2 Row}|{MakeTile 2 Row-1}
tile(column:Col row:Row player:0 neighbours:N)
else
if Row==11 then N in
N = {MakeTile 1 Row-1}|{MakeTile 2 Row-1}|{MakeTile 2 Row}
tile(column:Col row:Row player:0 neighbours:N)
else N in % Row==1
N = {MakeTile 1 Row+1}|{MakeTile 2 Row}
tile(column:Col row:Row player:0 neighbours:N)
end
end
else
tile(column:Col row:Row player:0 neighbours:nil)
% TODO: Handle other edge of the board
end
end
{Browse {MakeTile 'A' 1}}
程序一直在运行。
我们必须以声明式的方式进行编程。我不习惯这些语言,递归方法是创建这种板的好方法吗?
【问题讨论】:
-
嗨!这是在编辑审核队列中找到的。我已经根据 Oz OPI 的缩进方式对代码进行了格式化,这使它更易于阅读。不幸的是,我不是oz 专家,所以我无法为您的实际程序提供太多帮助。不过有一条评论-您似乎将
'A'传递给Col,但是您为Col==1实现了测试的代码-您的代码不是总是会转到包含% TODO: Handle other edge of the board的分支吗?
标签: oz