Delete everything, only keep frame

pull/1/head
drinkjava2 5 years ago
parent 752006f6f9
commit 7c4af9bef1

@ -1,5 +1,4 @@
## Frog | 人工生命
(Engish instruction see README_EN.md)
这是一个人工生命试验项目最终目标是创建“有自我意识表现”的模拟生命体技术架构基于02年提出的 [一个人工脑模型](一个人工脑模型.md)。
这个项目永远没有结束的时候,开始于模拟一个简单的生命体,然后是青蛙、狗......, 结束于有“自我意识表现”的人工脑,或者说,结束于被机器人代替人类的那一天。

File diff suppressed because one or more lines are too long

@ -9,7 +9,6 @@ import java.util.List;
import javax.swing.JPanel;
import com.github.drinkjava2.frog.brain.group.RandomConnectGroup;
import com.github.drinkjava2.frog.egg.Egg;
import com.github.drinkjava2.frog.egg.EggTool;
import com.github.drinkjava2.frog.objects.Food;
@ -27,10 +26,10 @@ import com.github.drinkjava2.frog.util.RandomUtils;
@SuppressWarnings("all")
public class Env extends JPanel {
/** Speed of test */
public static final int SHOW_SPEED = 500; // 测试速度,-1000~1000,可调, 数值越小,速度越慢
public static final int SHOW_SPEED = 5; // 测试速度,-1000~1000,可调, 数值越小,速度越慢
/** Delete eggs at beginning of each run */
public static final boolean DELETE_EGGS = false;// 每次运行是否先删除保存的蛋
public static final boolean DELETE_EGGS = true;// 每次运行是否先删除保存的蛋
public static final int EGG_QTY = 25; // 每轮下n个蛋可调只有最优秀的前n个青蛙们才允许下蛋
@ -203,11 +202,6 @@ public class Env extends JPanel {
Frog f = frogs.get(screen * FROG_PER_SCREEN + j);
if (f.active(this))
allDead = false;
if (f.alive && RandomUtils.percent(0.2f)) {// 有很小的机率在青蛙活着时就创建新的器官
RandomConnectGroup newConGrp = new RandomConnectGroup();
newConGrp.initFrog(f);
f.organs.add(newConGrp);
}
}
if (SHOW_SPEED > 0 && i % SHOW_SPEED != 0) // 用画青蛙的方式来拖慢速度

@ -22,12 +22,6 @@ public class Cell {
// this cell belong to frog's which organ
public Organ organ;
// inputs of cell
public Input[] inputs; // 每个细胞有一组输入触突
// outputs of cell
public Output[] outputs; // 每个细胞有一组输出触突
// energy of cell, energy got from food
public float energy; // 每个细胞当前的能量值

@ -1,26 +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;
/**
* Input is the sensor of nerve cell
*
* @author Yong Zhu
* @since 1.0
*/
@SuppressWarnings("serial")
public class Input extends Zone {
public Cell cell; // 这个输入触突属于哪个脑细胞
public Input(Zone z) {
super(z);
}
}

@ -42,19 +42,6 @@ public class Organ extends Zone {
}
/** If active in this organ's zone? */
public boolean outputActive(Frog f) { // 如果一个细胞能量>10,且它的输出触突位于这个器官内,则器官被激活
for (Cell cell : f.cells) {
if (cell.energy > organActiveEnergy)
for (Output output : cell.outputs) { //
if (this.nearby(output)) {
cell.organ.fat++;
cell.energy -= 30;//
return true;
}
}
}
return false;
}
/** Set X, Y, Radius, name of current Organ */
public Organ setXYRN(float x, float y, float r, String name) {

@ -1,26 +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;
/**
* Output can active other nerve cell's input
*
* @author Yong Zhu
* @since 1.0
*/
@SuppressWarnings("serial")
public class Output extends Zone {
public Cell cell; // 这个输出触突属于哪个脑细胞
public Output(Zone z) {
super(z);
}
}

@ -1,100 +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.group;
import java.awt.Color;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.BrainPicture;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Input;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.brain.Output;
import com.github.drinkjava2.frog.brain.Zone;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
* RandomConnectGroup
*
* GroupCellGroupZone
* frogRandomConnectGroup
*
* (Group )
*
* @author Yong Zhu
* @since 1.0
*/
public class RandomConnectGroup extends Group {
private static final long serialVersionUID = 1L;
public Zone inputZone; // 输入触突区
public Zone outputZone; // 输出触突区
@Override
public boolean allowBorrow() { // 是否允许在精子中将这个器官借出
return true;
}
@Override
public void initFrog(Frog f) {
if (!initilized) {
initilized = true;
// organWasteEnergy=.05f;
x = Env.FROG_BRAIN_WIDTH / 2;
y = Env.FROG_BRAIN_WIDTH / 2;
r = Env.FROG_BRAIN_WIDTH / 2;
inputZone = RandomUtils.randomPosInAnyFrogOrgan(f);
outputZone = RandomUtils.randomPosInAnyFrogOrgan(f);
}
this.fat = 0;// 每次fat清0因为遗传下来的fat不为0
Cell c = new Cell();
Input in = new Input(inputZone);
in.cell = c;
c.inputs = new Input[] { in };
Output out = new Output(outputZone);
out.cell = c;
c.outputs = new Output[] { out };
c.organ = this;
f.cells.add(c);
}
@Override
public Organ[] vary() {
if (fat <= 0)// 如果胖值为0表示这个组的细胞没有用到可以小概率丢掉它了
if (RandomUtils.percent(30))
return new Organ[] {};
if (RandomUtils.percent(3)) // 有3%的几率丢掉它,防止这个器官数量只增不减
return new Organ[] {};
return new Organ[] { this };
}
@Override
public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来
if (fat <= 0)
pic.setColor(Color.LIGHT_GRAY); // 没用到? 灰色
else
pic.setColor(Color.red); // 用到了?红色
pic.drawLine(inputZone, outputZone);
pic.drawZone(this);
pic.drawZone(inputZone);
pic.fillZone(outputZone);
if (fat > 0) {
pic.setColor(Color.red);
pic.drawCircle(outputZone); // 如果胖了,表示激活过了,下次下蛋少不了这一组
}
}
}

@ -1,47 +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.organ;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Input;
import com.github.drinkjava2.frog.brain.Organ;
/**
* Active always keep active
*
*
*/
public class Active extends Organ {//以前的实验发现添加一个始终激活的区比用Hungry来驱动更能提高找食效率
private static final long serialVersionUID = 1L;
@Override
public void initFrog(Frog f) {
if (!initilized) {
initilized = true;
organOutputEnergy = 2;
}
}
@Override
public void active(Frog f) {
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 near by happy zone
cell.energy += organOutputEnergy;
}
}
}

@ -1,62 +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.organ;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Input;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
* Chance is a random number generator
*
*
*/
public class Chance extends Organ { // 至于这个器官能不能被选中,是另外一回事,听天由命了
private static final long serialVersionUID = 1L;
public int percent; // 初始化的机率为5%
@Override
public void initFrog(Frog f) {
if (!initilized) {
initilized = true;
percent = 5;
}
}
@Override
public Organ[] vary() {
if (RandomUtils.percent(5)) {
percent = percent + 1 - 2 * RandomUtils.nextInt(2);
if (percent < 1)
percent = 1;
if (percent > 98)
percent = 98;
}
return new Organ[] { this };
}
@Override
public void active(Frog f) {
if (RandomUtils.percent(percent)) {// 如果靠近边界,痛苦信号生成
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
cell.energy += 30;
}
}
}
}

