Monthly Archives: June 2016

Pengantar Teknologi Game: Serigala VS Domba

Game Serigala VS Domba ini adalah pengembangan dari game tic tac toe 4×4 yang terdapat pada strawberry prolog. Pada game tic tac toe 4 X 4 hanya terdiri dari 4 baris dan 4 kolom, tetapi dalam pengembangannya game ini berubah menjadi tic tac toe 9 X 9 yang terdiri dari 9 baris dan 9 kolom. Game ini mempunyai tujuan yaitu untuk mengalahkan musuh dengan dengan cara user yang kita kendalikan harus bisa terlebih dahulu mengisi setiap kotak yang ada pada game secara berurutan baik secara horizontal, vertical, ataupun diagonal.

Pada tampilan game terdapat splash screen, menu dan button. Saat ketika ingin memulai game akan terlebih dahulu muncul tampilan splash screen seperti loading pada window.

Setelah loading selesai akan masuk ke window menu yang berisikan button Mulai dan About, di tampilan ini jika ingin mulai permainan silakan pilih button mulai. Dan jika ingin mencari profil pembuat silakan pilih About. Jika memilih mulai akan langsung masuk ke tampilan game, ditampilan game pemain bisa langsung memainkan gamenya tetapi jika tidak tahu cara bermainnya silakan pilih menu help. Menu help akan memberitahukan user cara bermain game Serigala Vs Domba. Selajutnya silakan memainkan gamenya, jika kita kalah dalam memainkan game tersebut akan muncul sebuah tampilan bahwa anda user telah kalah, tetapi jika ingin mencoba lagi silakan memilih New Game untuk memulai permainan dari awal kembali.

Tampilan Pada Saat Splash Screen

game1

Tampilan Menu awal

game2

tampilan game saat komputer menang

game3

saat game dengan hasil imbang

game4

Listing Program

