Hello, I am using Mozart Oz for an assignment at uni and am encountering a
problem with recursion. The two functions involved are below, I can't seem
to return a true or false value to the browser window. If someone could
point out where my logic falls apart I would appreciate it. Please do NOT
sent me optimization hints etc as this may lead me to place code I do not
fully understand into this assignment. I would like to keep this code as
clean and as very much my code as I can, but am really struggling to get my
head around the way Mozart Oz does things sometimes.

Thanks in advance.
Neil Munro

local L W R in
   fun {Attack U V}
      % First convert the co-ords into the actual location on the canvas.
      % Get the Length and Width.
      L = 993 div BoardSize
      W = 650 div BoardSize

      case U of XI#YI then
     case V of XII#YII then

        % This could be written using lazy orelse andthen keywords.
        % However I do not fully understand how to use them correctly
        % from the online Oz documentation.

        if U.1 == V.1 then     % Horizontal line.
           R = true
        elseif U.2 == V.2 then     % Vertical line.
           R = true
        elseif ( XI - XII ) == ( YI - YII) then      % Diagonal lines.
           R = true
        elseif ( XI - XII ) == ( YII - YI ) then
           R = true
        else
           R = false
        end
     end
      end
    R
   end
end

% This function will use {Attack} to determine
% if the list (L) {Threaten} is given can attack
% the position given in U.
fun {Threaten L U}
   case L of H|T then
      % If {Attack H U} is true, return true.
      % Otherwise recurse with T and U as args.
      {Attack H U} orelse {Threaten T U}
   else
      false
   end
end

{Browse {Threaten [1#2 4#5 8#8] 8#4}}
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to