• DOTA ALL STAR CHESS PROLOG

    pada kali ini saya mengembangkan sebuah game yang ada di strawberry prolog dimana game ini saya buat seunik mungkin agar player bisa bermain dengan menyenakngkan.

    berikut script programnya :
    %============================================
    %|| DOTA ALL STAR BY : CHANDRA_WP :D        ||
    %============================================
    %|| UNIVERSITAS GUNADARMA PROLOG PROGRAMMING||
    %============================================

    %mulai permainan, deklarasi pengambilan gambar
    ?-
      G_Deep=3, %G_Deep>0
      G_I=0,
      G_squareW is bitmap_image("chess_pic\\squareW.bmp",_),
      G_squareB is bitmap_image("chess_pic\\squareB.bmp",_),
      G_PawnW1 is bitmap_image("chess_pic\\PawnW1.bmp",_),
      G_PawnW2 is bitmap_image("chess_pic\\PawnW2.bmp",_),
      G_PawnB1 is bitmap_image("chess_pic\\PawnB1.bmp",_),
      G_PawnB2 is bitmap_image("chess_pic\\PawnB2.bmp",_),
      G_KingW1 is bitmap_image("chess_pic\\KingW1.bmp",_),
      G_KingW2 is bitmap_image("chess_pic\\KingW2.bmp",_),
      G_KingB1 is bitmap_image("chess_pic\\KingB1.bmp",_),
      G_KingB2 is bitmap_image("chess_pic\\KingB2.bmp",_),
      G_RookW1 is bitmap_image("chess_pic\\RookW1.bmp",_),
      G_RookW2 is bitmap_image("chess_pic\\RookW2.bmp",_),
      G_RookB1 is bitmap_image("chess_pic\\RookB1.bmp",_),
      G_RookB2 is bitmap_image("chess_pic\\RookB2.bmp",_),
      G_opening is bitmap_image("chess_pic\\dota2.bmp",_),
      window(_,_,chess_func(_),"BLACK N WHITE THE DOTA ALL STAR",100,100,400,450).
    chess_func(paint):-
      draw_bitmap(0,0,G_opening,_,_),
      beep("music\\Firstblood.wav"),
      fail.

    %++++++++++++++MENU++++++++++++++++++++++
    chess_func(init):-
        menu(pop_up, _, _, menu_new(_), "&New Game"),
        menu(normal, _, _, menu_about(_), "&About"),
        menu(normal, _, _, menu_help(_), "&Help"),
        menu(normal, _, _, menu_exit(_), "&Exit").
    %======================================================
    %new game menu
    menu_new(init):-
    menu(normal, _, _, menu_Killing_Spree(_), "&Killing_Spree"),
    menu(normal, _, _, menu_Dominating(_), "&Dominating"),
    menu(normal, _, _, menu_MegaKill(_), "&MegaKill"),
    menu(normal, _, _, menu_GodLike(_), "&GodLike").
    % menu pop up game
    menu_Killing_Spree(press) :-
     set(pos([[pb,f,kb,f,pb],
        [f,rb,rb,rb,f],
        [f,f,f,f,f],
        [f,rw,rw,rw,f],
        [pw,f,kw,f,pw]])),
    beep("music\\Killing_Spree.wav"),
    beep("music\\double_kill.wav"),
    beep("music\\triple_kill.wav"),
    beep("music\\ultrakill.wav"),
    beep("music\\Rampage.wav"),
     update_window(_).

    menu_Dominating(press) :-
     set(pos([[f,f,kb,f,f],
        [f,rb,f,rb,f],
        [f,f,f,f,f],
        [f,rw,f,rw,f],
        [f,f,kw,f,f]])),
    beep("music\\Dominating.wav"),
    beep("music\\double_kill.wav"),
    beep("music\\triple_kill.wav"),
    beep("music\\ultrakill.wav"),
    beep("music\\Rampage.wav"),
     update_window(_).

    menu_MegaKill(press) :-
     set(pos([[f,f,kb,f,f],
        [pb,pb,pb,pb,pb],
        [f,f,f,f,f],
        [pw,pw,pw,pw,pw],
        [f,f,kw,f,f]])),
    beep("music\\MegaKill.wav"),
    beep("music\\double_kill.wav"),
    beep("music\\triple_kill.wav"),
    beep("music\\ultrakill.wav"),
    beep("music\\Rampage.wav"),
     update_window(_).

    menu_GodLike(press) :-
     set(pos([[f,f,f,rb,kb],
        [f,f,f,f,rb],
        [f,f,f,f,f],
        [rw,f,f,f,f],
        [kw,rw,f,f,f]])),
    beep("music\\GodLike.wav"),
    beep("music\\double_kill.wav"),
    beep("music\\triple_kill.wav"),
    beep("music\\ultrakill.wav"),
    beep("music\\Rampage.wav"),
     update_window(_).

    %about menu
    menu_about(press) :-
    beep("music\\Unstoppable.wav"),
      message("developer programing dota chess by ","  
    chandra widya permana\n
    npm : 59410189\n
    kelas : 3ia05\n
    Universitas Gunadarma 2012", i),
    beep("music\\HolyShit.wav").
    %help menu
    menu_help(press) :-
    beep("music\\Unstoppable.wav"),
      message("cara bermain","permainan ini hanya bisa duel dengan 1 user dan 1 AI.\n
    terus game ini berbeda dengan catur yang biasanya\n
    karena game ini telah dimodifikasi sebelumnya\n
    sehingga game ini yang biasanya catur dengan bidak 8x8\n
    sekarang dirubah dengan 5x5, masih ada lagi\n
    dota all star chess ini jg mempunyai 4 jenis tipe permainan\n
    setiap permainan berbeda beda posisi heronya\n
    catur dota ini heronya di rubah yaitu hanya ada benteng, pion, dan king \n
    dan tidak ada ratu didalam catur ini\n
    melainkan tetap raja yang mendominasi permainan\n
    aturan bermain apabila musuh atau user sudah tidak dapat berjalan lagi\n
    maka dia yang kalah :D\n", i),
    beep("music\\Ownage.wav").


    %exit menu
    menu_exit(press) :-
    beep("music\\Unstoppable.wav"),
     (yes_no("please wait","what? udahan ni maenya??", ?)),
      beep("music\\Firstblood.wav"),
    close_window(_).

    %=++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    chess_func(paint):-
        pos(Pos),
        mem(Row,Pos,J),
        mem(Fig,Row,I),
        draw_fig(Fig,I,J),
        fail.

    chess_func(mouse_click(X,Y)):-
        I is X//50,J is Y//50,I>0,J>0,I=<5,J=<5,
        pos(Pos),
        mem(Row,Pos,J),
        mem(Fig,Row,I),
        (G_I=0 ->
            Fig=[_|w],
            G_Fig:=Fig,
            G_I:=I,
            G_J:=J,
            clean_field(I, J)
        else (can_move(G_Fig,G_I,G_J,Pos,I,J,_)->                       
            draw_fig(G_Fig,I,J),
            move(G_I,G_J,Pos,I,J,Pos2),
            G_I:=0,
            set_text("...", _),
            play(b,w,Pos2,G_Deep,Max),
                write(Max),nl,
            clean_field(G_I1, G_J1),
            move(G_I1,G_J1,Pos2,G_I2,G_J2,Pos3),
            mem(Row2,Pos3,G_J2),
            mem(Fig2,Row2,G_I2),
            draw_fig(Fig2,G_I2,G_J2),
                write(pos(Pos3)),nl,
            set(pos(Pos3)),
            set_text("DOTA ALL STAR!!!", _),
            beep("music\\Combowhore.wav")

        else
            draw_fig(G_Fig,G_I,G_J),
            G_I:=0
        )),

        fail.

    play(C1,C2,Pos,0,Max):-
        Max:= 0,
        mem(Row,Pos,J),
        mem([Fig|C1],Row,I),
        can_move([Fig|C1],I,J,Pos,_,_,[F|C2]),
        val([F|C2],Val),
        (Max<Val->
            Max:=Val
        ),
        fail.
    play(C1,C2,Pos,Deep,Max):-
        Deep>0,
        Deep1 is Deep- 1,
        Max:= -200,
        mem(Row,Pos,J),
        mem([Fig|C1],Row,I),
        can_move([Fig|C1],I,J,Pos,X,Y,Fig2),
        move(I,J,Pos,X,Y,Pos2),
        play(C2,C1,Pos2,Deep1,Max2),
        val(Fig2,Val),
        (Max<Val-Max2->
            Max:=Val-Max2,
            (G_Deep=Deep->
                G_I1:=I,G_J1:=J,G_I2:=X,G_J2:=Y
            )
        ),
        fail.
    play(_,_,_,_,_).

    val(f,0).
    val([p|_],1).
    val([h|_],3).
    val([b|_],3).
    val([r|_],5).   
    val([q|_],10).
    val([k|_],100).

    %posisi hero dota

    pos([[pb,f,kb,f,pb],
        [f,rb,rb,rb,f],
        [f,f,f,f,f],
        [f,rw,rw,rw,f],
        [pw,f,kw,f,pw]]).

    clean_field(I, J):-
      draw_fig(f,I,J).

    draw_fig(Fig,I,J):-
      N is 1+ (I+J) mod 2,
      fig(Fig, N, Bitmap),
      draw_bitmap(I*50,J*50,Bitmap,_,_).

    %variabel hero dota yang akan di panggil

    fig(f, 1, G_squareW).
    fig(pb, 1, G_PawnB1).
    fig(pw, 1, G_PawnW1).
    fig(kb, 1, G_KingB1).
    fig(kw, 1, G_KingW1).
    fig(rb, 1, G_RookB1).
    fig(rw, 1, G_RookW1).
    fig(f, 2, G_squareB).
    fig(pb, 2, G_PawnB2).
    fig(pw, 2, G_PawnW2).
    fig(kb, 2, G_KingB2).
    fig(kw, 2, G_KingW2).
    fig(rb, 2, G_RookB2).
    fig(rw, 2, G_RookW2).

    mem(E,[E,_,_,_,_],1).
    mem(E,[_,E,_,_,_],2).
    mem(E,[_,_,E,_,_],3).
    mem(E,[_,_,_,E,_],4).
    mem(E,[_,_,_,_,E],5).

    replace(E,[_,A,B,C,D],[E,A,B,C,D],1).
    replace(E,[A,_,B,C,D],[A,E,B,C,D],2).
    replace(E,[A,B,_,C,D],[A,B,E,C,D],3).
    replace(E,[A,B,C,_,D],[A,B,C,E,D],4).
    replace(E,[A,B,C,D,_],[A,B,C,D,E],5).




    move(I1,J1,Pos1,I2,J2,Pos2):-
        mem(Row1,Pos1,J1),
        mem(Fig,Row1,I1),
        replace(f,Row1,Row2,I1),
        replace(Row2,Pos1,Pos1a,J1),
        mem(Row3,Pos1a,J2),
        replace(Fig,Row3,Row4,I2),
        replace(Row4,Pos1a,Pos2,J2).


    %logika cara berjalan hero dota

        %king
    can_move([k|Color], I1, J1, Pos, I2, J2,Fig):-
        (I2 is I1+ 1; I2 is I1- 1; I2= I1),
          (J2 is J1+ 1; J2 is J1- 1; J2= J1),
        not(I1=I2, J1=J2),
        mem(Row, Pos, J2),
        mem(Fig, Row, I2),
        not(Fig=[_|Color]).


        %pawn
    can_move(pw, I, J1, Pos, I, J2,f):-
        J2 is J1- 1,
        mem(Row, Pos, J2),
        mem(f, Row, I).

        %pawn
    can_move(pb, I, J1, Pos, I, J2,f):-
        J2 is J1+ 1,
        mem(Row, Pos, J2),
        mem(f, Row, I).

        %pawn
    can_move(pw, I1, J1, Pos, I2, J2,[F|b]):-
        (I2 is I1+ 1; I2 is I1- 1), J2 is J1- 1,
        mem(Row, Pos, J2),
        mem([F|b], Row, I2).

        %pawn
    can_move(pb, I1, J1, Pos, I2, J2,[F|w]):-
        (I2 is I1+ 1; I2 is I1- 1), J2 is J1+ 1,
        mem(Row, Pos, J2),
        mem([F|w], Row, I2).

        %rook
    can_move([r|Color],I1,J1,Pos,I2,J2,Fig):-
        move_up(Color,I1,J1,Pos,I2,J2,Fig);
        move_down(Color,I1,J1,Pos,I2,J2,Fig);
        move_left(Color,I1,J1,Pos,I2,J2,Fig);
        move_right(Color,I1,J1,Pos,I2,J2,Fig).



    move_up(Color,I,J1,Pos,I,J2,Fig2):-
        J is J1- 1,
        mem(Row,Pos,J),
        mem(Fig,Row,I),
        (Fig=f->
            (J2=J, Fig=Fig2;move_up(Color,I,J,Pos,I,J2,Fig2))
        else (Fig = [_|Color]->
            fail
        else
            J2=J, Fig=Fig2
        )).

    move_down(Color,I,J1,Pos,I,J2,Fig2):-
        J is J1+1,
        mem(Row,Pos,J),
        mem(Fig,Row,I),
        (Fig=f ->
            (J2=J, Fig=Fig2;move_down(Color,I,J,Pos,I,J2,Fig2))
        else (Fig = [_|Color]->
            fail
        else
            J2=J, Fig=Fig2
        )).

    move_left(Color,I1,J,Pos,I2,J,Fig2):-
        I is I1- 1,
        mem(Row,Pos,J),
        mem(Fig,Row,I),
        (Fig=f ->
            (I2=I, Fig=Fig2;move_left(Color,I,J,Pos,I2,J,Fig2))
        else (Fig = [_|Color]->
            fail
        else
            I2=I, Fig=Fig2
        )).
       
    move_right(Color,I1,J,Pos,I2,J,Fig2):-
        I is I1+1,
        mem(Row,Pos,J),
        mem(Fig,Row,I),
        (Fig=f ->
            (I2=I, Fig=Fig2;move_right(Color,I,J,Pos,I2,J,Fig2))
        else (Fig = [_|Color]->
            fail
        else
            I2=I, Fig=Fig2
        )).
       
           
    move_up_left(Color,I1,J1,Pos,I2,J2,Fig2):-
        I is I1- 1,
        J is J1- 1,
        mem(Row,Pos,J),
        mem(Fig,Row,I),
        (Fig=f->
            (I2=I,J2=J, Fig=Fig2;move_up_left(Color,I,J,Pos,I2,J2,Fig2) )
        else (Fig = [_|Color]->
            fail
        else

            I2=I,J2=J, Fig=Fig2
        )).

    move_down_left(Color,I1,J1,Pos,I2,J2,Fig2):-
        I is I1- 1,
        J is J1+1,
        mem(Row,Pos,J),
        mem(Fig,Row,I),
        (Fig=f->
            (I2=I,J2=J, Fig=Fig2; move_down_left(Color,I,J,Pos,I2,J2,Fig2) )
        else (Fig = [_|Color]->
            fail
        else

            I2=I,J2=J, Fig=Fig2
        )).

    move_up_right(Color,I1,J12,J2,Fig2):-
        I is I1+1,
        J is J1- 1,
        mem(Row,Pos,J),
        mem(Fig,Row,I),
        (Fig=f->
            (I2=I,J2=J, Fig=Fig2; move_up_right(Color,I,J,Pos,I2,J2,Fig2) )
        else (Fig= [_|Color]->
            fail
        else
            I2=I,J2=J, Fig=Fig2
        )).

    move_down_right(Color,I1,J1,Pos,I2,J2,Fig2):-
        I is I1+1,
        J is J1+1,
        mem(Row,Pos,J),
        mem(Fig,Row,I),
        (Fig=f->
            (I2=I,J2=J, Fig=Fig2;move_down_right(Color,I,J,Pos,I2,J2,Fig2) )
        else (Fig = [_|Color]->
            fail
        else
            I2=I,J2=J, Fig=Fig2
        )).



0 komentar:

Posting Komentar