(* †bungen zur Vorlesung Informatik I, WS 2003/04 Programmieraufgabe P-23 :: landkarte.ml ---------------------------------------------- Leonhard Fellermayr, Mat. Nr. 22128130XXXX *) let two_from_three (a, b, c) = if ((a==b || a==c) && c <> b) || (b == c && c <> a) then true else false;; (* what (x,y) ermittelt den Typ des an Position (x,y) gelegenen Kšrpers. In der Funktion what (x,y) sind die verschiedenen Kšrper so codiert: 0 -> WŸste 1 -> See 2 -> Berg *) let rec what (x,y) = match (x,y) with (* horizontale Vordefinitionen *) |(x,0) when (x mod 3 == 0) -> 0 |(x,0) when ((x-1) mod 3 == 0) -> 2 |(x,0) when ((x-2) mod 3 == 0) -> 1 (* vertikale Vordefinitionen *) |(0,y) when (y mod 3 == 0) -> 0 |(0,y) when ((y-1) mod 3 == 0) -> 1 |(0,y) when ((y-2) mod 3 == 0) -> 2 (* alle 3 Nachbarfelder gleich -> WŸste *) |(_,_) when (what((x-1),(y-1)) == what((x-1),y)) && (what((x-1),y) == what(x,(y-1))) -> 0 (* alle 3 Nachbarfelder verschieden -> Berg *) |(_,_) when (what(x-1,y-1) <> what(x-1,y)) && (what(x-1,y-1) <> what(x,y-1)) && (what(x-1,y) <> what(x,y-1)) -> 2 (* genau 2 von 3 Nachbarfeldern gleich -> See *) |(_,_) when two_from_three (what(x-1,y), what(x-1,y-1), what (x,y-1)) -> 1 (* else-Fall: tritt nie auf, aber sonst beschwert sich OCAML Ÿber "bad style" *) |(_,_) -> 4711;; (* Ab hier werden die in der Aufgabenstellung verlangten Funktionen definiert. Sie greifen auf what (x,y) zurŸck und geben einen Wert vom Typ bool zurŸck. *) let wueste (x,y) = if (what(x,y) == 0) then true else false;; let see (x,y) = if (what(x,y) == 1) then true else false;; let berg (x,y) = if (what(x,y) == 2) then true else false;;