WELCOME TO

rumblecleverΤεχνίτη Νοημοσύνη και Ρομποτική

1 Δεκ 2013 (πριν από 3 χρόνια και 9 μήνες)

93 εμφανίσεις

P
op
ulation
S
imulator

Page:

1

W
ELCOME
T
O

S
INISTER
S
IMULATIONS

P
OPULATION
S
IMULATOR

Contents:

Page 1: Contents

Page 2: About The Simulator

Page 2: Requirements

Page 4: Websites

Page 5: Games

Page 5: Design

Page 9: Screen Design

Page 9: Coding

Page 10
-
11: Class Diagram

Page 15: Java Over

C++

Page 15: AWT Over Swing

Page 16: Testing

Page 17: Walkthrough

Page 20: Credits

P
op
ulation
S
imulator

Page:

2

About The Simulator:


The goal of this population simulator is to create a program
that can generate a new world according to the users specifications
then create a species

based on the users input and finally allow the
user to place these species on the map in whatever pattern they
want and set the simulation running.


When designing the simulator the primary goal was to create a
realistic simulation of the evolution and sp
read of life on a large
world. This includes the use of height and fertility in the tiles as well
as being governed by the intelligence, sociality and size of the
species involved.


However to use the simulator a map generator was required
and so the world

builder was designed. At first it was crude with no
water and just random placement of height and fertility. Over time
though it eventually became more and more sophisticated in the
strive to create realistic worlds complete with water erosion and
tectoni
c plates.


P
op
ulation
S
imulator

Page:

3

To inhabit the world a way of customising species was required
and so the species builder was created to allow the user to create
their own species.



Requirements:


To create such a program it was first necessary to research in
several places t
he best ways to go about writing the code. There were
many problems along the way that could only be solved by extensive
research into the Java technology and the work by other programmers
on the Internet.


One such problem was encountered near the start w
hen the
primary goal was to create a program capable of drawing an array of
coloured squares onto the screen in a full screen application.


This was only solved by research into the AWT code and the
JFrame full screen methods.


What follows is the original

Design Document from the 15
th

of
September 2005.

P
op
ulation
S
imulator

Page:

4


“This project will consist of a simulator to reproduce as accurately
as possible the growth and spread of a species according to many
different factors including the local climate, fertility of the land, a
nd the
hostility of predators and the general landscape.


This will be achieved using a cellular
automaton system
displaying an entire world in 512x256 cells, each with their own
values for the above mentioned factors.


The first phase in the creation of t
his project will be
researching previous systems that run along similar principles. One
of the simplest of these is the “Game of Life” that can be found here:

http://www.math.com/students/
wonders/life/life.html


Also on this website are several more complicated programs
using complex mathematics to show designs or perform rudimentary
tasks.


The second phase of design will be to determine exactly the
rules governing the different factors a
nd how the species will react
to the environment and to other species that they come across.

P
op
ulation
S
imulator

Page:

5


The third phase of creation will be to create a simple cellular
automaton such as the original game of life created by John Conway.
This will involve using java t
o show images on screen and to
determine the rules of the system.


Once we have this basic program in place we can move on to
implementing the more advanced factors such as fertility and
climate.


At this stage we will need to work on creating our world bu
ilder
that will make a world of tiles, giving each tile values for each of the
variables needed. This will be done in a way to create as realistic a
world as possible.


At the end of the project we hope to have a system that will be
able to create a world,

then create species and then be able to place
multiple species into the world environment and see how they grow and
interact with the environment and each other.”


While the primary goals have been achieved some details have
been changed. For example the
world size is now a 320 by 160 array of
P
op
ulation
S
imulator

Page:

6

tiles instead of the originally planned 512 by 256 array due to
performance issues.


Climate didn’t make it into the final program but height and water
erosion were added and temperature is planned for the future.


T
he implementation of the species has been improved beyond
what was originally envisioned as well. Allowing the species to evolve
was a later addition to the simulator.


Surprisingly a lot of details in the original design document were
removed only to be a
dded
again at later stages. This method of
prototyping allowed for extensive development of the design during the
actual coding.


This freestyle approach to the design process led to the
implementation of several features that weren’t originally in the
des
ign. For example this program has its own GUI code with its own
classes for buttons, lists, sliders, textboxes and alerts.




P
op
ulation
S
imulator

Page:

7

Websites:


Research during the development of the program was one of
the prime concerns. Several websites were found to have valua
ble
information and none more so then Suns own website here:

http://java.sun.com/j2se/1.5.0/docs/


