【问题标题】:I'm creating a chess board in Oz, my program seems not to terminate我正在 Oz 创建一个棋盘,我的程序似乎没有终止
【发布时间】: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


【解决方案1】:

声明式方法可能是正确的方法。我测试了您的代码并适用于您编写的内容,它只是按预期打印tile(column:'A' neighbours:nil player:0 row:1)。它不继续运行,你的问题是什么?

【讨论】:

    猜你喜欢
    • 2018-02-15
    • 2017-12-12
    • 2017-03-27
    • 2023-03-07
    • 2011-04-29
    • 2021-10-15
    • 1970-01-01
    • 2020-10-03
    • 2015-08-13
    相关资源
    最近更新 更多