Skip to content

Commit a41df3b

Browse files
author
Jonathan Lundholm
committed
Initialized repo
0 parents  commit a41df3b

File tree

132 files changed

+5270
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+5270
-0
lines changed

Lab1/bin/tddc17/MyAgentProgram.class

5.08 KB
Binary file not shown.

Lab1/bin/tddc17/MyAgentState.class

1.54 KB
Binary file not shown.

Lab1/bin/tddc17/MyVacuumAgent.class

309 Bytes
Binary file not shown.
1.67 KB
Binary file not shown.
356 Bytes
Binary file not shown.
1.83 KB
Binary file not shown.
362 Bytes
Binary file not shown.

Lab1/doc/behaviour

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
choosing algorithm
2+
When I choose algorithm I wanted something simple and had as few turns as possible.
3+
I found out that going in serpentine, going in an inwards spiral and going in a
4+
more complicated pattern that is a double spiral(first inwards leaving space for
5+
the later outwards spiral) to be good algorithms. All of them have very few
6+
turns and each of them have there own advantages and disadvantages. The
7+
serpentine had the biggest amount of turns, and you always ended up very far
8+
away from home. The double spiral had the advantage of never visit a square
9+
twice, but the algorithm for it is more complicated than the others and cant
10+
cover all squares if both sides are an odd number. Thus I choose to go in an
11+
inwards circle. It was the simplest and had very few turns.
12+
13+
action queue,
14+
The way to decide how to move was a bit troublesome to use. I didnt like that I
15+
couldnt stack commands. For that I created a actionQueue. At every call to the
16+
execute command I check if there already is a command in the actionQueue. If
17+
there is I will return the first command in the actionQueue.
18+
19+
suck on dirt
20+
there is no reason not to suck when there is dirt on the floor tile pacman is
21+
standing on.
22+
23+
remembering the room
24+
By using the MyAgentState class I stored different data about the room. I didnt
25+
bother to save if there was dirt anywhere as I made the agent to always clean up
26+
dirt if there was any. When the agent hits a wall it stores the data for that
27+
square too.
28+
29+
turn on bump
30+
The basic algorithm is very simple, if pacman bumps into something turnRight,
31+
else go formward.When the next square has been visited before pacman also turns
32+
to the right. To calculate if the next square has been visited I created a
33+
function beenVisited(), I also created two functions, nextX() and nextY(), that
34+
would calculate the next square pacman would go to, these made it easy to define
35+
the condition that checks when to turn.
36+
37+
find out when done
38+
How do pacman know when he have been in the whole room? By using the
39+
beenVisited() function I defined the function surroundedByVisited() that checks
40+
if pacman has been on all surrounding squares. When there are no obstacles in
41+
the room pacman dont need to check if all unknown squares are out of reach.
42+
Pacman cant be surrounded by visited squares if he isnt done.
43+
44+
find the path home
45+
The agent also have two variables storing the x and y of the home square. By
46+
using this information I made a very simple pathfinding algorithm.
47+
48+
while my x is different from the target x:
49+
move in x towards target.
50+
while my y is different from the target y:
51+
move in y towards target.
52+
53+
here I had much use of my abstraction. Being able to stacking commands made this
54+
very simple, I also made the functions goWest(), goNorth(), goSouth(), goEast(),
55+
that made some abstraction for turning the agent in the right direction.
56+
57+