It contains definitions of all the methods and variables in the
latest version of the SDK and was usefu
l for finding out the best
ways to implement parts of the program.


Another website that was useful when trying to implement
sound and video was the Java Media Framework site here:


http://java.s
un.com/products/java
-
media/jmf/


The Java Media Framework allows for the
Playing of videos and
sounds in a java application.


Of particular note is the ability of the JMFs MP3 player plug
-
in to
play MP3 sound files. This is used to play the background mus
ic in the
P
op
ulation
S
imulator

Page:

8

program and allows the program to play any MP3 files placed into the
music folder. Here is the website for the MP3 player plug
-
in:

http://java.sun.com/products/java
-
med
ia/jmf/mp3/download.html




Games:


The design of this simulator was influenced by several games
before and during its development. The most noticeable influence
coming from Civilisation and its sequels. Civilisation is a turn based
strategy game set betw
een 4000bc and 2100ad where you lead your
civilisation to victory or defeat on a world map. Even though it is a
game and not a simulator the depth of civilisation allowed me to draw
strongly from its design.

http://ww
w.firaxis.com





P
op
ulation
S
imulator

Page:

9

Design:


The original design of the simulator was simply a simulation of a
species growing and expanding on a map.


From this the current design was created through a process of
prototyping to see what worked and what didn’t work. The eq
uations
used to govern the simulation were developed along with the program
and constantly modified and tested to observe their effects and finally
to create a realistic portrayal of the growth of a species.


The main class in the program is the controller

class. From here
all the other classes are controlled including the simulator and renderer
class that are the two next most important classes.


All the GUI objects have their own class such as the pButton and
pList classes. These are added to the screen a
s needed by the
controller class.


The different windows are accessed by simply changing the
objects that are painted to the screen in the controllers paint method.


P
op
ulation
S
imulator

Page:

10

Screen Design:


The interface of the program is strongly influenced by game
designs with t
he map to the top and the main interface and buttons
below it.


The program starts off with the main menu from where you can
access any of the three prime areas as well as the options screen.


The three prime areas are the Simulator, the World Builder and
the Species Builder. There is also the menu in these screens from
where you can access any of the other parts. This leads to a smooth
path through the entire program as easily as possible.


The buttons that are not immediately obvious have tool tips to
hel
p new users.


Coding:


The simulator is coded entirely in java using java’s AWT API to
render the program to a full screen JFrame window.

The class diagram can be found on the following page.

P
op
ulation
S
imulator

Page:

11


PopSim
Controller
simtile
Species
Simulator
tile
initiate
BuildMap
renderer
pButton
pList
pSlider
pTextbox
pAlert
MusicPlayer
P
op
ulation
S
imulator

Page:

12

As can be seen from the diagram the

PopSim class is main class.
This then instantiates the Controller class.


The controller class being the primary class starts up all the other
classes that are needed. The GUI object classes are the pButton, pList,
pSlider, pTextBox and pAlert to the righ
t of the diagram. These are
used throughout the program to hold the data needed for the buttons
and lists and so on.


The controller also instantiates the MusicPlayer class thread that
plays the songs in the background. These songs loop over time or they
c
an be controlled by the user through commands inputted through the
controller class to the MusicPlayer.


The controller also starts the renderer class that is responsible for
rendering the tile class that makes up the map. This is renderer only in
the Buil
d Map window and the Simulator window.


It then starts the Simulator class which is a thread on its own
that controls the actual simulation once it is playing. The controller then
sets up the simtile class and Species object for the Simulator class and
pas
ses them into it.

P
op
ulation
S
imulator

Page:

13


When the user enters the build map window and creates a new
map the initiate class is called which in turn calls the BuildMap class to
create a new tile array with all the data for the new map stored inside
it. That tile array is then pa
ssed back by the initiate class to the
controller class from where it can be sent to the simulator class for use
in the simulation.


Only one tile array is loaded into the program at once so the
other maps are saved as text files to the hard drive from whe
re they
can be loaded by the user at a later time.


The species object must also be saved to the hard drive for future
loading in the Simulator before it can be placed onto the map.


The simtile array is the same size as the tile array and holds all
the da
ta for the simulator during the simulation. This includes the
species ID that occupies that tile and its population.


The simulator then uses this data to run through the simtiles and
judge what should happen on the next iteration of the simulator. The
si
mulator runs through the array once on each iteration checking every
P
op
ulation
S
imulator

Page:

14

simtile that is occupied by a species. It then decides what action should
be taken and changes the species ID or population of the relevant
simtiles nearby accordingly.


