Beispiel #1
0
def _moveByDirection(gameMap, position, direction):
    '''Move a unit one square in the given direction.
    
    Ignores all robots on the map but does take into account walls, conveyor 
    belts and gears.  Returns the final location of the move.
    '''
    #watch for wall in this direction
    sideExit  = SIDE[_sideMoveOut[DIRS[direction]]]
    sideEnter = SIDE[_sideMoveIn [DIRS[direction]]]
    location  = BoardLocation(position, direction)
    
    #can we exit this square?
    sq = gameMap.getSquare(position)
    if (sq.walls & sideExit) != 0:
        return MovePoint(location)
    moveTo = location.move(1)
    
    #did we go off the board?
    if (    moveTo.mapPosition[0] < 0 or gameMap.width  <= moveTo.mapPosition[0] or
            moveTo.mapPosition[1] < 0 or gameMap.height <= moveTo.mapPosition[1] or 
            gameMap.getSquare(moveTo.mapPosition).type == "PIT" ):
        return MovePoint(location, dead=True)
    
    #can we enter the new square?
    sq = gameMap.getSquare(moveTo.mapPosition)
    if (sq.walls & sideEnter) != 0:
        return MovePoint(location)
    
    return MovePoint(moveTo)