Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and...

16
CAMINO DE SANTIAGO SAINT JAMES’ WAY Matías Blanco – Sergio Pérez

Transcript of Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and...

Page 1: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

CAMINO DE SANTIAGOSAINT JAMES’ WAY

Matías Blanco – Sergio Pérez

Page 2: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

The ProblemA few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start their journey from three different places: Roncesvalles, Somport or Nájera… but the way is long and they will need to rest in order to recover their energy.When a peregrin arrives to a city the first thing he does is trying to sleep at a free hostel. In this case he spents no money at all. If the hostel is at its full capacity he’ll try to pay for a room at a Hotel. He’ll be always resting better at a hotel than at a free hostel. He’ll recover more energy but at a cost. If a peregrin can’t pay, he’ll not rest at all. If he has not enought energy to move to the next city, he’ll quit his journey.

Page 3: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

Our solution We’ve used protected types – A city is a

protected type, and the whole way is formed by them. So the way could be know as an array of protected types.

A city will have these properties: The next city (integer representing the position of

the city in the array) The cost for moving to the next city (in terms of

energy) The numbersof rooms the local hostel has. The energy recovered if sleeping at a free hoStel The energy recovered if sleeping at a Hotel The price of a room at the hotel

Page 4: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

Ciudadprotected type Ciudad is

procedure Init(next_cost : Integer;next_c: Integer; plazasA : Integer; F_Recupera_Alb : Integer; HotelCuesta :Integer; F_Recupera_Hot : Integer);procedure DormirEnAlbergue (Id : Integer; PuedeDormir : out Boolean; Fuerza : in out Integer);procedure SalirDeAlbergue (Id : Integer);procedure DormirEnHotel (Id : Integer; Dinero : in out Integer; PuedeDormir : out Boolean; Fuerza : in out

Integer);procedure SalirDeHotel(Id : Integer);function get_next_ciu return Integer;function get_next_ciu_cuesta return Integer;

privatenext_ciu_cuesta : Integer;next_ciu : Integer;PlazasAlbergue : Integer;F_Recupera_Alblbergue : Integer;Precio_hotel : Integer;F_Recupera_Hotel: Integer;

end Ciudad;

Page 5: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

Ciudad (2)procedure DormirEnAlbergue (Id : Integer; PuedeDormir : out Boolean;

Fuerza : in out Integer) is begin PuedeDormir := False; -- En un principio no

if PlazasAlbergue > 0 then Put_Line("El peregrino "&Integer'Image(Id)&" consigue sitio en

albergue"); Put_Line("+ "&Integer'Image(F_Recupera_Alblbergue)&"

fuerza"); Put_Line(Integer'Image(PlazasAlbergue)&" plazas"); plazasAlbergue := PlazasAlbergue - 1; Fuerza := Fuerza + F_Recupera_Alblbergue; PuedeDormir := True; -- Entonces sà end if; end DormirEnAlbergue;

Page 6: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

Ciudad (4)procedure SalirDeHotel (Id : Integer) is begin

Put_Line("El peregrino "&Integer'Image(Id)&" se va del hotel");

end SalirDeHotel;

function get_next_ciu return Integer is begin return next_ciu; end get_next_ciu;

function get_next_ciu_cuesta return Integer is begin return next_ciu_cuesta; end get_next_ciu_cuesta;

Page 7: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

Camino

type Camino is array (1 .. MAX_CIUDADES) of Ciudad;

CaminoDeSantiago : Camino;

Page 8: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

Peregrino task body Peregrino is Dinero : Integer; Fuerzas : Integer; Fracaso : Boolean; Tiempo_Dormir : constant := 3.0; CiudadActual : Integer; PuedeDormir : Boolean; Descansa_En : TDescanso; begin Fuerzas := Integer(Random(G)*Float(MAX_FUERZAS-2))+2; Dinero := Integer(Random(G)*Float(MAX_DINERO-1))+1; CiudadActual := Integer(Random(G)*2.0)+1; -- 1, 2 o 3

Fracaso := False; -- Inicializado a false

Page 9: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

Peregrino (2)while CiudadActual /= SANTI and not Fracaso loop

Descansa_En := nada; -- Por defecto

CaminoDeSantiago(CiudadActual).DormirEnAlbergue(Id, PuedeDormir, Fuerzas);

if not PuedeDormir then Put_Line("El peregrino "&Integer'Image(Id)&" no encuentra sitio en el albergue");

CaminoDeSantiago(CiudadActual).DormirEnHotel(Id, Dinero, PuedeDormir, Fuerzas);

if not PuedeDormir then Put_Line("El peregrino "&Integer'Image(Id)&" no puede

permitirse el hotel"); else Descansa_En := hotel; end if; else Descansa_En := albergue; end if; ...

Page 10: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

Peregrino (3)

if PuedeDormir then delay Duration(Tiempo_Dormir*Random(G)); if Descansa_En = albergue then

CaminoDeSantiago(CiudadActual).SalirDeAlbergue(Id); elsif Descansa_En = hotel then

CaminoDeSantiago(CiudadActual).SalirDeHotel(Id); end if; -- Se va si ha descansado else Put_Line("El peregrino "&Integer'Image(Id)&" no descansa

en "&Integer'Image(CiudadActual)); end if;

Page 11: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

Peregrino (4) if Fuerzas < CaminoDeSantiago(CiudadActual).get_next_ciu_cuesta

then Put_Line(“¡¡POBRE!! El peregrino "&Integer'Image(Id)&"

fracaso, no tiene fuerzas!!"); Fracaso := True; -- Jarl else -- Si puede... if CiudadActual /= SANTI then Put_Line("El peregrino "&Integer'Image(Id)&" a por la ciudad

"&Integer'Image(CaminoDeSantiago(CiudadActual).get_next_ciu)); Fuerzas := Fuerzas -

CaminoDeSantiago(CiudadActual).get_next_ciu_cuesta; Ciudadactual :=

CaminoDeSantiago(CiudadActual).get_next_ciu; end if; end if;end loop; -- sale de aquí = ya no va a ningín sitio más

Page 12: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

Peregrino (5)

… continúa desde “fin loop” de recorrer nodos

if not Fracaso then Put_Line("BIENNNNN!!!

Peregrino"&Integer'Image(Id)&" ha llegado a Santiago de Compostela!! Rece por nosotros! Para aprobar!!");

end if;end Peregrino;

Page 13: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

Initializationprocedure InitNodos is begin

-- Informacion del camino, ayuda x J. Peris (gracias) CaminoDeSantiago(1).Init(3,3,2,1,3,2); --

Roncesvalles CaminoDeSantiago(2).Init(4,4,2,1,3,1); -- Somport CaminoDeSantiago(3).Init(2,2,1,1,3,1); -- Nájera CaminoDeSantiago(4).Init(5,6,1,2,3,2); -- Otro CaminoDeSantiago(5).Init(6,4,1,2,3,2); --

… CaminoDeSantiago(9).Init(0,0,1000,1000,1000,1000);

end InitNodos;

Page 14: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

Initialization (2)

begin

InitNodos;

for I in 1..MAX_PEREGRIN loop Peregrinos := new Peregrino(I); delay Duration(Random(G)); end loop;

end CaminoTProtAda;

Page 15: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

Screenshot

Page 16: Matías Blanco – Sergio Pérez. The Problem A few peregrins, each one with his own strenght and money want to make the Saint James’ Way. They can start.

Questions?

Thank you.