Download presentation
Presentation is loading. Please wait.
Published byJohanne Quimby Modified over 10 years ago
1
Daniel Strebel Eduardo Hernández Marquina Advanced Functional Programming
2
1.- The Problem 2.- Design 3.- Demo 4.- Limitations 5.- Algorithms 6.- Why we produces correct results 7.- Difficult cases Agenda
3
The board: A grid where the different elements are going to interact. The Problem
4
Elements »Fences: Static elements »Grass: Procreate The Problem Cont.
5
Elements Cont: Abilities: - Move - Eat - Procreate The Problem Cont.
6
Design
7
Design cont. Fox_1Rabbit_1Grass_1Rabbit_2 {4,3}, rabbit_1 {3,6}, fox_2 {1,4}, grass_2 {4,8}, grass_3 {7,3}, grass_1 {5,8}, rabbit_2 {8,5}, fox_1 Todo Position-PID
8
Design cont. Initialization Todo > 0 Build new Todo Wait for Message NOYES
9
Design cont. time {start} {move, 3,2 } {ok} {req_neighbors} {neighbors, [{5,4, fox},.]}
10
Design cont. time {start} {move, 3,2 } {conflict, [{5,4, fox},.]} {req_neighbors} {neighbors, [{5,4, fox},.]} {eat, 4,4} Request not valid! {ok}
11
Demo
12
Missing AI - Now action choices are random. How to add simple AI? - Need to know the positions around. - Develop action priorities. 1.- Stay alive: scape from predators or eat. 2.- To find food: move away from borders. Limitations
13
Algorithms Atoms for element types Code sharing between animals Used libraries
14
Algorithms cont animal_loop(Position, States, Default_States, Types) -> receive {die, _} -> urks; {start, Gameboard_PID} -> Gameboard_PID ! {request_neighbors, Position, self()}, receive {die, _} -> urks; {neighbors, Neighbor_List} -> decide_animal(Neighbor_List, Gameboard_PID, Position, States, Default_States, Types) end end. {Eat_timer, Procreation_timer, Starvation_timer, Move_timer} {Own_Type, Prey_Type}
15
Algorithms cont decide_animal(Neighbor_List, Gameboard_PID, Position, States, Default_States, Types) -> {Own_Type, Prey_Type} = Types, {Eat_timer, Procreation_timer, Starvation_timer, Move_timer} = States, Prey_Cells = [{X_cell, Y_cell} || {_, Type, X_cell, Y_cell}<-Neighbor_List, Type==Prey_Type], Free_Cells = [{X_cell, Y_cell} || {_, Type, X_cell, Y_cell}<-Neighbor_List, Type==none], case {Free_Cells, Prey_Cells, Move_timer, Eat_timer, Procreation_timer} of {_, [_|_], _, 0, 0} -> % eat timer and procreation timer are zero and there is at least one neighboring prey cell [...] {[_|_], _, 0, _, _} -> % move timer is zero and there is at least one neighboring empty cell [...] {_, _, _, _, _} -> % no possible actions [...] end.
16
Why this produces correct results Gameboard in charge -> consistent Elements can always select a possible actions -> no dead locks, single turns will terminate Order of execution is not guaranteed -> Non-deterministic behaviour
17
Difficult cases Find all possible cases of inconsistency What should be done in conflict situations? Why the heck is there a dead lock???
18
??!! *?#~! http://code.google.com/p/pasture-uu-ht11/
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.