Ai 5 - 6
Ai 5 - 6
Experiment-5
Prolog Predicate:
% Define the possible state transitions move((X, Y), (4, Y), 'Fill the 4 gallon jug') :- X < 4.
move((X, Y), (X, 3), 'Fill the 3 gallon jug') :- Y < 3. move((X, Y), (X1, Y), 'Pour some water
out of the 4 gallon jug') :- X > 0, X1 is X - min(X, 4). move((X, Y), (X, Y1), 'Pour some water
out of the 3 gallon jug') :- Y > 0, Y1 is Y - min(Y, 3). move((X, Y), (0, Y), 'Empty the 4 gallon
jug') :- X > 0. move((X, Y), (X, 0), 'Empty the 3 gallon jug') :- Y > 0.
move((X, Y), (4, Y1), 'Pour water from the 3 gallon jug into the 4 gallon jug until the 4 gallon
jug is full') :-
move((X, Y), (X1, 3), 'Pour water from the 4 gallon jug into the 3-gallon jug until the 3 gallon
jug is full') :-
move((X, Y), (X1, 0), 'Pour all the water from the 3 gallon jug into the 4 gallon jug') :-
X + Y =< 4, Y > 0, X1 is X + Y.
move((X, Y), (0, Y1), 'Pour all the water from the 4 gallon jug into the 3 gallon jug') :-
X + Y =< 3, X > 0, Y1 is X + Y.
move((0, 2), (2, 0), 'Pour the 2 gallons from 3 gallon jug into the 4 gallon jug'). move((2,
Y), (0, Y), 'Empty the 2 gallons in the 4 gallon jug on the ground').
Output:
Date -
Experiment-6
Aim: Write a program to generate Tic-Tac Toe problem.
Prolog Predicate:
% Tic-Tac-Toe Win Case Checker in Prolog
% Winning conditions
win(Player, Board) :-
nl,
display_board(FinalBoard3),
write('Draw Case (Game Draw):'),
7, B22),
display_board(FinalBoard4).
Output: