1 implementation module Team_MartLubbers
4 import FootballerFunctions
24 Team_MartLubbers :: !Home !FootballField -> Team
25 Team_MartLubbers home field
26 | home==West = westTeam
27 | otherwise = eastTeam
29 eastTeam = mirror field westTeam
30 westTeam = [keeper : fielders]
31 clubname = base_TeamName_MartLubbers +++ if (home == West) "_W" "_E"
32 keeper = Aesir clubname home field {zero & px=scale -0.5 field.flength} 1 "Thor"
33 fielders = [Aesir clubname home field {px=scale (-0.5*dx) field.flength,py=scale (0.5*dy) field.fwidth} nr name
34 \\ (dx,dy) <- west_positions_fielders
38 west_positions_fielders = [(0.20, 0.40)
50 :: Mem = {home :: !Home, origpos :: Position}
52 Aesir :: !ClubName !Home !FootballField !Position !PlayersNumber !String -> Footballer
53 Aesir club home field position nr name
54 = { playerID = {clubName=club,playerNr=nr}
55 , name = name +++ "_" <+++ nr
60 , skills = (Running, Kicking, Rotating)
62 , stamina = max_stamina
64 , brain = {memory = {home=home, origpos=position}, ai = mind field }
67 closerToGoal :: !Home -> Metre Metre -> Bool
68 closerToGoal East = (<)
69 closerToGoal West = (>)
71 mind :: !FootballField !(!BrainInput, !Mem) -> (!BrainOutput, !Mem)
72 mind field (x=:{referee,football,others,me}, mm=:{home,origpos})
73 | ballIsGainedBy me.playerID football
74 | me.stamina > 0.5 = fix nextPos (m 1.0) (x, mm)
75 | otherwise = kick nextPos (x, mm)
76 | isClosest others me ballPos.pxy = afterfix (\(_, m).(GainBall, m)) ballPos.pxy (scale 0.5 (maxKickReach me)) (x, mm)
78 | we_have_ball = fix {px=min ballPos.pxy.px (field.flength-me.pos.px), py=me.pos.py} (m 1.0) (x, mm)
79 | otherwise = fix origpos (m 1.0) (x, mm)
82 ballPos = (getBall x).ballPos
83 nextPos = let np = nextPlayer home us me.pos in if (isNothing np) (centerOfGoal (other home) field) (fromJust np)
84 we_have_ball = or (map (\x.ballIsGainedBy x.playerID football) us)
86 nextPlayer :: !Home [Footballer] Position -> Maybe Position
87 nextPlayer home xs pos
88 # xs = filter (\x.closerToGoal home x.pos.px pos.px) xs
90 | otherwise = Just (minListBy (\x y.(dist x.pos pos) < (dist y.pos pos)) xs).pos
92 closest :: [Footballer] Position -> Footballer
93 closest xs p = minListBy (\x y.(dist x.pos p) < (dist y.pos p)) xs
95 isClosest :: [Footballer] Footballer Position -> Bool
96 isClosest xs x p = closest [x:xs] p == x
98 afterfix :: (FootballerAI m) !Position !Metre !(!BrainInput, m) -> (BrainOutput, m)
99 afterfix after point diff (input=:{me}, m)
100 | d < diff = after (input, m)
101 | otherwise = (move, m)
104 a = bearing zero me point
105 r = bearing me.nose me point
106 v = ms (max 6.0 (toReal d))
107 move = Move {direction=a, velocity=v} r
109 base_TeamName_MartLubbers :: String
110 base_TeamName_MartLubbers = "Æsir"