@ -1,37 +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.organ;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Organ;
/**
* Eat food at current x, y position
*/
public class Eat extends Organ {// Eat这个类将食物转化为能量能量小于0则青蛙死掉
private static final long serialVersionUID = 1L;
@Override
public void active(Frog f) {
if (Env.foundAndAteFood(f.x, f.y)) {
f.ateFood++;
// 所有的硬编码都是bug包括这个1000
f.energy += 1000;// 如果青蛙的坐标与食物重合吃掉food能量境加
// 能量境加青蛙感觉不到但是Happy区激活青蛙能感觉到因为Happy区是一个脑器官
Organ o = f.organs.get(0);
((Happy) o).happy += 2; // 找到食物有奖!
}
}
}

@ -1,138 +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.organ;
import com.github.drinkjava2.frog.Application;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.BrainPicture;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Input;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.brain.Zone;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
* Eye can only see 4 direction
*
* @author Yong Zhu
* @since 1.0
*/
public class Eye extends Organ {// 这个Eye是老版的眼睛只能看到四个方向但它的调节距离会自动随机调整到一个最佳值这就是随机试错算法的一个应用
private static final long serialVersionUID = 1L;
public int seeDistance; // 眼睛能看到的距离
@Override
public void initFrog(Frog f) { // 仅在Frog生成时这个方法会调用一次
if (!initilized) {
initilized = true;
organOutputEnergy = 30;
seeDistance = 8;
}
}
@Override
public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来
if (!Application.SHOW_FIRST_FROG_BRAIN)
return;
super.drawOnBrainPicture(f, pic);
float qRadius = r / 4;
float q3Radius = (float) (r * .75);
Zone seeUp = new Zone(x, y + q3Radius, qRadius);
Zone seeDown = new Zone(x, y - q3Radius, qRadius);
Zone seeLeft = new Zone(x - q3Radius, y, qRadius);
Zone seeRight = new Zone(x + q3Radius, y, qRadius);
pic.drawZone(seeUp);
pic.drawZone(seeDown);
pic.drawZone(seeLeft);
pic.drawZone(seeRight);
}
@Override
public Organ[] vary() {
if (RandomUtils.percent(5)) { // 可视距离有5%的机率变异
seeDistance = seeDistance + 1 - 2 * RandomUtils.nextInt(2);
if (seeDistance < 1)
seeDistance = 1;
if (seeDistance > 50)
seeDistance = 50;
}
return new Organ[] { this };
}
@Override
public void active(Frog f) {
// 第一个眼睛只能观察上、下、左、右四个方向有没有食物
float qRadius = r / 4;
float q3Radius = (float) (r * .75);
Zone seeUp = new Zone(x, y + q3Radius, qRadius);
Zone seeDown = new Zone(x, y - q3Radius, qRadius);
Zone seeLeft = new Zone(x - q3Radius, y, qRadius);
Zone seeRight = new Zone(x + q3Radius, y, qRadius);
boolean seeSomething = false;
boolean atUp = false;
boolean atDown = false;
boolean atLeft = false;
boolean atRight = false;
for (int i = 1; i < seeDistance; i++)
if (Env.foundAnyThing(f.x, f.y + i)) {
seeSomething = true;
atUp = true;
break;
}
for (int i = 1; i < seeDistance; i++)
if (Env.foundAnyThing(f.x, f.y - i)) {
seeSomething = true;
atDown = true;
break;
}
for (int i = 1; i < seeDistance; i++)
if (Env.foundAnyThing(f.x - i, f.y)) {
seeSomething = true;
atLeft = true;
break;
}
for (int i = 1; i < seeDistance; i++)
if (Env.foundAnyThing(f.x + i, f.y)) {
seeSomething = true;
atRight = true;
break;
}
if (seeSomething)
for (Cell cell : f.cells) {
if (cell.energy < 100)
for (Input input : cell.inputs) {
if (input.nearby(this)) {
if (atUp && input.nearby(seeUp)) {
input.cell.energy += organOutputEnergy;
}
if (atDown && input.nearby(seeDown)) {
input.cell.energy += organOutputEnergy;
}
if (atLeft && input.nearby(seeLeft)) {
input.cell.energy += organOutputEnergy;
}
if (atRight && input.nearby(seeRight)) {
input.cell.energy += organOutputEnergy;
}
}
}
}
}
}

