Changeset 6.1.39
- Timestamp:
- 08/20/2016 09:24:21 PM (8 years ago)
- branch-nick:
- state
- revision id:
- dsowen@fugue88.ws-20160820212421-8n0c6gf6pytyy6np
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main.py
r6.1.38 r6.1.39 64 64 self.team_size = team_size 65 65 66 def assemble_team(self): 67 print("Captain is {}".format(self.shared.captain)) 68 team = self.shared.players[self.shared.captain].propose_team(self.team_size) 69 print("He proposed {}".format(team)) 70 71 votes = [p.approve_team(team) for p in self.shared.players] 72 approvals = sum(votes) 73 approved = approvals > self.team_size / 2 74 75 print("Team {}: {} for, {} against".format( 76 {True: "approved", False: "rejected"}[approved], 77 approvals, self.shared.player_count - approvals 78 )) 79 80 for p in self.shared.players: 81 p.observe_team_vote(approved, votes) 82 83 self.shared.captain = (self.shared.captain + 1) % self.shared.player_count 84 85 if approved: 86 self.shared.team_failures = 0 87 return PerformMission(self.shared, team) 88 else: 89 self.shared.team_failures += 1 90 return AssembleTeam(self.shared, self.team_size) 91 66 92 67 93 class PerformMission(object): … … 94 120 losses = 0 95 121 96 def assemble_team():97 print("Captain is {}".format(state.shared.captain))98 team = state.shared.players[state.shared.captain].propose_team(state.team_size)99 print("He proposed {}".format(team))100 101 votes = [p.approve_team(team) for p in state.shared.players]102 approvals = sum(votes)103 approved = approvals > state.team_size / 2104 105 print("Team {}: {} for, {} against".format(106 {True: "approved", False: "rejected"}[approved],107 approvals, state.shared.player_count - approvals108 ))109 110 for p in state.shared.players:111 p.observe_team_vote(approved, votes)112 113 state.shared.captain = (state.shared.captain + 1) % state.shared.player_count114 115 if approved:116 state.shared.team_failures = 0117 return PerformMission(shared, team)118 else:119 state.shared.team_failures += 1120 return AssembleTeam(shared, state.team_size)121 122 122 def perform_mission(): 123 123 nonlocal wins, losses … … 149 149 state = state.do() 150 150 elif isinstance(state, AssembleTeam): 151 state = assemble_team()151 state = state.assemble_team() 152 152 elif isinstance(state, PerformMission): 153 153 state = perform_mission()
Note: See TracChangeset
for help on using the changeset viewer.