2

射手が4 x 4 グリッド上で安全な隣接する正方形に移動する Prolog アプリケーションを作成しようとしています。

例えば、射手は四角の列 1 行 4にいて、 Mとして記録されたモンスターが含まれていない場合、上または右に移動できます。したがって、列 2 行 4モンスター (M)がある場合、射手 (A)はそこに移動できませんが、列 1 行 3空 (E) の場合、彼はこれに移動できます。射手は、隣接する正方形が安全かどうかを確認できますが、それ以上離れていない.

これが私がこれまでに得たものです:

:- dynamic square/3.
:- dynamic show/1.

createBoard(N) :- 
    retractall(show(_)),
    assert(show([[1,1]])),
    retractall(square(_,_,_)),
    createBoard(N,N).

testBoard :-
    retractall(square(_,_,_)),
    retractall(show(_)),
    assert(show([[4,1]])),
    asserta(square(1,1,[e])),
    asserta(square(1,2,[e])),
    asserta(square(1,3,[s])),
    asserta(square(1,4,[e])),
    asserta(square(2,1,[e])),
    asserta(square(2,2,[b,s])),
    asserta(square(2,3,[m])),
    asserta(square(2,4,[g,s])),
    asserta(square(3,1,[b])),
    asserta(square(3,2,[p])),
    asserta(square(3,3,[g,b,s])),
    asserta(square(3,4,[x])),
    asserta(square(4,1,[a,e])),
    asserta(square(4,2,[b])),
    asserta(square(4,3,[e])),
    asserta(square(4,4,[g])).

% you can place a piece on a board of N size if you can generate a row
%   and column value and you can place that piece on an square empty square
place(Piece,N) :-
    Row1 is random(N),
    Col1 is random(N),
    place(Piece,Row1,Col1,N).

% you can place a pit if the square is empty at the specified
% position
place(p,Row,Col,_) :-
    square(Row,Col,[e]),
    retract(square(Row,Col,[e])),
    assert(square(Row,Col,[p])).

% Find an Item at a position R,C by
% examining the contents of the R,C, location
find(R,C,Item) :-
    square(R,C,Contents),
    member(Item,Contents).

隣接する正方形が安全かどうかをアーチャーに確認させ、安全な場合はその正方形に移動するのに苦労しています。

これはどのように行うことができますか?

4

0 に答える 0