initial team
[fp1415-soccerfun.git] / src / Game / Team.icl
1 implementation module Team
2
3 import StdEnvExt
4 import Footballer
5 /* Import all standard teams: */
6 import TeamMiniEffie
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
17
18 allAvailableTeams :: [Home FootballField -> Team]
19 allAvailableTeams = [ Team_MiniEffies
20 , Team_Student_Rounds
21 , Team_Student_Slalom
22 , Team_Student_Passing
23 , Team_Student_DeepPass
24 , Team_Student_Keeper
25 , Team_Opponent_Slalom
26 , Team_Opponent_Passing
27 , Team_Opponent_DeepPass
28 , Team_Opponent_Keeper
29 , Team_MartLubbers
30 ]
31
32 instance nameOf Team where nameOf players
33 = case players of
34 [fb:_] = nameOf fb.playerID
35 none = abort "nameOf[Team]: applied to empty team.\n"
36
37 validateTeam :: !Team -> Team
38 validateTeam team = map validateFootballer team
39 where
40 validateFootballer :: !Footballer -> Footballer
41 validateFootballer fb=:{length} = {fb & length = setbetween length min_length max_length
42 , stamina = max_stamina
43 , health = max_health
44 }
45
46 isValidTeam :: !Team -> Bool
47 isValidTeam team = length clubNames == 1
48 &&
49 (isEmpty keepers || isValidKeeper (hd keepers))
50 &&
51 all isValidPlayer players
52 &&
53 sort (map nrOf players) == sort (removeDup (map nrOf players))
54 &&
55 not (isMember 1 (map nrOf fielders))
56 where
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
65
66 allPlayersAtHome :: !FootballField !Home !Team -> Bool
67 allPlayersAtHome field home team = all atHome team
68 where
69 atHome = if (home == West) (\player -> player.Footballer.pos.px <= zero)
70 (\player -> player.Footballer.pos.px >= zero)
71
72 replaceInTeam :: ![Footballer] !Team -> Team
73 replaceInTeam fbs team = removeMembers team fbs ++ fbs
74
75 getTeam :: !ClubName ![Team] -> Team
76 getTeam cn teams = case [team \\ team<-teams | nameOf team==cn] of
77 [team:_] = team
78 _ = abort ("Team " <+++ cn <+++ " does not seem to exist.\n")
79
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
84 }
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