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