コード例 #1
0
ファイル: Agent.py プロジェクト: CDevin5/CS151StrategoAI
    def getAction(self, state):
        legalActions = state.getLegalActions(self.index)
        if legalActions == []:
            return None
        # Maybe Explore:
        r = random.random()
        if (r < self.exploreRate):
            return random.choice(legalActions)

        # Exploit:
        return randoMax([(self.getQValue(state, a), a) for a in legalActions])
コード例 #2
0
ファイル: Agent.py プロジェクト: CDevin5/CS151StrategoAI
 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)
コード例 #3
0
ファイル: Agent.py プロジェクト: CDevin5/CS151StrategoAI
 def getAction(self, state):
     actions = state.getLegalActions(self.index)
     return random.choice(actions)