1

For a homework assignment I have to (amongst other things) create a chess board in Oz.

I'm rather unfamiliar with the language but here's how I wanted to do it:

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}}

The program just keeps running.

We have to program in a declarative style. I'm not used to these kinds of languages, is the recursive approach the good way to create such a board?

J Richard Snape
  • 20,116
  • 5
  • 51
  • 79
RaptorDotCpp
  • 1,425
  • 14
  • 26
  • Hi! This came to me in the Editing review queue. I've formatted the code according to how the Oz OPI indents it, which makes it a little easier to read. Unfortunately, I'm not an [tag:oz] expert so I can't help you very much with your actual program. One comment though - you seem to pass in `'A'` to `Col` and yet the code you've implemented tests for `Col==1` - isn't your code always going to go to the branch containing `% TODO: Handle other edge of the board` ? – J Richard Snape Mar 06 '15 at 15:07

1 Answers1

0

the declarative approach could be the right way. I tested your code and works for what you wrote, it simply print tile(column:'A' neighbours:nil player:0 row:1) as expected. It doesn't keep running, what's your problem?

rok
  • 2,574
  • 3
  • 23
  • 44