Exemplo n.º 1
0
    def getFeatures(self, state, agent):
        me = agent
        you = 1-agent

        flag = state.getFlag(me)
        feats = Counter()

        myAlive = state.getAlivePieces(me)
        yourAlive = state.getAlivePieces(you)

        feats["mynumpieces"] = len(myAlive)/10.0
        feats["yournumpieces"] = len(yourAlive)/10.0

        feats["mypiecesum"] = sum([p.rank for p in myAlive])/52.0
        feats["yourpiecesum"] = sum([p.rank for p in yourAlive])/52.0

        feats["numbombdiffusers"] = sum([1 if p.rank == piece.MINER else 0 for p in myAlive])/3.0

        feats["numbombs"] = sum([1 if p.rank == piece.BOMB else 0 for p in myAlive])/3.0

        feats["distflagenemy"] = float("inf") if len(yourAlive) == 0 else min([manhattanDistance(flag, p) for p in yourAlive])/15.0

        feats["mysumofpiecesrows"] = sum([p.position[1] for p in myAlive])/80.0
        feats["yoursumofpiecesrows"] = sum([p.position[1] for p in yourAlive])/80.0

        flagx, flagy = flag.position
        surroundings = [(flagx, flagy+1), (flagx, flagy-1), (flagx-1, flagy), (flagx+1, flagy)]
        surrpieces = [state.getPieceAtPos(p) for p in surroundings]
        feats["flagsurrounded"] = sum([1 if (p != None and p.agentIndex == me) else 0 for p in surrpieces])/4.0

        # Maybe add the row of the general or the bomb diffusers

        return feats
Exemplo n.º 2
0
 def getAction(self, state):
     piece = None
     newPos = None
     actions = state.getLegalActions(self.index)
     print "Legal actions:", [(str(p), p.position, pos) for (p, pos) in actions]
     while piece == None:
         print state
         userInput = raw_input("What is your move? (x0,y0) (x1,y1) ").split()
         oldList = list(userInput[0])
         oldPos = (int(oldList[1]), int(oldList[3]))
         newList = list(userInput[1])
         newPos = (int(newList[1]), int(newList[3]))
         piece = state.getPieceAtPos(oldPos)
         print "Old pos", oldPos
         print "New pos", newPos
         if piece == None:
             print "Invalid initial position"
         elif (piece, newPos) not in actions:
             print "Not a legal action"
             piece = None
         else:
             print "moving", piece, "from", oldPos, "to", newPos
     return (piece, newPos)