initial framework added
[fp1415-soccerfun.git] / src / Game / Football.icl
1 implementation module Football
2
3 import Footballer, randomstream
4
5 instance zero Football where zero = {ballPos=zero, ballSpeed=zero}
6 instance toPosition Football where toPosition {ballPos} = ballPos.pxy
7 instance toPosition3D Football where toPosition3D {ballPos} = ballPos
8
9 mkFootball :: !Position !Speed -> Football
10 mkFootball pos2D speed2D = {ballPos = toPosition3D pos2D, ballSpeed = toSpeed3D speed2D}
11
12 ballIsFree :: !FootballState -> Bool
13 ballIsFree (Free _) = True
14 ballIsFree _ = False
15
16 ballIsGainedBy :: !FootballerID !FootballState -> Bool
17 ballIsGainedBy id (GainedBy id`) = id == id`
18 ballIsGainedBy _ _ = False
19
20 getFootball :: !FootballState !.[Footballer] -> Football
21 getFootball (Free ball) _ = ball
22 getFootball (GainedBy playerID) allPlayers
23 = case filter (identify_player playerID) allPlayers of
24 [] = abort "getFootball: no player found with requested identifier."
25 [{pos,speed}:_] = mkFootball pos speed