Скачиваний:
5
Добавлен:
01.05.2014
Размер:
9 Кб
Скачать
inittired :- asserta(tiredlist([])).

!(X) :- call(X),!,fail.
!(_).

gettired(L) :- tiredlist(L),!.

tire(Z) :- gettired(L),
              adde(Z,L,L1),
              retract(tiredlist(_)),!,
              asserta(tiredlist(L1)).

tired(Z,[]) :- !, fail.

tired(Z,[A|L]) :- A == Z,!;
                         tired(Z,L).

tired(Z) :- gettired(L),
                tired(Z,L).

init :- asserta(counter(1)).

getc(X) :- counter(X).

setc(X) :- retract(counter(_)),asserta(counter(X)).

incer :- getc(X), X1 is X + 1, setc(X1).

init(Z,Y,X) :- Y == 1,!, asserta(rank(Z,X));
                    Y == 2,!, asserta(patriotism(Z,X));
                    Y == 3,!, asserta(mood(Z,X));
                    Y == 4,!, asserta(knowledge(Z,X));
                    Y == 5,!, asserta(experience(Z,X)).

set(Z,Y,X) :- Y == 1,!, retract(rank(Z,_)), asserta(rank(Z,X)),!;
                    Y == 2,!, retract(patriotism(Z,_)), asserta(patriotism(Z,X)),!;
                    Y == 3,!, retract(mood(Z,_)), asserta(mood(Z,X)),!;
                    Y == 4,!, retract(knowledge(Z,_)), asserta(knowledge(Z,X)),!;
                    Y == 5,!, retract(experience(Z,_)), asserta(experience(Z,X)),!.

gets(Z,Y,X) :- Y == 1,!, rank(Z,X),!;
                      Y == 2,!, patriotism(Z,X),!;
                      Y == 3,!, mood(Z,X),!;
                      Y == 4,!, knowledge(Z,X),!;
                      Y == 5,!, experience(Z,X),!.

conditions(Y,X) :- Y  == 1,!, (X>0) , (X<12);
                            Y  == 2,! ;
                            Y  == 3,!, (X>=0) , (X<11);
                            Y  == 4,!, (X>=0) , (X<21);
                            Y  == 5,!, (X>=0).

priority(Z,Y,X) :- gets(Z,1,R),
                           gets(Z,2,P),
                           gets(Z,3,M),
                           gets(Z,4,K),
                           gets(Z,5,E),                       
                          (Y == 1,!, X is (77-7*R);
                           Y == 2,!, X is (60+4*abs(R-6)-floor(E/6)-2*K-M);
                           Y == 3,!, X is (60-floor(E/2)+P-R);
                           Y == 4,!, X is (50+3*R-2*M+floor(E/12));
                           Y == 5,!, X is (30+3*R+floor(P/4));
                           Y == 6,!, X is (40-2*R-floor(E/10)+2*K+2*M);
                           Y == 7,!, X is (60-floor(E/6)+M);
                           Y == 8,!, X is (50-3*R+floor(P/5))).


inconce(Z,Y) :- gets(Z,Y,X),
                        X1 is X+1,
                        conditions(Y,X1),!,
                        set(Z,Y,X1).
inconce(Z,Y).

inc(Z,Y,N) :- N>0,!,
                    N1 is N-1,
                    inconce(Z,Y),
                    inc(Z,Y,N1).
inc(Z,Y,0). 

deconce(Z,Y) :- gets(Z,Y,X),
                         X1 is X-1,
                         conditions(Y,X1),!,
                         set(Z,Y,X1).
deconce(Z,Y).

dec(Z,Y,N) :- N>0,!,
                     N1 is N-1,
                     deconce(Z,Y),
                     dec(Z,Y,N1).
dec(Z,Y,0). 

adde(A,[],[A]):-!.
adde(A,L,[A|L]).

printl([]):-!.
printl([A|L]) :- write(A),
                      write('            '),
                      printl(L).

getlist(Z,L,6) :- !.
getlist(Z,L,N) :- N < 6,!,
                        N1 is N + 1,
                        gets(Z,N,X),
                        getlist(Z,L1,N1),
                        adde(X,L1,L).
getlist(Z,L) :- getlist(Z,L,1).


printdat :- write('                |    rank    | patriotism |    mood    | knowledge  | experience |').

showone(Z) :- !(tired(Z)),!,
                      write('an officer # '),
                      write(Z),
                      write('        '),
                      getlist(Z,L),
                      printl(L),
                      nl.
