users-prolog
[Top][All Lists]
Advanced

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

Fwd: A user application bug (domino game layout manager).


From: Ugoretzc
Subject: Fwd: A user application bug (domino game layout manager).
Date: Thu, 13 Mar 2003 23:16:06 EST

I fixed the bug myself.  It was not that hard.
--- Begin Message --- Subject: A user application bug (domino game layout manager). Date: Thu, 13 Mar 2003 19:47:26 EST I am writing a GUI layout manager in Prolog for a domino game that I am developing.
I am just learning Prolog.  I have written some code that manages some graphics transformations.  There is a problem with the code, specifically a predicate "calc_solution_e".  There are multiples variations of this predicate - the one that I am concerned with has the comment "Single domino next to single domino - not attached to root".  I set spypoints on the predicates "calc_solution_e", "rotation_around_point", "translate", "rotation", and "compensate for theta".  If you use the debug and press 'l' to leap through the program, which by the way has the goal "write_results_to_file", you will notice that the last call to "rotation_around_point" is skipped, and the predicate "calc_solution_e" exits without values bound to the "Sol_X" and "Sol_Y" variables.  If someone could give me some help, I would greatly appreciate it.  Thank you.  The program is given below:

:- op(500, xfx, 'is_parent_of').
:- op(500, xfx, 'is_type1_related_to').


%domino (ID, parent, child type, direction, no_orientation/single/double, angle)
id_list([f,a,b,c,d,e]).
domino(a,0,0,root,no_orientation,0).
domino(b,a,0,north,single,45).
domino(c,a,0,east,single, 0).
domino(d,a,0,south,single,0).
domino(e,a,0,west,single,0).
domino(f,b,0,north,single,0).
domino_length(100).
domino_width(50).
pi(3.141592654).

not(P) :- (call(P) -> fail ; true).
Y is_parent_of X :-domino(X,Y,_,_    ,_     ,_).
is_single(X)     :-domino(X,_,_,_    ,single,_).
is_double(X)     :-domino(X,_,_,_    ,double,_).
is_root(X)       :-domino(X,_,_,root ,_     ,_).
is_north(X)      :-domino(X,_,_,north,_     ,_).
is_east(X)       :-domino(X,_,_,east ,_     ,_).
is_west(X)       :-domino(X,_,_,west ,_     ,_).
is_south(X)      :-domino(X,_,_,south,_     ,_).
is_child_type1(X):-domino(X,_,1,_    ,_     ,_).
is_child_type2(X):-domino(X,_,2,_    ,_     ,_).
is_child_type3(X):-domino(X,_,3,_    ,_     ,_).
angle(X,Y)       :-domino(X,_,_,_    ,_     ,Y).

% -------------------------- ADJUSTED ANGLE CALCULATIONS ---------------
adjusted_angle(Node,0)    :-is_root(Node),!.

adjusted_angle(Node,Angle):-Parent is_parent_of Node,
                    not(is_root(Parent)),
                    domino(Node,_,_,_    ,_     ,Angle).

adjusted_angle(Node,Angle):-Parent is_parent_of Node,
            is_root(Parent),
            is_east(Node),
                            domino(Node,_,_,_    ,_     ,Angle).

adjusted_angle(Node,Angle):-Parent is_parent_of Node,
                            is_root(Parent),
                            is_north(Node),
            domino(Node,_,_,_    ,_     ,A1),
            Angle is 90 + A1.

adjusted_angle(Node,Angle):-Parent is_parent_of Node,
                            is_root(Parent),
                            is_west(Node),
            domino(Node,_,_,_    ,_     ,A1),
            Angle is 180 + A1.

adjusted_angle(Node,Angle):-Parent is_parent_of Node,
                            is_root(Parent),
                            is_south(Node),
            domino(Node,_,_,_    ,_     ,A1),
            Angle is 270 + A1.

% ---------------- GRAPHICS TRANSFORMATIONS --------------------
translate(X,Y, Delta_X, Delta_Y, Result_X, Result_Y):- Result_X is X + Delta_X,
       Result_Y is Y + Delta_Y.

rotation(X, Y, Theta, Result_X, Result_Y):- pi(Pi),
                                            Result_X is X*cos(Theta*Pi/180) - Y*sin(Theta*Pi/180),
    Result_Y is X*sin(Theta*Pi/180) + Y*cos(Theta*Pi/180).