Lab1/doc/behaviour.lyx

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#LyX 2.0 created this file. For more info see http://www.lyx.org/
2+
\lyxformat 413
3+
\begin_document
4+
\begin_header
5+
\textclass article
6+
\use_default_options true
7+
\maintain_unincluded_children false
8+
\language english
9+
\language_package default
10+
\inputencoding auto
11+
\fontencoding global
12+
\font_roman default
13+
\font_sans default
14+
\font_typewriter default
15+
\font_default_family default
16+
\use_non_tex_fonts false
17+
\font_sc false
18+
\font_osf false
19+
\font_sf_scale 100
20+
\font_tt_scale 100
21+
22+
\graphics default
23+
\default_output_format default
24+
\output_sync 0
25+
\bibtex_command default
26+
\index_command default
27+
\paperfontsize default
28+
\use_hyperref false
29+
\papersize default
30+
\use_geometry false
31+
\use_amsmath 1
32+
\use_esint 1
33+
\use_mhchem 1
34+
\use_mathdots 1
35+
\cite_engine basic
36+
\use_bibtopic false
37+
\use_indices false
38+
\paperorientation portrait
39+
\suppress_date false
40+
\use_refstyle 1
41+
\index Index
42+
\shortcut idx
43+
\color #008000
44+
\end_index
45+
\secnumdepth 3
46+
\tocdepth 3
47+
\paragraph_separation indent
48+
\paragraph_indentation default
49+
\quotes_language english
50+
\papercolumns 1
51+
\papersides 1
52+
\paperpagestyle default
53+
\tracking_changes false
54+
\output_changes false
55+
\html_math_output 0
56+
\html_css_as_file 0
57+
\html_be_strict false
58+
\end_header
59+
60+
\begin_body
61+
62+
\begin_layout Standard
63+
When I choose algorithm I wanted something simple and had as few turns as
64+
possible.
65+
I found out that going in serpentine, going in an inwards spiral and going
66+
in a more complicated pattern that is a double spiral(first inwards leaving
67+
space for the later outwards spiral) to be good algorithms.
68+
All of them have very few turns and each of them have there own advantages
69+
and disadvantages.
70+
The serpentine had the biggest amount of turns, and you always ended up
71+
very far away from home.
72+
The double spiral had the advantage of never visit a square twice, but
73+
the algorithm for it is more complicated than the others and cant cover
74+
all squares if both sides are an odd number.
75+
Thus I choose to go in an inwards circle.
76+
It was the simplest and had very few turns.
77+
\end_layout
78+
79+
\begin_layout Standard
80+
The way to decide how to move was a bit troublesome to use.
81+
I didnt like that I couldnt stack commands.
82+
For that I created a actionQueue.
83+
At every call to the execute command I check if there already is a command
84+
in the actionQueue.
85+
If there is I will return the first command in the actionQueue.
86+
\end_layout
87+
88+
\begin_layout Standard
89+
There is no reason not to suck when there is dirt on the floor tile pacman
90+
is standing on.
91+
\end_layout
92+
93+
\begin_layout Standard
94+
By using the MyAgentState class I stored different data about the room.
95+
I didnt bother to save if there was dirt anywhere as I made the agent to
96+
always clean up dirt if there was any.
97+
When the agent hits a wall it stores the data for that square too.
98+
\end_layout
99+
100+
\begin_layout Standard
101+
turn on bump The basic algorithm is very simple, if pacman bumps into something
102+
turnRight, else go formward.When the next square has been visited before
103+
pacman also turns to the right.
104+
To calculate if the next square has been visited I created a function beenVisit
105+
ed(), I also created two functions, nextX() and nextY(), that would calculate
106+
the next square pacman would go to, these made it easy to define the condition
107+
that checks when to turn.
108+
\end_layout
109+
110+
\begin_layout Standard
111+
How do pacman know when he have been in the whole room? By using the beenVisited
112+
() function I defined the function surroundedByVisited() that checks if
113+
pacman has been on all surrounding squares.
114+
When there are no obstacles in the room pacman dont need to check if all
115+
unknown squares are out of reach.
116+
Pacman cant be surrounded by visited squares if he isnt done.
117+
\end_layout
118+
119+
\begin_layout Standard
120+
The agent also have two variables storing the x and y of the home square.
121+
By using this information I made a very simple pathfinding algorithm.
122+
123+
\end_layout
124+
125+
\begin_layout LyX-Code
126+
while my x is different from the target x:
127+
\end_layout
128+
129+
\begin_deeper
130+
\begin_layout LyX-Code
131+
move in x towards target.
132+
133+
\end_layout
134+
135+
\end_deeper
136+
\begin_layout LyX-Code
137+
while my y is different from the target y:
138+
\end_layout
139+
140+
\begin_deeper
141+
\begin_layout LyX-Code
142+
move in y towards target.
143+
\end_layout
144+
145+
\end_deeper
146+
\begin_layout Standard
147+
Here I had much use of my abstraction.
148+
Being able to stacking commands made this very simple, I also made the
149+
functions goWest(), goNorth(), goSouth(), goEast(), that made some abstraction
150+
for turning the agent in the right direction.
151+
\end_layout
152+
153+
\end_body
154+
\end_document

