Advice needed again... 
Author Message
 Advice needed again...

completedgame(M) :-
     validate_square(M),
     validate_entry(M).

validate_square([Head|Tail]) :-
     length(Head,Length),
     is_square(Tail,Length,1).

is_square([],Length,Counter) :-
     same_row_col(Length,Counter),
     !.
is_square([Head|Tail],Length,Counter) :-
     same_length(Head,Length),
     Counter2 is Counter+1,
     is_square(Tail,Length,Counter2).

same_row_col(Length,Counter) :-
     Length is Counter.

entry(e).
entry(o).
entry(x).

validate_entry([Head|Tail]) :-
    validate_entry(Head),
    validate_entry(Tail).
validate_entry([]).
validate_entry(E) :-
    entry(E).
--------------------------------------------------
I am supposed to implement a completedgame predicate where M contains no
empty squares ("e" entries) and there are no lines of n noughts or crosses
("o" as noughts and "x" as cross).

I came across almost similar cases of Tic-Tac-Toe but those are restricted
to 3X3 game board and those 'hard-code' their possible wins in a predicate.
However, mine needs to be any square n by n matrix (as in the above code).

Please advise on how I can check whether there are lines of noughts or
crosses?

Regards and HAPPY NEW YEAR!!!



Sat, 18 Jun 2005 23:40:19 GMT  
 Advice needed again...

: Please advise on how I can check whether there are lines of noughts or
: crosses?
You might want to try to code the following relations:

matrix_rows(Mss, Rss) :-                        % (1)
   Rss is a list of rows of matrix Mss.

matrix_columns(Mss, Css) :-                     % (2)
   Css is a list of columns of matrix Mss.

matrix_firstdiagonal(Mss, Ds) :-                % (3)
   Ds is a list of all diagonal elements of matrix Mss.

matrix_diagonals(Mss, Dss) :-                   % (4)
   Dss is a list of all diagonals of matrix Mss.

Depending on your matrix representation, the first relation (or the
second one) should be trivial to implement.

Once you have coded (1)-(4), solving your problem should have
become a lot easier.

Hope this helps...

Regards,
Stefan

--
Stefan Kral            http://www.complang.tuwien.ac.at/skral/



Sun, 19 Jun 2005 08:32:36 GMT  
 Advice needed again...
Thanks for all the help renderd.

I really appreciate it.

Once again, a million thanks...


Quote:

> : Please advise on how I can check whether there are lines of noughts or
> : crosses?
> You might want to try to code the following relations:

> matrix_rows(Mss, Rss) :- % (1)
>    Rss is a list of rows of matrix Mss.

> matrix_columns(Mss, Css) :- % (2)
>    Css is a list of columns of matrix Mss.

> matrix_firstdiagonal(Mss, Ds) :- % (3)
>    Ds is a list of all diagonal elements of matrix Mss.

> matrix_diagonals(Mss, Dss) :- % (4)
>    Dss is a list of all diagonals of matrix Mss.

> Depending on your matrix representation, the first relation (or the
> second one) should be trivial to implement.

> Once you have coded (1)-(4), solving your problem should have
> become a lot easier.

> Hope this helps...

> Regards,
> Stefan

> --
> Stefan Kral            http://www.complang.tuwien.ac.at/skral/



Fri, 24 Jun 2005 01:32:07 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Need some advice again!!

2. Scheme vs ML again and again and again and again

3. Scheme vs ML again and again and again and again

4. H1B Smalltalker needs advice

5. Need advice on ObjectStudio: Filename length restrictions??

6. Some advice needed....

7. need advice

8. i need some educational advice

9. Assembler advice needed.

10. Advice needed for creating SLLs

11. beginner smalltalker...need starter advice

12. Need advice : printf

 

 
Powered by phpBB® Forum Software