Clean up core folder

pull/2/head
drinkjava2 5 years ago
parent 6fdf44d86b
commit 484ff1300a

@ -1,4 +1,5 @@
## Frog | 人工生命
(Engish instruction see README_EN.md)
这是一个人工生命试验项目最终目标是创建“有自我意识表现”的模拟生命体技术架构基于02年提出的 [一个人工脑模型](一个人工脑模型.md)。
这个项目永远没有结束的时候,开始于模拟一个简单的生命体,然后是青蛙、狗......, 结束于有“自我意识表现”的人工脑,或者说,结束于被机器人代替人类的那一天。
@ -90,15 +91,15 @@ Frog: 这是人工生命的主体,目前起名叫青蛙(Frog),其实叫什
另外,这次更新加强了暂停功能,可以在脑图任一时刻暂停,并加上了脑图的剖面显示。所有脑图快捷键有: T:顶视 F前视 L:左视 R:右视 X:斜视 方向键:剖视 空格:暂停 鼠标操作:缩放旋转平移
![result6](https://gitee.com/drinkjava2/frog/raw/master/result6_letter.gif)
2019-11-26 优化了一下程序用8个汉字来进行模式识别原理演示但容错性依然没有变形、变位后的文字识别率很差。以后要考虑借签算法中的侧抑制、卷积、分层等原理来提高它的容错性这方面算法已经很成熟了目前只需要拿来主义用图形化模拟的方式来实现。但总体上算法和图形化模拟是两条路算法通常可以用模拟的方式来表达但不是所有模拟都可以归纳成算法因为模拟(或者说软件本身)有时会非常复杂,不容易总结出规律。也就是说模拟的表现力比算法更强,但模拟的缺点是资源消耗大。
2019-12-27 在history\003a_legs目录下依然是2维脑)尝试给青蛙加两条腿,看它能不能自动学会走路。一条腿位于下方,一条腿位于右侧,每条腿有位置感觉细胞、抬腿、落腿运动和感觉细胞,转动腿运动细胞。只有当腿落下且转动时青蛙才会位移。经过一段时间的生存汰淘之后,青蛙自动进化出会利用腿走路了,但效果不太理想,找食效率不高,往往只能朝一个方向利用单条腿前进,但至少这是青蛙第一次利用腿来走路,有兴趣的可以运行试试看
2019-12-27 在history\003a_legs目录下依然是2维脑)尝试给青蛙加两条腿,看它能不能自动学会走路。一条腿位于下方,负责左右移动一条腿位于右侧负责上下移动每条腿有抬腿、落腿、转动和相应的感觉细胞。只有当腿落下且转动而且另一条脚抬起来时青蛙才会位移具体什么时候抬腿、什么时候转动腿完全由随机数决定。经过一段时间的生存汰淘之后青蛙会进化出会利用两条腿走路了但需要的时间非常长约几个小时之后才达到最高吃食率50%左右,走路风格也比较诡异,是小碎步而不是大踏步。但至少这是青蛙第一次利用两条腿来走路,还是有点意义的,这证明生命进化中就算神经元随机排布,进化出眼睛和腿也是非常简单自然的事
## 运行方式 | Run
运行core或history各个子目录下的run.bat批处理文件即可启动运行history下有多个子目录按时间顺序按列存放着这个项目演化过程中的主要历史版本供演示。
运行core或history各个子目录下的run.bat批处理文件即可启动运行history下有多个子目录按时间顺序按列存放着这个项目演化过程中的主要历史版本供演示。
另外如果想要研究这个项目的任一旧版本可以结合gitk命令和参考"版本提交记录.md"的介绍用git reset命令回复到以前任一个版本例如用:
git reset --hard ae34b07e 可以转回到以前一个分组测试的找食版本。
## 重要参数 | Parameters
在Env.java类中以下有以下可调整参数请手工修改这些参数进行不同的测试前5个参数很重要:
在Env.java类中以下有以下可调整参数请手工修改这些参数进行不同的测试前5个参数很重要:
```
SHOW_SPEED 调整实验的速度(1~1000),值越小则越慢。
DELETE_EGGS: 每次运行是否先删除保存的蛋,如果设为false将不删除保存的蛋会接着上次的测试结果续继运行。

File diff suppressed because one or more lines are too long

@ -11,8 +11,8 @@ import javax.swing.JPanel;
import com.github.drinkjava2.frog.egg.Egg;
import com.github.drinkjava2.frog.egg.EggTool;
import com.github.drinkjava2.frog.objects.LetterTester;
import com.github.drinkjava2.frog.objects.EnvObject;
import com.github.drinkjava2.frog.objects.LetterTester;
import com.github.drinkjava2.frog.objects.Material;
import com.github.drinkjava2.frog.util.RandomUtils;
@ -73,7 +73,7 @@ public class Env extends JPanel {
public static List<Egg> eggs = new ArrayList<>(); // 这里存放新建或从磁盘载入上轮下的蛋,每个蛋可能生成几个青蛙,
public static EnvObject[] things = new EnvObject[] {};// 所有外界物体如食物、字母测试工具都放在这个things里面
public static EnvObject[] things = new EnvObject[] {new LetterTester()};// 所有外界物体如食物、字母测试工具都放在这个things里面
static {
System.out.println("唵缚悉波罗摩尼莎诃!"); // 杀生前先打印往生咒见码云issue#IW4H8

@ -19,7 +19,6 @@ import java.util.List;
import javax.imageio.ImageIO;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.CellActions;
import com.github.drinkjava2.frog.brain.Cuboid;
import com.github.drinkjava2.frog.brain.Hole;
import com.github.drinkjava2.frog.brain.Organ;
@ -125,7 +124,7 @@ public class Frog {// 这个程序大量用到public变量而不是getter/setter
for (int k = 0; k < Env.FROG_BRAIN_ZSIZE; k++) {
Cell cell = cells[i][j][k];
if (cell != null)
CellActions.act(this, activeNo, cell); // 调用每个细胞的act方法
cell.act(this,activeNo);
}
}
return alive;

@ -12,6 +12,7 @@ package com.github.drinkjava2.frog.brain;
import java.util.Arrays;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.util.ColorUtils;
import com.github.drinkjava2.frog.util.RandomUtils;
@ -61,6 +62,34 @@ public class Cell {
public int photonSum = 0; // 这个细胞里曾经收到的光子总数
/*-
* Each cell's act method will be called once at each loop step
*
* act
* )
* action,organs
*
*
*
* 穿穿
*
* 线()(沿线)
* +
*
*
*/
public void act(Frog f, int activeNo) {
if (organs == null)
return;
if (holes != null)
for (Hole h : holes) // 洞的年龄增加,目的是让年龄越接近的洞之间,绑定的概率和强度越大
h.age++;
for (int i = 0; i < organs.length; i++) {
Organ o = f.organs.get(organs[i]);
o.cellAct(f, this, activeNo);
}
}
public void regOrgan(int orgNo) {// 每个Cell可以被多个Organ登记通常只在青蛙初始化器官时调用这个方法
if (organs == null)
organs = new int[] {};

@ -1,117 +0,0 @@
/*
* Copyright 2018 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
* applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package com.github.drinkjava2.frog.brain;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
* CellActions have many cell action stored
*
* CellActionsacttype
*
* @author Yong Zhu
* @since 2.0.2
*/
public class CellActions {
/*-
* Each cell's act method will be called once at each loop step
*
* act
* )
* action,organs
*
*
*
* 穿穿
*
* 线()(沿线)
* +
*
*
*/
public static void act(Frog frog, int activeNo, Cell c) {
if (c.holes != null)
for (Hole h : c.holes) {// 洞的年龄增加,目的是让年龄越接近的洞之间,绑定的概率和强度越大
h.age++;
}
if (c.organs != null)
for (int orgNo : c.organs) {
Organ o = frog.organs.get(orgNo);
switch (o.type) { // 添加细胞的行为,这是硬编码
case Organ.MOVE: // 如果是MOVE细胞它的行为是让每个光子穿过这个细胞走到下一格保持光子沿直线运动
if (c.x == 0 || c.z == Env.FROG_BRAIN_ZSIZE - 1) {// 但是对于输入区,将删除光子,并合计一共收到多少
if (c.photonQty > 0) {
c.photonSum += c.photonQty;
c.photons = null;
}
break;
}
if (c.photons != null) {
for (int ii = 0; ii < c.photons.length; ii++) {
Photon p = c.photons[ii];
if (p == null || p.activeNo == activeNo)// 同一轮新产生的光子或处理过的光子不再走了
continue;
p.activeNo = activeNo;
c.removePhoton(ii);
frog.addAndWalk(p); // 让光子自已往下走,走到哪就停到哪个细胞里
}
}
break;
case Organ.MOVE_JELLY: // 如果是MOVE_JELLY细胞它让每个光子穿过这个细胞走到下一格并在下一个细胞上打出洞来
if (c.x == 0 || c.z == Env.FROG_BRAIN_ZSIZE - 1) {// 但是对于输入区,将删除光子,并合计一共收到多少
if (c.photonQty > 0) {
c.photonSum += c.photonQty;
c.photons = null;
}
break;
}
if (c.photons != null) {
for (int ii = 0; ii < c.photons.length; ii++) {
Photon p = c.photons[ii];
if (p == null || p.activeNo == activeNo)// 同一轮新产生的光子或处理过的光子不再走了
continue;
p.activeNo = activeNo;
c.removePhoton(ii);
frog.addAndWalkAndDig(p); // 让光子自已往下走,走到哪就停到哪个细胞里,并且还在细胞上挖洞
}
}
break;
case Organ.EYE: // 如果是视网膜细胞它的行为是只要Cell有输入信号就产生向右的多个光子发散出去模拟波源
if (c.hasInput && RandomUtils.percent(40)) {// 随机数的作用是减少光子数,加快速度
for (float yy = -0.1f; yy <= 0.1f; yy += 0.03) {// 形成一个扇面向右发送
for (float zz = -0.1f; zz <= 0.1f; zz += 0.03) {
Photon p = new Photon(orgNo, o.color, c.x, c.y, c.z, 1.0f, yy, zz);
p.activeNo = activeNo; // 用这个activeNo防止一直被赶着走
frog.addAndWalk(p);// 光子不是直接添加,而是走一格后添加在相邻的细胞上
}
}
}
break;
case Organ.EAR: // 如果是听力细胞它的行为是将只要Cell有输入信号就产生向下的多个光子发散出去模拟波源
if (c.hasInput && RandomUtils.percent(40)) {// 随机数的作用是减少光子数,加快速度
for (float xx = -0.3f; xx <= 0.3f; xx += 0.15) {// 形成一个扇面向下发送
for (float yy = -1f; yy <= 1f; yy += 0.06) {
Photon p = new Photon(o.organNo, o.color, c.x, c.y, c.z, xx, yy, -1);
p.activeNo = activeNo;
frog.addAndWalk(p);// 光子不是直接添加,而是走一格后添加在相邻的细胞上
}
}
}
break;
default:
break;
}
}
}
}

@ -28,8 +28,7 @@ import com.github.drinkjava2.frog.util.RandomUtils;
* ,
*
*
*
*
*
*
*
* )
@ -37,14 +36,6 @@ import com.github.drinkjava2.frog.util.RandomUtils;
* Cell,
* Cell
*
*
* ;
*
* ,线()
*
* <br/>
* 线cell
*
*
* @author Yong Zhu
* @since 1.0.4
@ -53,17 +44,6 @@ public class Organ implements Serializable, Cloneable {// 因为要保存在蛋
private static final long serialVersionUID = 1L;
// 以下是各种器官类型每个神经元都属于一个器官每个器官都有一个type类型参数
public static final int EMPTY = 0;// 空细胞,不处理光子
public static final int MOVE = 1;// 会让光子沿直线走一格
public static final int MOVE_JELLY = 2;// 会让光子沿直线走一格,并在下一个细胞上打洞
public static final int EYE = 3;// 眼细胞会根据cell激活度产生发散到各个方向的光子
public static final int EAR = 4;// 耳细胞,类似眼细胞,不同点是为了简化脑内听觉区和输入区混用一个区所以它也可吸收光子倒过来激活cell
public static final int JELLY = 5; // 光子在当前细胞上可以打出洞来
public static final int STATIC = 6; // 只有静态洞的细胞,它忽略动态洞参数
public static final int MIX = 7; // 同时具有静态和动态洞的细胞
public static final int TYPE_QTY = 8;// 所有的type都是预先写好在这里的自动生成的type也只能在写好的type里选一个
private static int organNoIndex = 1;
public int organNo = organNoIndex++; // 每个器官都有一个唯一的编号,作用是同一个编号的光子间将不产生绑定
public int color = 1;// 这个不重要表示它生成的光子的显示在脑图中的颜色号见ColorUtils
@ -72,49 +52,14 @@ public class Organ implements Serializable, Cloneable {// 因为要保存在蛋
public boolean allowBorrow;// 是否允许在精子中将这个器官借出,有一些器官是手工创建的,在项目初级阶段禁止它们借出
public String organName;// 器官的名字通常只有手工创建的器官才有名字可以用frog.findOrganByName来查找到这个器官
// ======= 本行以下是一些假设的参数,受变异和生存竟争影响 ,并通过大样本数、随机变异、生存竟争来进行多参数的优化选择 ========
public int type; // 器官类型,见上面的常量定义,这个字段通常很稳定。一旦变异,将从根本上改变器官的播种行为和神经元的行为
public Shape shape; // 器官的形状,不同的形状要写出不同的播种行为
public float cellDistance; // 细胞播种间隔每隔多少个cell进行器官行为的播种
public float centerDensityRate; // 中心相对于边沿的播种密度比为1时为均匀分布
public int holeLimit;// 细胞允许创建动态洞的数量上限详见Cell类的holes.字段
public float energyLimit;// 细胞能量上限,当能量超过能存贮的上限,多余的光子能量将不被细胞吸收,直接煙灭或以光子的形式转发出去
public float outputRate;// 细胞激活后,一次脉冲会释放出细胞存贮的能量比率(或释放出一个固定值) 根据能量守恒这个值通常小于1
public float outputDoor;// 输出阀值,细胞当前能量小于这个阀值时,细胞不会产生输出
public float inputRate;// 能量接收率,细胞存贮的能量占输入能量的比率(或吸收一个固定值) 根据能量守恒这个值通常小于1
public float inputDoor;// 接收阀值,接收的能量小于这个阀值时,细胞不会吸收这份能量,直接煙灭或以光子的形式转发出去
public float radius;// 细胞即使没有洞也可以处理光子这个radius是细胞的管辖半径但处理信号角度只限于穿透和反射或6个正方向
public float dropRate;// 是一个介于0~1的值反映了细胞存贮能量的下降速率在每一步长中细胞能量都以这个速率损失可以参考遗忘曲线
// =====注意以下三个字段可以让细胞具备一些固定角度的洞这个不占内存但缺点是不灵活不智能详见与Cell类中动态洞的对比 =====
public Hole[] holes; // 输出洞
public Organ() {// 缺省构造器,生成具有缺省参数但没有形状的器官
allowVary = true;
allowBorrow = true;
type = 0;
cellDistance = 1;
centerDensityRate = 1;
holeLimit = 10;
energyLimit = 100;
outputRate = 30;
outputDoor = 30;
inputRate = 100;
inputDoor = 5;
radius = 1;
dropRate = 95;
holes = null;
}
@ -123,18 +68,7 @@ public class Organ implements Serializable, Cloneable {// 因为要保存在蛋
if (!allowVary)
return new Organ[] { this };// 如果不允许变异,器官就把自身返回,存放在蛋里
// 各参数 随机有大概率小变异,小概率大变异,极小概率极大变异
type = RandomUtils.vary(type, 10);// 这个type通常不允许变所以只给它10%的机率去变, 也就是说在正常变异概率上再乘以10%的变异可能性
shape = RandomUtils.vary(shape);
cellDistance = RandomUtils.vary(cellDistance);
centerDensityRate = RandomUtils.vary(centerDensityRate);
holeLimit = RandomUtils.vary(holeLimit);
energyLimit = RandomUtils.vary(energyLimit);
outputRate = RandomUtils.vary(outputRate);
outputDoor = RandomUtils.vary(outputDoor);
inputRate = RandomUtils.vary(inputRate);
inputDoor = RandomUtils.vary(inputDoor);
radius = RandomUtils.vary(radius);
dropRate = RandomUtils.vary(dropRate);
holes = RandomUtils.vary(holes);
return new Organ[] { this };
}
@ -151,6 +85,11 @@ public class Organ implements Serializable, Cloneable {// 因为要保存在蛋
// do nothing
}
/** each step will call Organ's active methodd */
public void cellAct(Frog frog, Cell c, int activeNo) { // 每个细胞都会调用cellAct方法,这是针对细胞级别的方法,子类要覆盖它
}
/** Child class can override this method to drawing picture */
public void drawOnBrainPicture(Frog f, BrainPicture pic) { // 把器官的轮廓显示在脑图上
if (shape == null)
@ -161,16 +100,4 @@ public class Organ implements Serializable, Cloneable {// 因为要保存在蛋
shape.drawOnBrainPicture(pic);
}
public static Organ randomCuboidOrgan() {
Organ o = new Organ();
o.shape = RandomUtils.randomCuboid();
return o;
}
public static Organ randomConeOrgan() {
Organ o = new Organ();
o.shape = RandomUtils.randomCone();
return o;
}
}

@ -12,9 +12,12 @@ package com.github.drinkjava2.frog.brain.organ;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Cuboid;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.brain.Photon;
import com.github.drinkjava2.frog.util.ColorUtils;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
* Ear can accept sound input
@ -29,20 +32,31 @@ public class Ear extends Organ {// 耳朵位于脑的顶上,也是长方体
private static final long serialVersionUID = 1L;
public Ear() {
this.shape = new Cuboid(15, 5, Env.FROG_BRAIN_ZSIZE - 1, 1, 10, 1);// 手工固定耳区的大小
this.type = Organ.EAR;
this.shape = new Cuboid(15, 5, Env.FROG_BRAIN_ZSIZE - 1, 1, 10, 1);// 手工固定耳区的大小
this.organName = "Ear";
this.allowVary = false;// 不允许变异
this.allowBorrow = false;// 不允许借出
this.color = ColorUtils.BLUE;
}
public void cellAct(Frog frog, Cell c, int activeNo) {
if (c.hasInput && RandomUtils.percent(40)) {// 随机数的作用是减少光子数,加快速度
for (float xx = -0.3f; xx <= 0.3f; xx += 0.15) {// 形成一个扇面向下发送
for (float yy = -1f; yy <= 1f; yy += 0.06) {
Photon p = new Photon(organNo, this.color, c.x, c.y, c.z, xx, yy, -1);
p.activeNo = activeNo;
frog.addAndWalk(p);// 光子不是直接添加,而是走一格后添加在相邻的细胞上
}
}
}
}
public void hearSound(Frog f, int code) {
Cuboid c = (Cuboid) this.shape;
f.getOrCreateCell(c.x, c.y + code, c.z).hasInput = true;
}
public int readcode(Frog f) {//找出收取光子数最多的点
public int readcode(Frog f) {// 找出收取光子数最多的点
int temp = -10000;
int yPos = -1;
Cuboid c = (Cuboid) this.shape;

@ -11,10 +11,13 @@
package com.github.drinkjava2.frog.brain.organ;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Cuboid;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.brain.Photon;
import com.github.drinkjava2.frog.util.ColorUtils;
import com.github.drinkjava2.frog.util.PixelsUtils;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
* Eye can only see env material
@ -25,14 +28,25 @@ public class Eye extends Organ {// 眼睛是长方体
private static final long serialVersionUID = 1L;
public Eye() {
this.shape = new Cuboid(0, 3, 2, 1, 13, 13);
this.type = Organ.EYE;
this.shape = new Cuboid(0, 3, 2, 1, 13, 13);
this.organName = "Eye";
this.allowVary = false;// 不允许变异
this.allowBorrow = false;// 不允许借出
this.color = ColorUtils.GRAY;
}
public void cellAct(Frog frog, Cell c, int activeNo) {
if (c.hasInput && RandomUtils.percent(40)) {// 随机数的作用是减少光子数,加快速度
for (float yy = -0.1f; yy <= 0.1f; yy += 0.03) {// 形成一个扇面向右发送
for (float zz = -0.1f; zz <= 0.1f; zz += 0.03) {
Photon p = new Photon(organNo, this.color, c.x, c.y, c.z, 1.0f, yy, zz);
p.activeNo = activeNo; // 用这个activeNo防止一直被赶着走
frog.addAndWalk(p);// 光子不是直接添加,而是走一格后添加在相邻的细胞上
}
}
}
}
/** Clear image on retina */
public void seeNothing(Frog f) {// 外界可以直接调用这个方法,清除视网膜图像
f.setCuboidVales((Cuboid) shape, false);

@ -0,0 +1,58 @@
/*
* Copyright 2018 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
* applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package com.github.drinkjava2.frog.brain.organ;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Cuboid;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.brain.Photon;
/**
* Move is a special organ the action move photon go to next cell
*
* MoveCell沿
*
* @author Yong Zhu
*/
public class Move extends Organ {
private static final long serialVersionUID = 1L;
public Move() {
super();
this.shape = new Cuboid(0, 0, 0, Env.FROG_BRAIN_XSIZE - 5, Env.FROG_BRAIN_YSIZE, Env.FROG_BRAIN_ZSIZE);
this.organName = "Move";
this.allowVary = false;// 不允许变异
this.allowBorrow = false;// 不允许借出
}
public void cellAct(Frog frog, Cell c, int activeNo) {
if (c.x == 0 || c.z == Env.FROG_BRAIN_ZSIZE - 1) {// 但是对于输入区,将删除光子,并合计一共收到多少
if (c.photonQty > 0) {
c.photonSum += c.photonQty;
c.photons = null;
}
return;
}
if (c.photons != null) {
for (int ii = 0; ii < c.photons.length; ii++) {
Photon p = c.photons[ii];
if (p == null || p.activeNo == activeNo)// 同一轮新产生的光子或处理过的光子不再走了
continue;
p.activeNo = activeNo;
c.removePhoton(ii);
frog.addAndWalk(p); // 让光子自已往下走,走到哪就停到哪个细胞里
}
}
}
}

@ -11,8 +11,11 @@
package com.github.drinkjava2.frog.brain.organ;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Cuboid;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.brain.Photon;
/**
* Move is a special organ the action move photon go to next cell
@ -27,10 +30,28 @@ public class MoveJelly extends Organ {
public MoveJelly() {
super();
this.shape = new Cuboid(0, 0, 0, Env.FROG_BRAIN_XSIZE - 5, Env.FROG_BRAIN_YSIZE, Env.FROG_BRAIN_ZSIZE);
this.organName = "MoveJelly";
this.type = Organ.MOVE_JELLY; // Empty这个器官并不播种cell,它存在的唯一目的只是充当光子媒介,否则光子会一直走下去消失
this.organName = "MoveJelly";
this.allowVary = false;// 不允许变异
this.allowBorrow = false;// 不允许借出
}
public void cellAct(Frog frog, Cell c, int activeNo) {
if (c.x == 0 || c.z == Env.FROG_BRAIN_ZSIZE - 1) {// 但是对于输入区,将删除光子,并合计一共收到多少
if (c.photonQty > 0) {
c.photonSum += c.photonQty;
c.photons = null;
}
return;
}
if (c.photons != null) {
for (int ii = 0; ii < c.photons.length; ii++) {
Photon p = c.photons[ii];
if (p == null || p.activeNo == activeNo)// 同一轮新产生的光子或处理过的光子不再走了
continue;
p.activeNo = activeNo;
c.removePhoton(ii);
frog.addAndWalkAndDig(p); // 让光子自已往下走,走到哪就停到哪个细胞里,并且还在细胞上挖洞
}
}
}
}

@ -13,7 +13,7 @@ package com.github.drinkjava2.frog.objects;
import java.awt.Color;
/**
* Object means some thing in Env
* Material store material types
*
* 01020,
*

@ -18,7 +18,7 @@ import com.github.drinkjava2.frog.Frog;
/**
* Trap will kill all frogs inside of it, if frog's position has material and
* it's not food, frog will die
* it's trap, frog will die
*
* @author Yong Zhu
* @since 2019-08-05

@ -27,10 +27,10 @@ import com.github.drinkjava2.frog.util.RandomUtils;
@SuppressWarnings("all")
public class Env extends JPanel {
/** Speed of test */
public static final int SHOW_SPEED = 800; // 测试速度,-1000~1000,可调, 数值越小,速度越慢
public static final int SHOW_SPEED = 2000; // 测试速度,-1000~1000,可调, 数值越小,速度越慢
/** Delete eggs at beginning of each run */
public static final boolean DELETE_EGGS = true;// 每次运行是否先删除保存的蛋
public static final boolean DELETE_EGGS = false;// 每次运行是否先删除保存的蛋
public static final int EGG_QTY = 25; // 每轮下n个蛋可调只有最优秀的前n个青蛙们才允许下蛋

@ -60,8 +60,6 @@ public class Organ extends Zone {
/** Active other cells */
public void activeOtherCells(Frog f) {// 与activedByCells相反它将器官的状态转化为输出能量激活与它相关的其它细胞区
for (Cell cell : f.cells) {
if (cell.energy > 0)
cell.energy--;
if (cell.energy < Cell.MAX_ENERGY_LIMIT)
for (Input input : cell.inputs)
if (input.nearby(this)) // if input zone nearby this zone

@ -0,0 +1,52 @@
/*
* Copyright 2018 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
* applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package com.github.drinkjava2.frog.brain.organ;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.brain.Output;
/**
* LogicAnd has a "AND" logic, i.e. if 2 cells active it at same time, it active
*
*
*/
public class LogicAnd extends Organ { // 随意布置一些"与门"在脑里,至于能不能被选中,就听天由命了
private static final long serialVersionUID = 1L;
@Override
public void active(Frog f) {
Cell c1 = null;
Cell c2 = null;
for (Cell cell : f.cells) {
if (cell.energy > organActiveEnergy)
for (Output output : cell.outputs) { //
if (this.nearby(output)) {
if (c1 == null)
c1 = cell;
else {
c2 = cell;
break;
}
}
}
}
if (c2 != null) {// 同时找到两个cell激活同一个区了开始实施与门的逻辑激活其它与这个器官相连的神经
c1.organ.fat++;
c1.energy -= 10;//
c2.organ.fat++;
c2.energy -= 10;//
activeOtherCells(f);
}
}
}

@ -0,0 +1,32 @@
/*
* Copyright 2018 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
* applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package com.github.drinkjava2.frog.brain.organ;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Organ;
/**
* LogicAnd has a "NOT" logic, i.e. if any cells active it, it doesnot active,
* if no cell active it, it active
*
*
*/
public class LogicNot extends Organ { // 随意布置一些"非门"在脑里,至于能不能被选中,就听天由命了
private static final long serialVersionUID = 1L;
@Override
public void active(Frog f) {// 非门的逻辑最简单,如果它被激活,则没有输出,如果它没被激活,则输出信号
if (activedByCells(f))
return;
activeOtherCells(f);
}
}

@ -30,6 +30,8 @@ import com.github.drinkjava2.frog.brain.organ.Eye;
import com.github.drinkjava2.frog.brain.organ.FootPosFeel;
import com.github.drinkjava2.frog.brain.organ.Happy;
import com.github.drinkjava2.frog.brain.organ.Hungry;
import com.github.drinkjava2.frog.brain.organ.LogicAnd;
import com.github.drinkjava2.frog.brain.organ.LogicNot;
import com.github.drinkjava2.frog.brain.organ.NewEye;
import com.github.drinkjava2.frog.brain.organ.Pain;
import com.github.drinkjava2.frog.brain.organ.RFootDrop;
@ -88,10 +90,15 @@ public class Egg implements Serializable {
organs.add(new RFootFeelDown().setXYRN(800, 600, 30, "FeelDown"));// 底脚降下感受细胞
for (int i = 0; i <= 10; i++)
organs.add(new FootPosFeel().setXYRN(FootPosFeel.RFOOTPOSSTART_X + i * 30, 650, 10, "")); // 底脚位置感受细胞
for (int i = 0; i < 5; i++) {
organs.add(new LogicAnd().setXYRN(100+i*30, 10, 5, "")); // 底脚位置感受细胞
organs.add(new LogicNot().setXYRN(100+i*30, 50, 5, "")); // 底脚位置感受细胞
}
// 以上器官就是FIXED_ORGAN_QTY值
FIXED_ORGAN_QTY = organs.size();
organs.add(new Eat().setXYRN(0, 0, 0, "Eat")); // EAT不是感觉或输出器官没有位置和大小
}

Loading…
Cancel
Save