-
Notifications
You must be signed in to change notification settings - Fork 6
/
agente002.pl
140 lines (130 loc) · 6.65 KB
/
agente002.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Hunt The Wumpus - World Simulator %
% Copyright (C) 2012 - 2022 Ruben Carlo Benante <rcb at beco dot cc> %
% %
% This program is free software; you can redistribute it and/or modify %
% it under the terms of the GNU General Public License as published by %
% the Free Software Foundation; version 2 of the License. %
% %
% This program is distributed in the hope that it will be useful, %
% but WITHOUT ANY WARRANTY; without even the implied warranty of %
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
% GNU General Public License for more details. %
% %
% You should have received a copy of the GNU General Public License along %
% with this program; if not, write to the Free Software Foundation, Inc., %
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Special thanks to:
% - Gregory Yob
% - Larry Holder
% - Walter Nauber
%
% A Prolog implementation of the Wumpus world invented by Gregory Yob (1972)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% To allow an agent to run with the Wumpus Simulator you need to define:
% init_agent :
% It will be called only once, at the start. Put here definitions and
% other start code you need (asserts, retracts, and so on)
% run_agent :
% It will be called each turn by the simulator.
% Input: perceptions from the world.
% Expected output: an action for the agent to perform.
% world_setup([Size, Type, Move, Gold, Pit, Bat, [RandS, RandA]]):
% This is a fact. It will be consulted only once at the beginning,
% even before init_agent. It will configure the world as you say,
% or use a default in case of conflicts or mistakes.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Lista de Percepcao: [Stench, Breeze, Glitter, Bump, Scream, Rustle]
% Traducao: [Fedor, Vento, Brilho, Trombada, Grito, Ruido]
% Acoes possiveis (abreviacoes):
% goforward (go) - andar
% turnright (turn, turnr ou tr) - girar sentido horario
% turnleft (turnl ou tl) - girar sentido anti-horario
% grab (gr) - pegar o ouro
% climb (cl) - sair da caverna
% shoot (sh) - atirar a flecha
% sit (si) - sentar (nao faz nada, passa a vez)
%
% Costs (Custos):
% Actions: -1 (Andar/Girar/Pegar/Sair/Atirar/Sentar)
% Die: -1000 (morrer no buraco, wumpus ou de fadiga)
% Killing the Wumpus: +1000 (matar Wumpus)
% Climbing alive with golds: +500 for each gold (sair com ouro)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% To run the example, start PROLOG with (rode o exemplo iniciando o prolog com):
% swipl -s agenteXXX.pl
% then do the query (faca a consulta):
% ?- start.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% world_setup([Size, Type, Move, Gold, Pit, Bat, Adv])
%
% Size and Type: - fig62, 4
% - grid, [2-9] (default 4)
% - dodeca, 20
% +--------+-----------+
% | Type | Size |
% +--------+-----------+
% | fig62 | 4 (fixed) |
% | grid | 2 ... 9 |
% | dodeca | 20 (fixed)|
% +--------+-----------+
%
% Configuration:
% 1. Size: 0,2..9,20, where: grid is [2-9] or 0 for random, dodeca is 20, fig62 is 4.
% 2. Type: fig62, grid or dodeca
% 3. Move: stander, walker, runner (wumpus movement)
% 4. Gold: Integer is deterministic number, float from 0.0<G<1.0 is probabilistic
% 5. Pits: Idem, 0 is no pits.
% 6. Bats: Idem, 0 is no bats.
% 7. Adv: a list with advanced configuration in the form [RandS, RandA]:
% - RandS - yes or no, random agent start position
% - RandA - yes or no, random agent start angle of orientation
%
% examples:
% * default:
% world_setup([4, grid, stander, 0.1, 0.2, 0.1, [no, no]]).
% * size 5, 1 gold, 3 pits, some bats prob. 0.1, agent randomly positioned
% world_setup([5, grid, stander, 1, 3, 0.1, [yes]]).
%
% Types of Wumpus Movement
% walker : original: moves when it hears a shoot, or you enter its cave
% runner : go forward and turn left or right on bumps, maybe on pits
% wanderer : arbitrarily choses an action from [sit,turnleft,turnright,goforward]
% spinner : goforward, turnright, repeat.
% hoarder : go to one of the golds and sit
% spelunker : go to a pit and sit
% stander : do not move (default)
% trapper : goes hunting agent as soon as it leaves [1,1]; goes home otherwise
% bulldozer : hunt the agent as soon as it smells him
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% agente002.pl:
%
% Strategy: runs a prefixed set of actions from a list
% Performance:
% - perfect for fig62
% - does not so well in any other case
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- use_module(wumpus, [start/0]). % agente usa modulo simulador
% Mundo:
% famosa figura da seção 6.2 do livro "Inteligencia Artificial: uma abordagem moderna", de Russel & Norvig.
% 4x4, quadrado, wumpus fica parado em [1,3]
% 1 ouro (em [2,3]), 3 buracos (em [3,1], [3,3] e [4,4]), 0 morcegos
% agente inicia na casa [1,1] olhando para leste/direita (0 graus)
% Maximo de acoes antes de morrer de fome: Size^2x4 = 4x4x4 = 64
world_setup([4, fig62, stander, 1, 3, 0, [no]]). % size 4, 1 gold, 3 pits and 0 bat
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Inicie aqui seu programa.
:- dynamic([lacoes/1]).
init_agent :-
assert(lacoes([goforward,turnleft,goforward,goforward,turnleft,shoot,grab,turnleft,goforward,goforward,turnright,goforward,climb])).
run_agent(_, Acao) :-
seguelista(Acao).
seguelista(A) :-
retract(lacoes([A|F])),
assert(lacoes(F)).
seguelista(climb). % default in case of empty list
/* ----------------------------------------------------------------------- */
/* vi: set ai et ts=4 sw=4 tw=0 wm=0 fo=croql : PL config for Vim modeline */
/* Template by Dr. Beco <rcb at beco dot cc> Version 20150620.224740 */