rotation_around_point(X,Y,X_P, Y_P, Theta, Result_X, Result_Y):- translate(X,Y,-X_P,-Y_P, X1, Y1),
rotation(X1,Y1,Theta,X2,Y2),
translate(X2,Y2,X_P,Y_P,Result_X,Result_Y).

compensate_for_theta(X,Y,Delta_X,Delta_Y,Theta, Result_X, Result_Y):- translate(X,Y,Delta_X,Delta_Y, X2, Y2),
      rotation_around_point(X2,Y2,X,Y,Theta, Result_X, Result_Y).


% ------------- ANGLE OF ROTATION CALCULATIONS -----------------
angle_of_rotation(Node, 0) :- is_root(Node).


angle_of_rotation(Node, Angle) :- Parent is_parent_of Node,
                                  angle_of_rotation(Parent, A2),
          angle(Parent, A1),
          Angle is A1 + A2.

% ------- ADJUSTED ANGLE OF ROTATION CALCULATIONS --------------
adjusted_angle_of_rotation(Node, 0) :- is_root(Node).


adjusted_angle_of_rotation(Node, Angle) :- Parent is_parent_of Node,
                                           adjusted_angle_of_rotation(Parent, A2),
               adjusted_angle(Node, A1),
                   Angle is A1 + A2.
% -------------COORDINATE CALCULATIONS--------------------------
% Center of root domino
calc_solution_e(a, 0, 0).

% North domino next to root
calc_solution_e(Node, Sol_X, Sol_Y) :- Parent is_parent_of Node,
                                       angle(Node, Angle),
                           is_root(Parent),
                                       is_north(Node),
       Angle >= 0,
       domino_width(Width),
       domino_length(Length),
       rotation_around_point(0,
                                                             Width/2+Length/2,
                                                             -Width/2,
                                                             Width/2,
     Angle,
     Sol_X,
     Sol_Y),!.

calc_solution_e(Node, Sol_X, Sol_Y):- Parent is_parent_of Node,
                                      angle(Node, Angle),
      is_root(Parent),
                                      is_north(Node),
              Angle < 0,
      domino_width(Width),
                  domino_length(Length),
                  rotation_around_point(0,
                                                            Width/2+Length/2,
                                                            Width/2,
                                                            Width/2,
               Angle,
    Sol_X,
    Sol_Y),!.

% East domino next to root
calc_solution_e(Node, Sol_X, Sol_Y) :- Parent is_parent_of Node,
                                       angle(Node, Angle),
                           is_root(Parent),
                                       is_east(Node),
       Angle >= 0,
       domino_width(Width),
       domino_length(Length),
       rotation_around_point(Length,
                                                             0,
                                                             Length/2,
                                                             Width/2,
     Angle,
     Sol_X,
     Sol_Y),!.

calc_solution_e(Node, Sol_X, Sol_Y):- Parent is_parent_of Node,
                                      angle(Node, Angle),
      is_root(Parent),
                                      is_east(Node),
              Angle < 0,
      domino_width(Width),
                  domino_length(Length),
                  rotation_around_point(Length,
    0,
                                                            Length/2,
                                                            -Width/2,
               Angle,
    Sol_X,
    Sol_Y),!.

% South domino next to root
calc_solution_e(Node, Sol_X, Sol_Y):- Parent is_parent_of Node,
                                      angle(Node, Angle),
      is_root(Parent),
                                      is_south(Node),
              Angle >= 0,
      domino_width(Width),
                  domino_length(Length),
                  rotation_around_point(0,
    -Length/2-Width/2,
                                                            Width/2,
                                                            -Width/2,
               Angle,
    Sol_X,
    Sol_Y),!.


calc_solution_e(Node, Sol_X, Sol_Y):- Parent is_parent_of Node,
                                      angle(Node, Angle),
      is_root(Parent),
                                      is_south(Node),
              Angle < 0,
      domino_width(Width),
                  domino_length(Length),
                  rotation_around_point(0,
    -Length/2-Width/2,
                                                            -Width/2,
                                                            -Width/2,
               Angle,
    Sol_X,
    Sol_Y),!.

% West domino next to root
calc_solution_e(Node, Sol_X, Sol_Y):- Parent is_parent_of Node,
                                      angle(Node, Angle),
      is_root(Parent),
                                      is_west(Node),
              Angle >= 0,
      domino_width(Width),
                  domino_length(Length),
                  rotation_around_point(-Length,
    0,
                                                            -Length/2,
                                                            -Width/2,
               Angle,
    Sol_X,
    Sol_Y),!.

calc_solution_e(Node, Sol_X, Sol_Y):- Parent is_parent_of Node,
                                      angle(Node, Angle),
      is_root(Parent),
                                      is_west(Node),
              Angle < 0,
      domino_width(Width),
                  domino_length(Length),
                  rotation_around_point(-Length,
    0,
                                                            -Length/2,
                                                            Width/2,
               Angle,
    Sol_X,
    Sol_Y),!.

% Single domino next to single domino - not attached to root.
calc_solution_e(Node, Sol_X, Sol_Y) :-   angle(Node, Angle),
         Angle >= 0,   
         Parent is_parent_of Node,
         is_single(Node),
         not(is_root(Parent)),
         is_single(Parent),
                                         calc_solution_e(Parent, X1, Y1),
     domino_length(Length),
     domino_width(Width),
         adjusted_angle_of_rotation(Node, Adj_Ang_of_Rotate),