showone(Z):-!.

showall(10):-!.
showall(N) :- N < 10,
                    N1 is N + 1,
                    showone(N),
                    showall(N1).

showstate :- nl,nl,
                   printdat,nl,
                   showall(0).


qualify(Z) :- init(Z,1,2),
                   init(Z,2,0),
                   init(Z,3,3),
                   init(Z,4,15),
                   init(Z,5,0).
                    

cyclequalify(N) :- N > -1,!,
                           N1 is N - 1,
                           qualify(N),
                           cyclequalify(N1).
cyclequalify(-1).

qualifyall(N) :- cyclequalify(N),
                       inittired,
                       init,
                       randomize,
                       showstate.
                              

act(Z,Y) :-     Y == 1,
                            gets(Z,1,X),
                            X < 11,!,
                            inc(Z,1,1),
                            inc(Z,2,2),
                            inc(Z,3,2),
                            dec(Z,4,2),
                            inc(Z,5,3);
                     Y == 2,!,
                            gets(Z,1,X),
                            (X > 1,!,
                            dec(Z,1,1),
                            inc(Z,2,1),
                           dec(Z,3,2),
                            inc(Z,5,2);
                            tire(Z));
                     Y == 3,!, 
                            dec(Z,2,1),
                            dec(Z,3,1),
                             inc(Z,4,1),
                             inc(Z,5,1);
                     Y == 4,
                             gets(Z,5,X),
                             X > 8,!,
                             inc(Z,3,1),
                             inc(Z,2,1);
                     Y == 5,
                             gets(Z,1,X),
                             X > 2,!, 
                              inc(Z,3,1),
                              inc(Z,5,1),
                             dec(Z,4,1);
                     Y == 6,!,
                              inc(Z,5,1),
                             dec(Z,2,1),
                             dec(Z,3,1);
                     Y == 7,!,
                             inc(Z,2,1),
                            dec(Z,3,1),
                             inc(Z,4,1);
                     Y == 8,!,
                            dec(Z,3,2),
                             inc(Z,5,1).

act(Z,Y) :-     Y == 1,!,
                             nl,write('promotion is impossible'),nl,nl;
                    Y == 2,!,
                             nl,write('degrading is impossible'),nl,nl;
                    Y == 4,!,
                             nl,write('too less experience to get money'),nl,nl;
                    Y == 5,!,
                             nl,write('too low rank to manage anybody'),nl,nl.

act(Z,Y).

action(Z,Y) :- act(Z,Y).

writename(Y) :- Y == 1,!,
                            nl,write('promotion');
                        Y == 2,!,
                            nl,write('degrading');
                        Y == 3,!, 
                            nl,write('make task');
                        Y == 4,!,
                             nl,write('get money');
                        Y == 5,!,
                             nl,write('manage');
                        Y == 6,!,
                              nl,write('be punished');
                        Y == 7,!,
                             nl,write('take a political lesson');
                        Y == 8,!,
                            nl,write('be re-allot').


condact(Z,Y) :-!(tired(Z)), 
                        s(S),
                        random(X),
                        T is X*100,
                        priority(Z,Y,N),
                        T =< N,!,
                        retract(s(_)),
                        S1 is S + 1,
                        asserta(s(S1)),
                        action(Z,Y).
condact(Z,Y):- !.

condactall(-1,Y):-!.
condactall(Z,Y) :-  Z > -1,!,
                            condact(Z,Y),
                            Z1 is Z - 1,
                            condactall(Z1,Y).

ret :- retract(s(_)),!.
ret.

condact(Y) :- ret,
                     asserta(s(0)),
                     condactall(9,Y),
                     s(S),
                     S > 0,!,
                     writename(Y),
                     showstate.

condact(Y) :- fail.


day :- random(X),
          Y is floor(X*8)+1,
          condact(Y),!.
day :- day.
                 
step(N) :- N == 0,!.

step(N) :- N1 is N -1,
               getc(X),nl,nl,nl,
               write('Step # '), write(X), nl, nl,
               day,
               incer,
               step(N1).

serve :-  getc(X),
             nl,nl,write('how many steps should be listed? '),
             read(P),             
             P \= 0,!,
             step(P),
             serve.
               
career :- qualifyall(10),!,
             serve.


                            


Соседние файлы в папке Моделирование объекта офицеры