1 implementation module Team
5 /* Import all standard teams: */
7 import Team_Opponent_Slalom_Assignment
8 import Team_Opponent_Passing_Assignment
9 import Team_Opponent_DeepPass_Assignment
10 import Team_Opponent_Keeper_Assignment
11 import Team_Student_Rounds_Assignment
12 import Team_Student_Slalom_Assignment
13 import Team_Student_Passing_Assignment
14 import Team_Student_DeepPass_Assignment
15 import Team_Student_Keeper_Assignment
16 import Team_MartLubbers
18 allAvailableTeams :: [Home FootballField -> Team]
19 allAvailableTeams = [ Team_MiniEffies
22 , Team_Student_Passing
23 , Team_Student_DeepPass
25 , Team_Opponent_Slalom
26 , Team_Opponent_Passing
27 , Team_Opponent_DeepPass
28 , Team_Opponent_Keeper
32 instance nameOf Team where nameOf players
34 [fb:_] = nameOf fb.playerID
35 none = abort "nameOf[Team]: applied to empty team.\n"
37 validateTeam :: !Team -> Team
38 validateTeam team = map validateFootballer team
40 validateFootballer :: !Footballer -> Footballer
41 validateFootballer fb=:{length} = {fb & length = setbetween length min_length max_length
42 , stamina = max_stamina
46 isValidTeam :: !Team -> Bool
47 isValidTeam team = length clubNames == 1
49 (isEmpty keepers || isValidKeeper (hd keepers))
51 all isValidPlayer players
53 sort (map nrOf players) == sort (removeDup (map nrOf players))
55 not (isMember 1 (map nrOf fielders))
57 (keepers,fielders) = spanfilter isKeeper team
58 clubNames = removeDup (map clubOf players)
59 clubName = hd clubNames
60 players = keepers ++ fielders
61 clubOf fb = fb.playerID.clubName
62 nrOf fb = fb.playerID.playerNr
63 isValidKeeper fb = fb.playerID == {clubName=clubName,playerNr=1}
64 isValidPlayer fb = clubOf fb == clubName
66 allPlayersAtHome :: !FootballField !Home !Team -> Bool
67 allPlayersAtHome field home team = all atHome team
69 atHome = if (home == West) (\player -> player.Footballer.pos.px <= zero)
70 (\player -> player.Footballer.pos.px >= zero)
72 replaceInTeam :: ![Footballer] !Team -> Team
73 replaceInTeam fbs team = removeMembers team fbs ++ fbs
75 getTeam :: !ClubName ![Team] -> Team
76 getTeam cn teams = case [team \\ team<-teams | nameOf team==cn] of
78 _ = abort ("Team " <+++ cn <+++ " does not seem to exist.\n")
80 instance mirror [a] | mirror a where mirror field as = map (mirror field) as
81 instance mirror Footballer where mirror field fb = {fb & pos = mirror field fb.pos
82 , nose = mirror field fb.nose
83 , speed = mirror field fb.speed
85 instance mirror Position where mirror field pos = {pos & px = ~pos.px}
86 instance mirror Speed where mirror field speed = {speed & direction = mirror field speed.direction}
87 instance mirror Angle where mirror field angle = rad pi - angle