>
> Hi,
>
> Ok, if we are both confused about what it's asking, lets look at the function
> requirements. 2. (a) Write an oz function {Attack U V} whose input
> parameters U and V are both squares in the form col#row. The function
> should
>
> return true if U and V are on the same row, column or diagonal;
> otherwise it should return false.
>
> No problem with that.
>
> (b) Write an oz function {Threaten L U} whose L is a (possibly empty) list
> of squares in the form col#row and whose input pa-
>
> rameter U is a square in the same form. The function should
> return true if U is attacked, in the sense of the Attack function
>
> above, by any of the squares in L ; otherwise it should return false.
>
> No problem with that either.
>
> (c) Write an oz function {Queens L N} whose input parameter N is
> the board size, and whose input parameter L is a non-empty list of
> squares in the form col#row, whose rows run consecutively from 1,
> L being a partial solution of the N queens problem. The function
>
> has to extend L if this is possible to a full solution of the N queens
>
> problem, returning this as a list of squares in the same col#row
> form. Otherwise, if no such extension is possible, the function
> must return an empty list.
>
> To me that reads pretty explicit that the list contains tuples, but then I
> _DID_ have to email the tutor about what C really asks, so I may just be
> confused over the wording of the assignment. If so, please do correct me
> cos if my understanding of what it's asking me is wrong then my
> implementation will also be wrong.
>
> Yes, that makes it very,very clear!
>
> The only thing in that case that looks possibly wrong to me is in the {Queens}
> function. It calls {Revise} with 0|L but if L is a list running FROM 1
> then surely this is moving the columns along and creating a new first
> column?
>
> Is it the case that the 0 should be added at the end of L and then Revised?
> Notice i'm getting less confident the more i confuse myself? :+)
>
>
Well if {Revise} is called with 0|L then it means we can do the H+1 trick.
This is why I was using the {AddToList} function to actually add the
determined element to the end of the list, as opposed to the beginning. Lets
dissect the Revise function:
BoardSize = 7
List = 0, 1#1, 3#2, 5#3
fun {Revise L}
case L of H|T then
if H == BoardSize then {Revise T} % Since H
is an integer it CAN be checked against the BoardSize.
else N = (GetLengthOfList L} in
if {Threaten {BuildList T} H+1#N} then {Revise H+1|T}
else H+1#N|T %
Or {AddToList H+1#N T}
end
end
else nil
end
end
In the first run 0 is compared against 7 and is false.
N is assigned the value of 4 (the length of the list [0 1#1 3#2 5#3]).
BuildList T builds a tempory list for threaten
{Threaten} uses this new list and checks H+1#N against the List
If a conflict occurs Recurse with obviously H+1 which will then be 1
otherwise return the tail with N+1#N at the end (this is where I ran
addtolist to put the new co-ordinates at the end of the list).
I mean it MIGHT be possible to add 0 to the end and recurse until the end of
the list is reached and backtrack from there, but it hurts my head to think
of that.
>
> I'm beginning to wish I hadn't said anything at all because it seems like
> i've wasted your time exploring problems that don't exist! If it makes you
> feel more comfortable, I think you've interpreted the wording just fine.
>
> Regards
> Mark
>
>
Well I've been running around for weeks trying to fix this, any help was
worth trying.
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users