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 :: Role = Attack | Mid | Defense | Keeper
52 isAttack :: Role -> Bool
53 isAttack Attack = True
60 isDefense :: Role -> Bool
61 isDefense Defense = True
64 isKeep :: Role -> Bool
68 fromNumber :: Int -> Role
75 :: Mem = {home :: !Home, origpos :: Position, seed :: !RandomSeed, role :: Role}
77 mirrorMem :: !Mem !FootballField -> Mem
78 mirrorMem mm field = {mm & home=other mm.home, origpos=mirror field mm.origpos}
80 Aesir :: !ClubName !Home !FootballField !Position !PlayersNumber !String -> Footballer
81 Aesir club home field position nr name
82 = { playerID = {clubName=club,playerNr=nr}
83 , name = name +++ "_" <+++ nr
88 , skills = (Running, Kicking, Rotating)
90 , stamina = max_stamina
92 , brain = {memory=if (home == West) mm (mirrorMem mm field), ai = mind field}
95 mm = {home=West, origpos=position, seed=nullRandomSeed, role=fromNumber nr}
97 nextRandomNumber :: !Mem -> (Int, !Mem)
98 nextRandomNumber mm=:{seed} = let (i, newseed) = random seed in (i rem 100, {mm & seed=newseed})
100 mind :: !FootballField !(!BrainInput, !Mem) -> (!BrainOutput, !Mem)
101 mind field (x=:{referee,football,others,me}, mm=:{home,origpos,role})
102 // In case of the end of the half, mirror memory
103 | any (isEndHalf) referee = mind field ({x & referee=filter (\x.not (isEndHalf x)) referee}, mirrorMem mm field)
104 // In case of a pause or end, just halt
105 | any (isPauseGame) referee || any (isGameOver) referee = halt (x, mm)
108 // Ball is in the other half of the field
109 | closerToGoal home ballPos zero = halt (x, mm)
112 // Ball not in penalty area
113 | closerToGoal home ballPos {px=penalty_area_depth, py=zero} = halt (x, mm)
114 // Ball in penalty area
116 // Ball gained by them
117 | otherwise = halt (x, mm)
118 // If I'm a field player
120 // TODO:: The ball is free
121 | ballIsFree football
122 // I'm closest to the ball
123 | isClosest us me ballPos.pxy = afterfix (\(_,_).(GainBall, mm)) ballPos.pxy prec (x, mm)
124 // TODO: Some other player is the closest to the ball
125 | otherwise = halt (x, mm)
126 // TODO: We have the ball
127 | we_have_ball = halt (x, mm)
128 // TODO: I have the ball
129 | ballIsGainedBy me.playerID football
130 // TODO: Someone else has the ball
131 | otherwise = halt (x, mm)
132 // TODO: The ball is with the others
133 | otherwise = halt (x, mm)
135 we_have_ball = any (\x.ballIsGainedBy x.playerID football) us
136 ballPos = (getBall x).ballPos
137 them = me opponents others
139 prec = scale 0.5 (maxKickReach me)
141 closest :: [Footballer] Position -> Footballer
142 closest xs p = minListBy (\x y.(dist x.pos p) < (dist y.pos p)) xs
144 isClosest :: [Footballer] Footballer Position -> Bool
145 isClosest xs x p = closest [x:xs] p == x
147 closerToGoal :: !Home -> Metre Metre -> Bool
148 closerToGoal East = (<)
149 closerToGoal West = (>)
151 distToLine :: Position Position Position -> Metre
152 distToLine a b c = (abs (((b.px-a.px)*(a.py-c.py))-((a.px-c.px)*(b.py-a.py))))/d
154 (*) m1 m2 = (m (toReal m1)/(toReal m2))
155 (/) m1 m2 = (m (toReal m1)/(toReal m2))
156 d = sqrt(((b.px-a.px)*(b.px-a.px))+((b.py-a.py)*(b.py-a.py)))
158 afterfix :: (FootballerAI Mem) !Position !Metre !(!BrainInput, !Mem) -> (BrainOutput, !Mem)
159 afterfix after point diff (input=:{me,others}, mm)
160 # (i, mm) = nextRandomNumber mm
161 | d < diff = after (input, mm)
162 // There is a enemy standing in the way and I feel like it
163 | (dist closestOpp me.pos) < (maxTackleReach me) && i < 15 = (Tackle closestOpp.playerID (ms 6.0), mm)
164 // There is no enemy standing in the way
165 | otherwise = (move, mm)
167 closestOpp = closest (me opponents others) me.pos
169 a = bearing zero me point
170 r = bearing me.nose me point
171 v = ms (max 6.0 (toReal d))
172 move = Move {direction=a, velocity=v} r
174 base_TeamName_MartLubbers :: String
175 base_TeamName_MartLubbers = "Æsir"