-
Notifications
You must be signed in to change notification settings - Fork 0
/
rapport.tex
110 lines (95 loc) · 3.76 KB
/
rapport.tex
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
\documentclass{article}
\usepackage{listings}
\usepackage{float}
\usepackage[superscript]{cite}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[utf8]{inputenc}
\title{TDT4258: Excercise 2}
\author{Halvor G. Bjørnstad, Even Lislebø}
\date{\today}
\lstset {
language=C,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=none,
keywordstyle=\color{blue},
stringstyle=\color{green},
breaklines=true,
breakatwhitespace=true,
tabsize=4,
xleftmargin=.1in
}
\hypersetup{
colorlinks,
citecolor=black,
linkcolor=black,
urlcolor=black
}
\begin{document}
\maketitle
\section*{Introduction}
\paragraph{}
This report describes the group's efforts to solve excercise 3 in the course TDT4258. The task is to make a retro-style game for the EFM32 Gecko board with energy optimization in mind.
\section*{Description and Methodology}
\paragraph{The game}
The game is a 1-player, turn-based shooter. The map is generated with 4 surrounding walls, some obstacles (wall pieces randomly positioned on the board), a random (but within a certain interval) number of enemies, and of course the player. For each turn, the player must choose to either move up, down, left or right, or to shoot in one of said directions. If an enemy makes it to the tile next to the player, it attacks the player and the game is over.
\paragraph{Technology}
The game will be written in C, and linked as a driver with the uClinux kernel distribution running on the board.
\subsection*{Results and Tests}
\subsection*{Brief Code Overview}
The map generation algorithm calculates the number of obstacles and enemies to be placed with a random percentage (of the number of open spaces) of 5-10 and 9-13, respectively:
\begin{lstlisting}
int obstacleRatio = (rand()%5) + 5;
int nofObstacles = (int)(openSpaces*obstacleRatio/100.0);
int enemyRatio = (rand()%9) + 4;
int nofEnemies = (int)(openSpaces * enemyRatio/100.0);
\end{lstlisting}
Randomly positioning enemies and obstacles on the board is done with the C standard library's rand()-function, using time as the seed:
\begin{lstlisting}
srand(time(NULL));
...
int randomPosition = rand()%(MAP_WIDTH*MAP_HEIGHT-MAP_WIDTH*2);
\end{lstlisting}
As can be seen from the code snippet above, we subtract 2 times the map width from the randomly generated number to ensure that an open space will be found. The first open space after the randomly generated position is returned:
\begin{lstlisting}
while (map[randomPosition] == TILE_WALL ||
getEnemyAtPosition(randomPosition % MAP_WIDTH, randomPosition / MAP_WIDTH)) {
if (++randomPosition >= MAP_WIDTH*MAP_HEIGHT) {
exit(1);
}
}
return randomPosition;
\end{lstlisting}
The enemies are organized in a linked list for easily removing a "dead" enemy:
\begin{lstlisting}
void addEnemy(Entity enemy) {
struct EntityList* current = enemies;
while(current) {
struct EntityList* next = current->next;
if (!next){
next = (struct EntityList*) malloc(sizeof(struct EntityList));
next->entity = enemy;
return;
}
current = next;
}
}
\end{lstlisting}
We contemplated using an array to hold the enemies, but decided that would yield rendering issues if we were to expand on the game, and for instance add enemies during the game. The algorithm deciding where the enemies should move between player turns employs the Hamilton distance
\subsection*{Energy Efficiency Measures}
\paragraph{Deep Sleep}
The device is in deep sleep by default, only a GPIO interrupt can wake it.
\paragraph{Possible Improvements}
\paragraph{Effects of employed measusers}
\section*{Results and Tests}
\section*{Evaluation of Assignment}
\paragraph{}
\section*{Conclusion}
\paragraph{}
\begin{thebibliography}{9}
\end{thebibliography}
\end{document}