Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Game LT

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

Program of prolog Game LT.

Code for Game LT in Artificial Intelligence

trace
domains
    gamelist = symbol*
    teamlist = symbol*
    finallist = symbol*
    newlist = symbol*
    
database
    players(integer,symbol,gamelist)
    games(symbol,integer)
    student_db(integer,symbol)
    
    
predicates
    find_players(symbol,teamlist)
    enter_game()
    go
    repeate
    initialize()
    member(symbol,gamelist)
    display_list(finallist,integer)
    display_db(finallist,integer)
    combination(integer,finallist,newlist)
    
goal 
    go.
    
    
clauses        
    repeate.
    repeate :- repeate.
    
    go :-
        initialize(),
        enter_game().
    
    initialize() :-
        assert(players(1,"hemal",[cricket,football])),
        assert(players(2,"shashank",[football,carrom])),
        assert(players(3,"nilay",[carrom,chess])),
        assert(players(4,"khilan",[cricket,chess])),
        assert(players(5,"gediya",[football,carrom])),
        assert(players(6,"kk",[carrom,cricket])),
        assert(players(7,"hh",[carrom,football])).
        
    member(X,[X|_]).
    member(X,[_|Tail]) :- member(X,Tail).
        


    enter_game() :-
        write("Enter the Name of Game : "),
        readln(GNAME),
        find_players(GNAME,TEAMLIST),
        display_db(FINALLIST,0).
    
    find_players(GNAME,TEAMLIST) :-
        players(NO,NAME,G_LIST),
        member(GNAME,G_LIST),
        assert(student_db(NO,NAME)),
        fail.

    find_players(GNAME,TEAMLIST).
        
    
    display_db(FINALLIST,CNT) :-
        
        student_db(N1,N),
        FINALLIST1 = [N | FINALLIST],
        write(N), write(" "),
        retract(student_db(N1,N)),
        CNT1 = CNT + 1,
        display_db(FINALLIST1,CNT1).
        
    display_db(FINALLIST,CNT) :- 
%        display_list(FINALLIST,CNT),
        nl,
        write("The possible combinations are : "),
        combination(2,FINALLIST,NEWLIST),
        nl,
        readchar(_),
        write(NEWLIST),
        fail.
    
    
    display_list([H | T],CNT) :-
    
        TMPLIST1 = [H|T],
        write(H),        
        CNT1 = CNT - 1,
        CNT > 0,
        display_list(T,CNT1).
        
        
    combination(NPLAYER,[X|TAIL],[X|COMB]) :-
        NPLAYER > 0,
        TMP = NPLAYER - 1,
        combination(TMP,TAIL,COMB).
        
    combination(NPLAYER,[_|TAIL],COMB) :-
        NPLAYER > 0,
        combination(NPLAYER,TAIL,COMB).
        
    combination(0,_,[]).
  
Share: 


Didn't find what you were looking for? Find more on Game LT Or get search suggestion and latest updates.

Milind Mishra
Milind Mishra author of Game LT 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!