Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Game

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

Program of Game in prolog.

Code for Game in Artificial Intelligence

trace
domains
    gamelist = symbol*
    teamlist = symbol*
    finallist = symbol*
    
database
    players(integer,symbol,gamelist)
    games(symbol,integer)
    student_db(integer,integer,symbol)
    
    
predicates
%    read_players(integer)
%    read_games()
    find_players(symbol,teamlist,integer)
%    search(symbol)
%    enter_games(integer,gamelist)
    enter_game()
    go
    repeate
    initialize()
    member(symbol,gamelist)
    display_list(finallist,integer)
%    addtolist(symbol,teamlist,integer)
    display_db(finallist,integer)
    
goal 
    go.
    
    
clauses        
    repeate.
    repeate :- repeate.
    
    go :-
%        read_players(0),
        initialize(),
        enter_game().
%        display_db(FINALLIST).
%        save("try.txt").
    
/*    read_players(3).    read_players(CNT) :-        write("Enter Name : "),        readln(PNAME),        write("Enter Gamelist : "),        enter_games(2,GAMELIST),        CNT = CNT + 1,        assert(players(PNAME,GAMELIST)).    enter_games(CNT,GAMELIST) :-        write("Enter Game : "),        readln(GNAME),        GAMELIST1 = [GNAME|GAMELIST],        CNT1 = CNT - 1,        CNT1 <> 0,        enter_games(CNT1,GAMELIST1).*/
    
    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])).
        
    member(X,[X|_]).
    member(X,[_|Tail]) :- member(X,Tail).
        

/*    read_games() :-        repeate,        write("Enter Game Name : "),        readln(GNAME),        write("Enter No. of players : "),        readint(NUM),        assert(games(GNAME,NUM)),        NUM = 0.    search(GNAME) :-        players(N,GNAME),        write(N), write(" "), write(GNAME),        fail.*/
    
    enter_game() :-
        write("Enter the Name of Game : "),
        readln(GNAME),
        find_players(GNAME,TEAMLIST,1),
%        repeate,
        display_db(FINALLIST,0).
    
%    find_players(GNAME,TEAMLIST,0) :-
%        display_db().
    
    find_players(GNAME,TEAMLIST,CNT) :-
        players(NO,NAME,G_LIST),
        member(GNAME,G_LIST),
%        write(NAME), writ0e(" "), nl,
%        addtolist(NAME,TEAMLIST,CNT),
%        CNTR1 = CNT + 1,
        assert(student_db(0,NO,NAME)),
        
%        TEAMLIST1 = [NAME|TEAMLIST],

%        CNT1 = CNT + 1,
%        find_players(GNAME,TEAMLIST1,CNT1).
        
%        display_db(),
        fail.
%        CNT1 = CNT - 1,
%        find_players(GNAME,TEAMLIST1,CNT1).

    find_players(GNAME,TEAMLIST,CNT).
        
/*    addtolist(NAME,TEAMLIST,CNT) :-        CNT <> 0,        TEAMLIST1 = [NAME|TEAMLIST],        addtolist(NAME,TEAMLIST1,0).*/            
    
    display_db(FINALLIST,CNT) :-
        
        student_db(N1,N2,N),
        FINALLIST1 = [N | FINALLIST],
        write(N), write(" "),
        retract(student_db(N1,N2,N)),
        CNT1 = CNT + 1,
        display_db(FINALLIST1,CNT1).
        
    display_db(FINALLIST,CNT) :- 
            display_list(FINALLIST,CNT).
    
    
    display_list([H | T],CNT) :-
    
        TMPLIST1 = [H|T],
        write(H),
        CNT1 = CNT - 1,
        CNT > 0,
        display_list(T,CNT1).
  
Share: 


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

Milind Mishra
Milind Mishra author of Game is from India.
 
View All Articles

 

Other Interesting Articles in Artificial Intelligence:


 
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!