added harmless teams and keeper v1.0
[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 , Team_Student_Rounds
23 , Team_Student_Slalom
24 , Team_Student_Passing
25 , Team_Student_DeepPass
26 , Team_Student_Keeper
27 , Team_Opponent_Slalom
28 , Team_Opponent_Passing
29 , Team_Opponent_DeepPass
30 , Team_Opponent_Keeper
31 ] ++ [MostlyHarmless (11, Level n) \\ n <- [0..10]]
32
33 instance nameOf Team where nameOf players
34 = case players of
35 [fb:_] = nameOf fb.playerID
36 none = abort "nameOf[Team]: applied to empty team.\n"
37
38 validateTeam :: !Team -> Team
39 validateTeam team = map validateFootballer team
40 where
41 validateFootballer :: !Footballer -> Footballer
42 validateFootballer fb=:{length} = {fb & length = setbetween length min_length max_length
43 , stamina = max_stamina
44 , health = max_health
45 }
46
47 isValidTeam :: !Team -> Bool
48 isValidTeam team = length clubNames == 1
49 &&
50 (isEmpty keepers || isValidKeeper (hd keepers))
51 &&
52 all isValidPlayer players
53 &&
54 sort (map nrOf players) == sort (removeDup (map nrOf players))
55 &&
56 not (isMember 1 (map nrOf fielders))
57 where
58 (keepers,fielders) = spanfilter isKeeper team
59 clubNames = removeDup (map clubOf players)
60 clubName = hd clubNames
61 players = keepers ++ fielders
62 clubOf fb = fb.playerID.clubName
63 nrOf fb = fb.playerID.playerNr
64 isValidKeeper fb = fb.playerID == {clubName=clubName,playerNr=1}
65 isValidPlayer fb = clubOf fb == clubName
66
67 allPlayersAtHome :: !FootballField !Home !Team -> Bool
68 allPlayersAtHome field home team = all atHome team
69 where
70 atHome = if (home == West) (\player -> player.Footballer.pos.px <= zero)
71 (\player -> player.Footballer.pos.px >= zero)
72
73 replaceInTeam :: ![Footballer] !Team -> Team
74 replaceInTeam fbs team = removeMembers team fbs ++ fbs
75
76 getTeam :: !ClubName ![Team] -> Team
77 getTeam cn teams = case [team \\ team<-teams | nameOf team==cn] of
78 [team:_] = team
79 _ = abort ("Team " <+++ cn <+++ " does not seem to exist.\n")
80
81 instance mirror [a] | mirror a where mirror field as = map (mirror field) as
82 instance mirror Footballer where mirror field fb = {fb & pos = mirror field fb.pos
83 , nose = mirror field fb.nose
84 , speed = mirror field fb.speed
85 }
86 instance mirror Position where mirror field pos = {pos & px = ~pos.px}
87 instance mirror Speed where mirror field speed = {speed & direction = mirror field speed.direction}
88 instance mirror Angle where mirror field angle = rad pi - angle