The pButton objec
t is given the necessary data for it to paint
itself to the screen when it is instantiated by the controller. Each
window has its own list of buttons and other GUI objects and they are
instantiated when the window is changed.


On each iteration of the cont
rollers paint method it calls each
button in turn to paint itself onto the screen. If the mouse is hovering
over a button then the buttons setstate method is called and when it is
painted next it uses it’s “Over” image instead of its normal image.


When a
button is clicked the number ID of the button that the
mouse was in is used to get the name of the button and from that the
controller decides which action to take in its MouseListener methods.


The same method is used for when sliders and lists are clicke
d
on. When a slider is changed it passes the value back to the controller
to change
the relevant variable there. It
s name is again used to judge
which variable should be changed.

P
op
ulation
S
imulator

Page:

15

Java Over C++:


Java was used in the development of this program due to the
e
ase with which such a GUI orientated project can be designed and
created. The Object
-
Orientated Java foundation was necessary for
some parts of the program.


While C++ is purportedly slightly faster when performing CPU
intensive actions such as the simulat
ion itself the benefits that Java
gives to the program far outweigh any loss of performance.



AWT Over Swing:


While the JFrame method of Swing was used to provide the full
screen window in which to paint the program the main type of
rendering used were t
he AWT paint methods.


While Swing could have been used for the GUI side of the
program the control given by creating program specific code such as
the pButton class was considered beneficial enough to deserve the
extra effort.

P
op
ulation
S
imulator

Page:

16

The educational benefit of d
esigning all the code needed was also
a strong factor.




Testing:


Testing was performed throughout the development of the
program both by external testers and through the prototype testing
phases of the coding.


Bugs were found and reported by several pe
ople and all these
bugs were fixed as best as possible.

Errors in the code were found through the use of the JCreator
compiling tool as well as in
-
depth testing using a combination of
printing error messages to the console and performing each action that
was given trouble piece by piece until the problem was discovered and
fixed.


At the end of the development several people were asked to use
the program and provide their thoughts on the layout and general
design. They were then asked to try and break the
program as best
P
op
ulation
S
imulator

Page:

17

they could and although no one managed to actually break the program
several small bugs were found and fixed.


The need for testing in a programs development is to expose
bugs and flaws in the flow of the game and in this the testing
succee
ded admirably.




Walkthrough:


What follows is a short walkthrough that describes how to create
a world and a species and then load the world up in the simulator and
set the species growing on the world.


-

First of all when you start the program you’ll s
ee the main
screen. From here click on the Build Map button to get into the Build
Map window.


-

Here you can see three sliders down at the bottom. Change
these to suit your tastes. Please note that for a realistic water level that
slider should be kept be
tween 90 and 140.

P
op
ulation
S
imulator

Page:

18


-

Once you have these sliders set then click on the Rebuild button
to create the world. The world should be created in just a few seconds.
If you are pleased with your world you can move on to the next part. If
not then you can change th
e sliders and click Rebuild again to create a
new world.


-

Once you have a world you like click on the menu button in the
right hand area of the Action Bar beneath the map.


-

Click on Save Map and choose a name for your map.


-

Now that your map is sav
ed you can go into the menu again
and click on the Build Species button to enter the Build Species window.


-

You’ll see sliders here where you can set the various attributes
of your species.


-

Once you are happy with these you can save your species from
the menu.


P
op
ulation
S
imulator

Page:

19

-

Now that you have a map and a species you can go into the
simulator window from the menu. You will be asked to load a map. Pick
the map you created from the list.


-

Once the map is loaded you can load your species from the
menu. You can load

up to 8 species to inhabit your map at once.


-

When you have loaded all the species you want to use click on
their corresponding colour in the Species Section to the bottom right.


-

After you have clicked on them their name should be following
the mouse
. Click on the map to place the species. You can do this as
many times as you want even after the simulator has started to play.

-

Once you are ready you can show the Sim Player by clicking on
the button to the left of the Action Bar.





-

Choose the a
mount of turns to play the simulation for then hit
the Play button.



P
op
ulation
S
imulator

Page:

20

While the simulation is playing you can load more species to place
or place more of the existing species or just sit back and watch them
thrive.


You can also pause the simulation in
the Sim Player. If you want
to restart the simulation then you just have to load a new map or the
same map again from the menu.


You can access the music controls from the music player by
clicking on the button to the right of the Action Bar.



Moving y
our mouse over a tile will give you detailed information
on that tile and the species in it.








P
op
ulation
S
imulator

Page:

21

Credits:


Design: Shane Christopher


Programming: Shane Christopher


Art: Shane Christopher


Manual: Shane Christopher


Production: Shane Christopher