def decrementTimer( ghostState):
timer = ghostState.scaredTimer
if timer == 1:
ghostState.configuration.pos = nearestPoint( ghostState.configuration.pos )
ghostState.scaredTimer = max( 0, timer - 1 )
python类nearestPoint()的实例源码
def decrementTimer( ghostState):
timer = ghostState.scaredTimer
if timer == 1:
ghostState.configuration.pos = nearestPoint( ghostState.configuration.pos )
ghostState.scaredTimer = max( 0, timer - 1 )
def decrementTimer( ghostState):
timer = ghostState.scaredTimer
if timer == 1:
ghostState.configuration.pos = nearestPoint( ghostState.configuration.pos )
ghostState.scaredTimer = max( 0, timer - 1 )
def decrementTimer( ghostState):
timer = ghostState.scaredTimer
if timer == 1:
ghostState.configuration.pos = nearestPoint( ghostState.configuration.pos )
ghostState.scaredTimer = max( 0, timer - 1 )
def decrementTimer( ghostState):
timer = ghostState.scaredTimer
if timer == 1:
ghostState.configuration.pos = nearestPoint( ghostState.configuration.pos )
ghostState.scaredTimer = max( 0, timer - 1 )
def decrementTimer( ghostState):
timer = ghostState.scaredTimer
if timer == 1:
ghostState.configuration.pos = nearestPoint( ghostState.configuration.pos )
ghostState.scaredTimer = max( 0, timer - 1 )
def decrementTimer( ghostState):
timer = ghostState.scaredTimer
if timer == 1:
ghostState.configuration.pos = nearestPoint( ghostState.configuration.pos )
ghostState.scaredTimer = max( 0, timer - 1 )
def applyAction( state, action, agentIndex ):
"""
Edits the state to reflect the results of the action.
"""
legal = AgentRules.getLegalActions( state, agentIndex )
if action not in legal:
raise Exception("Illegal action " + str(action))
# Update Configuration
agentState = state.data.agentStates[agentIndex]
speed = 1
# if agentState.isPacman: speed = 0.5
vector = Actions.directionToVector( action, speed )
oldConfig = agentState.configuration
agentState.configuration = oldConfig.generateSuccessor( vector )
# Eat
next = agentState.configuration.getPosition()
nearest = nearestPoint( next )
if next == nearest:
isRed = state.isOnRedTeam(agentIndex)
# Change agent type
agentState.isPacman = [isRed, state.isRed(agentState.configuration)].count(True) == 1
# if he's no longer pacman, he's on his own side, so reset the num carrying timer
#agentState.numCarrying *= int(agentState.isPacman)
if agentState.numCarrying > 0 and not agentState.isPacman:
score = agentState.numCarrying if isRed else -1*agentState.numCarrying
state.data.scoreChange += score
agentState.numReturned += agentState.numCarrying
agentState.numCarrying = 0
redCount = 0
blueCount = 0
for index in range(state.getNumAgents()):
agentState = state.data.agentStates[index]
if index in state.getRedTeamIndices():
redCount += agentState.numReturned
else:
blueCount += agentState.numReturned
if redCount >= (TOTAL_FOOD/2) - MIN_FOOD or blueCount >= (TOTAL_FOOD/2) - MIN_FOOD:
state.data._win = True
if agentState.isPacman and manhattanDistance( nearest, next ) <= 0.9 :
AgentRules.consume( nearest, state, state.isOnRedTeam(agentIndex) )