Presentation is loading. Please wait.

# Daniel Strebel Eduardo Hernández Marquina Advanced Functional Programming.

## Presentation on theme: "Daniel Strebel Eduardo Hernández Marquina Advanced Functional Programming."— Presentation transcript:

Daniel Strebel Eduardo Hernández Marquina Advanced Functional Programming

1.- The Problem 2.- Design 3.- Demo 4.- Limitations 5.- Algorithms 6.- Why we produces correct results 7.- Difficult cases Agenda

The board: A grid where the different elements are going to interact. The Problem

Elements »Fences: Static elements »Grass: Procreate The Problem Cont.

Elements Cont: Abilities: - Move - Eat - Procreate The Problem Cont.

Design

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

Design cont. Initialization Todo > 0 Build new Todo Wait for Message NOYES

Design cont. time {start} {move, 3,2 } {ok} {req_neighbors} {neighbors, [{5,4, fox},.]}

Design cont. time {start} {move, 3,2 } {conflict, [{5,4, fox},.]} {req_neighbors} {neighbors, [{5,4, fox},.]} {eat, 4,4} Request not valid! {ok}

Demo

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

Algorithms Atoms for element types Code sharing between animals Used libraries

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}

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.

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

Difficult cases Find all possible cases of inconsistency What should be done in conflict situations? Why the heck is there a dead lock???

??!! *?#~! http://code.google.com/p/pasture-uu-ht11/

Similar presentations

Ads by Google