示例#1
0
    def initMatch(self):

        numGroups = int(self.currentMatch['customParams']['numGroups'])
        groupSize = int(math.ceil(float(len(self.clients)) / float(numGroups)))
        self.groups = GroupData.makeGroups(numGroups)
        pos = 0
        for group in self.groups:
            group.assignClients(self.clients[pos:(pos+groupSize)])
            pos += groupSize
        for group in self.groups:
            print 'clients in group %d' % group.id
            for client in group.clients:
                print ' %d' % client.id
示例#2
0
    def __init__(self, server, params, communicator, clients, outputDir):
        GameControl.GameControl.__init__(self, server, params, communicator, clients, outputDir)

        # Get experiment-level parameters, hackishly expected as the values from
        # the first match
        self.numGroups = int(params["matches"][0]["customParams"]["numGroups"])

        # Group clients (once per game)
        self.groups = GroupData.groupClients_random(self.clients, numGroups=self.numGroups)

        # Assign industries (alternate blue and red)
        # g.blueIDs is a list of blue client IDs we send to the clients,
        # because they need to know who's which color so the chat messages can
        # be marked with that color.
        for g in self.groups:
            g.blueIDs = []
            for i in range(len(g.clients)):
                if i % 2 == 0:
                    g.clients[i].color = "blue"
                    g.blueIDs.append(g.clients[i].id)
                else:
                    g.clients[i].color = "red"

        # initialize clients
        for c in self.clients:
            #
            #
            c.acct = {}  # Account data
            #
            # c.events[match][round] is a dictionary of non-market events for
            # that match and round:
            # productionChoice_blue
            # productionChoice_red
            # productionChoice_green
            # prodShock
            # moneyShock_blueMkt
            # moneyShockAmount_blueMkt
            # moneyShockAmountRealized_blueMkt
            # moneyShock_redMkt
            # moneyShockAmountRealized_redMkt
            c.events = []

        # Keep market history and other event history separate.  That way
        # mktHist is easier to analyze, and it can be sent without filtering to
        # any client that needs it upon re-connect.
        #
        # group.mktHist[match][round]{market} is a list of market events
        for g in self.groups:
            g.mktHist = []

        ## Output files

        # Market history
        self.mktHistFilename = os.path.join(self.outputDir, server.sessionID + "-market-history.csv")
        file = open(self.mktHistFilename, "wb")
        csvwriter = csv.writer(file)
        self.mktHistHeaders = [
            "Match",
            "Round",
            "Group",
            "Market",
            "Action",
            "Buyer",
            "Bid",
            "Accept",
            "Ask",
            "Seller",
            "Time",
        ]
        csvwriter.writerow(self.mktHistHeaders)
        file.close()

        # Round output
        self.roundOutputFilename = os.path.join(self.outputDir, server.sessionID + "-history.csv")
        self.roundOutputHeaders = [
            "Match",
            "Round",
            "Group",
            "Subject",
            "color",
            # c.acct
            "dollars",
            "blue",
            "red",
            "green",
            "matchScore",
            "roundScore",
            # c.events
            "productionChoice_blue",
            "productionChoice_red",
            "productionChoice_green",
            "prodShock",
            "moneyShock_blueMkt",
            "moneyShockAmount_blueMkt",
            "moneyShockAmountRealized_blueMkt",
            "moneyShock_redMkt",
            "moneyShockAmountRealized_redMkt",
        ]
        file = open(self.roundOutputFilename, "wb")
        csvwriter = csv.DictWriter(file, self.roundOutputHeaders)
        rowdict = {}
        for header in self.roundOutputHeaders:
            rowdict[header] = header
        csvwriter.writerow(rowdict)
        file.close()

        # market events are given timestamps along a timeline that starts with
        # the first auction and "pauses" in between auctions.  baseTime is the
        # number of seconds of auction time so far, incremented at the end of
        # every auction.
        self.baseTime = 0.0
示例#3
0
    def initClients(self):

        # initialize client data
        for c in self.clients:
            #
            #
            c.acct = {}  # Account data
            #
            # c.events[match][round] is a dictionary of non-market events for
            # that match and round:
                # productionChoice_blue
                # productionChoice_red
                # productionChoice_green
                # prodShock
                # moneyShock_blueMkt
                # moneyShockAmount_blueMkt
                # moneyShockAmountRealized_blueMkt
                # moneyShock_redMkt
                # moneyShockAmount_redMkt
                # moneyShockAmountRealized_redMkt
            c.events = []

        # Group clients (once per game)
        self.numGroups = int(self.params['numGroups'])
        self.groups = GroupData.groupClients_random(
                self.clients, numGroups=self.numGroups)

        # Assign industries (alternate blue and red)
        # g.blueIDs is a list of blue client IDs we send to the clients,
        # because they need to know who's which color so the chat messages can
        # be marked with that color.
        for g in self.groups:
            g.blueIDs = []
            for i in range(len(g.clients)):
                if i % 2 == 0:
                    g.clients[i].color = 'blue'
                    g.blueIDs.append(g.clients[i].id)
                else:
                    g.clients[i].color = 'red'

        # Keep market history and other event history separate.  That way
        # mktHist is easier to analyze, and it can be sent without filtering to
        # any client that needs it upon re-connect.
        #
        # group.mktHist[match][round]{market} is a list of market events
        for g in self.groups:
            g.mktHist = []

        ## Output files

        # Market history
        self.mktHistFilename = os.path.join(self.outputDir,
                self.sessionID + '-market-history.csv')
        file = open(self.mktHistFilename, 'wb')
        csvwriter = csv.writer(file)
        self.mktHistHeaders = ['Match', 'Round', 'Group', 'Market', 'Action',
                'Buyer', 'Bid', 'Accept', 'Ask', 'Seller', 'Time']
        csvwriter.writerow(self.mktHistHeaders)
        file.close()

        # Round output
        self.roundOutputFilename = os.path.join(self.outputDir,
                self.sessionID + '-history.csv')
        self.roundOutputHeaders = ['Match', 'Round', 'Group', 'Subject', 
                'color',

                # c.acct
                'dollars', 'blue', 'red', 'green', 'matchScore', 'roundScore',

                # c.events
                'productionChoice_blue',
                'productionChoice_red',
                'productionChoice_green',
                'prodShock',
                'moneyShock_blueMkt',
                'moneyShockAmount_blueMkt',
                'moneyShockAmountRealized_blueMkt',
                'moneyShock_redMkt',
                'moneyShockAmount_redMkt',
                'moneyShockAmountRealized_redMkt']
        file = open(self.roundOutputFilename, 'wb')
        csvwriter = csv.DictWriter(file, self.roundOutputHeaders)
        rowdict = {}
        for header in self.roundOutputHeaders:
            rowdict[header] = header
        csvwriter.writerow(rowdict)
        file.close()