update team
[fp1415-soccerfun.git] / src / Team_MartLubbers.icl
1 implementation module Team_MartLubbers
2
3 import Footballer
4 import FootballerFunctions
5
6 Names:: [String]
7 Names = [
8 "Odin",
9 "Frigg",
10 "Thor",
11 "Balder",
12 "Njord",
13 "Freyr",
14 "Freyja",
15 "Tyr",
16 "Bragi",
17 "Heimdall",
18 "Hoder",
19 "Vidar",
20 "Vale",
21 "Ullr",
22 "Forseti"]
23
24 Team_MartLubbers :: !Home !FootballField -> Team
25 Team_MartLubbers home field
26 | home==West = westTeam
27 | otherwise = eastTeam
28 where
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
35 & nr <- [2..]
36 & name <- Names
37 ]
38 west_positions_fielders = [(0.20, 0.40)
39 ,(0.20,-0.40)
40 ,(0.23, 0.00)
41 ,(0.50, 0.45)
42 ,(0.50,-0.45)
43 ,(0.60, 0.00)
44 ,(0.70, 0.35)
45 ,(0.70,-0.35)
46 ,(0.90, 0.05)
47 ,(0.90,-0.05)
48 ]
49
50 :: Mem = {home :: !Home, origpos :: Position}
51
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
56 , length = min_length
57 , pos = position
58 , nose = zero
59 , speed = zero
60 , skills = (Running, Kicking, Rotating)
61 , effect = Nothing
62 , stamina = max_stamina
63 , health = max_health
64 , brain = {memory = {home=home, origpos=position}, ai = mind field }
65 }
66
67 closerToGoal :: !Home -> Metre Metre -> Bool
68 closerToGoal East = (<)
69 closerToGoal West = (>)
70
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)
76 where
77 nextPos = let np = nextPlayer home others me.pos in if (isNothing np) (centerOfGoal (other home) field) (fromJust np)
78
79 nextPlayer :: !Home [Footballer] Position -> Maybe Position
80 nextPlayer home xs pos
81 # xs = filter (\x.closerToGoal home x.pos.px pos.px) xs
82 | xs == [] = Nothing
83 | otherwise = Just (minListBy (\x y.(dist x.pos pos) < (dist y.pos pos)) xs).pos
84
85 closest :: [Footballer] Position -> Footballer
86 closest xs p = minListBy (\x y.(dist x.pos p) < (dist y.pos p)) xs
87
88 isClosest :: [Footballer] Footballer Position -> Bool
89 isClosest xs x p = closest [x:xs] p == x
90
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)
95 where
96 d = dist me point
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
101
102 base_TeamName_MartLubbers :: String
103 base_TeamName_MartLubbers = "Æsir"