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