Hi again,
>
> I have a couple of pointers for you that may help.
>
> Firstly (ignore this if you already know it)
>
> The program is basically trying to complete a list showing the positions of
> queens on a given board size.
> The way this list is set up is this:


Yes, I understand what it's trying to do :)

>
>
> Imagine you have a board of size 4, with a queen at row 1 in column 3, row
> 4 in column 2, and row 2 in column 1.
> Ie we are looking for the row for the 4th column.
> Reading in columns from right to left, the queens are currently at rows 1,4
> and 2 respectively.
> The list that represents this is [1 4 2] - note, just row numbers from
> right to left!
> So, the members of this list are all integers.


Ok, now this would be allowed in the previous assignment, however the
assignment explicitly states that the Queens function, which passes it's
list to revise takes tuples in the form Column#Row where row numbers are
numerically sequential. [1#1 3#2 5#3...].

>
>
> Now, your {BuildList} function expects a list of integers as above, so the
> line which starts H.1#..... makes
> no sense because H is an integer and doesn't have a '.1' to access.


It is because it is my understanding that revise is passed a tuple in the
form column#row and because {Revise} uses {BuildList} {BuildList} will also
inevitably be passed the same tuples, now with {BuildList} we recurse quite
a bit, getting a smaller and smaller list until we get a list of size 1,
now, since the assignment wants everything in tuples it seems, I had to make
a way of working around this, so lets assume we have three elements on a 7x7
grid [1#1 3#2 5#3] now once {Buildlist} gets to these elements H is going to
represent the whole tuple. So if we get the first part of the tuple H.1,
which will in the first element in the list be 1, now because {BuildList}
has recursed to there only being one element in the list, and it's the first
element, then it MUST be in the first row (part of the assignment
constraints) so if we just measure the size of the list we can assume it's
accuratly going to be the correct row number so that's how the
H.1#{GetLengthOfList L}|{BuildList T} came from. H.1#{GetLengthOfList L}
will become 1#1. It's a bit roundabout in it's execution, but that's how and
why it does what it does.

If it's wrong, fine, ok, but within the assignment limits and this overuse
of tuples it's the only solution I understand.

>
>
> Secondly, as I said before, stick with the version of {Revise} that the
> lecturer gave you (exactly as it is) it works 100% guaranteed!
> I suspect the line
>     else {AddToList H+1#N T}
> should be different in the original version.


I have amended {Revise} to be as the tutor wrote, however new grid
co-ordiantes which are 'discovered' are added to the beginning of the list
not the end, this is why I wrote and used the {AddToList} function. If there
is an easier way to add elements to the end of the list I am unaware of it.

>
> This is why - Revise is taking this list of integers we mentioned and is
> looking for another integer, representing a non-conflicting row for the next
> column, to stick on the head  of the list.  Now,  in this function,  the
> value being tested is always H+1 , so if H+1 is not {Threatened} then H+1 is
> the value that must be added to the head of the list.


{Threatened} is given a list and a co-ordinate, the co-ordinate is then
passed to {Attack} along with the next element in the list. It then checks
if the co-ordiante and the next element in the list, conflict, if so return
true (which implies a new co-ordinate has to be generated) if not, accept
this as a usable position for a new queen.

As we add elements to the list the list grows, now lets assume a 7x7 grid
with three 'known' queens, we add 0 to the head of the list and then go to
revise.
The co-ordinate is then H+1 (so 0+1 = 1) #{lengthoflist}(the list WAS 3, but
had 0 added to the beginning, so it's actually now size 4), which creates
1#4. This generates the co-ordinates that get passed into {Attack}

Also lets assume 1#1 has been taken, 1#4 can't be used, so we recurse and
H+1, which generates 2#4 and so on until we find a new non-conflicting
queens position.

>
>
> I hope you'll appreciate that I can't just give you code to use, but I've
> amended your code with these points in mind on my machine and everything as
> far as revising the list seems to work fine. I was a little dubious about
> the logic in the {Attack} function simply because it is different to the way
> I would have done it, but having said that it seems to work as far as I can
> tell.


I don't want to be given the code, as that is obviously against assignment
regulations, but with what I believe is 95% of this bit done I would
consider it a win if I complete this question.

>
>
> Hope this helps.
> Regards
> Mark


Thanks
Neil Munro

Attachment: ICA.oz
Description: Binary data

_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to