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
19 allAvailableTeams :: [Home FootballField -> Team]
20 allAvailableTeams = [ Team_MartLubbers
25 , Team_Student_Passing
26 , Team_Student_DeepPass
28 , Team_Opponent_Slalom
29 , Team_Opponent_Passing
30 , Team_Opponent_DeepPass
31 , Team_Opponent_Keeper
34 instance nameOf Team where nameOf players
36 [fb:_] = nameOf fb.playerID
37 none = abort "nameOf[Team]: applied to empty team.\n"
39 validateTeam :: !Team -> Team
40 validateTeam team = map validateFootballer team
42 validateFootballer :: !Footballer -> Footballer
43 validateFootballer fb=:{length} = {fb & length = setbetween length min_length max_length
44 , stamina = max_stamina
48 isValidTeam :: !Team -> Bool
49 isValidTeam team = length clubNames == 1
51 (isEmpty keepers || isValidKeeper (hd keepers))
53 all isValidPlayer players
55 sort (map nrOf players) == sort (removeDup (map nrOf players))
57 not (isMember 1 (map nrOf fielders))
59 (keepers,fielders) = spanfilter isKeeper team
60 clubNames = removeDup (map clubOf players)
61 clubName = hd clubNames
62 players = keepers ++ fielders
63 clubOf fb = fb.playerID.clubName
64 nrOf fb = fb.playerID.playerNr
65 isValidKeeper fb = fb.playerID == {clubName=clubName,playerNr=1}
66 isValidPlayer fb = clubOf fb == clubName
68 allPlayersAtHome :: !FootballField !Home !Team -> Bool
69 allPlayersAtHome field home team = all atHome team
71 atHome = if (home == West) (\player -> player.Footballer.pos.px <= zero)
72 (\player -> player.Footballer.pos.px >= zero)
74 replaceInTeam :: ![Footballer] !Team -> Team
75 replaceInTeam fbs team = removeMembers team fbs ++ fbs
77 getTeam :: !ClubName ![Team] -> Team
78 getTeam cn teams = case [team \\ team<-teams | nameOf team==cn] of
80 _ = abort ("Team " <+++ cn <+++ " does not seem to exist.\n")
82 instance mirror [a] | mirror a where mirror field as = map (mirror field) as
83 instance mirror Footballer where mirror field fb = {fb & pos = mirror field fb.pos
84 , nose = mirror field fb.nose
85 , speed = mirror field fb.speed
87 instance mirror Position where mirror field pos = {pos & px = ~pos.px}
88 instance mirror Speed where mirror field speed = {speed & direction = mirror field speed.direction}
89 instance mirror Angle where mirror field angle = rad pi - angle