本文整理汇总了Python中Engine类的典型用法代码示例。如果您正苦于以下问题:Python Engine类的具体用法?Python Engine怎么用?Python Engine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Engine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: waitForClick
def waitForClick():
Engine.flipOnce()
cont = True
while(cont):
for evt in pygame.event.get():
if evt.type is pygame.MOUSEBUTTONDOWN:
cont = False
示例2: __init__
def __init__(self):
# Storing the engines of this car
self.__leftengine = Engine('A')
self.__rightengine = Engine('B')
self.__engines = [self.__leftengine,self.__rightengine]
# Storing a reference to a brickpi thread
self.__brickpi = BrickPi_Thread(self.__engines)
示例3: execute
def execute(self, s):
if self.isUsable():
# perform altering commands
self.alter()
Engine.getInstance().show(self.description)
else:
Engine.getInstance().show("You can not do that")
raise Exception
示例4: shutdown
def shutdown() :
global addToQueue, queueIsEmpty, clearQueue
msg("SMDS Shutting down.")
Engine.shutdown()
Dispatch.shutdown()
if theCache : theCache.close()
addToQueue = notInit
queueIsEmpty = notInit
clearQueue = notInit
示例5: updateEvents
def updateEvents():
#print("here")
for evt in pygame.event.get():
if evt.type is pygame.QUIT:
#Engine.stop()
if g.multithreading:
Engine.stop()
pygame.quit()
sys.exit()
#print(pygame.event.event_name(evt.type))
EventList[pygame.event.event_name(evt.type)](evt)
示例6: __init__
def __init__(self):
# Storing the engines of this car
self.__leftengine = Engine("A")
self.__rightengine = Engine("B")
self.__engines = [self.__leftengine, self.__rightengine]
# Storing the distance between the centers of the cars
self.__widthcar = 2.6 + 11.1 - 0.2
self.__gearratio = 1.0
# Storing the perimeter of the wheels (2*pi*r)
self.__perimeter = 2 * math.pi * 2.579
# Storing a reference to a brickpi thread
self.__brickpi = BrickPi_Thread(self.__engines)
self.__command_going = False
self.__command_thread = None
示例7: main
def main():
"""Run the engine and start the game"""
if len(sys.argv) < 3:
print("Usage: multiplegames.py player1,player2(,playerx)? games_per_pairing [config_file]")
sys.exit(0)
players = sys.argv[1].split(",")
rrPlay = abs(int(sys.argv[2]))
if len(players) != 2:
print("Exactly 2 players are required")
sys.exit(0)
# Get config
if len(sys.argv) < 4:
cfg = Config(GlobalConfig.DEFAULT_CFG)
else:
cfg = Config(sys.argv[3])
cfg.data['UI'] = False
cfg.data['STDOUT_LOGGING'] = False
# build player win dictionary
playerWins = {}
for player in players:
if player.strip()in playerWins.keys():
print("Player names must be unique. Clone your player module to play against yourself.")
sys.exit(0)
playerWins[player.strip()] = 0
# round-robin the players
game = 1
# play all pairings the players
while game <= rrPlay:
pairings = []
for pairing in itertools.permutations(playerWins.keys(), 2):
pairings.append(pairing)
random.shuffle(pairings)
for pairing in pairings:
if game <= rrPlay:
print ("Game: %s Pairing: %s" % (game, pairing))
cfg.data['PLAYER_MODULES'] = pairing
s = time.clock()
winningPlayer, valid = Engine.run(cfg)
if winningPlayer != False:
print ("\tWinner: %s" % (cfg.data['PLAYER_MODULES'][winningPlayer - 1]))
playerWins[cfg.data['PLAYER_MODULES'][winningPlayer - 1]] += 1
else:
print ("\tNo winner.")
print ("\tValid players: " + str(valid))
print ("\tTime: %s seconds." % (time.clock() - s))
game += 1
# sort dictionary by wins and display rankings
rank = 1
for item in sorted(playerWins.items(), key=operator.itemgetter(1), reverse=True):
print("Rank", rank, "is player", item[0], "with", item[1], "wins.")
rank += 1
示例8: validMoves
def validMoves(self, position):
"""returns positions of valid moves for a regular red gamepiece on an empty board"""
moves = []
if Engine.isOnTopRow(position):
moves = []
elif Engine.isOnRightEdge(position) or Engine.isOnLeftEdge(position):
# Edges only have one valid move
moves = [position - 4]
elif Engine.isOnOddRow(position):
# diagonals above pieces on odd rows are always 4 and 5 pieces after
moves = [position - 4, position - 3]
elif Engine.isOnEvenRow(position):
# diagonals below pieces on even rows are always 3 and 4 piececs after
moves = [position - 5, position - 4]
return moves
示例9: getJumpPosition
def getJumpPosition(self, position, middlePosition):
# On odd rows, the square on the right is not at position - 4
# On even rows, the square on the right is at position - 4
isSkippingRight = Engine.isOnOddRow(position) != (position - middlePosition == 4)
distanceToNextPosition = 7 if isSkippingRight else 9
finalPosition = position - distanceToNextPosition
return finalPosition
示例10: updateEvents
def updateEvents():
#print("here")
for evt in pygame.event.get():
if evt.type is pygame.QUIT:
#Engine.stop()
if g.multithreading:
Engine.stop()
pygame.quit()
sys.exit()
#print(pygame.event.event_name(evt.type))
EventList[pygame.event.event_name(evt.type)](evt)
if g.draggedEventActive:
if evt.type is pygame.MOUSEBUTTONDOWN:
g.mouseDown = True
elif evt.type is pygame.MOUSEBUTTONUP:
g.mouseDown = False
#print(g.mouseDown)
if g.mouseDown and (evt.type is pygame.MOUSEMOTION):
EventList["MouseDragged"](evt)
示例11: writeMultiSolution
def writeMultiSolution(targetSolutionName, candidates, projectExt, solutionHeader, is2010):
basePath = os.path.dirname(targetSolutionName)
projects = []
for item in map(os.path.abspath, candidates):
generalDict, projectDict, solutionDict = Engine.readConfiguration(item)
if len(solutionDict) == 0:
logging.debug('No solution section found, skipping (offending file %s)' % item)
continue
baseProject = os.path.splitext(item)[0] + projectExt
try:
dependencies = Engine.findDependencies( basePath, solutionDict['dependencies'], solutionDict['dependenciespaths'], generalDict['platform'], lambda x: x+'.bdgcfg' )
except KeyError:
dependencies = []
# HACK: The platform will just be the last one referenced.
platform = projectDict['platform']
projects.append( [baseProject] + [os.path.splitext(x)[0] + projectExt for x in dependencies] )
solution = writeSolution( basePath, projects, platform, Engine.getConfigurations(projectDict) )
# All is now done, try to write the target file to disk...
Engine.writeConfigFile( targetSolutionName, solutionHeader + '\n' + solution )
示例12: isUsable
def isUsable(self):
engine = Engine.getInstance()
# ignore execution if the location where the command can be executed is not equal
# to the name of the current scenario
if not self.requirements:
print "no requirements, automatically pass"
return True
for item in self.requirements:
if not engine.getPlayer().hasItem(item):
print "failed, did not have " + item
return False
print "pass requirements check"
return True
示例13: __init__
def __init__(self):
# Storing the engines of this car
self.__leftengine = Engine('A')
self.__rightengine = Engine('B')
self.__topengine = Engine('C')
self.__engines = [self.__leftengine,self.__rightengine,self.__topengine]
# Storing the distance between the centers of the cars
self.__widthcar = 2.6 + 11.1 - .2
# Storing the Lego MINDSTORM distance sensor
self.__distanceLego = MindstormSensor('1','ULTRASONIC_CONT')
# Storing the GPIO distance sensor
self.__distancePi = DistanceSensor(17,4)
# Storing the current gearration
self.__gearratio = 1./1.
# Storing the perimeter of the wheels (2*pi*r)
self.__perimeter = 2*math.pi*2.758
# Storing a reference to a brickpi thread
self.__brickpi = BrickPi_Thread(self.__engines,[self.__distanceLego])
# Storing a reference to a gpio thread
self.__gpio = GPIO_Thread([self.__distancePi])
# Turn the threads on
self.__brickpi.on()
self.__gpio.on()
示例14: initialize
def initialize(dispatch = True, seed = None, cache = None, autoClean = True) :
"""initialize(dispatch = True, seed = None, cache = None, autoClean = True)
Initialize the Single-Molecule Diffusion Simulator.
If dispatch is True, SMDS will attempt to contact the local Foundry to
operate in distributed mode. If this contact fails or if dispatch is
False, SMDS will operate in single-processor mode. An optional seed for
the random number generator may be provided, otherwise the generator is
initialized with the current time.\n"""
global initialized, addToQueue, queueIsEmpty, clearQueue, theCache
if initialized : return
if dispatch and Dispatch.initialize() :
addToQueue = Dispatch.addToQueue
queueIsEmpty = Dispatch.queueIsEmpty
clearQueue = Dispatch.clearQueue
msg("SMDS Initialized in Dispatch mode.")
else :
Engine.initialize()
addToQueue = Engine.addToQueue
queueIsEmpty = Engine.queueIsEmpty
clearQueue = Engine.clearQueue
msg("SMDS Initialized in Single-processor mode.")
if seed : Cores.c2D.sRnd(int(seed))
else : Cores.c2D.sRnd()
initialized = True
if cache : theCache = Cache(cache, autoClean)
# Ensure proper shutdown()
from atexit import register
from sys import exit
from signal import signal, SIGTERM
register(shutdown)
signal(SIGTERM, lambda x,y : exit())
try :
from signal import SIGBREAK
signal(SIGBREAK, lambda x,y : exit())
except :
pass
示例15: writeSingleSolution
def writeSingleSolution(configFileName, projectExt, solutionExt, solutionHeader, is2010):
basePath = os.path.dirname(configFileName)
try:
# Load the overall configuration from the .tcfg file.
generalDict, projectDict, solutionDict = Engine.readConfiguration(configFileName)
if len(solutionDict) == 0:
logging.debug('No solution section found, bailing out of solution generation (offending file %s)' % configFileName)
return 1
if 'dependencies' not in solutionDict:
solutionDict['dependencies'] = ''
if 'dependenciespaths' not in solutionDict:
solutionDict['dependenciespaths'] = ''
if 'additionalprojects' not in solutionDict:
solutionDict['additionalprojects'] = ''
if 'additionalprojectspaths' not in solutionDict:
solutionDict['additionalprojectspaths'] = ''
# Determine the output product path.
targetName = os.path.join( basePath, generalDict['name'] + solutionExt )
logging.debug( 'Now generating solution %s' % targetName )
baseProject = os.path.splitext(configFileName)[0] + projectExt
dependencies = Engine.findDependencies( basePath, solutionDict['dependencies'], solutionDict['dependenciespaths'], generalDict['platform'], lambda x: x+'.bdgcfg')
additionalProjects = Engine.findDependencies( basePath, solutionDict['additionalprojects'], solutionDict['additionalprojectspaths'], generalDict['platform'], lambda x: x+'.bdgcfg')
platform = projectDict['platform']
solution = writeSolution( basePath, [[baseProject] + [os.path.splitext(x)[0] + projectExt for x in dependencies]] + [[os.path.splitext(x)[0] + projectExt for x in additionalProjects]], platform, Engine.getConfigurations(projectDict))
# All is now done, try to write the target file to disk...
Engine.writeConfigFile( targetName, solutionHeader + '\n' + solution )
except SyntaxError, e:
logging.error( str(e) )
return 1