Example #1
0
    def step(self):
        '''
         first choose  an action  to request., ie move or play the pd.
         some agents may loook at thr ooponents history, or
         at thrir own witution. others might play a "pure" dtrategy               or a random one.
         this ;particular agent shooses pd 50%, 50% move

             ex
  *wihou t  lokin at whhat is leagal! so t easeds a lot of turn.s
        '''
        if world.debug > 1:
            print("Ag .%s step " % (self.agent_id))

        if len(world.agent_list) < 2:

            print "cant run with 1 or fewer agents"
            return None

        other = world.pickRandomOther(self)
        play = world.cooperate
        grec = world.requestPlayPD(self, other, play)
Example #2
0
    def step(self):
        '''
         first choose  an action  to request., ie move or play the pd.
         some agents may loook at thr ooponents history, or
         at thrir own witution. others might play a "pure" dtrategy
         or a random one.
         this ;particular agent shooses pd 50%, 50% move

             ex
             *wihou t  lokin at whhat is leagal! so t easeds a lot of turn.s
        '''
        if world.debug > 1:
            print("Ag .%s step " % (self.agent_id))

        if len(world.agent_list) < 2:

            print "cant run with 1 or fewer agents"
            return None

        if world.debug > 0:
            # testing
            openvis = world.space.openVisibleCells(self)
            if world.debugb > 2:
                print "%s at %s can see open  " % \
                    (self.agent_id, world.space.posStr(self.position))
            #
            openplay = world.space.getPlayableAgents(self)

        if random.random() < 0.5:
             # play pd now, pick ran oppdo
            if world.debug > 1:
                print "Chose to playe,,,"
            other = world.pickRandomOther(self)
            play = world.cooperate
            grec = world.requestPlayPD(self, other, play)

        else:
            # see if theere is  randomly chosesn place to momve
            if world.debug > 1:
                print "Chose to move,,,"
            opensps = world.space.getOpenSpaces(self.position,
                                                self.agentCapabilitiesDict["speed"])
            if len(opensps) == 0:
                if world.debug > 1:
                    print " aid %s no where to go" % (agent.agent_id)

                #  focal, action, rmv, omv, fresult , oresult, other ):
                grec = GameRecord(
                    self,
                    World.move,
                    None,
                    None,
                    None,
                    None,
                    None)
                world.add_to_history(grec)
                return

            #  opick abn oprex cell to go to
            r = random.randrange(len(opensps))
            pickpos = opensps[r]
            grec = world.requestMoveTo(self, pickpos)