@ -1,61 +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.organ;
import java.awt.Color;
import com.github.drinkjava2.frog.Application;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.BrainPicture;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Input;
import com.github.drinkjava2.frog.brain.Organ;
/**
* Happy zone active after ate food
*/
public class Happy extends Organ { // Happy器官是进食后的产生的快感痛苦和快感是条件反射形成的前题
private static final long serialVersionUID = 1L;
public float happy = 0; // happy初始值为0, 进食后将由eat器官增加happy值
@Override
public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来
if (!Application.SHOW_FIRST_FROG_BRAIN)
return;
if (happy > 0) {
pic.setColor(Color.red);
pic.fillZone(this);
} else {
pic.setColor(Color.white);
pic.fillZone(this);
pic.setColor(Color.BLACK);
pic.drawZone(this);
}
if (this.name != null)
pic.drawText(this, String.valueOf(this.name));
}
@Override
public void active(Frog f) {
if (happy > 0) {
happy--;
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 near by happy zone
cell.energy += happy / 10; // 所有的硬编码都是bug包括这个2和10
}
}
}
}

@ -1,73 +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.organ;
import java.awt.Color;
import com.github.drinkjava2.frog.Application;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.BrainPicture;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Input;
import com.github.drinkjava2.frog.brain.Organ;
/**
* Hungry will active cell's inputs, if frog's energy not enough
*/
public class Hungry extends Organ {
private static final long serialVersionUID = 1L;
@Override
public void initFrog(Frog f) { // 仅在Frog生成时这个方法会调用一次缺省啥也不干通常用于Organ类的初始化
if (!initilized) {
initilized = true;
// organWasteEnergy = 20f;
organOutputEnergy = 2;
}
}
@Override
public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来
if (!Application.SHOW_FIRST_FROG_BRAIN)
return;
if (f.energy < 10000) {
pic.fillZone(this);
} else {
pic.setColor(Color.white);
pic.fillZone(this);
pic.setColor(Color.BLACK);
pic.drawZone(this);
}
if (this.name != null)
pic.drawText(this, String.valueOf(this.name));
}
@Override
public Organ[] vary() {
// if (RandomUtils.percent(20)) // 有20机率权重变化
// organOutputEnergy = RandomUtils.vary(organOutputEnergy);
return new Organ[] { this };
}
@Override
public void active(Frog f) {
if (f.energy < 10000)// 所有的硬编码都是bug
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)) // input zone near by hungry zone
cell.energy += 2;
}
}
}

