initial framework added
[fp1415-soccerfun.git] / src / Game / Football.icl
diff --git a/src/Game/Football.icl b/src/Game/Football.icl
new file mode 100644 (file)
index 0000000..528091c
--- /dev/null
@@ -0,0 +1,25 @@
+implementation module Football\r
+\r
+import Footballer, randomstream\r
+\r
+instance zero         Football where zero                                      = {ballPos=zero, ballSpeed=zero}\r
+instance toPosition   Football where toPosition   {ballPos} = ballPos.pxy\r
+instance toPosition3D Football where toPosition3D {ballPos}    = ballPos\r
+\r
+mkFootball :: !Position !Speed -> Football\r
+mkFootball pos2D speed2D                       = {ballPos = toPosition3D pos2D, ballSpeed = toSpeed3D speed2D}\r
+\r
+ballIsFree :: !FootballState -> Bool\r
+ballIsFree (Free _)                                    = True\r
+ballIsFree _                                           = False\r
+\r
+ballIsGainedBy :: !FootballerID !FootballState -> Bool\r
+ballIsGainedBy id (GainedBy id`)       = id == id`\r
+ballIsGainedBy _ _                                     = False\r
+\r
+getFootball :: !FootballState !.[Footballer] -> Football\r
+getFootball (Free ball) _                      = ball\r
+getFootball (GainedBy playerID) allPlayers\r
+       = case filter (identify_player playerID) allPlayers of\r
+               []                                                      = abort "getFootball: no player found with requested identifier."\r
+               [{pos,speed}:_]                         = mkFootball pos speed\r