当前位置: 首页>>代码示例>>Python>>正文


Python Field.step方法代码示例

本文整理汇总了Python中field.Field.step方法的典型用法代码示例。如果您正苦于以下问题:Python Field.step方法的具体用法?Python Field.step怎么用?Python Field.step使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在field.Field的用法示例。


在下文中一共展示了Field.step方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import step [as 别名]
class Grid:
    # Class to rasterize a Field down into a big grid of squares

    def __init__( self, wide, high ):
        # Basic, keep a background field, and a 2d array of values

        self.f = Field( )

        self.w = wide
        self.h = high

        self.vals = [ [ 0 for i in range( self.w ) ] for j in range( self.h ) ]

        # Pre-compute all the box values
        self.step( 0.0 )

    def reset( self ):
        # Basic, reset the underlying field

        self.f.reset( )

    def step( self,perc ):
        # Again basic, step the field, then compute all the box values

        self.f.step( perc )

        self.compute( )

    def compute( self ):

        for y in range( self.h ):

            for x in range( self.w ):

                # Map the x and y to the center of the box, get a value from the field
                self.vals[ y ][ x ] = self.f.getVal( float( x ) / ( self.w - 1 ), float( y ) / ( self.h - 1 ) )

    def getVal( self, x, y ):
        # Basic as it gets

        return self.vals[ y ][ x ]
开发者ID:DweebsUnited,项目名称:LightingSim,代码行数:43,代码来源:grid.py

示例2: GameManager

# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import step [as 别名]

#.........这里部分代码省略.........
    file.write("unit")
    for i in unit.encode():
      file.write(str(i))
  def writeMessageBullet(self,bullet,file):
    file.write("bullet")
    for i in bullet.encode():
      file.write(str(i))
  def writeMessageBase(self,base,file):
    file.write("base")
    for i in base.encode():
      file.write(str(i))
  def writeMessageItem(self,item,file):
    file.write("item")
    for i in item.encode():
      file.write(str(i))      
  def writeMessageField(self,field,file):
    file.write("field")
    for i in field.encode():
      file.write(str(i))


    
  def addBullet(self, bullet):
    self.bullets.append(bullet)
  def addItem(self, item):
    self.items.append(item)
  def addBase(self, base):
    self.bases.append(base)
  def getBase(self, teamFlag):
    for i in self.bases:
      if i.getTeamFlag() == teamFlag:
        #baseはひとつだと仮定
        return i
  def step(self):
    if self.debugmode:
      self.readKeyEvent()
#    self.specialUnit.step()
    self.field.step()
    self.units.step()
    #baseはunitの後
    self.bases.step()
    self.bullets.step()
    self.items.step()
    self.debugObjects.step()

    for counter in range(20):
      #振動して無限ループになったとき、20回で終了するようにしている。
      #押し合い
      powerList = [Coordinate(0,0) for i in range(len(self.units))]
      for ii in range(len(self.units)):
        for jj in range(ii):
          i = self.units[ii].getPosition()
          j = self.units[jj].getPosition()
          if abs(i - j) < RADIUS_OF_THE_UNIT * 2 :
            factor = (RADIUS_OF_THE_UNIT * 2 - abs(i - j))/(abs(i - j) + 10 **(-7)) * (i - j)
            powerList[ii] += factor
            powerList[jj] -= factor
            #重なっているとき
      for ii in range(len(self.units)):
        for jj in range(len(self.bases)):
          i = self.units[ii].getPosition()
          j = self.bases[jj].getPosition()
          if abs(i - j) < RADIUS_OF_THE_UNIT + RADIUS_OF_THE_BASE:
            factor = (RADIUS_OF_THE_UNIT + RADIUS_OF_THE_BASE - abs(i - j))/(abs(i - j) + 10 **(-7)) * (i - j)
            powerList[ii] += factor
            #重なっているとき
开发者ID:ymzk,项目名称:AiContest2012,代码行数:70,代码来源:gameManager.py


注:本文中的field.Field.step方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。