<commit_before>from carrying import CarryingReferralGame
from disclosuregame.Measures import measures_midwives, measures_women
from disclosuregame.Util import random_expectations
from disclosuregame.Agents.bayes import Agent
from random import Random
from math import copysign
import operator
from collections import OrderedDict
from copy import deepcopy
try:
    import scoop
    scoop.worker
    scoop_on = True
    LOG = scoop.logger
except:
    scoop_on = False
    import multiprocessing
    LOG = multiprocessing.get_logger()
    pass

class CarryingInformationGame(CarryingReferralGame):
    """
    A game type identical with the carrying referral game, but where some information
    is shared on each round. Sharing is controlled by the share_prob parameters which
    are the probability that any given memory is shared.
    """
    def __init__(self, mw_share_prob=0, mw_share_bias=-.99, women_share_prob=0, women_share_bias=0.99,
                 signaller_args=None, responder_args=None, **kwargs):
        if not responder_args:
            responder_args = {}
        if not signaller_args:
            signaller_args = {}
        super(CarryingInformationGame, self).__init__(**kwargs)
        self.parameters['mw_share_prob'] = mw_share_prob
        self.parameters['mw_share_bias'] = mw_share_bias
        self.parameters['women_share_prob'] = women_share_prob
        self.parameters['women_share_bias'] = women_share_bias
        self.mw_share_bias = mw_share_bias
        self.mw_share_prob = mw_share_prob
        self.women_share_bias = women_share_bias
        self.women_share_prob = women_share_prob
        self.signaller_args = signaller_args
        self.responder_args = responder_args

    def __str__(self):
        return "sharing_%s" % super(CarryingInformationGame, self).__unicode__()

    #@profile
    def play_game(self, players, file_name=""):
        #self.random.seed(1)
        try:
            worker = scoop.worker[0]
        except:
            worker = multiprocessing.current_process()
        LOG.debug("Worker %s playing a game." % worker)
        women, midwives = players

        rounds, birthed, num_midwives, women_res, mw_res, women_memories = self.pre_game(women, midwives)
        LOG.debug("Starting play.")
        for self.current_round in range(rounds):
            women_res, mw_res = self.run_round(women, midwives, num_midwives, women_res, mw_res)
            self.post_round(players, women, women_memories=women_memories)
        del women
        del midwives
        del women_memories
        LOG.debug("Worker %s completed a game." % worker)
        return women_res, mw_res

    def pre_game(self, women, midwives):
        """
        Setup function for running a game.
        """
        self.signaller_generator = self.signaller_fn.generator(random=self.player_random, type_distribution=self.women_weights, 
            agent_args=self.signaller_args, initor=self.signaller_initor,init_args=self.signaller_init_args)
        LOG.debug("Made player generator.")
        rounds = self.rounds
        birthed = []
        self.random.shuffle(women)
        num_midwives = len(midwives)
        women_res = self.measures_women.dump(None, self.rounds, self)
        mw_res = self.measures_midwives.dump(None, self.rounds, self)
        women_memories = []
        return rounds, birthed, num_midwives, women_res, mw_res, women_memories

    def run_round(self, women, midwives, num_midwives, women_res, mw_res):
        """
        Run one round of simulation.
        """
        players = [women.pop() for j in range(num_midwives)]
        self.random.shuffle(midwives)
        map(self.play_round, players, midwives)
        for x in midwives:
            x.finished += 1
        women_res = self.measures_women.dump(women + players, self.current_round, self, results=women_res)
        mw_res = self.measures_midwives.dump(midwives, self.current_round, self, results=mw_res)
        return women_res, mw_res
        
<commit_msg>Move some locals to class<commit_after>from carrying import CarryingReferralGame
from disclosuregame.Measures import measures_midwives, measures_women
from disclosuregame.Util import random_expectations
from disclosuregame.Agents.bayes import Agent
from random import Random
from math import copysign
import operator
from collections import OrderedDict
from copy import deepcopy
try:
    import scoop
    scoop.worker
    scoop_on = True
    LOG = scoop.logger
except:
    scoop_on = False
    import multiprocessing
    LOG = multiprocessing.get_logger()
    pass

class CarryingInformationGame(CarryingReferralGame):
    """
    A game type identical with the carrying referral game, but where some information
    is shared on each round. Sharing is controlled by the share_prob parameters which
    are the probability that any given memory is shared.
    """
    def __init__(self, mw_share_prob=0, mw_share_bias=-.99, women_share_prob=0, women_share_bias=0.99,
                 signaller_args=None, responder_args=None, **kwargs):
        if not responder_args:
            responder_args = {}
        if not signaller_args:
            signaller_args = {}
        super(CarryingInformationGame, self).__init__(**kwargs)
        self.parameters['mw_share_prob'] = mw_share_prob
        self.parameters['mw_share_bias'] = mw_share_bias
        self.parameters['women_share_prob'] = women_share_prob
        self.parameters['women_share_bias'] = women_share_bias
        self.mw_share_bias = mw_share_bias
        self.mw_share_prob = mw_share_prob
        self.women_share_bias = women_share_bias
        self.women_share_prob = women_share_prob
        self.signaller_args = signaller_args
        self.responder_args = responder_args

    def __str__(self):
        return "sharing_%s" % super(CarryingInformationGame, self).__unicode__()

    #@profile
    def play_game(self, players, file_name=""):
        #self.random.seed(1)
        try:
            worker = scoop.worker[0]
        except:
            worker = multiprocessing.current_process()
        LOG.debug("Worker %s playing a game." % worker)
        women, midwives = players

        women_res, mw_res, women_memories = self.pre_game(women, midwives)
        LOG.debug("Starting play.")
        for self.current_round in range(self.rounds):
            women_res, mw_res = self.run_round(women, midwives, women_res, mw_res)
            self.post_round(players, women, women_memories=women_memories)
        del women
        del midwives
        del women_memories
        LOG.debug("Worker %s completed a game." % worker)
        return women_res, mw_res

    def pre_game(self, women, midwives):
        """
        Setup function for running a game.
        """
        self.signaller_generator = self.signaller_fn.generator(random=self.player_random, type_distribution=self.women_weights, 
            agent_args=self.signaller_args, initor=self.signaller_initor,init_args=self.signaller_init_args)
        LOG.debug("Made player generator.")
        birthed = []
        self.random.shuffle(women)
        self.num_midwives = len(midwives)
        women_res = self.measures_women.dump(None, self.rounds, self)
        mw_res = self.measures_midwives.dump(None, self.rounds, self)
        women_memories = []
        return women_res, mw_res, women_memories

    def run_round(self, women, midwives, women_res, mw_res):
        """
        Run one round of simulation.
        """
        players = [women.pop() for j in range(self.num_midwives)]
        self.random.shuffle(midwives)
        map(self.play_round, players, midwives)
        for x in midwives:
            x.finished += 1
        women_res = self.measures_women.dump(women + players, self.current_round, self, results=women_res)
        mw_res = self.measures_midwives.dump(midwives, self.current_round, self, results=mw_res)
        return women_res, mw_res
        

{'fraction_non_alphanumeric': 0.08198585144012127, 'fraction_numerical': 0.0025265285497726125, 'mean_word_length': 2.9984848484848485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7367628', 'n_tokens_mistral': 2473, 'n_tokens_neox': 2351, 'n_words': 544}