win_deep(0). % semakin besar kedua nilai ini semakin pintar AI%
nolose_deep(0).
?-
%=========Deklarasi Gambar==========%
G_awal is bitmap_image(“purnama2.bmp”,_),
G_background is bitmap_image(“bulan.bmp”,_),
G_x is bitmap_image(“serigala4.bmp”,_),
G_o is bitmap_image(“domba.bmp”,_),
%===================Splash Screen====================
window(G_load,_,win_awal(_),”LOADING…”,400,100,700,400).
win_awal(init):-
G_batas=0,
G_loading=10,
G_waktu is set_timer(_,0.050,time_func).
8 | P a g e
time_func(end):-
(G_loading<50->
line(50,50,G_loading,50)
else
line(100,50,G_loading,50)),
font(20,55,”Arial”),
text_out(130,70,print(“PLEASE WAIT…”)),
G_loading := G_loading + 10,
G_batas := G_batas + 1,
(G_batas>=68->
close_window(G_load),
window(G_menu,_,win_kedua(_),”Serigala VS Domba”,400,150,580,450)).
%======================Menu Awal======================
win_kedua(paint):-
draw_bitmap(0,0,G_awal,_,_),
button(_,_,new_game(_),”Mulai”,50,100,100,40),
button(_,_,about(_),”About”,50,200,100,40).
new_game(press):-
close_window(G_menu),
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]])),
set(lose_flag(false)),
brush(system_color(window)),
window( _, _, win_func(_), “Serigala VS Domba”, 30, 90, 700, 700).
%=======Window Button Main==========%
win_func(init) :-
menu(normal,_,_,menu_new(_), “&New Game”),
menu(normal,_,_,menu_help(_),”Help”),
menu(normal,_,_,about(_),”About”),
menu(normal,_,_,menu_exit(_), “&Exit”).
put_mark(Mark) :-
pos(Current_Pos),
member(Current_Pos, L, Y),
member(L, Mark, X),
X1 is 40 + 60*X, Y1 is 40 + 60*Y, X2 is X1 + 40, Y2 is Y1 +40,
write_mark(Mark, X1, Y1, X2, Y2),
fail.
put_mark(_).
9 | P a g e
write_mark(x, X1, Y1, X2, Y2) :-
draw_bitmap(X1, Y1,G_o, _, _).
write_mark(o, X1, Y1, X2, Y2) :-
draw_bitmap(X1, Y1,G_x, _, _).
%=======window papan permainan======%
win_func(paint) :-
draw_bitmap(0,0,G_background,_,_),
pen(4, rgb(1,2,3)), %green
%garis horizontal
line(30, 30, 570, 30),
line(30, 90, 570, 90),
line(30, 150, 570, 150),
line(30, 210, 570, 210),
line(30, 270, 570, 270),
line(30, 330, 570, 330),
line(30, 390, 570, 390),
line(30, 450, 570, 450),
line(30, 510, 570, 510),
line(30, 570, 570, 570),
%garis vertikal
line(30, 30, 30, 570),
line(90, 30, 90, 570),
line(150, 30, 150, 570),
line(210, 30, 210, 570),
line(270, 30, 270, 570),
line(330, 30, 330, 570),
line(390, 30, 390, 570),
line(450, 30, 450, 570),
line(510, 30, 510, 570),
line(570, 30, 570, 570),
put_mark(x),
put_mark(o),
fail.
win_func(mouse_click(X, Y)) :-
lose_flag(false),
10 | P a g e
X>30, Y>30,
X<570, Y<570,
X1 is (X – 30)//60,
Y1 is (Y – 30)//60,
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_func(paint)),
think(Current_Pos2).
win_func(mouse_click(X, Y)) :-
beep.
think(Pos) :-
victory(x, Pos), !,
set(lose_flag(true)),
message(“You win”,”Congrats”,!).
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_func(paint)).
think(Pos) :-
message(“Nice”, “Keep Spirit!!”, n),
move(o, Pos, Sit2),
nolose(x, Sit2, 0), !, % Tries to make the lose farther
set(pos(Sit2)),
not(win_func(paint)).
think(Pos) :-
move(o, Pos, Sit2),
set(pos(Sit2)),
not(win_func(paint)).
try_nolose(Pos) :-
move(o, Pos, Sit2),
nolose_deep(Deep),
nolose(x, Sit2, Deep),
set(last_good_move(Sit2)),
11 | P a g e
random(3)=:=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_func(paint)),
set(lose_flag(true)),
beep(“suara ketawa.wav”),
message(“Sorry”,”You lose!”,s).
is_it_win(Sit2) :-
win_deep(Deep),
win(x, Sit2, Deep),
set(pos(Sit2)),
not(win_func(paint)),
message(“Please”,”Give up”,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).
replace([Element, A, B, C, D, E, F, G, H], [_, A, B, C, D, E, F, G, H], Element, 0).
replace([A, Element, B, C, D, E, F, G, H], [A, _, B, C, D, E, F, G, H], Element, 1).
replace([A, B, Element, C, D, E, F, G, H], [A, B, _, C, D, E, F, G, H], Element, 2).
replace([A, B, C, Element, D, E, F, G, H], [A, B, C, _, D, E, F, G, H], Element, 3).
replace([A, B, C, D, Element, E, F, G, H], [A, B, C, D, _, E, F, G, H], Element, 4).
replace([A, B, C, D, E, Element, F, G, H], [A, B, C, D, E, _, F, G, H], Element, 5).
replace([A, B, C, D, E, F, Element, G, H], [A, B, C, D, E, F, _, G, H], Element, 6).
replace([A, B, C, D, E, F, G, Element, H], [A, B, C, D, E, F, G, _, H], Element, 7).
12 | P a g e
replace([A, B, C, D, E, F, G, H, Element], [A, B, C, D, E, F, G, H, _], Element, 8).
%======kondisi menang horizontal======%
victory( Who, [[Who, Who, Who, Who, Who, Who, Who, Who, Who], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _]]).
victory( Who, [[_, _, _, _, _, _, _, _, _], [Who, Who, Who, Who, Who, Who, Who, Who, Who], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _]]).
victory( Who, [[_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [Who, Who, Who, Who, Who, Who, Who, Who, Who], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _]]).
victory( Who, [[_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [Who, Who, Who, Who, Who, Who, Who, Who, Who], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _]]).
victory( Who, [[_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [Who, Who, Who, Who, Who, Who, Who, Who, Who], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _]]).
victory( Who, [[_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [Who, Who, Who, Who, Who, Who, Who, Who, Who], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _]]).
victory( Who, [[_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [Who, Who, Who, Who, Who, Who, Who, Who, Who], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _]]).
victory( Who, [[_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [Who, Who, Who, Who, Who, Who, Who, Who, Who], [_, _, _, _, _, _, _, _, _]]).
13 | P a g e
victory( Who, [[_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [Who, Who, Who, Who, Who, Who, Who, Who, Who]]).
%=========kondisi menang vertikal=======%
victory( Who, [[Who, _, _, _, _, _, _, _, _], [Who, _, _, _, _, _, _, _, _], [Who, _, _, _, _, _, _, _, _], [Who, _, _, _, _, _, _, _, _], [Who, _, _, _, _, _, _, _, _], [Who, _, _, _, _, _, _, _, _], [Who, _, _, _, _, _, _, _, _], [Who, _, _, _, _, _, _, _, _], [Who, _, _, _, _, _, _, _, _]]).
victory( Who, [[_, Who, _, _, _, _, _, _, _], [_, Who, _, _, _, _, _, _, _], [_, Who, _, _, _, _, _, _, _], [_, Who, _, _, _, _, _, _, _], [_, Who, _, _, _, _, _, _, _], [_, Who, _, _, _, _, _, _, _], [_, Who, _, _, _, _, _, _, _], [_, Who, _, _, _, _, _, _, _], [_, Who, _, _, _, _, _, _, _]]).
victory( Who, [[_, _, Who, _, _, _, _, _, _], [_, _, Who, _, _, _, _, _, _], [_, _, Who, _, _, _, _, _, _], [_, _, Who, _, _, _, _, _, _], [_, _, Who, _, _, _, _, _, _], [_, _, Who, _, _, _, _, _, _], [_, _, Who, _, _, _, _, _, _], [_, _, Who, _, _, _, _, _, _], [_, _, Who, _, _, _, _, _, _]]).
victory( Who, [[_, _, _, Who, _, _, _, _, _], [_, _, _, Who, _, _, _, _, _], [_, _, _, Who, _, _, _, _, _], [_, _, _, Who, _, _, _, _, _], [_, _, _, Who, _, _, _, _, _], [_, _, _, Who, _, _, _, _, _], [_, _, _, Who, _, _, _, _, _], [_, _, _, Who, _, _, _, _, _], [_, _, _, Who, _, _, _, _, _]]).
victory( Who, [[_, _, _, _, Who, _, _, _, _], [_, _, _, _, Who, _, _, _, _], [_, _, _, _, Who, _, _, _, _], [_, _, _, _, Who, _, _, _, _], [_, _, _, _, Who, _, _, _, _], [_, _, _, _, Who, _, _, _, _], [_, _, _, _, Who, _, _, _, _], [_, _, _, _, Who, _, _, _, _], [_, _, _, _, Who, _, _, _, _]]).
victory( Who, [[_, _, _, _, _, Who, _, _, _], [_, _, _, _, _, Who, _, _, _], [_, _, _, _, _, Who, _, _, _], [_, _, _, _, _, Who, _, _, _], [_, _, _, _, _, Who, _, _, _], [_, _, _, _, _, Who, _, _, _], [_, _, _, _, _, Who, _, _, _], [_, _, _, _, _, Who, _, _, _], [_, _, _, _, _, Who, _, _, _]]).
victory( Who, [[_, _, _, _, _, _, Who, _, _], [_, _, _, _, _, _, Who, _, _], [_, _, _, _, _, _, Who, _, _], [_, _, _, _, _, _, Who, _, _], [_, _, _, _, _, _, Who, _, _], [_, _, _, _, _, _, Who, _, _], [_, _, _, _, _, _, Who, _, _], [_, _, _, _, _, _, Who, _, _], [_, _, _, _, _, _, Who, _, _]]).
victory( Who, [[_, _, _, _, _, _, _, Who, _], [_, _, _, _, _, _, _, Who, _], [_, _, _, _, _, _, _, Who, _], [_, _, _, _, _, _, _, Who, _], [_, _, _, _, _, _, _, Who, _], [_, _, _, _, _, _, _, Who, _], [_, _, _, _, _, _, _, Who, _], [_, _, _, _, _, _, _, Who, _], [_, _, _, _, _, _, _, Who, _]]).
14 | P a g e
victory( Who, [[_, _, _, _, _, _, _, _, Who], [_, _, _, _, _, _, _, _, Who], [_, _, _, _, _, _, _, _, Who], [_, _, _, _, _, _, _, _, Who], [_, _, _, _, _, _, _, _, Who], [_, _, _, _, _, _, _, _, Who], [_, _, _, _, _, _, _, _, Who], [_, _, _, _, _, _, _, _, Who], [_, _, _, _, _, _, _, _, Who]]).
victory( Who, [[Who, _, _, _, _, _, _, _, _], [_, Who, _, _, _, _, _, _, _], [_, _, Who, _, _, _, _, _, _], [_, _, _, Who, _, _, _, _, _], [_, _, _, _, Who, _, _, _, _], [_, _, _, _, _, Who, _, _, _], [_, _, _, _, _, _, Who, _, _], [_, _, _, _, _, _, _, Who, _], [_, _, _, _, _, _, _, _, Who]]).
victory( Who, [[_, _, _, _, _, _, _, _, Who], [_, _, _, _, _, _, _, Who, _], [_, _, _, _, _, _, Who, _, _], [_, _, _, _, _, Who, _, _, _], [_, _, _, _, Who, _, _, _, _], [_, _, _, Who, _, _, _, _, _], [_, _, Who, _, _, _, _, _, _], [_, Who, _, _, _, _, _, _, _], [Who, _, _, _, _, _, _, _, _]]).
victory( Who, [[_, _, Who, _, _, _, _, _, _], [_, _, _, Who, _, _, _, _, _], [_, _, _, _, Who, _, _, _, _], [_, _, _, _, _, Who, _, _, _], [_, _, _, _, _, _, Who, _, _], [_, _, _, _, _, _, _, Who, _], [_, _, _, _, _, _, _, _, Who], [Who, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _]]).
victory( Who, [[_, Who, _, _, _, _, _, _, _], [_, _, Who, _, _, _, _, _, _], [_, _, _, Who, _, _, _, _, _], [_, _, _, _, Who, _, _, _, _], [_, _, _, _, _, Who, _, _, _], [_, _, _, _, _, _, Who, _, _], [_, _, _, _, _, _, _, Who, _], [_, _, _, _, _, _, _, _, Who], [_, _, _, _, _, _, _, _, _]]).
victory( Who, [[_, _, _, _, _, _, _, _, _], [Who, _, _, _, _, _, _, _, _], [_, Who, _, _, _, _, _, _, _], [_, _, Who, _, _, _, _, _, _], [_, _, _, Who, _, _, _, _, _], [_, _, _, _, Who, _, _, _, _], [_, _, _, _, _, Who, _, _, _], [_, _, _, _, _, _, Who, _, _], [_, _, _, _, _, _, _, Who, _]]).
victory( Who, [[_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, Who], [_, _, _, _, _, _, _, Who, _], [_, _, _, _, _, _, Who, _, _], [_, _, _, _, _, Who, _, _, _], [_, _, _, _, Who, _, _, _, _], [_, _, _, Who, _, _, _, _, _], [_, _, Who, _, _, _, _, _, _], [_, Who, _, _, _, _, _, _, _]]).
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).
15 | P a g e
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, _).
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]])),
set(lose_flag(false)),
update_window(_).
about(press):-
shell_execute(“index.html”).
menu_help(press):-
shell_execute(“carabermain.txt”).
%===========Window Exit=============%
menu_exit(press) :-
close_window(_).
win_func(close):- %—-> isi menu keluar
ask.
ask:-
yes_no( “Exit”,”udahan boy?”, ?),
!,message(“Yes”, “cupu lu”,!),
end.
16 | P a g e
ask:-
message(“No”, “Ayo lah jangan nyerah”, s).

 

Advertisements