domains
l=integer*.
i=integer.
status = char.
player_name,match_name = symbol.
batting_avg,strick_rate = real.
age,matches_played,total_out,total_run,best_score,total_fifty,total_century,balls_faced,runs_scored = integer.
database
cricket_player(player_name,age,matches_played,total_out,total_run,strick_rate,best_score,total_fifty,total_century)
match_detail(match_name,player_name,balls_faced,runs_scored,status)
predicates
savedatabase.
consultdatabase.
getPlayerDetail.
readPlayerDetail.
getMatchDetail.
readMatchDetail.
updatePlayerDetail(symbol,integer,integer,char).
getStatus(char,char,integer,integer).
getBestScore(integer,integer,integer).
getFifty(integer,integer,integer,integer,integer)
compString(symbol,symbol).
compChar(char,symbol).
clauses
getPlayerDetail:-
write("\nEnter Name Of Player : "),
readln(Name),
write("\nEnter Age : "),
readint(Age),
write("\nEnter Matches Played : "),
readint(MatchesPlayed),
write("\nEnter No of Times got Out : "),
readint(TotalOut),
write("\nEnter Total Runs Scored : "),
readint(TotalRun),
write("\nEnter StrickRate : "),
readreal(StrickRate),
write("\nEnter Best Score : "),
readint(BestScore),
write("\nEnter Total Fifty : "),
readint(TotalFifty),
write("\nEnter Total Century : "),
readint(TotalCentury),
assertz(cricket_player(Name,Age,MatchesPlayed,TotalOut,TotalRun,StrickRate,BestScore,TotalFifty,TotalCentury)),
write("\nDo you want to continue(y/n)= "),
readchar(Ans),
write(Ans),
Ans='y',
getPlayerDetail.
getPlayerDetail.
readPlayerDetail:-
%consult("cricket.dat"),
cricket_player(Name,Age,MatchesPlayed,TotalOut,TotalRun,StrickRate,BestScore,TotalFifty,TotalCentury),
retract(cricket_player(Name,Age,MatchesPlayed,TotalOut,TotalRun,StrickRate,BestScore,TotalFifty,TotalCentury)),
write("\nPlayer Name : ",Name),
write("\n===================="),
write("\nAge : ",Age),
write("\nMatches Played : ",MatchesPlayed),
write("\nNo Of Times got Out : ",TotalOut),
write("\nTotal Runs : ",TotalRun),
BatAvg = TotalRun/TotalOut,
write("\nBatting Average : ",BatAvg),
write("\nStrick Rate : ",StrickRate),
write("\nBestScore : ",BestScore),
write("\nTotal Fifty : ",TotalFifty),
write("\nTotal Century : ",TotalCentury),
fail.
readPlayerDetail.
getMatchDetail:-
write("\n\nEnter Name Of Match : "),
readln(Name),
write("\nEnter Name of Player : "),
readln(PlayerName),
write("\nEnter Balls Faced : "),
readint(BallsFaced),
write("\nEnter Runs Scored : "),
readint(RunsScored),
write("\nEnter Batting Status : "),
readchar(Status),
write(Status),
assertz(match_detail(Name,PlayerName,BallsFaced,RunsScored,Status)),
write("\nDo you want to continue(y/n) : "),
readchar(Ans),
write(Ans),
Ans='y',
getMatchDetail.
getMatchDetail.
savedatabase:- save("cricket.dat").
consultdatabase:- consult("cricket.dat").
readMatchDetail:-
consultdatabase,!,
match_detail(Name,PlayerName,BallsFaced,RunsScored,Status),
retract(match_detail(Name,PlayerName,BallsFaced,RunsScored,Status)),!,
write("\nM Player : ",PlayerName),
updatePlayerDetail(PlayerName,BallsFaced,RunsScored,Status),!.
readMatchDetail:- savedatabase, readPlayerDetail.
updatePlayerDetail(PlayerName,BallsFaced,RunsScored,Status):-
cricket_player(Name,Age,MatchesPlayed,TotalOut,TotalRun,StrickRate,BestScore,TotalFifty,TotalCentury),
retract(cricket_player(Name,Age,MatchesPlayed,TotalOut,TotalRun,StrickRate,BestScore,TotalFifty,TotalCentury)),
write("\nM : ",PlayerName," C: ",Name),
compString(PlayerName,Name),!,
MatchesPlayed1 = MatchesPlayed + 1,
TotalRun1 = TotalRun + RunsScored,
StrickRate1 = (StrickRate + ((RunsScored*100)/BallsFaced))/2,
Status1 = 'O',
getStatus(Status1,Status,TotalOut,TotalOut1),
getBestScore(RunsScored,BestScore,BestScore1),
getFifty(RunsScored,TotalCentury,TotalCentury1,TotalFifty,TotalFifty1),
assertz(cricket_player(Name,Age,MatchesPlayed1,TotalOut1,TotalRun1,StrickRate1,BestScore1,TotalFifty1,TotalCentury1)),
write("\nasserted"),
fail.
updatePlayerDetail(_,_,_,_).
getStatus(Status1,Status,TotalOut,TotalOut1):-
Status1 <> Status,
TotalOut1 = TotalOut + 1.
getStatus(Status1,Status,TotalOut,TotalOut1):-
Status1 = Status,
TotalOut1 = TotalOut.
getBestScore(RunsScored,BestScore,BestScore1):-
RunsScored >= BestScore,
BestScore1 = RunsScored.
getBestScore(RunsScored,BestScore,BestScore1):-
RunsScored < BestScore,
BestScore1 = BestScore.
getFifty(RunsScored,TotalCentury,TotalCentury1,TotalFifty,TotalFifty1):-
RunsScored >= 100,
TotalCentury1 = TotalCentury + 1,
TotalFifty1 = TotalFifty.
getFifty(RunsScored,TotalCentury,TotalCentury1,TotalFifty,TotalFifty1):-
RunsScored < 100, RunsScored >= 50,
TotalFifty1 = TotalFifty + 1,
TotalCentury1 = TotalCentury.
getFifty(RunsScored,TotalCentury,TotalCentury1,TotalFifty,TotalFifty1):-
RunsScored < 50,
TotalFifty1 = TotalFifty,
TotalCentury1 = TotalCentury.
compString(Str1,Str2):-
Str1 <> "",
frontchar(Str1,Char1,Rest1),
compChar(Char1,Str2),
compString(Rest1,Str2).
compString(Str1,_):-
Str1 = "".
compString(_,_):-
fail.
compChar(Char1,Str2):-
frontchar(Str2,Char2,Rest2),
Char1 <> Char2,
Rest2 <> "",
compChar(Char1,Rest2).
compChar(Char1,Str2):-
frontchar(Str2,Char2,_),
Char1 = Char2.
compChar(_,_):-
fail.
goal
clearwindow,
%getPlayerDetail,
%getMatchDetail,
%savedatabase.
consultdatabase,
readPlayerDetail,
readMatchDetail,
savedatabase.