本文整理汇总了Golang中github.com/dnesting/alife/goalife/grid2d/org.Organism类的典型用法代码示例。如果您正苦于以下问题:Golang Organism类的具体用法?Golang Organism怎么用?Golang Organism使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Organism类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Run
// Run executes Step repeatedly, until Step returns an error, at which point this
// method will invoke o.Die and return.
func (c *Cpu) Run(o *org.Organism) error {
Logger.Printf("%v.Run(%v)\n", c, o)
for {
if err := c.Step(o); err != nil {
Logger.Printf("%v.Run: %v\n", c, err)
o.Die()
return err
}
}
}
开发者ID:dnesting,项目名称:alife,代码行数:12,代码来源:cpu.go
示例2: opSenseOthers
// opSenseOthers: sense energy ahead, excluding those with the same bytecode, capped at 255
func opSenseOthers(o *org.Organism, c *Cpu) error {
filter := func(n interface{}) float64 {
if org, ok := n.(*org.Organism); ok {
if nc, ok := org.Driver.(*Cpu); ok {
if c.Hash() == nc.Hash() {
return 0.0
}
}
}
return 1.0
}
c.R[0] = clip(int(o.Sense(filter)), 0, 255)
return nil
}
开发者ID:dnesting,项目名称:alife,代码行数:15,代码来源:ops.go
示例3: Step
// Step executes one CPU operation. Any error returned either assessing the
// operation's energy cost or executing it will be returned by this method.
// Execution is expected to cease (and the organism's Die method
// invoked) if an error is returned.
func (c *Cpu) Step(o *org.Organism) (err error) {
op, ip := c.readOp()
c.Ip = ip
if op == nil {
return unableToReadErr
}
Logger.Printf("%v.Step(%v): %v\n", c, o, op)
// All operations cost at least 1 energy, to avoid infinite loops.
if err := o.Discharge(1 + op.Cost); err != nil {
return err
}
if err := op.Fn(o, c); err != nil {
return err
}
return nil
}
开发者ID:dnesting,项目名称:alife,代码行数:23,代码来源:cpu.go
示例4: opDivide
// opDivide: spawn a new organism in neighboring cell with same bytecode
// and energy fraction described by A/256.
func opDivide(o *org.Organism, c *Cpu) error {
lenc := len(c.Code)
if err := o.Discharge(lenc); err != nil {
return err
}
nc := c.Copy()
if rand.Float64() < MutationRate {
nc.Mutate()
}
n, err := o.Divide(nc, float64(c.R[0])/256.0)
if err == org.ErrNotEmpty {
return nil
}
if err != nil {
return err
}
go nc.Run(n)
return nil
}
开发者ID:dnesting,项目名称:alife,代码行数:21,代码来源:ops.go
示例5: opSense
// opSense: sense energy ahead, capped at 255
func opSense(o *org.Organism, c *Cpu) error {
c.R[0] = clip(int(o.Sense(nil)), 0, 255)
return nil
}
开发者ID:dnesting,项目名称:alife,代码行数:5,代码来源:ops.go
示例6: opForward
// opForward: move forward if able
func opForward(o *org.Organism, c *Cpu) error {
if err := o.Forward(); err != nil && err != org.ErrNotEmpty {
return err
}
return nil
}
开发者ID:dnesting,项目名称:alife,代码行数:7,代码来源:ops.go
示例7: opRight
// opRight: turn right
func opRight(o *org.Organism, c *Cpu) error {
o.Right()
return nil
}
开发者ID:dnesting,项目名称:alife,代码行数:5,代码来源:ops.go
示例8: opLeft
// opLeft: turn left
func opLeft(o *org.Organism, c *Cpu) error {
o.Left()
return nil
}
开发者ID:dnesting,项目名称:alife,代码行数:5,代码来源:ops.go
示例9: opEat
// opEat: Consume A*10 energy from neighbor
func opEat(o *org.Organism, c *Cpu) error {
if _, err := o.Eat(c.R[0] * 10); err != nil {
return err
}
return nil
}
开发者ID:dnesting,项目名称:alife,代码行数:7,代码来源:ops.go
注:本文中的github.com/dnesting/alife/goalife/grid2d/org.Organism类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论