compensate_for_theta(X1, Y1, Length, 0, Adj_Ang_of_Rotate, X2, Y2).
compensate_for_theta(X1, Y1, Length/2, Width/2, Adj_Ang_of_Rotate, X3, Y3),
rotation_around_point(X2,Y2,X3,Y3,Adj_Ang_of_Rotate, Sol_X, Sol_Y).

    
% Edges of domino
calc_solution_a_x(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
    pi(Pi),
    domino_length(Length),
    domino_width(Width),
    adjusted_angle_of_rotation(Node, Adj_Ang_of_Rotate),
    Solution is CenterX -
(Length/2)*cos(Adj_Ang_of_Rotate*Pi/180) -
(Width/2)*sin(Adj_Ang_of_Rotate*Pi/180).

calc_solution_b_x(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
    pi(Pi),
    domino_length(Length),
    domino_width(Width),
    adjusted_angle_of_rotation(Node, Adj_Ang_of_Rotate),
    Solution is CenterX +
(Length/2)*cos(Adj_Ang_of_Rotate*Pi/180) -
(Width/2)*sin(Adj_Ang_of_Rotate*Pi/180).

calc_solution_c_x(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
    domino_length(Length),
    domino_width(Width),
    pi(Pi),
    adjusted_angle_of_rotation(Node, Adj_Ang_of_Rotate),
    Solution is CenterX +
(Length/2)*cos(Adj_Ang_of_Rotate*Pi/180) +
(Width/2)*sin(Adj_Ang_of_Rotate*Pi/180).
    
calc_solution_d_x(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
    domino_length(Length),
    domino_width(Width),
    pi(Pi),
    adjusted_angle_of_rotation(Node, Adj_Ang_of_Rotate),
    Solution is CenterX -
(Length/2)*cos(Adj_Ang_of_Rotate*Pi/180) +
(Width/2)*sin(Adj_Ang_of_Rotate*Pi/180).


calc_solution_a_y(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
    domino_length(Length),
    domino_width(Width),
    pi(Pi),
    adjusted_angle_of_rotation(Node, Adj_Ang_of_Rotate),       
    Solution is CenterY +
(Width/2)*cos(Adj_Ang_of_Rotate*Pi/180) -
(Length/2)*sin(Adj_Ang_of_Rotate*Pi/180).

calc_solution_b_y(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
    domino_length(Length),
    domino_width(Width),
    pi(Pi),
    adjusted_angle_of_rotation(Node, Adj_Ang_of_Rotate),
    Solution is CenterY +
                                                (Width/2)*cos(Adj_Ang_of_Rotate*Pi/180) +
(Length/2)*sin(Adj_Ang_of_Rotate*Pi/180).
              
calc_solution_c_y(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
    domino_length(Length),
    domino_width(Width),
    adjusted_angle_of_rotation(Node, Adj_Ang_of_Rotate),
    pi(Pi),
    Solution is CenterY -
                                                (Width/2)*cos(Adj_Ang_of_Rotate*Pi/180) +
(Length/2)*sin(Adj_Ang_of_Rotate*Pi/180).

calc_solution_d_y(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
    domino_length(Length),
    domino_width(Width),
    pi(Pi),
    adjusted_angle_of_rotation(Node, Adj_Ang_of_Rotate),
    Solution is CenterY -
(Width/2)*cos(Adj_Ang_of_Rotate*Pi/180)-
(Length/2)*sin(Adj_Ang_of_Rotate*Pi/180).

write_results_to_file :- open('C:/GNU-Prolog/test/output.txt', write, Output_Stream),
id_list(Id_List),
write_solution(Id_List,Output_Stream),
close(Output_Stream).

write_solution([], _):- true.
write_solution([X|Xs],Output_Stream):- write(Output_Stream, X),
       write(Output_Stream, ' '),
                                       calc_solution_a_x(X,Solution1),
                       write(Output_Stream, Solution1),
       write(Output_Stream,' '),
               calc_solution_a_y(X,Solution2),
                   write(Output_Stream, Solution2),
       write(Output_Stream,' '),
               calc_solution_b_x(X,Solution3),
                   write(Output_Stream, Solution3),
       write(Output_Stream,' '),
               calc_solution_b_y(X,Solution4),
                   write(Output_Stream, Solution4),
       write(Output_Stream,' '),
               calc_solution_c_x(X,Solution5),
                   write(Output_Stream, Solution5),
       write(Output_Stream,' '),
               calc_solution_c_y(X,Solution6),
                   write(Output_Stream, Solution6),
       write(Output_Stream,' '),
               calc_solution_d_x(X,Solution7),
                   write(Output_Stream, Solution7),
       write(Output_Stream,' '),
               calc_solution_d_y(X,Solution8),
                   write(Output_Stream, Solution8),
       write(Output_Stream,' '),
               calc_solution_e(X,Solution9,Solution10),
                   write(Output_Stream, Solution9),
       write(Output_Stream,' '),
               write(Output_Stream, Solution10),
       write(Output_Stream,'\n'),
       write_solution(Xs, Output_Stream).
:- op(500, xfx, 'is_parent_of').
:- op(500, xfx, 'is_type1_related_to').


%domino (ID, parent, child type, direction, no_orientation/single/double, angle)
id_list([f,a,b,c,d,e]).
domino(a,0,0,root,no_orientation,0).
domino(b,a,0,north,single,45).
domino(c,a,0,east,single, 0).
domino(d,a,0,south,single,0).
domino(e,a,0,west,single,0).
domino(f,b,0,north,single,0).
domino_length(100).
domino_width(50).
pi(3.141592654).

not(P) :- (call(P) -> fail ; true). 
Y is_parent_of X :-domino(X,Y,_,_    ,_     ,_).
is_single(X)     :-domino(X,_,_,_    ,single,_).
is_double(X)     :-domino(X,_,_,_    ,double,_).
is_root(X)       :-domino(X,_,_,root ,_     ,_).
is_north(X)      :-domino(X,_,_,north,_     ,_).
is_east(X)       :-domino(X,_,_,east ,_     ,_).
is_west(X)       :-domino(X,_,_,west ,_     ,_).
is_south(X)      :-domino(X,_,_,south,_     ,_).
is_child_type1(X):-domino(X,_,1,_    ,_     ,_).
is_child_type2(X):-domino(X,_,2,_    ,_     ,_).
is_child_type3(X):-domino(X,_,3,_    ,_     ,_).
angle(X,Y)       :-domino(X,_,_,_    ,_     ,Y).

 % -------------------------- ADJUSTED ANGLE CALCULATIONS ---------------
adjusted_angle(Node,0)    :-is_root(Node),!.

adjusted_angle(Node,Angle):-Parent is_parent_of Node,
                            not(is_root(Parent)), 
                            domino(Node,_,_,_    ,_     ,Angle).

adjusted_angle(Node,Angle):-Parent is_parent_of Node,
                            is_root(Parent), 
                            is_east(Node),
                            domino(Node,_,_,_    ,_     ,Angle).

adjusted_angle(Node,Angle):-Parent is_parent_of Node,
                            is_root(Parent),
                            is_north(Node),
                            domino(Node,_,_,_    ,_     ,A1),
                            Angle is 90 + A1.

adjusted_angle(Node,Angle):-Parent is_parent_of Node,
                            is_root(Parent),
                            is_west(Node),
                            domino(Node,_,_,_    ,_     ,A1),
                            Angle is 180 + A1.

adjusted_angle(Node,Angle):-Parent is_parent_of Node,
                            is_root(Parent),
                            is_south(Node),
                            domino(Node,_,_,_    ,_     ,A1),
                            Angle is 270 + A1.

% ---------------- GRAPHICS TRANSFORMATIONS --------------------
translate(X,Y, Delta_X, Delta_Y, Result_X, Result_Y):- Result_X is X + Delta_X,
                                                       Result_Y is Y + Delta_Y.

rotation(X, Y, Theta, Result_X, Result_Y):- pi(Pi),
                                            Result_X is X*cos(Theta*Pi/180) - 
Y*sin(Theta*Pi/180),
                                            Result_Y is X*sin(Theta*Pi/180) + 
Y*cos(Theta*Pi/180).

rotation_around_point(X,Y,X_P, Y_P, Theta, Result_X, Result_Y):- 
translate(X,Y,-X_P,-Y_P, X1, Y1),
                                                                 
rotation(X1,Y1,Theta,X2,Y2),
                                                                 
translate(X2,Y2,X_P,Y_P,Result_X,Result_Y).

compensate_for_theta(X,Y,Delta_X,Delta_Y,Theta, Result_X, Result_Y):- 
translate(X,Y,Delta_X,Delta_Y, X2, Y2),
                                                                      
rotation_around_point(X2,Y2,X,Y,Theta, Result_X, Result_Y).


% ------------- ANGLE OF ROTATION CALCULATIONS -----------------
angle_of_rotation(Node, 0) :- is_root(Node).


angle_of_rotation(Node, Angle) :- Parent is_parent_of Node,     
                                  angle_of_rotation(Parent, A2),
                                  angle(Parent, A1),
                                  Angle is A1 + A2.

% ------- ADJUSTED ANGLE OF ROTATION CALCULATIONS --------------
adjusted_angle_of_rotation(Node, 0) :- is_root(Node).


adjusted_angle_of_rotation(Node, Angle) :- Parent is_parent_of Node,    
                                           adjusted_angle_of_rotation(Parent, 
A2),
                                           adjusted_angle(Node, A1),
                                           Angle is A1 + A2.
% -------------COORDINATE CALCULATIONS--------------------------
% Center of root domino
calc_solution_e(a, 0, 0).

% North domino next to root
calc_solution_e(Node, Sol_X, Sol_Y) :- Parent is_parent_of Node,
                                       angle(Node, Angle),
                                       is_root(Parent),
                                       is_north(Node),          
                                       Angle >= 0,
                                       domino_width(Width),
                                       domino_length(Length),
                                       rotation_around_point(0, 
                                                             Width/2+Length/2,
                                                             -Width/2, 
                                                             Width/2, 
                                                             Angle,
                                                             Sol_X,
                                                             Sol_Y),!.

calc_solution_e(Node, Sol_X, Sol_Y):- Parent is_parent_of Node,
                                      angle(Node, Angle),
                                      is_root(Parent),
                                      is_north(Node),           
                                      Angle < 0,
                                      domino_width(Width),
                                      domino_length(Length),
                                      rotation_around_point(0, 
                                                            Width/2+Length/2,
                                                            Width/2, 
                                                            Width/2, 
                                                            Angle,
                                                            Sol_X,
                                                            Sol_Y),!.

% East domino next to root
calc_solution_e(Node, Sol_X, Sol_Y) :- Parent is_parent_of Node,
                                       angle(Node, Angle),
                                       is_root(Parent),
                                       is_east(Node),           
                                       Angle >= 0,
                                       domino_width(Width),
                                       domino_length(Length),
                                       rotation_around_point(Length, 
                                                             0,
                                                             Length/2, 
                                                             Width/2, 
                                                             Angle,
                                                             Sol_X,
                                                             Sol_Y),!.

calc_solution_e(Node, Sol_X, Sol_Y):- Parent is_parent_of Node,
                                      angle(Node, Angle),
                                      is_root(Parent),
                                      is_east(Node),            
                                      Angle < 0,
                                      domino_width(Width),
                                      domino_length(Length),
                                      rotation_around_point(Length,
                                                            0,  
                                                            Length/2, 
                                                            -Width/2, 
                                                            Angle,
                                                            Sol_X,
                                                            Sol_Y),!.

% South domino next to root
calc_solution_e(Node, Sol_X, Sol_Y):- Parent is_parent_of Node,
                                      angle(Node, Angle),
                                      is_root(Parent),
                                      is_south(Node),           
                                      Angle >= 0,
                                      domino_width(Width),
                                      domino_length(Length),
                                      rotation_around_point(0,
                                                            -Length/2-Width/2,  
                                                            Width/2, 
                                                            -Width/2, 
                                                            Angle,
                                                            Sol_X,
                                                            Sol_Y),!.


calc_solution_e(Node, Sol_X, Sol_Y):- Parent is_parent_of Node,
                                      angle(Node, Angle),
                                      is_root(Parent),
                                      is_south(Node),           
                                      Angle < 0,
                                      domino_width(Width),
                                      domino_length(Length),
                                      rotation_around_point(0,
                                                            -Length/2-Width/2,  
                                                            -Width/2, 
                                                            -Width/2, 
                                                            Angle,
                                                            Sol_X,
                                                            Sol_Y),!.

% West domino next to root
calc_solution_e(Node, Sol_X, Sol_Y):- Parent is_parent_of Node,
                                      angle(Node, Angle),
                                      is_root(Parent),
                                      is_west(Node),            
                                      Angle >= 0,
                                      domino_width(Width),
                                      domino_length(Length),
                                      rotation_around_point(-Length,    
                                                            0,
                                                            -Length/2, 
                                                            -Width/2, 
                                                            Angle,
                                                            Sol_X,
                                                            Sol_Y),!.

calc_solution_e(Node, Sol_X, Sol_Y):- Parent is_parent_of Node,
                                      angle(Node, Angle),
                                      is_root(Parent),
                                      is_west(Node),            
                                      Angle < 0,
                                      domino_width(Width),
                                      domino_length(Length),
                                      rotation_around_point(-Length,    
                                                            0,
                                                            -Length/2, 
                                                            Width/2, 
                                                            Angle,
                                                            Sol_X,
                                                            Sol_Y),!.

% Single domino next to single domino - not attached to root.
calc_solution_e(Node, Sol_Xa, Sol_Ya) :-   angle(Node, Angle),  
                                         Angle >= 0,                            
                
                                         Parent is_parent_of Node,
                                         is_single(Node),
                                         not(is_root(Parent)),
                                         is_single(Parent),
                                         calc_solution_e(Parent, X1, Y1),
                                         domino_length(Length),
                                         domino_width(Width),
                                         adjusted_angle_of_rotation(Node, 
Adj_Ang_of_Rotate),
                                         compensate_for_theta(X1, Y1, Length, 
0, Adj_Ang_of_Rotate, X2, Y2).
                                         compensate_for_theta(X1, Y1, Length/2, 
Width/2, Adj_Ang_of_Rotate, X3, Y3),
                                         
rotation_around_point(X2,Y2,X3,Y3,Adj_Ang_of_Rotate, Sol_Xa, Sol_Ya).

                                     
% Edges of domino
calc_solution_a_x(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
                                    pi(Pi),
                                    domino_length(Length),
                                    domino_width(Width),
                                    adjusted_angle_of_rotation(Node, 
Adj_Ang_of_Rotate),
                                    Solution is CenterX -
                                                
(Length/2)*cos(Adj_Ang_of_Rotate*Pi/180) -
                                                
(Width/2)*sin(Adj_Ang_of_Rotate*Pi/180).

calc_solution_b_x(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
                                    pi(Pi),
                                    domino_length(Length),
                                    domino_width(Width),
                                    adjusted_angle_of_rotation(Node, 
Adj_Ang_of_Rotate),
                                    Solution is CenterX +
                                                
(Length/2)*cos(Adj_Ang_of_Rotate*Pi/180) -
                                                
(Width/2)*sin(Adj_Ang_of_Rotate*Pi/180).

calc_solution_c_x(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
                                    domino_length(Length),
                                    domino_width(Width),
                                    pi(Pi),
                                    adjusted_angle_of_rotation(Node, 
Adj_Ang_of_Rotate),
                                    Solution is CenterX +
                                                
(Length/2)*cos(Adj_Ang_of_Rotate*Pi/180) +
                                                
(Width/2)*sin(Adj_Ang_of_Rotate*Pi/180).
                                     
calc_solution_d_x(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
                                    domino_length(Length),
                                    domino_width(Width),
                                    pi(Pi),
                                    adjusted_angle_of_rotation(Node, 
Adj_Ang_of_Rotate),
                                    Solution is CenterX -
                                                
(Length/2)*cos(Adj_Ang_of_Rotate*Pi/180) +
                                                
(Width/2)*sin(Adj_Ang_of_Rotate*Pi/180).
                                                

calc_solution_a_y(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
                                    domino_length(Length),
                                    domino_width(Width),
                                    pi(Pi),
                                    adjusted_angle_of_rotation(Node, 
Adj_Ang_of_Rotate),                                                        
                                    Solution is CenterY + 
                                                
(Width/2)*cos(Adj_Ang_of_Rotate*Pi/180) -
                                                
(Length/2)*sin(Adj_Ang_of_Rotate*Pi/180).

calc_solution_b_y(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
                                    domino_length(Length),
                                    domino_width(Width),
                                    pi(Pi),
                                    adjusted_angle_of_rotation(Node, 
Adj_Ang_of_Rotate),
                                    Solution is CenterY +
                                                
(Width/2)*cos(Adj_Ang_of_Rotate*Pi/180) +
                                                
(Length/2)*sin(Adj_Ang_of_Rotate*Pi/180).
                                                   
calc_solution_c_y(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
                                    domino_length(Length),
                                    domino_width(Width),
                                    adjusted_angle_of_rotation(Node, 
Adj_Ang_of_Rotate),
                                    pi(Pi),
                                    Solution is CenterY -
                                                
(Width/2)*cos(Adj_Ang_of_Rotate*Pi/180) +
                                                
(Length/2)*sin(Adj_Ang_of_Rotate*Pi/180).

calc_solution_d_y(Node,Solution) :- calc_solution_e(Node, CenterX, CenterY),
                                    domino_length(Length),
                                    domino_width(Width),
                                    pi(Pi),
                                    adjusted_angle_of_rotation(Node, 
Adj_Ang_of_Rotate),
                                    Solution is CenterY -
                                                
(Width/2)*cos(Adj_Ang_of_Rotate*Pi/180)-
                                                
(Length/2)*sin(Adj_Ang_of_Rotate*Pi/180).

write_results_to_file :- open('C:/GNU-Prolog/test/output.txt', write, 
Output_Stream),
                         id_list(Id_List),
                         write_solution(Id_List,Output_Stream),
                         close(Output_Stream).

write_solution([], _):- true.
write_solution([X|Xs],Output_Stream):- write(Output_Stream, X),
                                       write(Output_Stream, ' '),
                                       calc_solution_a_x(X,Solution1),
                                       write(Output_Stream, Solution1),
                                       write(Output_Stream,' '),
                                       calc_solution_a_y(X,Solution2),
                                       write(Output_Stream, Solution2),
                                       write(Output_Stream,' '),
                                       calc_solution_b_x(X,Solution3),
                                       write(Output_Stream, Solution3),
                                       write(Output_Stream,' '),
                                       calc_solution_b_y(X,Solution4),
                                       write(Output_Stream, Solution4),
                                       write(Output_Stream,' '),
                                       calc_solution_c_x(X,Solution5),
                                       write(Output_Stream, Solution5),
                                       write(Output_Stream,' '),
                                       calc_solution_c_y(X,Solution6),
                                       write(Output_Stream, Solution6),
                                       write(Output_Stream,' '),
                                       calc_solution_d_x(X,Solution7),
                                       write(Output_Stream, Solution7),
                                       write(Output_Stream,' '),
                                       calc_solution_d_y(X,Solution8),
                                       write(Output_Stream, Solution8),
                                       write(Output_Stream,' '),
                                       calc_solution_e(X,Solution9,Solution10),
                                       write(Output_Stream, Solution9),
                                       write(Output_Stream,' '),
                                       write(Output_Stream, Solution10),
                                       write(Output_Stream,'\n'),
                                       write_solution(Xs, Output_Stream).
                                
                                       

        



--- End Message ---

reply via email to

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