module SoccerFun.RefereeAction where
import SoccerFun.Types
import SoccerFun.Geometry
import SoccerFun.Field
data RefereeAction
= ReprimandPlayer PlayerID Reprimand
| Hands PlayerID
| TackleDetected PlayerID
| SchwalbeDetected PlayerID
| TheaterDetected PlayerID
| DangerousPlay PlayerID
| GameOver
| PauseGame
| AddTime ExtraTime
| EndHalf
| Goal ATeam
| Offside PlayerID
| DirectFreeKick ATeam Position
| GoalKick ATeam
| Corner ATeam Edge
| ThrowIn ATeam Position
| Penalty ATeam
| CenterKick ATeam
| Advantage ATeam
| OwnBallIllegally PlayerID
| DisplacePlayers Displacements
| ContinueGame
| TellMessage String
deriving (Show, Eq)
isReprimandPlayer ∷ RefereeAction → Bool
isReprimandPlayer (ReprimandPlayer _ _) = True
isReprimandPlayer _ = False
isHands ∷ RefereeAction → Bool
isHands (Hands _) = True
isHands _ = False
isTackleDetected ∷ RefereeAction → Bool
isTackleDetected (TackleDetected _) = True
isTackleDetected _ = False
isSchwalbeDetected ∷ RefereeAction → Bool
isSchwalbeDetected (SchwalbeDetected _) = True
isSchwalbeDetected _ = False
isTheaterDetected ∷ RefereeAction → Bool
isTheaterDetected (TheaterDetected _) = True
isTheaterDetected _ = False
isDangerousPlay ∷ RefereeAction → Bool
isDangerousPlay (DangerousPlay _) = True
isDangerousPlay _ = False
isGameOver ∷ RefereeAction → Bool
isGameOver GameOver = True
isGameOver _ = False
isPauseGame ∷ RefereeAction → Bool
isPauseGame PauseGame = True
isPauseGame _ = False
isAddTime ∷ RefereeAction → Bool
isAddTime (AddTime _) = True
isAddTime _ = False
isEndHalf ∷ RefereeAction → Bool
isEndHalf EndHalf = True
isEndHalf _ = False
isGoal ∷ RefereeAction → Bool
isGoal (Goal _) = True
isGoal _ = False
isOffside ∷ RefereeAction → Bool
isOffside (Offside _) = True
isOffside _ = False
isDirectFreeKick ∷ RefereeAction → Bool
isDirectFreeKick (DirectFreeKick _ _ ) = True
isDirectFreeKick _ = False
isGoalKick ∷ RefereeAction → Bool
isGoalKick (GoalKick _) = True
isGoalKick _ = False
isCorner ∷ RefereeAction → Bool
isCorner (Corner _ _) = True
isCorner _ = False
isThrowIn ∷ RefereeAction → Bool
isThrowIn (ThrowIn _ _) = True
isThrowIn _ = False
isPenalty ∷ RefereeAction → Bool
isPenalty (Penalty _) = True
isPenalty _ = False
isCenterKick ∷ RefereeAction → Bool
isCenterKick (CenterKick _) = True
isCenterKick _ = False
isAdvantage ∷ RefereeAction → Bool
isAdvantage (Advantage _) = True
isAdvantage _ = False
isOwnBallIllegally ∷ RefereeAction → Bool
isOwnBallIllegally (OwnBallIllegally _) = True
isOwnBallIllegally _ = False
isDisplacePlayers ∷ RefereeAction → Bool
isDisplacePlayers (DisplacePlayers _) = True
isDisplacePlayers _ = False
isContinueGame ∷ RefereeAction → Bool
isContinueGame ContinueGame = True
isContinueGame _ = False
isTellMessage ∷ RefereeAction → Bool
isTellMessage (TellMessage _) = True
isTellMessage _ = False
isGoal4ATeam ∷ ATeam → RefereeAction → Bool
isGoal4ATeam t (Goal t') = t == t'
isGoal4ATeam _ _ = False
getKickPos ∷ Field → Half → RefereeAction → Maybe Position
getKickPos field half (GoalKick team) = Just $ Position { py = (fwidth field)/2.0
, px = if (team == Team1 && half == FirstHalf || team == Team2 && half == SecondHalf)
then penaltyAreaDepth
else (flength field) penaltyAreaDepth }
getKickPos field half (Corner team edge) = Just $ Position { px = if (team == Team1 && half == SecondHalf || team == Team2 && half == FirstHalf)
then halfRadiusCornerKickArea
else ((flength field) halfRadiusCornerKickArea)
, py = if (edge == North)
then halfRadiusCornerKickArea
else ((fwidth field) halfRadiusCornerKickArea)
}
where
halfRadiusCornerKickArea = radiusCornerKickArea / 2.0
getKickPos field half (Penalty team) = Just $ Position { py = (fwidth field)/2.0
, px = if (team == Team1 && half == SecondHalf || team == Team2 && half == FirstHalf)
then penaltySpotDepth
else ((flength field) penaltySpotDepth)
}
getKickPos field _ (CenterKick _) = Just $ Position { px = (flength field)/2.0
, py = (fwidth field) /2.0
}
getKickPos _ _ (DirectFreeKick _ pos) = Just pos
getKickPos _ _ (ThrowIn _ pos) = Just pos
getKickPos _ _ _ = Nothing