@ -1,28 +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.organ;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Organ;
/**
* Move down frog 1 unit if outputs of nerve cells active in this zone
*/
public class MoveDown extends Organ {
private static final long serialVersionUID = 1L;
@Override
public void active(Frog f) {
if (outputActive(f))
f.y++;
}
}

@ -1,27 +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.organ;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Organ;
/**
* Move left frog 1 unit if outputs of nerve cells active in this zone
*/
public class MoveLeft extends Organ {
private static final long serialVersionUID = 1L;
@Override
public void active(Frog f) {
if (outputActive(f))
f.x--;
}
}

@ -1,29 +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.organ;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Organ;
/**
* Move right frog 1 unit if outputs of nerve cells active in this zone
*/
public class MoveRight extends Organ {
private static final long serialVersionUID = 1L;
@Override
public void active(Frog f) {
if (outputActive(f))
f.x++;
}
}

@ -1,28 +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.organ;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Organ;
/**
* Move up frog 1 unit if outputs of nerve cells active in this zone
*/
public class MoveUp extends Organ {
private static final long serialVersionUID = 1L;
@Override
public void active(Frog f) {
if (outputActive(f))
f.y--;
}
}

@ -1,91 +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.organ;
import com.github.drinkjava2.frog.Application;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.BrainPicture;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Input;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.brain.Zone;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
* Eye is an organ can see environment, and active brain cells which inputs are
* located in eye range
*
* @author Yong Zhu
* @since 1.0
*/
public class NewEye extends Organ {// 这个新版的眼睛有nxn个感光细胞可以看到青蛙周围nxn网络内有没有食物
private static final long serialVersionUID = 1L;
public int n = 3; // 眼睛有n x n个感光细胞 用随机试错算法自动变异(加1或减1最小是3x3)
@Override
public void initFrog(Frog f) { // 仅在Frog生成时这个方法会调用一次缺省啥也不干通常用于Organ类的初始化
if (!initilized) {
initilized = true;
organOutputEnergy = 30;
}
}
@Override
public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来
if (!Application.SHOW_FIRST_FROG_BRAIN)
return;
super.drawOnBrainPicture(f, pic);
float r2 = r / n; // r2是每个感光细胞的半径
float x0 = x - r;
float y0 = y - r; // x0,y0是眼睛的左上角
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
Zone cell = new Zone(x0 + i * 2 * r2 + r2, y0 + j * 2 * r2 + r2, r2);
if (Env.foundAnyThing(f.x - n / 2 + i, f.y - n / 2 + j))
pic.fillZone(cell);
else
pic.drawZone(cell);
}
}
}
@Override
public Organ[] vary() {
if (RandomUtils.percent(50)) {
n = n + 1 - 2 * RandomUtils.nextInt(2);
if (n < 3)
n = 3;
if (n > 12)
n = 12;
}
return new Organ[] { this };
}
@Override
public void active(Frog f) {// 如果看到食物就激活对应脑区的所有输入触突
float r2 = r / n; // r2是每个感光细胞的半径
float x0 = x - r;
float y0 = y - r; // x0,y0是眼睛的左上角
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (Env.foundAnyThing(f.x - n / 2 + i, f.y - n / 2 + j)) {
Zone eyeCell = new Zone(x0 + i * 2 * r2 + r2, y0 + j * 2 * r2 + r2, r2);
for (Cell cell : f.cells)
for (Input input : cell.inputs)
if (input.nearby(eyeCell))
input.cell.energy += organOutputEnergy;
}
}
}
}
}

@ -1,70 +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.organ;
import java.awt.Color;
import com.github.drinkjava2.frog.Application;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.BrainPicture;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Input;
import com.github.drinkjava2.frog.brain.Organ;
/**
* Pain zone active after some bad thing happen like close to edge, hurt...
*
*
*/
public class Pain extends Organ { // Pain器官目前激活的条件是离边境20个单元之类痛苦和快感是条件反射形成的前题
private static final long serialVersionUID = 1L;
@Override
public void initFrog(Frog f) {
if (!initilized) {
initilized = true;
organOutputEnergy = 5;
}
}
@Override
public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来
if (!Application.SHOW_FIRST_FROG_BRAIN)
return;
if (Env.closeToEdge(f)) {
pic.fillZone(this);
} else {
pic.setColor(Color.white);
pic.fillZone(this);
pic.setColor(Color.BLACK);
pic.drawZone(this);
}
if (this.name != null)
pic.drawText(this, String.valueOf(this.name));
}
@Override
public void active(Frog f) {
if (Env.closeToEdge(f)) {// 如果靠近边界,痛苦信号生成
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
cell.energy += organOutputEnergy;
}
}
}
}

@ -17,18 +17,6 @@ import java.util.List;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.brain.group.Group;
import com.github.drinkjava2.frog.brain.organ.Active;
import com.github.drinkjava2.frog.brain.organ.Chance;
import com.github.drinkjava2.frog.brain.organ.Eat;
import com.github.drinkjava2.frog.brain.organ.Eye;
import com.github.drinkjava2.frog.brain.organ.Happy;
import com.github.drinkjava2.frog.brain.organ.Hungry;
import com.github.drinkjava2.frog.brain.organ.MoveDown;
import com.github.drinkjava2.frog.brain.organ.MoveLeft;
import com.github.drinkjava2.frog.brain.organ.MoveRight;
import com.github.drinkjava2.frog.brain.organ.MoveUp;
import com.github.drinkjava2.frog.brain.organ.NewEye;
import com.github.drinkjava2.frog.brain.organ.Pain;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
@ -53,21 +41,7 @@ public class Egg implements Serializable {
public List<Group> groups = new ArrayList<>();
public Egg() {// 无中生有,创建一个蛋,先有蛋,后有蛙
organs.add(new Happy().setXYRN(600, 700, 60, "Happy")); // Happy必须第一个加入
organs.add(new Hungry().setXYRN(300, 100, 60, "Hungry"));
organs.add(new MoveUp().setXYRN(800, 100, 60, "Up"));
organs.add(new MoveDown().setXYRN(800, 400, 60, "Down"));
organs.add(new MoveLeft().setXYRN(700, 250, 60, "Left"));
organs.add(new MoveRight().setXYRN(900, 250, 60, "Right"));
organs.add(new Eye().setXYRN(100, 300, 100, "Eye"));
organs.add(new NewEye().setXYRN(200, 700, 200, "NewEye"));
organs.add(new Pain().setXYRN(800, 700, 60, "Pain")); // 痛苦在靠近边界时触发
organs.add(new Active().setXYRN(500, 100, 60, "Active")); // 永远激活
organs.add(new Chance().setXYRN(650, 100, 60, "Chance")); // 永远激活
// 以上为11个, 就是FIXED_ORGAN_QTY值
organs.add(new Eat().setXYRN(0, 0, 0, "Eat")); // EAT不是感觉或输出器官没有位置和大小
}

@ -22,8 +22,6 @@ import java.util.List;
import com.github.drinkjava2.frog.Application;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.organ.Chance;
import com.github.drinkjava2.frog.brain.organ.Eye;
import com.github.drinkjava2.frog.util.FrogFileUtils;
/**
@ -54,8 +52,6 @@ public class EggTool {
ObjectOutputStream so = new ObjectOutputStream(fo);
so.writeObject(Env.eggs);
so.close();
System.out.print("\r1st frog has " + first.organs.size() + " organs, energy=" + first.energy + ", seeDist="
+ ((Eye) first.organs.get(6)).seeDistance + ", chance=" + ((Chance) first.organs.get(10)).percent);
System.out.println(", Last frog has " + last.organs.size() + " organs, energy=" + last.energy);
System.out.println("Saved "+Env.eggs.size() +" eggs to file '" + Application.CLASSPATH + "eggs.ser'");
} catch (IOException e) {

Binary file not shown.
Loading…
Cancel
Save