small referee patch to place ball correctly and passing done
[fp1415-soccerfun.git] / src / StdTeam / Team_Student_Slalom_Assignment.icl
1
2 implementation module Team_Student_Slalom_Assignment
3
4 /** Implement a solution to the slalom assignment.
5
6 Your team consists of one field player, with player's number 2.
7 Below you should only change the definition of footballer to your solution.
8 Do not change the position and player identification.
9 Do not change the implementation of base_TeamName_Student_Slalom.
10 */
11
12 import Footballer
13 import FootballerFunctions
14
15 Team_Student_Slalom :: !Home FootballField -> Team
16 Team_Student_Slalom home field = team
17 where
18 team = [{footballer {clubName=club,playerNr=2} & pos = if (home == West) position (mirror field position)}]
19 club = base_TeamName_Student_Slalom +++ if (home == West) "_W" "_E"
20 position = {zero & px = scale -0.5 field.flength + penalty_area_depth}
21 footballer player_id = {defaultFootballer player_id & name = "Peter88", brain = {memory = Void, ai = mind field home}}
22
23 base_TeamName_Student_Slalom :: String
24 base_TeamName_Student_Slalom = "Student Slalom"
25
26 mind :: !FootballField !Home !(!BrainInput, !Void) -> (!BrainOutput, !Void)
27 mind field home (x=:{me,others}, mm)
28 | dist (getBall x).ballPos me.pos < (maxKickReach me) = (kick {px=sig (scale 0.5 field.flength), py=m 0.0}) (x, mm)
29 | otherwise = (fix {px=pp2 cp.px (m 2.5), py=up cp.py (m 3.5)} (maxKickReach me)) (x, mm)
30 where
31 (comparator, pp1, pp2, sig) = if (home == West) ((<), (-), (+), (\w.w)) ((>), (+), (-), (~))
32 sf2 = sortBy (\x y.comparator x.pos.px y.pos.px) others
33 sf = sf2 % (0, (length sf2) - 2)
34 (cp, up) = closestPos (zip2 [1..] sf) (pp1 me.pos.px xWidthFootballer) (getBall x).ballPos.pxy comparator
35
36 closestPos :: [(Int, Footballer)] Metre Position (Metre Metre -> Bool) -> (Position, (Metre Metre -> Metre))
37 closestPos [] _ d _ = (d, (\x y.x))
38 closestPos [(i, x):xs] p d c
39 | c p x.pos.px = (x.pos, if (i rem 2 == 0) (+) (-))
40 | otherwise = closestPos xs p d c
41
42
43