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})
73 # others = (me team others)
74 | isClosest others me (getBall x).ballPos.pxy = (afterfix (kick nextPos) (getBall x).ballPos.pxy (maxKickReach me)) (x, mm)
75 | otherwise = halt (x, mm)
77 nextPos = let np = nextPlayer home others me.pos in if (isNothing np) (centerOfGoal (other home) field) (fromJust np)
79 nextPlayer :: !Home [Footballer] Position -> Maybe Position
80 nextPlayer home xs pos
81 # xs = filter (\x.closerToGoal home x.pos.px pos.px) xs
83 | otherwise = Just (minListBy (\x y.(dist x.pos pos) < (dist y.pos pos)) xs).pos
85 closest :: [Footballer] Position -> Footballer
86 closest xs p = minListBy (\x y.(dist x.pos p) < (dist y.pos p)) xs
88 isClosest :: [Footballer] Footballer Position -> Bool
89 isClosest xs x p = closest [x:xs] p == x
91 afterfix :: (FootballerAI m) !Position !Metre !(!BrainInput, m) -> (BrainOutput, m)
92 afterfix after point diff (input=:{me}, m)
93 | d < diff = after (input, m)
94 | otherwise = (move, m)
97 a = bearing zero me point
98 r = bearing me.nose me point
99 v = ms (max 6.0 (toReal d))
100 move = Move {direction=a, velocity=v} r
102 base_TeamName_MartLubbers :: String
103 base_TeamName_MartLubbers = "Æsir"