Changeset 6.1.39 for main.py


Ignore:
Timestamp:
08/20/2016 09:24:21 PM (8 years ago)
Author:
David Owen <dsowen@fugue88.ws>
branch-nick:
state
revision id:
dsowen@fugue88.ws-20160820212421-8n0c6gf6pytyy6np
Message:

Moved assemble_team() to state object

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main.py

    r6.1.38 r6.1.39  
    6464        self.team_size = team_size
    6565
     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
    6692
    6793class PerformMission(object):
     
    94120    losses = 0
    95121
    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 / 2
    104 
    105         print("Team {}: {} for, {} against".format(
    106             {True: "approved", False: "rejected"}[approved],
    107             approvals, state.shared.player_count - approvals
    108         ))
    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_count
    114 
    115         if approved:
    116             state.shared.team_failures = 0
    117             return PerformMission(shared, team)
    118         else:
    119             state.shared.team_failures += 1
    120             return AssembleTeam(shared, state.team_size)
    121 
    122122    def perform_mission():
    123123        nonlocal wins, losses
     
    149149            state = state.do()
    150150        elif isinstance(state, AssembleTeam):
    151             state = assemble_team()
     151            state = state.assemble_team()
    152152        elif isinstance(state, PerformMission):
    153153            state = perform_mission()
Note: See TracChangeset for help on using the changeset viewer.