-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Football simulation framework for teaching functional programming
--
-- This is a Haskell port of the the SoccerFun framework originally
-- implemented in Clean. From the website: Soccer-Fun is an educational
-- project to stimulate functional programming by thinking about,
-- designing, implementing, running, and competing with the brains of
-- football players! It is open for participation by everybody who likes
-- to contribute. It is not restricted to a particular functional
-- programming language.
@package SoccerFun
@version 0.3
module SoccerFun.Geometry
type Metre = Float
type Length = Metre
type XPos = Metre
type YPos = Metre
type ZPos = Metre
data Position
Position :: XPos -> YPos -> Position
-- | x-coordinate in plane (0.0<=px)
px :: Position -> XPos
-- | y-coordinate in plane (0.0<=py)
py :: Position -> YPos
data Position3D
Position3D :: Position -> ZPos -> Position3D
pxy :: Position3D -> Position
pz :: Position3D -> ZPos
coordinates :: Position3D -> (XPos, YPos, ZPos)
type XRadius = Metre
type YRadius = Metre
type ZRadius = Metre
inRadiusOfPosition :: Position3D -> XRadius -> YRadius -> ZRadius -> Position -> Bool
type Angle = Radian
type Radian = Float
angleHowFarFromPi :: Angle -> Angle
angleHowFarFromAngle :: Angle -> Angle -> Angle
-- | movePoint v p moves point p over vector v.
movePoint :: RVector -> Position -> Position
movePoint3D :: RVector3D -> Position3D -> Position3D
-- | pointToRectangle (a,b) c returns c if
-- pointInRectangle (a,b) c and the | projected point
-- c' of c that is exactly on the closest edge of
-- rectangle | (a,b).
pointToRectangle :: (Position, Position) -> Position -> Position
-- | pointInRectangle (a,b) c | returns True iff point
-- c is inside the rectangle determined by | the diagonal corner
-- points a and b.
pointInRectangle :: (Position, Position) -> Position -> Bool
inCircleRadiusOfPosition :: Position3D -> XRadius -> ZRadius -> Position -> Bool
data RVector
RVector :: Metre -> Metre -> RVector
-- | difference in x-coordinate |dx| <= 1.0
dx :: RVector -> Metre
-- | difference in y-coordinate |dy| <= 1.0
dy :: RVector -> Metre
data RVector3D
RVector3D :: RVector -> Metre -> RVector3D
dxy :: RVector3D -> RVector
dz :: RVector3D -> Metre
-- | speed of an object
data Speed
Speed :: Angle -> Velocity -> Speed
-- | direction of object
direction :: Speed -> Angle
-- | velocity of object
velocity :: Speed -> Velocity
-- | speed of an object in space
data Speed3D
Speed3D :: Speed -> Velocity -> Speed3D
-- | surface speed of object
vxy :: Speed3D -> Speed
-- | velocity in z-axis (positive: goes up; negative: goes down; 0:
-- horizontally)
vz :: Speed3D -> Velocity
type Velocity = Float
class ToSpeed a
toSpeed :: (ToSpeed a) => a -> Speed
class FromSpeed a
fromSpeed :: (FromSpeed a) => Speed -> a
class ToSpeed3D a
toSpeed3D :: (ToSpeed3D a) => a -> Speed3D
class FromSpeed3D a
fromSpeed3D :: (FromSpeed3D a) => Speed3D -> a
class ToRVector a
toRVector :: (ToRVector a) => a -> RVector
class ToPosition a
toPosition :: (ToPosition a) => a -> Position
class FromPosition a
fromPosition :: (FromPosition a) => Position -> a
class ToPosition3D a
toPosition3D :: (ToPosition3D a) => a -> Position3D
class FromPosition3D a
fromPosition3D :: (FromPosition3D a) => Position3D -> a
-- | Conversion of radians to degrees and vice versa:
type Degrees = Int
-- | scaleVector k {dx,dy} returns {k*dx,k*dy} | scaleVector3D
-- k {dxy,dz} returns {scaleVector k dxy,k*dz}
scaleVector :: Float -> RVector -> RVector
scaleVector3D :: Float -> RVector3D -> RVector3D
fromRadian :: Radian -> Degrees
toRadian :: Degrees -> Radian
-- | betweenPoints (a,b) c returns True iff c is on the line
-- between a and b.
betweenPoints :: (Position, Position) -> Position -> Bool
-- | sizeVector {dx,dy} = sqrt (dx**2 + dy**2) | sizeVector3D
-- {dxy,dz} = sqrt ((dx dxy)**2 + (dy dxy)**2 + dz**2)
sizeVector :: RVector -> Float
sizeVector3D :: RVector3D -> Float
class Dist a b
dist :: (Dist a b) => a -> b -> Float
-- | orthogonal a returns the left- and right- orthogonal angles
-- to a
orthogonal :: Angle -> (Angle, Angle)
oppositeAngle :: Angle -> Angle
angleWithObject :: Position -> Position -> Angle
-- | gets the angle between two objects | positive angle is CW, negative is
-- CCW
angleWithObjectForRun :: (Position, Angle) -> Position -> Angle
instance Show Speed3D
instance Eq Speed3D
instance Show Speed
instance Eq Speed
instance Show RVector3D
instance Eq RVector3D
instance Show RVector
instance Eq RVector
instance Show Position3D
instance Eq Position3D
instance Show Position
instance Eq Position
instance FromSpeed3D Speed
instance ToSpeed3D Speed
instance FromSpeed Speed3D
instance ToSpeed Speed3D
instance FromPosition3D Position
instance FromPosition3D (Float, Float, Float)
instance ToPosition3D Position
instance ToPosition3D (Float, Float, Float)
instance FromPosition Position3D
instance FromPosition (Float, Float)
instance ToPosition Position3D
instance ToPosition (Float, Float)
instance Dist Position3D Position
instance Dist Position Position3D
instance Dist Position3D Position3D
instance Dist Position Position
instance Dist Float Float
instance ToRVector Position
instance ToRVector Float
instance Num Speed
instance Num Position
instance Num RVector
instance Num Position3D
instance Num Speed3D
instance Num RVector3D
module SoccerFun.Types
class NameOf a
nameOf :: (NameOf a) => a -> String
data Brain ai memory
Brain :: memory -> ai -> Brain ai memory
m :: Brain ai memory -> memory
ai :: Brain ai memory -> ai
data Half
FirstHalf :: Half
SecondHalf :: Half
type PlayingTime = Minutes
-- | type with an inverse value
class Other a
other :: (Other a) => a -> a
type TimeUnit = Seconds
type Seconds = Float
data Edge
North :: Edge
South :: Edge
data PlayerID
PlayerID :: ClubName -> PlayersNumber -> PlayerID
clubName :: PlayerID -> ClubName
playerNo :: PlayerID -> PlayersNumber
type ClubName = String
type PlayersNumber = Int
-- | If the referee gives a second yellow he should add red to it himself
data Reprimand
Warning :: Reprimand
YellowCard :: Reprimand
RedCard :: Reprimand
data Success
Success :: Success
Fail :: Success
type FramesToGo = Int
data RefereeAction
-- | player with given name receives reprimand
ReprimandPlayer :: PlayerID -> Reprimand -> RefereeAction
-- | person is seen for doing hands
Hands :: PlayerID -> RefereeAction
-- | person is seen for doing tackle
TackleDetected :: PlayerID -> RefereeAction
-- | person is seen for doing schwalbe
SchwalbeDetected :: PlayerID -> RefereeAction
TheaterDetected :: PlayerID -> RefereeAction
-- | person is seen for doing dangerous actions
DangerousPlay :: PlayerID -> RefereeAction
-- | end of game
GameOver :: RefereeAction
-- | game is paused
PauseGame :: RefereeAction
-- | extra time is added to the game
AddTime :: ExtraTime -> RefereeAction
-- | first half is over, teams go for a second half
EndHalf :: RefereeAction
-- | team playing at home has scored
Goal :: ATeam -> RefereeAction
-- | player is offside at Home
Offside :: PlayerID -> RefereeAction
-- | a direct free kick is granted for team home at given position
DirectFreeKick :: ATeam -> Position -> RefereeAction
-- | a goal kick is granted for team home
GoalKick :: ATeam -> RefereeAction
-- | a corner kick is granted for team home
Corner :: ATeam -> Edge -> RefereeAction
-- | a throw in ball is granted for team home at given position
ThrowIn :: ATeam -> Position -> RefereeAction
-- | penalty at homeside
Penalty :: ATeam -> RefereeAction
-- | team playing at home may start from the center
CenterKick :: ATeam -> RefereeAction
-- | referee gives advantages to home-team
Advantage :: ATeam -> RefereeAction
-- | ball was for the other team
OwnBallIllegally :: PlayerID -> RefereeAction
-- | displaces all players at the provided position (used with free kicks)
DisplacePlayers :: Displacements -> RefereeAction
ContinueGame :: RefereeAction
-- | no effect on match, message is displayed by referee
TellMessage :: String -> RefereeAction
data ATeam
Team1 :: ATeam
Team2 :: ATeam
type Displacements = [(PlayerID, Displacement)]
type Displacement = Position
type ExtraTime = Minutes
type Minutes = Float
instance Eq ATeam
instance Show ATeam
instance Show RefereeAction
instance Eq RefereeAction
instance Show Success
instance Eq Success
instance Show Reprimand
instance Eq Reprimand
instance Show PlayerID
instance Eq PlayerID
instance Eq Edge
instance Show Edge
instance Eq Half
instance Show Half
module SoccerFun.Field
data Field
Field :: FieldWidth -> FieldLength -> Field
-- | width of ball field (64m <=width <=75m)
fwidth :: Field -> FieldWidth
-- | height of ball field (100m<=height<=110m)
flength :: Field -> FieldLength
type FieldWidth = Metre
type FieldLength = Metre
defaultField :: Field
inPenaltyArea :: Field -> Home -> Position -> Bool
data Home
West :: Home
East :: Home
isWest :: Home -> Bool
isEast :: Home -> Bool
-- | goalPoles yields the py coordinates of the north pole and south pole
-- of the goal (note that north < south).
goalPoles :: Field -> (Metre, Metre)
instance Eq Home
instance Show Home
instance Show Field
instance Other Home
module SoccerFun.Ball
data BallState
Free :: Ball -> BallState
GainedBy :: PlayerID -> BallState
data Ball
Ball :: Position3D -> Speed3D -> Ball
ballPos :: Ball -> Position3D
ballSpeed :: Ball -> Speed3D
-- | mkBall returns a ball with 3D dimensions.
mkBall :: Position -> Speed -> Ball
-- | ballIsFree yields True iff argument is (Free ...).
ballIsFree :: BallState -> Bool
-- | ballAtCenter returns a non-moving ball at the center of the ball
-- field.
ballAtCenter :: Field -> Ball
-- | ballIsGainedBy yields True iff the ball is in possession by the given
-- player.
ballIsGainedBy :: PlayerID -> BallState -> Bool
data BounceDirection
Down :: BounceDirection
Up :: BounceDirection
Forward :: BounceDirection
Back :: BounceDirection
-- | Function used for giving a new random direction towards the given
-- BounceDirection (#param1)
bounceBall :: BounceDirection -> (Speed3D, StdGen) -> (Speed3D, StdGen)
radiusBall :: Float
surfaceResistance :: Float
airResistance :: Float
accellerationSec :: Float
instance Show Ball
instance Show BallState
-- | This module defines the part of the SoccerFun API that is concerned
-- with the player data types.
module SoccerFun.Player
data Player
Player :: PlayerID -> String -> Length -> Position -> Speed -> Angle -> MajorSkills -> Maybe PlayerEffect -> Stamina -> Health -> Brain (PlayerAI m) m -> Player
-- | must be unique
playerID :: Player -> PlayerID
-- | need not be unique
name :: Player -> String
-- | should be in range [minHeight..maxHeight]
height :: Player -> Length
-- | should be on the ball field
pos :: Player -> Position
-- | absolute direction and velocity with which player is moving
speed :: Player -> Speed
-- | absolute direction in which player is looking
nose :: Player -> Angle
-- | these improve performance of affected actions
skills :: Player -> MajorSkills
-- | The effect(s) of the previous action
effect :: Player -> Maybe PlayerEffect
-- | current stamina of a player: 1.0 is optimal, 0.0 is worst
stamina :: Player -> Stamina
-- | current health of a player: 1.0 is optimal, 0.0 is worst
health :: Player -> Health
-- | The precious asset: use and update the memory and make decisions
brain :: Player -> Brain (PlayerAI m) m
type PlayerAI memory = BrainInput -> State memory PlayerAction
data BrainInput
BrainInput :: [RefereeAction] -> BallState -> [Player] -> Player -> BrainInput
-- | the referee actions
referee :: BrainInput -> [RefereeAction]
-- | the state of the ball
ball :: BrainInput -> BallState
-- | all other ball players
others :: BrainInput -> [Player]
-- | the player himself
me :: BrainInput -> Player
type PlayerWithAction = (PlayerAction, PlayerID)
type PlayerWithEffect = (Maybe PlayerEffect, PlayerID)
type MajorSkills = (Skill, Skill, Skill)
data Skill
-- | Faster running without ball in possession
Running :: Skill
-- | Faster running with ball in possession
Dribbling :: Skill
-- | Wider range of rotation
Rotating :: Skill
-- | Better ball gaining ability
Gaining :: Skill
-- | More accurate and wider ball kicking
Kicking :: Skill
-- | More accurate and wider ball heading
Heading :: Skill
-- | Wider range of feint manouvre
Feinting :: Skill
-- | Further jumping
Jumping :: Skill
-- | Better catching
Catching :: Skill
-- | More effective tackling
Tackling :: Skill
-- | Better acting of tackles
Schwalbing :: Skill
-- | Better acting of playing theater
PlayingTheater :: Skill
data FeintDirection
FeintLeft :: FeintDirection
FeintRight :: FeintDirection
-- | actions a player can intend to perform
data PlayerAction
-- | wish to rotate over given angle, and then move with given speed
Move :: Speed -> Angle -> PlayerAction
-- | wish to make feint manouvre
Feint :: FeintDirection -> PlayerAction
-- | wish to kick ball with given speed
KickBall :: Speed3D -> PlayerAction
-- | wish to head ball with given speed
HeadBall :: Speed3D -> PlayerAction
-- | wish to gain possession of the ball from other player
GainBall :: PlayerAction
-- | wish to catch the ball with his hands
CatchBall :: PlayerAction
-- | wish to tackle identified player, higher velocity is higher chance of
-- succes AND injury (and foul?)
Tackle :: PlayerID -> Velocity -> PlayerAction
-- | wish to fall as if he was tackled
Schwalbe :: PlayerAction
-- | wish to act as if he was hurt
PlayTheater :: PlayerAction
data PlayerEffect
-- | player has rotated with given angle, and then ran with given speed
Moved :: Speed -> Angle -> PlayerEffect
-- | player had feinted
Feinted :: FeintDirection -> PlayerEffect
-- | player kicked ball (Just v) with velocity, or didn't (Nothing)
KickedBall :: (Maybe Speed3D) -> PlayerEffect
-- | player headed ball (Just v) with velocity, or didn't (Nothing)
HeadedBall :: (Maybe Speed3D) -> PlayerEffect
-- | player attempt to gain ball from other player
GainedBall :: Success -> PlayerEffect
-- | player caught the ball with his hands
CaughtBall :: Success -> PlayerEffect
-- | player attempt to tackle an opponent
Tackled :: PlayerID -> Velocity -> Success -> PlayerEffect
-- | player had performed a schwalbe
Schwalbed :: PlayerEffect
-- | player had started to act hurt
PlayedTheater :: PlayerEffect
-- | tackled by someone else; FramesToGo is the amount of frames that you
-- will be on the ground
OnTheGround :: FramesToGo -> PlayerEffect
type Stamina = Float
type Health = Float
defaultPlayer :: PlayerID -> Player
identifyPlayer :: PlayerID -> Player -> Bool
playerIdentity :: Player -> PlayerID
-- | getBall returns the ball (containing its position and
-- speed-information) | that is either free or gained by a player. | For
-- this reason, the list of players must contain all players, otherwise |
-- this function may fail.
getBall :: BallState -> [Player] -> Ball
-- | Returns True if the ball is held by a Keeper in his own penaltyarea |
-- Returns False when the ball is held by a Keeper in open field |
-- Returns False when the ball is not held by a Keeper | Keepers should
-- be numbered with 1.
ballGainedByKeeper :: BallState -> [Player] -> ClubName -> Home -> Field -> Bool
clonePlayer :: Brain (PlayerAI m) m -> Player -> Player
class SameClub a
sameClub :: (SameClub a) => a -> a -> Bool
class GetPosition a
getPosition :: (GetPosition a) => a -> Position
inRadiusOfPlayer :: Position -> Player -> Bool
skillsAsList :: Player -> [Skill]
isFirstHalf :: Half -> Bool
isSecondHalf :: Half -> Bool
-- | chest size of player
--
-- stomach size of player
getClubName :: Player -> ClubName
isKeeper :: Player -> Bool
isFielder :: Player -> Bool
-- | minimum length of a person. Advantages: better gainball; better
-- stamina at sprinting; better dribbling; less health damage when fall,
-- better rotating.
--
-- maximum length of a person. Advantages: wider gainball; better stamina
-- at running; higher headball; improved catching; harder kicking.
--
-- minimum height of a person. Advantages: better gainball; better
-- stamina at sprinting; better dribbling; less health damage when fall,
-- better rotating.
--
-- maximum height of a person. Advantages: wider gainball; better stamina
-- at running; higher headball; improved catching; harder kicking.
--
-- Player attribute dependent abilities: use these functions to make your
-- player correctly dependent of abilities.
maxGainReach :: Player -> Metre
-- | vertical jumping
maxJumpReach :: Player -> Metre
maxGainVelocityDifference :: Player -> Metre -> Velocity
maxCatchVelocityDifference :: Player -> Metre -> Velocity
maxKickReach :: Player -> Metre
maxHeadReach :: Player -> Metre
-- | includes horizontal jumping
maxCatchReach :: Player -> Metre
maxTackleReach :: Player -> Metre
maxVelocityBallKick :: Player -> Velocity
maxVelocityBallHead :: Player -> Velocity -> Velocity
maxKickingDeviation :: Player -> Angle
maxHeadingDeviation :: Player -> Angle
-- | maximum angle with which player can rotate
maxRotateAngle :: Player -> Angle
-- | maximum side step of player for feint manouvre
maxFeintStep :: Player -> Metre
-- | combination of stamina and health
type HealthStaminaFactor = Float
getHealthStaminaFactor :: Health -> Stamina -> HealthStaminaFactor
teamHome :: ATeam -> Half -> Home
opponentHome :: ATeam -> Half -> Home
isMove :: PlayerAction -> Bool
isGainBall :: PlayerAction -> Bool
isCatchBall :: PlayerAction -> Bool
isKickBall :: PlayerAction -> Bool
isHeadBall :: PlayerAction -> Bool
isFeint :: PlayerAction -> Bool
isPlayerTackle :: PlayerAction -> Bool
isSchwalbe :: PlayerAction -> Bool
isPlayTheater :: PlayerAction -> Bool
isSkillOfAction :: Skill -> PlayerAction -> Bool
isActionOnBall :: PlayerAction -> Bool
isMoved :: PlayerEffect -> Bool
isGainedBall :: PlayerEffect -> Bool
isKickedBall :: PlayerEffect -> Bool
isHeadedBall :: PlayerEffect -> Bool
isFeinted :: PlayerEffect -> Bool
isTackled :: PlayerEffect -> Bool
isSchwalbed :: PlayerEffect -> Bool
isCaughtBall :: PlayerEffect -> Bool
isPlayedTheater :: PlayerEffect -> Bool
isOnTheGround :: PlayerEffect -> Bool
failPlayerAction :: PlayerAction -> PlayerEffect
instance Eq PlayerAction
instance Show PlayerAction
instance Eq FeintDirection
instance Show FeintDirection
instance Eq Skill
instance Show Skill
instance SameClub Player
instance SameClub PlayerID
instance NameOf PlayerID
instance NameOf Player
instance GetPosition Player
instance Show Player
instance Eq Player
-- | This module defines the Soccer-Fun API that is concerned with teams.
-- All available teams are collected in this module (allAvailableTeams).
module SoccerFun.Team
type Team = [Player]
validateTeam :: Team -> Team
replaceInTeam :: [Player] -> Team -> Team
getTeam :: ClubName -> [Team] -> Team
class Mirror a
mirror :: (Mirror a) => Field -> a -> a
isValidTeam :: Team -> Bool
instance Mirror Angle
instance Mirror Speed
instance Mirror Position
instance Mirror Player
instance (Mirror a) => Mirror [a]
instance Other ATeam
instance NameOf Team
module SoccerFun.UI.GL
gameLength :: TimeUnit
runMatch :: (Home -> Field -> Team) -> (Home -> Field -> Team) -> IO ()
registerCallbacks :: Window -> IORef GLdouble -> IORef Match -> IO ()
colorRGB :: (GLfloat, GLfloat, GLfloat) -> IO ()
drawAt3D :: Position3D -> IO () -> IO ()
drawAt :: Position -> IO () -> IO ()
square :: IO ()
vector2 :: (Float, Float) -> Vector3 GLfloat
vertex2 :: (Float, Float) -> IO ()
convertDouble :: Double -> GLdouble
convertFloat :: Float -> GLfloat