win_deep(0). % You can change this two numbers
to make the AI more clever
nolose_deep(0).
?-
G_BG is bitmap_image("Gambar//depan.bmp",_),
G_BA is bitmap_image("Gambar//4.bmp",_),
G_BGA is bitmap_image("Gambar//about.bmp",_),
G_A is bitmap_image("Gambar//kpk1.bmp",_),
G_B is bitmap_image("Gambar//koruptor.bmp",_),
G_Rules is bitmap_image("Gambar//rules.bmp",_),
G_WIN is bitmap_image("Gambar//win.bmp",_),
G_Lost is bitmap_image("Gambar//lost.bmp",_),
set(pos([[f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f]])),
set(lose_flag(false)),
brush(system_color(window)),
%=========================== Splash Screen
=================================%
window(G_layar1,_,win_func1(_),"KPK VS KORUPTOR",200,100,900,600).
win_func1(paint):-
draw_bitmap(0,0,G_BG,_,_),
beep("Sound//1.wav").
%-----------------------
TOMBOL -------------------------%
win_func1(init):-
button(_,_,mulai_game(_),"START GAME",30,50,250,40),
button(_,_,about(_),"ABOUT",315,50,250,40),
button(_,_,keluar_game(_),"EXIT GAME",600,50,250,40).
%----------------
MULAI GAME --------------------%
mulai_game(press):-
window(G_layar2, _, win_func2(_), "KPK VS KORUPTOR", 200, 100, 900, 600),
close_window(G_layar1),
update_window(_).
%--------------
TENTANG GAME ------------------%
about(press):-
window(G_about,_,win_about(_),"About",200,100,920,620).
win_about(paint):-
draw_bitmap(0,0,G_BGA,_,_).
%---------------
KELUAR GAME --------------------%
keluar_game(press):-
close_window(G_layar1),
close_window(G_about).
%----------------
ULANG GAME --------------------%
ulang_game(press):-
close_window(G_layar2),
close_window(G_win),
close_window(G_lost),
window(G_layar2, _, win_func2(_), "KPK VS KORUPTOR", 200, 100, 900, 600),
set(pos([[f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f]])),
set(lose_flag(false)),
update_window(_).
%============================ Menu Utama
===================================%
win_func2(init):-
G_P:= 0,
menu( normal, _, _, menu_new(_), "&New Game"),
menu( normal, _, _, menu_rule(_), "&Rules"),
menu( right, _, _, menu_exit(_), "&Exit").
menu_exit(press) :-
close_window(_).
menu_rule(press):-
window(G_rule,_,win_rule(_),"Cara Bermain",200,100,920,620).
win_rule(paint):-
draw_bitmap(0,0,G_Rules,_,_).
menu_new(press) :-
set(pos([[f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f], [f,f,f,f,f,f,f,f,f,f,f,f]])),
set(lose_flag(false)),set(lose_flag(false)),
update_window(_), (G_P:=1->play).
put_mark(Mark) :-
pos(Current_Pos),
member(Current_Pos, L, Y),
member(L, Mark, X),
X1 is 31 + 40*X, Y1 is 31 + 40*Y, X2 is X1 + 30, Y2 is Y1 + 30,
write_mark(Mark, X1, Y1, X2, Y2),
fail.
put_mark(_).
write_mark(x, X1, Y1, X2, Y2) :-
%line(X1, Y1, X2, Y2),
%line(X2, Y1, X1, Y2).
draw_bitmap(X1, Y1, G_B, _, _).
write_mark(o, X1, Y1, X2, Y2) :-
%ellipse(X1, Y1, X2, Y2).
draw_bitmap(X1, Y1, G_A, _, _).
win_func2(paint) :-
pen(2, rgb(0, 0, 0)), % black
draw_bitmap(0, 0, G_BA, _, _),
line(30, 30, 30, 510),
line(30, 510, 510, 510),
line(510, 510, 510, 30),
line(510, 30, 30, 30),
line(70, 30, 70, 510),
line(110, 30, 110, 510),
line(150, 30, 150, 510),
line(190, 30, 190, 510),
line(230, 30, 230, 510),
line(270, 30, 270, 510),
line(310, 30, 310, 510),
line(350, 30, 350, 510),
line(390, 30, 390, 510),
line(430, 30, 430, 510),
line(470, 30, 470, 510),
line(30, 70, 510, 70),
line(30, 110, 510, 110),
line(30, 150, 510, 150),
line(30, 190, 510, 190),
line(30, 230, 510, 230),
line(30, 270, 510, 270),
line(30, 310, 510, 310),
line(30, 350, 510, 350),
line(30, 390, 510, 390),
line(30, 430, 510, 430),
line(30, 470, 510, 470),
pen(3, rgb(255, 0, 0)), % red
put_mark(x),
pen(3, rgb(0, 0, 255)), % blue
put_mark(o),
fail.
win_func2(mouse_click(X,
Y)) :-
lose_flag(false),
X>30, Y>30,
X<510, Y<510,
X1 is (X - 30)//40,
Y1 is (Y - 30)//40,
pos(Current_Pos),
member(Current_Pos, L, Y1),
member(L, f, X1),
!,
replace(L2, L, x, X1),
replace(Current_Pos2, Current_Pos, L2, Y1),
set(pos(Current_Pos2)),
not(win_func2(paint)),
think(Current_Pos2).
win_func2(mouse_click(X, Y)) :-
beep.
think(Pos) :-
victory(x, Pos), !,
set(lose_flag(true)),
window(G_win,_,win_win(_),"Congrat!!!",400,300,420,300),
beep("Sound//2.wav").
win_win(paint):-
draw_bitmap(0,0,G_WIN,_,_),
button(_,_,ulang_game(_),"OK",50,170,100,40).
think(Pos) :-
try_to_win(Pos), !.
think(Pos) :-
retractall(last_good_move(_)), try_nolose(Pos).
think(_) :-
last_good_move(Sit2), !,
set(pos(Sit2)),
not(win_func2(paint)).
think(Pos) :-
move(o, Pos, Sit2),
nolose(x, Sit2, 0), !, % Tries to make the lose farther
set(pos(Sit2)),
not(win_func2(paint)).
think(Pos) :-
move(o, Pos, Sit2),
set(pos(Sit2)),
not(win_func2(paint)).
try_nolose(Pos) :-
move(o, Pos, Sit2),
nolose_deep(Deep),
nolose(x, Sit2, Deep),
set(last_good_move(Sit2)),
random(5)=:=0, !, fail. % this makes the game more interesting
try_to_win(Pos) :-
move(o, Pos, Sit2),
is_it_win(Sit2).
is_it_win(Sit2) :-
victory(o, Sit2),
set(pos(Sit2)),
not(win_func2(paint)),
set(lose_flag(true)),
window(G_lost,_,win_lost(_),"Sorry!!!",400,300,420,340),
beep("Sound//2.wav").
win_lost(paint):-
draw_bitmap(0,0,G_Lost,_,_),
button(_,_,ulang_game(_),"OK",63,220,100,40).
is_it_win(Sit2) :-
win_deep(Deep),
win(x, Sit2, Deep),
set(pos(Sit2)),
not(win_func2(paint)),
message("Advice","Give up. Don't lose my
time.",i).
member([Element, _, _, _, _, _, _, _, _, _, _, _], Element, 0).
member([_, Element, _, _, _, _, _, _, _, _, _, _], Element, 1).
member([_, _, Element, _, _, _, _, _, _, _, _, _], Element, 2).
member([_, _, _, Element, _, _, _, _, _, _, _, _], Element, 3).
member([_, _, _, _, Element, _, _, _, _, _, _, _], Element, 4).
member([_, _, _, _, _, Element, _, _, _, _, _, _], Element, 5).
member([_, _, _, _, _, _, Element, _, _, _, _, _], Element, 6).
member([_, _, _, _, _, _, _, Element, _, _, _, _], Element, 7).
member([_, _, _, _, _, _, _, _, Element, _, _, _], Element, 8).
member([_, _, _, _, _, _, _, _, _, Element, _, _], Element, 9).
member([_, _, _, _, _, _, _, _, _, _, Element, _], Element, 10).
member([_, _, _, _, _, _, _, _, _, _, _, Element], Element, 11).
replace([Element, A, B, C, D, E, F, G, H, I, J, K], [_, A, B, C, D, E, F, G, H, I, J, K], Element, 0).
replace([A, Element, B, C, D, E, F, G, H, I, J, K], [A, _, B, C, D, E, F, G, H, I, J, K], Element, 1).
replace([A, B, Element, C, D, E, F, G, H, I, J, K], [A, B, _, C, D, E, F, G, H, I, J, K], Element, 2).
replace([A, B, C, Element, D, E, F, G, H, I, J, K], [A, B, C, _, D, E, F, G, H, I, J, K], Element, 3).
replace([A, B, C, D, Element, E, F, G, H, I, J, K], [A, B, C, D, _, E, F, G, H, I, J, K], Element, 4).
replace([A, B, C, D, E, Element, F, G, H, I, J, K], [A, B, C, D, E, _, F, G, H, I, J, K], Element, 5).
replace([A, B, C, D, E, F, Element, G, H, I, J, K], [A, B, C, D, E, F, _, G, H, I, J, K], Element, 6).
replace([A, B, C, D, E, F, G, Element, H, I, J, K], [A, B, C, D, E, F, G, _, H, I, J, K], Element, 7).
replace([A, B, C, D, E, F, G, H, Element, I, J, K], [A, B, C, D, E, F, G, H, _, I, J, K], Element, 8).
replace([A, B, C, D, E, F, G, H, I, Element, J, K], [A, B, C, D, E, F, G, H, I, _, J, K], Element, 9).
replace([A, B, C, D, E, F, G, H, I, J, Element, K], [A, B, C, D, E, F, G, H, I, J, _, K], Element, 10).
replace([A, B, C, D, E, F, G, H, I, J, K, Element], [A, B, C, D, E, F, G, H, I, J, K, _], Element, 11).
win( o, Sit, Deep) :- move(o, Sit, Sit2), win(x, Sit2, Deep).
win( x, Sit, _) :- victory(o, Sit).
win( x, Sit, 0) :- !, fail.
win( x, Sit, Deep) :- Deep1 is Deep - 1, not(nowin( x, Sit, Deep1)).
nowin(x, Sit, _) :- not(move(Sit)). % the last move
belongs to O
nowin(x, Sit, Deep) :- move(x, Sit, Sit2), nowin(o, Sit2, Deep).
nowin( o, Sit, _) :- victory(x, Sit).
nowin(o, Sit, Deep) :- not(win(o, Sit, Deep)).
lose( x, Sit, Deep) :- move(x, Sit, Sit2), lose(o, Sit2, Deep).
lose( o, Sit, _) :- victory(x, Sit).
lose( o, Sit, 0) :- !, fail.
lose( o, Sit, Deep) :- Deep1 is Deep - 1, not(nolose( o, Sit, Deep1)).
nolose(o, Sit, Deep) :- move(o, Sit, Sit2), nolose(x, Sit2, Deep).
nolose( x, Sit, _) :- victory(o, Sit).
nolose(x, Sit, _) :- not(move(Sit)). % the last move
belongs to O
nolose(x, Sit, Deep) :- not(lose(x, Sit, Deep)).
move(P, Sit, Sit2) :-
member(Sit, L, Y),
member(L, f, X),
replace(L2, L, P, X),
replace(Sit2, Sit, L2, Y).
move(Sit) :-
member(Sit, L, _),
member(L, f, _).
0 komentar:
Posting Komentar