Lab1/doc/behaviour.lyx~

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#LyX 2.0 created this file. For more info see http://www.lyx.org/
2+
\lyxformat 413
3+
\begin_document
4+
\begin_header
5+
\textclass article
6+
\use_default_options true
7+
\maintain_unincluded_children false
8+
\language english
9+
\language_package default
10+
\inputencoding auto
11+
\fontencoding global
12+
\font_roman default
13+
\font_sans default
14+
\font_typewriter default
15+
\font_default_family default
16+
\use_non_tex_fonts false
17+
\font_sc false
18+
\font_osf false
19+
\font_sf_scale 100
20+
\font_tt_scale 100
21+
22+
\graphics default
23+
\default_output_format default
24+
\output_sync 0
25+
\bibtex_command default
26+
\index_command default
27+
\paperfontsize default
28+
\use_hyperref false
29+
\papersize default
30+
\use_geometry false
31+
\use_amsmath 1
32+
\use_esint 1
33+
\use_mhchem 1
34+
\use_mathdots 1
35+
\cite_engine basic
36+
\use_bibtopic false
37+
\use_indices false
38+
\paperorientation portrait
39+
\suppress_date false
40+
\use_refstyle 1
41+
\index Index
42+
\shortcut idx
43+
\color #008000
44+
\end_index
45+
\secnumdepth 3
46+
\tocdepth 3
47+
\paragraph_separation indent
48+
\paragraph_indentation default
49+
\quotes_language english
50+
\papercolumns 1
51+
\papersides 1
52+
\paperpagestyle default
53+
\tracking_changes false
54+
\output_changes false
55+
\html_math_output 0
56+
\html_css_as_file 0
57+
\html_be_strict false
58+
\end_header
59+
60+
\begin_body
61+
62+
\begin_layout Standard
63+
When I choose algorithm I wanted something simple and had as few turns as
64+
possible.
65+
I found out that going in serpentine, going in an inwards spiral and going
66+
in a more complicated pattern that is a double spiral(first inwards leaving
67+
space for the later outwards spiral) to be good algorithms.
68+
All of them have very few turns and each of them have there own advantages
69+
and disadvantages.
70+
The serpentine had the biggest amount of turns, and you always ended up
71+
very far away from home.
72+
The double spiral had the advantage of never visit a square twice, but
73+
the algorithm for it is more complicated than the others and cant cover
74+
all squares if both sides are an odd number.
75+
Thus I choose to go in an inwards circle.
76+
It was the simplest and had very few turns.
77+
\end_layout
78+
79+
\begin_layout Standard
80+
The way to decide how to move was a bit troublesome to use.
81+
I didnt like that I couldnt stack commands.
82+
For that I created a actionQueue.
83+
At every call to the execute command I check if there already is a command
84+
in the actionQueue.
85+
If there is I will return the first command in the actionQueue.
86+
\end_layout
87+
88+
\begin_layout Standard
89+
There is no reason not to suck when there is dirt on the floor tile pacman
90+
is standing on.
91+
\end_layout
92+
93+
\begin_layout Standard
94+
By using the MyAgentState class I stored different data about the room.
95+
I didnt bother to save if there was dirt anywhere as I made the agent to
96+
always clean up dirt if there was any.
97+
When the agent hits a wall it stores the data for that square too.
98+
\end_layout
99+
100+
\begin_layout Standard
101+
turn on bump The basic algorithm is very simple, if pacman bumps into something
102+
turnRight, else go formward.When the next square has been visited before
103+
pacman also turns to the right.
104+
To calculate if the next square has been visited I created a function beenVisit
105+
ed(), I also created two functions, nextX() and nextY(), that would calculate
106+
the next square pacman would go to, these made it easy to define the condition
107+
that checks when to turn.
108+
\end_layout
109+
110+
\begin_layout Standard
111+
How do pacman know when he have been in the whole room? By using the beenVisited
112+
() function I defined the function surroundedByVisited() that checks if
113+
pacman has been on all surrounding squares.
114+
When there are no obstacles in the room pacman dont need to check if all
115+
unknown squares are out of reach.
116+
Pacman cant be surrounded by visited squares if he isnt done.
117+
\end_layout
118+
119+
\begin_layout Standard
120+
find the path home The agent also have two variables storing the x and y
121+
of the home square.
122+
By using this information I made a very simple pathfinding algorithm.
123+
124+
\end_layout
125+
126+
\begin_layout LyX-Code
127+
while my x is different from the target x:
128+
\end_layout
129+
130+
\begin_deeper
131+
\begin_layout LyX-Code
132+
move in x towards target.
133+
134+
\end_layout
135+
136+
\end_deeper
137+
\begin_layout LyX-Code
138+
while my y is different from the target y:
139+
\end_layout
140+
141+
\begin_deeper
142+
\begin_layout LyX-Code
143+
move in y towards target.
144+
\end_layout
145+
146+
\end_deeper
147+
\begin_layout Standard
148+
Here I had much use of my abstraction.
149+
Being able to stacking commands made this very simple, I also made the
150+
functions goWest(), goNorth(), goSouth(), goEast(), that made some abstraction
151+
for turning the agent in the right direction.
152+
\end_layout
153+
154+
\end_body
155+
\end_document

Lab1/doc/behaviour.pdf

48.8 KB
Binary file not shown.

Lab1/doc/decision_cases

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# = wall
2+
O = visited
3+
? = unknown
4+
5+
#
6+
OCO
7+
#
8+
9+
#
10+
OC#
11+
#
12+
13+
#
14+
OC#
15+
O
16+
17+
3
18+
3 2 3
19+
3 2 O 1 2 3
20+
3 2 3
21+
3

0 commit comments

Comments
 (0)