info-gnuprologjava
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Info-gnuprologjava] Re: Term execution problems


From: Daniel Thomas
Subject: [Info-gnuprologjava] Re: Term execution problems
Date: Wed, 01 Dec 2010 10:45:34 +0000

Hello,

I think I have found the problem - gnuprologjava won't match +M and -M
against +w and -w as +M will be interpreted as a atom term rather than a
variable term (I think anyway).

Changing to using:
Term[] args2 = { AtomTerm.get("+"), AtomTerm.get("w"), cube, newCube };
and changing the prolog file to:
/* Opposite Moves */        
move(+, M, OldState, NewState):- mov(M, OldState, NewState). 
move(-, M, OldState, NewState):- mov(M, NewState, OldState).

Results in my obtaining a return code of 0 rather than -1 which means
success.

(Side note: in GNU Prolog for Java 0.3.0 return codes will be an enum
PrologCode.RC)

I hope this helps,

Daniel

On Tue, 2010-11-30 at 20:01 +0100, Manuel Selva wrote:
> Hi there,
> 
> Sorry to bother you but I can't find a solution to the following
> problem. The following Java code always print -1
> 
>            cube = new VariableTerm("cube");
>             Term[] args = { cube };
>             CompoundTerm goalTerm = new
> CompoundTerm(AtomTerm.get("ghoul"),
>                     args);
>             interpreter.runOnce(goalTerm);
>             cubies = piecesCube();
> 
>             VariableTerm newCube = new VariableTerm("NewCube");
>             Term[] args2 = { AtomTerm.get("+w"), cube, newCube };
>             CompoundTerm move = new CompoundTerm(AtomTerm.get("move"),
> args2);
>             int runOnce = interpreter.runOnce(move);
>             System.out.println(runOnce);
> 
> with the following prolog file loaded:
> 
> /* ghoul is a prolog fact representing the goal state in flat notation
> */
> ghoul(cube('WHITE', 'WHITE', 'WHITE', 'WHITE', 'WHITE', 'WHITE',
> 'WHITE', 'WHITE','WHITE',    /*White*/
>            'GREEN', 'GREEN', 'GREEN', 'GREEN', 'GREEN', 'GREEN',
> 'GREEN', 'GREEN','GREEN',    /*Green*/
>            'RED', 'RED', 'RED', 'RED', 'RED', 'RED', 'RED',
> 'RED','RED',    /*Red*/
>            'BLUE', 'BLUE', 'BLUE', 'BLUE', 'BLUE', 'BLUE', 'BLUE',
> 'BLUE','BLUE',    /*Blue*/
>            'ORANGE', 'ORANGE', 'ORANGE', 'ORANGE', 'ORANGE', 'ORANGE',
> 'ORANGE', 'ORANGE','ORANGE',    /*Orange, Yellow*/
>            'YELLOW', 'YELLOW', 'YELLOW', 'YELLOW', 'YELLOW', 'YELLOW',
> 'YELLOW', 'YELLOW','YELLOW')).  
> 
> /* pieces converts from flat to pieces notation and vice versa*/
>     
> pieces(cube(X01, X02, X03, X04, X05, X06, X07, X08, X09,  /*White*/
>             X10, X11, X12, X13, X14, X15, X16, X17, X18,  /*Green*/
>             X19, X20, X21, X22, X23, X24, X25, X26, X27,  /*Red*/
>             X28, X29, X30, X31, X32, X33, X34, X35, X36,  /*Blue*/
>             X37, X38, X39, X40, X41, X42, X43, X44, X45,  /*Orange*/
>             X46, X47, X48, X49, X50, X51, X52, X53, X54), /*Yellow*/
>        [p(X05), p(X14), p(X23), p(X32), p(X41),p(X50),
>         p(X11, X08), p(X15, X22), p(X17, X47), p(X13, X42), /* Green
> edges */
>         p(X38, X04), p(X44, X49),                           /* Orange
> edges */
>         p(X20, X06), p(X26, X51),                           /* Red
> edges */
>         p(X29, X02), p(X33, X40), p(X35, X53), p(X31, X24), /* Blue
> edges */
>         p(X10, X07, X39), p(X12, X19, X09), p(X18, X48, X25), p(X16,
> X45, X46), /* Green coins */
>         p(X28, X03, X21), p(X30, X37, X01), p(X36, X52, X43), p(X34,
> X27, X54)]).
> 
>               
> /* Move of white face */
> mov(w, cube(X01, X02, X03, X04, X05, X06, X07, X08, X09,  /*White*/
>             X10, X11, X12, X13, X14, X15, X16, X17, X18,  /*Green*/
>             X19, X20, X21, X22, X23, X24, X25, X26, X27,  /*Red*/
>             X28, X29, X30, X31, X32, X33, X34, X35, X36,  /*Blue*/
>             X37, X38, X39, X40, X41, X42, X43, X44, X45,  /*Orange*/
>             X46, X47, X48, X49, X50, X51, X52, X53, X54), 
>        cube(X03, X06, X09, X02, X05, X08, X01, X04, X07,  /*White*/
>             X19, X20, X21, X13, X14, X15, X16, X17, X18,  /*Green*/
>             X28, X29, X30, X22, X23, X24, X25, X26, X27,  /*Red*/
>             X37, X38, X39, X31, X32, X33, X34, X35, X36,  /*Blue*/
>             X10, X11, X12, X40, X41, X42, X43, X44, X45,  /*Orange*/
>             X46, X47, X48, X49, X50, X51, X52, X53, X54)).
>         
> /* Opposite Moves */        
> move(+M, OldState, NewState):- mov(M, OldState, NewState). 
> move(-M, OldState, NewState):- mov(M, NewState, OldState).
> 
> How can I solve that ?
> 
> Thanks in advance for your help,
> Manu

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]