initial framework added
[fp1415-soccerfun.git] / src / Game / Footballer.dcl
1 definition module Footballer
2
3 /** This module defines the part of the SoccerFun API that is concerned with the footballer data types.
4 */
5 import StdMaybe, StdEnvExt
6 from StdIOCommon import :: Void(..)
7 import Football, Geometry, Team
8
9 :: Footballer = E. memory: // The memory of a footballer is a black box
10 { playerID :: !FootballerID // The identification of a player: this must be unique
11 , name :: !String // The name of a player: this need not be unique
12 , length :: !Length // The length of a player: should be in range [min_length..max_length]
13 , pos :: !Position // The position of a player: should be on the football field
14 , speed :: !Speed // The speed of a player: absolute direction and velocity with which player is moving
15 , nose :: !Angle // The bearing of a player: absolute direction in which player is looking
16 , skills :: !MajorSkills // The major skills of a player: these improve performance of affected actions
17 , effect :: !Maybe FootballerEffect // The effect(s) of the previous action
18 , stamina :: !Stamina // The current stamina of a player: 1.0 is optimal, 0.0 is worst
19 , health :: !Health // The current health of a player: 1.0 is optimal, 0.0 is worst
20 , brain :: !Brain (FootballerAI memory) memory // The precious asset: use and update the memory and compute an action
21 }
22 :: FootballerID = { clubName :: !ClubName // Club name of team
23 , playerNr :: !PlayersNumber // Number of player (1 for keeper, other for fielders)
24 }
25 instance == FootballerID
26 instance toString FootballerID
27 instance nameOf FootballerID
28
29 class sameClub a :: !a !a -> Bool // belong to same club
30 instance sameClub FootballerID
31 instance sameClub Footballer
32
33 :: ClubName :== String
34 :: Length :== Metre
35 :: MajorSkills :== (!Skill,!Skill,!Skill)
36 :: Skill = Running // Faster running without ball in possession
37 | Dribbling // Faster running with ball in possession
38 | Rotating // Wider range of rotation
39 | Gaining // Better ball gaining ability
40 | Kicking // More accurate and wider ball kicking
41 | Heading // More accurate and wider ball heading
42 | Feinting // Wider range of feint manouvre
43 | Jumping // Further jumping
44 | Catching // Better catching
45 | Tackling // More effective tackling
46 instance == Skill
47 instance toString Skill
48 :: PlayersNumber :== Int
49
50 instance == Footballer // two players are equal if their playerID's are equal
51 instance toPosition Footballer
52 instance toPosition3D Footballer
53
54 defaultFootballer :: !FootballerID -> Footballer
55
56 inRadiusOfFootballer :: !Position !Footballer -> Bool // True iff position touches/hits footballer
57 skillsAsList :: !Footballer -> [Skill] // Skills of the footballer as a list
58
59 :: FootballerAI memory :== (BrainInput,memory) -> (BrainOutput,memory)
60 :: FootballerAI` :== BrainInput -> BrainOutput
61 :: BrainInput = { referee :: [RefereeAction] // the referee actions
62 , football :: FootballState // the state of the football
63 , others :: [Footballer] // all other football players
64 , me :: Footballer // the player himself
65 }
66 :: BrainOutput :== FootballerAction // the footballer action
67
68 :: Half = FirstHalf | SecondHalf
69 instance == Half
70 instance toString Half
71 instance other Half
72
73 :: Home = West | East
74 instance == Home
75 instance toString Home
76 instance other Home
77
78 xWidthFootballer :== m (0.7/2.0) // chest size of footballer
79 yWidthFootballer :== m (0.4/2.0) // stomach size of footballer
80
81 identify_player :: !FootballerID !Footballer -> Bool
82 player_identity :: !Footballer -> FootballerID
83
84 class nameOf a :: !a -> String
85 instance nameOf Footballer
86
87 getClubName :: !Footballer -> ClubName
88 isKeeper :: !Footballer -> Bool
89 isFielder :: !Footballer -> Bool
90
91
92 :: Brain ai m = { ai :: !ai
93 , memory:: !m
94 }
95 :: Stamina :== Real
96 :: Health :== Real
97
98 min_length :== m 1.6 // minimum length of a person. Advantages: better gainball; better stamina at sprinting; better dribbling; less health damage when fall, better rotating.
99 max_length :== m 2.1 // maximum length of a person. Advantages: wider gainball; better stamina at running; higher headball; improved catching; harder kicking.
100 max_stamina :== 1.0
101 max_health :== 1.0
102
103 /** Footballer attribute dependent abilities:
104 use these functions to make your player correctly dependent of abilities.
105 */
106 maxGainReach :: !Footballer -> Metre
107 maxJumpReach :: !Footballer -> Metre // vertical jumping
108 maxGainVelocityDifference :: !Footballer !Metre -> Velocity
109 maxCatchVelocityDifference :: !Footballer !Metre -> Velocity
110 maxKickReach :: !Footballer -> Metre
111 maxHeadReach :: !Footballer -> Metre
112 maxCatchReach :: !Footballer -> Metre // includes horizontal jumping
113 maxTackleReach :: !Footballer -> Metre
114 maxVelocityBallKick :: !Footballer -> Velocity
115 maxVelocityBallHead :: !Footballer !Velocity -> Velocity
116 maxKickingDeviation :: !Footballer -> Angle
117 maxHeadingDeviation :: !Footballer -> Angle
118 maxRotateAngle :: !Footballer -> Angle // maximum angle with which footballer can rotate
119 maxFeintStep :: !Footballer -> Metre // maximum side step of footballer for feint manouvre
120
121 :: HealthStaminaFactor :== Real // combination of stamina and health
122 getHealthStaminaFactor :: !Health !Stamina -> HealthStaminaFactor
123
124
125 :: FootballField = { fwidth :: !FieldWidth // width of football field (64m <=width <=75m)
126 , flength :: !FieldLength // length of football field (100m<=length<=110m)
127 }
128 :: FieldWidth :== Metre
129 :: FieldLength :== Metre
130
131 getDefaultField :: FootballField
132 inPenaltyArea :: !FootballField !Home !Position -> Bool
133
134 /** Official metrics of a football field:
135 */
136 radius_centre_circle :== m 9.15
137 radius_centre_spot :== m 0.3 // not official, taken for rendering
138 goal_width :== m 7.32 // interior
139 goal_height :== m 2.44 // interior
140 goal_area_depth :== m 5.50
141 penalty_area_depth :== m 16.50
142 penalty_spot_depth :== m 11.00
143 radius_penalty_spot :== m 0.3 // not official, taken for rendering
144 radius_penalty_area :== m 9.15
145 radius_corner_kick_area :== m 0.90
146 goal_pole_width :== m 0.2 // not official
147
148 /** goal_poles yields the py coordinates of the interiors of (north pole, south pole) of the goal (note that north > 0 > south)
149 */
150 goal_poles :: !FootballField -> (!Metre,!Metre)
151
152 repell_distance :== m 9.15 // minimum distance of opponents from ball at (in)direct free kick
153
154 :: FootballerAction // actions a player can intend to perform
155 = Move !Speed !Angle // wish to rotate over given angle, and then move with given speed
156 | Feint !FeintDirection // wish to make feint manouvre
157 | KickBall !Speed3D // wish to kick ball with given speed
158 | HeadBall !Speed3D // wish to head ball with given speed
159 | GainBall // wish to gain possession of the ball
160 | CatchBall // wish to catch the ball with his hands
161 | Tackle !FootballerID !Velocity // wish to tackle identified player, higher velocity is higher chance of succes AND injury
162
163 isMove :: !FootballerAction -> Bool
164 isGainBall :: !FootballerAction -> Bool
165 isCatchBall :: !FootballerAction -> Bool
166 isKickBall :: !FootballerAction -> Bool
167 isHeadBall :: !FootballerAction -> Bool
168 isFeint :: !FootballerAction -> Bool
169 isFootballerTackle :: !FootballerAction -> Bool
170 isActionOnBall :: !FootballerAction -> Bool
171
172 instance == FootballerAction
173 instance toString FootballerAction
174
175 :: FeintDirection = FeintLeft | FeintRight
176 instance == FeintDirection
177 instance toString FeintDirection
178
179 :: FootballerEffect = Moved !Speed !Angle // player has rotated with given angle, and then ran with given speed
180 | Feinted !FeintDirection // player had feinted
181 | KickedBall !(Maybe Speed3D) // player kicked ball (Just v) with velocity, or didn't (Nothing)
182 | HeadedBall !(Maybe Speed3D) // player headed ball (Just v) with velocity, or didn't (Nothing)
183 | GainedBall !Success // player attempt to gain ball from other player
184 | CaughtBall !Success // player caught the ball with his hands
185 | Tackled !FootballerID !Velocity !Success // player attempt to tackle an opponent
186 | OnTheGround !FramesToGo // tackled by someone else; FramesToGo is the amount of frames that you will be on the ground
187 :: Reprimand = Warning | YellowCard | RedCard // If the referee gives a second yellow he should add red to it himself
188 instance toString Reprimand
189 instance == Reprimand
190 :: Success = Success | Fail
191 instance toString Success
192 instance == Success
193 :: FramesToGo :== Int // number of frames to go before event ends
194
195 isMoved :: !FootballerEffect -> Bool
196 isGainedBall :: !FootballerEffect -> Bool
197 isKickedBall :: !FootballerEffect -> Bool
198 isHeadedBall :: !FootballerEffect -> Bool
199 isFeinted :: !FootballerEffect -> Bool
200 isTackled :: !FootballerEffect -> Bool
201 isCaughtBall :: !FootballerEffect -> Bool
202 isOnTheGround :: !FootballerEffect -> Bool
203
204 failFootballerAction :: !FootballerAction -> FootballerEffect
205
206 :: RefereeAction = ReprimandPlayer !FootballerID !Reprimand // player with given name receives reprimand
207 | Hands !FootballerID // person is seen for doing hands
208 | TackleDetected !FootballerID // person is seen for doing tackle
209 | DangerousPlay !FootballerID // person is seen for doing dangerous actions
210 | GameOver // end of game
211 | GameCancelled !(Maybe Home) // game is cancelled, (Just home) wins
212 | PauseGame // game is paused
213 | AddTime !ExtraTime // extra time is added to the game
214 | EndHalf // first half is over, teams go for a second half
215 | Goal !Home // team playing at home has scored
216 | Offside !FootballerID // player is offside
217 | DirectFreeKick !Home !Position // a direct free kick is granted for team home at given position
218 | GoalKick !Home // a goal kick is granted for team home
219 | Corner !Home !Edge // a corner kick is granted for team home
220 | ThrowIn !Home !Position // a throw in ball is granted for team home at given position
221 | Penalty !Home // penalty at homeside
222 | CenterKick !Home // team playing at home may start from the center
223 | Advantage !Home // referee gives advantages to home-team
224 | OwnBallIllegally !FootballerID // ball was for the other team
225 | DisplacePlayers !Displacements // displaces all footballers at the provided position (used with free kicks)
226 | ContinueGame
227 | TellMessage !String // no effect on match, message is displayed by referee
228 showSuccintRefereeAction :: !RefereeAction -> String // yield a concise string representation of the referee decision
229
230 :: Edge = North | South
231 instance == Edge
232 instance toString Edge
233 instance other Edge
234
235 :: Displacements :== AssocList FootballerID Displacement // players that need to be displaced
236 :: Displacement :== Position // new position
237
238 displacements :: !Team -> Displacements
239
240 :: ExtraTime :== Minutes
241 :: Minutes
242 instance zero Minutes
243 instance < Minutes
244 instance == Minutes
245 instance + Minutes
246 instance - Minutes
247 instance scale Minutes
248 instance toString Minutes
249 instance toReal Minutes
250
251 class minutes a :: !a -> Minutes
252 instance minutes Real // (minutes m) interprets m as number of minutes
253
254 isReprimandPlayer :: !RefereeAction -> Bool
255 isHands :: !RefereeAction -> Bool
256 isTackleDetected :: !RefereeAction -> Bool
257 isDangerousPlay :: !RefereeAction -> Bool
258 isGameOver :: !RefereeAction -> Bool
259 isGameCancelled :: !RefereeAction -> Bool
260 isPauseGame :: !RefereeAction -> Bool
261 isAddTime :: !RefereeAction -> Bool
262 isEndHalf :: !RefereeAction -> Bool
263 isGoal :: !RefereeAction -> Bool
264 isOffside :: !RefereeAction -> Bool
265 isDirectFreeKick :: !RefereeAction -> Bool
266 isGoalKick :: !RefereeAction -> Bool
267 isCorner :: !RefereeAction -> Bool
268 isThrowIn :: !RefereeAction -> Bool
269 isPenalty :: !RefereeAction -> Bool
270 isCenterKick :: !RefereeAction -> Bool
271 isAdvantage :: !RefereeAction -> Bool
272 isOwnBallIllegally :: !RefereeAction -> Bool
273 isDisplacePlayers :: !RefereeAction -> Bool
274 isContinueGame :: !RefereeAction -> Bool
275 isTellMessage :: !RefereeAction -> Bool
276
277 getKickPos :: !FootballField !Half !RefereeAction -> Maybe Position