Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program of spiral game

Posted By: Milind Mishra     Category: Artificial Intelligence     Views: 3825

Prolog program of spiral game.......

Code for Prolog program of spiral game in Artificial Intelligence

%trace
domains
    
    startx,starty = integer
    dicevalx,dicevaly = integer
    %totalx,totaly = integer

database

    state(startx,starty,dicevalx,dicevaly)

predicates

    play(startx,starty)
    rand(startx,starty)
%turnx(startx,starty,totalx)
%turny(starty,startx,totaly)

clauses

    play(Startx,StartY):-
        Startx = 25,
        Starty <= 25,
        write("problem solved").
    
    play(Startx,StartY):-
        Starty = 25,
        Startx <= 25,
        write("problem solved").
    play(Startx,Starty):-
        Startx = 0,
        Starty = 0,
        rand(6,Dicevalx),
        Newx = Startx + Dicevalx,
        rand(6,Dicevaly),
        Newy = Starty + Dicevaly,
        %Newx <> Newy,
        Newvalx=Dicevalx,
        Newvaly=Dicevaly,
        assert(state(Newx,Newy,Newvalx,Newvaly)),
        play(Newx,Newy).
    
    play(Startx,Starty):-
        Startx <= 19,
        Starty <= 19,
        rand(6,Dicevalx),
        Newx =     Startx + Dicevalx,
        rand(6,Dicevaly),
        Newy = Starty + Dicevaly,
        Newvalx=Dicevalx,
        Newvaly=Dicevaly,
        assert(state(Newx,Newy,Newvalx,Newvaly)),
        play(Newx,Newy).
    
    play(Startx,Starty):-
        Startx < 26,
        Starty < 26,
        rand(6,Dicevalx),
        rand(6,Dicevaly),
        Startx + Dicevalx <= 25,
        Newx = Startx + Dicevalx,
        Newy = Starty + Dicevaly,
        Newx <= 25,
        Newy <= 25,
        Newvalx=Dicevalx,
        Newvaly=Dicevaly,
        assert(state(Newx,Newy,Newvalx,Newvaly)),
        play(Newx,Newy). 

    rand(X,Y):-
        random(Z),
        Y = (X - 1) * Z + 1.
        
    goal
        makewindow(1,2,3,"2 player spiral move game",0,0,25,80),
        play(0,0),
        save("outs.txt").

***************
spiral1



%trace
domains
    
    startx,starty = integer
    dicevalx,dicevaly = integer
    totalx,totaly = integer

database

    state(startx,starty,dicevalx,dicevaly)

predicates

    play(startx,starty)
    rand(startx,starty)
    turnx(startx,starty,dicevalx,totalx,totaly)
    turny(startx,starty,dicevaly,totalx,totaly)
    check(startx,dicevalx,finalvalx)

clauses

    play(Startx,StartY):-
        Startx = 25,
        Starty <= 25,
        write("problem solved").
    
    play(Startx,StartY):-
        Starty = 25,
        Startx <= 25,
        write("problem solved").
        
    play(Startx,Starty):-
        Startx = 0,
        Starty = 0,
        rand(6,Dicevalx),
        Newvalx = Dicevalx,
        turnx(Startx,Starty,Newvalx,Totalx,Totaly),
        rand(6,Dicevaly),
        Newvaly = Dicevaly,
        Totalxx = Totalx,
        Totalxy = Totaly,
        turny(Totalxx,Totalxy,Newvaly,Totalyx,Totalyy),
        Newx = Totalyx,
        Newy = Totalyy,
        assert(state(Newx,Newy,Newvalx,Newvaly)),
        play(Newx,Newy).
    
    play(Startx,Starty):-
        Startx <= 19,
        Starty <= 19,
        rand(6,Dicevalx),
        Newvalx = Dicevalx,
        turnx(Startx,Starty,Newvalx,Totalx,Totaly),
        rand(6,Dicevaly),
        Newvaly = Dicevaly,
        Totalxx = Totalx,
        Totalxy = Totaly,
        turny(Totalxx,Totalxy,Newvaly,Totalyx,Totalyy),
        Newx = Totalyx,
        Newy = Totalyy,
        assert(state(Newx,Newy,Newvalx,Newvaly)),
        play(Newx,Newy).
    
    play(Startx,Starty):-
        Startx < 26,
        Starty < 26,
        rand(6,Dicevalx),
        Newvalx=Dicevalx,
/*        turnx(Startx,Starty,Newvalx,Totalx,Totaly),        Totalxx = Totalx,        Totalxy = Totaly,        Totalxx < 25,*/
        check(Startx,Newvalx,Totalx),
        rand(6,Dicevaly),
        Newvaly=Dicevaly,
        turny(Totalxx,Totalxy,Newvaly,Totalyx,Totalyy),
        Newx = Totalyx,
        Newy = Totalyy,
        assert(state(Newx,Newy,Newvalx,Newvaly)),
        play(Newx,Newy). 

    rand(X,Y):-
        random(Z),
        Y = (X - 1) * Z + 1.
    
    turnx(Startx,Starty,Dicevalx,Totalx,Totaly):-
        Startx + Dicevalx <> Starty,
        free(Totalx),
        Totalx = Startx + Dicevalx,
        free(Totaly),
        Totaly = Starty.
    
    turnx(Startx,Starty,Dicevalx,Totalx,Totaly):-
        Startx + Dicevalx = Starty,
        free(Totalx),
        Totalx = Startx + Dicevalx,
        free(Totaly),
        Totaly = 0.
    
    turny(Startx,Starty,Dicevaly,Totalx,Totaly):-
        Starty + Dicevaly <> Startx,
        free(Totaly),
        Totaly = Starty + Dicevaly,
        free(Totalx),
        Totalx = Startx.
        
    turny(Startx,Starty,Dicevaly,Totalx,Totaly):-
        Starty + Dicevaly = Startx,
        free(Totaly),
        Totaly = Starty + Dicevaly,
        free(Totalx),
        Totalx = 0.

    check(Startx,Dicevalx,Finalvalx):-
        25 - Startx >= Dicevalx,
        free(Finalvalx),
        Finalvalx = Startx + Dicevalx.
        
    check(Startx,Dicevalx,Finalvalx):-
        25 - Startx <= Dicevalx,
        free(Finalvalx),
        Finalvalx = Startx.
        
    goal
        makewindow(1,2,3,"2 player spiral move game",0,0,25,80),
        play(0,0),
        save("outs.txt").


Output

state(0,2,2,2)
state(4,7,4,5)
state(9,10,5,3)
state(12,16,3,6)
state(15,21,3,5)
state(20,25,5,4)

************

state(3,5,3,5)
state(6,9,3,4)
state(10,13,4,4)
state(0,15,5,2)
state(5,19,5,4)
state(8,20,3,1)
state(11,23,3,3)
state(12,25,1,2)
  
Share: 


Didn't find what you were looking for? Find more on Prolog program of spiral game Or get search suggestion and latest updates.

Milind Mishra
Milind Mishra author of Prolog program of spiral game is from India.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!