170 likes | 269 Views
PASTURE. Advanced Functional Programming. Daniel Strebel Eduardo Hernández Marquina. The Problem. The board: A grid where the different elements are going to interact. The Problem Cont. Elements Fences : Static elements Grass : Procreate. The Problem Cont. Elements Cont :
E N D
PASTURE AdvancedFunctionalProgramming Daniel Strebel Eduardo Hernández Marquina
TheProblem The board: A grid where the different elements are going to interact.
TheProblem Cont. Elements • Fences: • Staticelements • Grass: • Procreate
TheProblem Cont. ElementsCont: Abilities: - Move - Eat - Procreate
Design Game Board
Design cont. Game Board Todo Position-PID
Design cont. Game Board Initialization NO YES Todo> 0 BuildnewTodo Waitfor Message
Design cont. Game Board {start} {req_neighbors} time {neighbors, [{5,4, fox},.]} {move, 3,2 } {ok} Game Board
Design cont. Game Board {start} {req_neighbors} time {neighbors, [{5,4, fox},.]} {move, 3,2 } Request not valid! {conflict, [{5,4, fox},.]} {eat, 4,4} {ok} Game Board
Limitations • 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.
Algorithms Atoms forelementtypes Usedlibraries Code sharingbetweenanimals
Algorithmscont {Eat_timer, Procreation_timer, Starvation_timer, Move_timer} 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. {Own_Type, Prey_Type}
Algorithmscont 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.
Whythis produces correctresults Gameboard in charge-> consistent Elements canalwaysselect a possibleactions-> nodeadlocks, singleturns will terminate Order of executionis not guaranteed -> Non-deterministicbehaviour
Difficult cases Find all possiblecases of inconsistency Whatshouldbedone in conflictsituations? Whythe heck isthere a dead lock???
*?#~! ??!! http://code.google.com/p/pasture-uu-ht11/