pull/1/head
Yong Zhu 6 years ago
parent e21b96fab4
commit cf3f514cbc

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 79 KiB

@ -43,19 +43,19 @@ public class Frog {
public List<Cell> cells = new ArrayList<Cell>(); public List<Cell> cells = new ArrayList<Cell>();
/** 视觉细胞的输入区在脑中的坐标,随便取一个区就可以了,以后再考虑进化成两个眼睛 */ /** 视觉细胞的输入区在脑中的坐标,随便取一个区就可以了,以后再考虑进化成两个眼睛 */
public Zone eye = new Zone(50, 250, 100); public Zone eye = new Zone(50, 250, 50);
/** 饥饿的感收区在脑中的坐标,先随便取就可以了,以后再考虑放到蛋里去进化 */ /** 饥饿的感收区在脑中的坐标,先随便取就可以了,以后再考虑放到蛋里去进化 */
public Zone hungry = new Zone(300, 100, 200); public Zone hungry = new Zone(300, 100, 100);
/** 进食奖励的感收区在脑中的坐标,先随便取就可以了,以后再考虑放到蛋里去进化 */ /** 进食奖励的感收区在脑中的坐标,先随便取就可以了,以后再考虑放到蛋里去进化 */
public Zone happy = new Zone(300, 600, 200); public Zone happy = new Zone(300, 600, 100);
/** 运动细胞的输入区在脑中的坐标,先随便取就可以了,以后再考虑放到蛋里去进化 */ /** 运动细胞的输入区在脑中的坐标,先随便取就可以了,以后再考虑放到蛋里去进化 */
public Zone moveDown = new Zone(700, 100, 50); // 屏幕y坐标是向下的 public Zone moveDown = new Zone(700, 100, 40); // 屏幕y坐标是向下的
public Zone moveUp = new Zone(700, 400, 50); public Zone moveUp = new Zone(700, 400, 40);
public Zone moveLeft = new Zone(650, 250, 50); public Zone moveLeft = new Zone(650, 250, 40);
public Zone moveRight = new Zone(750, 250, 50); public Zone moveRight = new Zone(750, 250, 40);
public int x; public int x;
public int y; public int y;
@ -113,7 +113,7 @@ public class Frog {
public boolean active(Env env) { public boolean active(Env env) {
if (!alive) if (!alive)
return false; return false;
energy -= 100; energy -= 20;
if (energy < 0) { if (energy < 0) {
alive = false; alive = false;
return false; return false;

@ -8,7 +8,6 @@ import java.awt.Graphics;
import javax.swing.JPanel; import javax.swing.JPanel;
import com.github.drinkjava2.frog.Frog; import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.egg.CellGroup; import com.github.drinkjava2.frog.egg.CellGroup;
import com.github.drinkjava2.frog.egg.Zone; import com.github.drinkjava2.frog.egg.Zone;
@ -25,11 +24,27 @@ public class BrainStructure extends JPanel {
} }
void drawZone(Graphics g, Zone z) { void drawZone(Graphics g, Zone z) {
g.drawRect(round(z.x - z.radius / 2), round(z.y - z.radius / 2), round(z.radius), round(z.radius)); g.drawRect(round(z.x - z.radius), round(z.y - z.radius), round(z.radius * 2), round(z.radius * 2));
} }
void fillZone(Graphics g, Zone z) { void fillZone(Graphics g, Zone z) {
g.fillRect(round(z.x - z.radius / 2), round(z.y - z.radius / 2), round(z.radius), round(z.radius)); g.fillRect(round(z.x - z.radius), round(z.y - z.radius), round(z.radius * 2), round(z.radius * 2));
}
private static Color color(float i) {
if (i <= 1)
return Color.GRAY;
if (i <= 3)
return Color.ORANGE;
if (i <= 10)
return Color.YELLOW;
if (i <= 20)
return Color.GREEN;
if (i <= 50)
return Color.CYAN;
if (i <= 100)
return Color.BLUE;
return Color.MAGENTA;
} }
public void drawBrain(Frog frog) { public void drawBrain(Frog frog) {
@ -58,25 +73,14 @@ public class BrainStructure extends JPanel {
g.setColor(Color.black); g.setColor(Color.black);
int c = 1;
for (int j = 0; j < frog.egg.realCellGroupQty; j++) { for (int j = 0; j < frog.egg.realCellGroupQty; j++) {
CellGroup group=frog.egg.cellgroups[j]; CellGroup group = frog.egg.cellgroups[j];
g.setColor(new Color((c++) * 130 + c * 70000 + c * 3333333));// 取随机色 g.setColor(color(group.cellQty));// 取随机色
g.drawLine(round(group.groupInputZone.x), round(group.groupInputZone.y), round(group.groupOutputZone.x), g.drawLine(round(group.groupInputZone.x), round(group.groupInputZone.y), round(group.groupOutputZone.x),
round(group.groupOutputZone.y)); round(group.groupOutputZone.y));
drawZone(g, group.groupInputZone); drawZone(g, group.groupInputZone);
fillZone(g, group.groupOutputZone); fillZone(g, group.groupOutputZone);
} }
// for (CellGroup group : frog.egg.cellgroups) {
// g.setColor(new Color((i++) * 130 + i * 70000 + i * 3333333));// 取随机色
// g.drawLine(round(group.groupInputZone.x), round(group.groupInputZone.y), round(group.groupOutputZone.x),
// round(group.groupOutputZone.y));
// drawZone(g, group.groupInputZone);
// fillZone(g, group.groupOutputZone);
// }
} }
} }

@ -25,7 +25,7 @@ public class Env extends JPanel {
public static int STEPS_PER_ROUND = 3000; public static int STEPS_PER_ROUND = 3000;
/** Delete eggs at beginning of each test */ /** Delete eggs at beginning of each test */
public static boolean DELETE_EGGS = true;// 每次测试先删除保存的蛋 public static boolean DELETE_EGGS = false;// 每次测试先删除保存的蛋
static { static {
if (DELETE_EGGS) if (DELETE_EGGS)
@ -42,9 +42,9 @@ public class Env extends JPanel {
public byte[][] foods = new byte[ENV_XSIZE][ENV_YSIZE]; public byte[][] foods = new byte[ENV_XSIZE][ENV_YSIZE];
public int FOOD_QTY = 80; // as name public int FOOD_QTY =800; // as name
public int EGG_QTY = 200; // as name public int EGG_QTY = 50; // as name
public List<Frog> frogs = new ArrayList<Frog>(); public List<Frog> frogs = new ArrayList<Frog>();
public List<Egg> eggs; public List<Egg> eggs;
@ -63,11 +63,11 @@ public class Env extends JPanel {
} }
} }
Random rand = new Random(); Random rand = new Random();
for (int j = 0; j < 12; j++) {//第一名多生出12个蛋 for (int j = 0; j < 12; j++) {// 第一名多生出12个蛋
Egg zygote = new Egg(eggs.get(0), eggs.get(r.nextInt(eggs.size()))); Egg zygote = new Egg(eggs.get(0), eggs.get(r.nextInt(eggs.size())));
frogs.add(new Frog(ENV_XSIZE / 2 + rand.nextInt(90), ENV_YSIZE / 2 + rand.nextInt(90), zygote)); frogs.add(new Frog(ENV_XSIZE / 2 + rand.nextInt(90), ENV_YSIZE / 2 + rand.nextInt(90), zygote));
} }
for (int i = 0; i < eggs.size()-3; i++) { // 1个Egg生出4个Frog但是最后3名不生蛋(名额让给了第一名) for (int i = 0; i < eggs.size() - 3; i++) { // 1个Egg生出4个Frog但是最后3名不生蛋(名额让给了第一名)
for (int j = 0; j < 4; j++) { for (int j = 0; j < 4; j++) {
Egg zygote = new Egg(eggs.get(i), eggs.get(r.nextInt(eggs.size()))); Egg zygote = new Egg(eggs.get(i), eggs.get(r.nextInt(eggs.size())));
frogs.add(new Frog(ENV_XSIZE / 2 + rand.nextInt(90), ENV_YSIZE / 2 + rand.nextInt(90), zygote)); frogs.add(new Frog(ENV_XSIZE / 2 + rand.nextInt(90), ENV_YSIZE / 2 + rand.nextInt(90), zygote));

@ -1,14 +0,0 @@
## 版本发布记录
### 2018-1-3
项目启动。
### 2019-3-11 1.0.0版Commit:Go frog go!)发布
开发环境完成演示第一个人工生命诞生。但是所有Frog脑部为空因为运动神经元被短路只能固定向一个方向运动。
### 2019-03-18 1.0.1版提交 (Commit:Add a button)
添加了脑结构图形点下方按钮可以显示第一个胜出的Frog的脑结构但是运动神经元依然被短路只能固定向一个方向运动。
### 2019-03-21 1.0.2版提交 (Commit:I'm hungry)
在脑区添加Hungry删除随机运动的硬编码改成由Hungry区来驱动一旦frog能量小于10000,hungry区的所有脑神经元的input区激活如果这些神经元的输出区位于move区则作相应的移动。这是一个更随机一点的运动不再总是固定向一个方向。

@ -0,0 +1,25 @@
## 版本提交记录
### 2018-1-3
项目启动,主要是文字方面的一些构想。
### 2019-3-11 1.0.0版, Commit:Go frog go!
开发环境完成演示第一个人工生命诞生。但是所有Frog脑部为空因为运动神经元被短路只能固定向一个方向运动。
这是第一个发布版,演示了生命的随机进化和优胜劣汰。
### 2019-3-18, Commit:Brain picture!
添加了脑结构图形用于调试用可以显示第一个胜出的Frog的脑结构但是运动神经元依然被短路只能固定向一个方向运动。
有了脑结构图就可以防止所有Frog都被淘汰掉还不知道问题发生在哪里。可以有针对性地改进进化算法、环境的参数改进。
### 2019-03-20, 1.0.1版, Commit:Add a button
添加了一个按钮可以显示、隐藏第一个胜出的Frog的脑结构图但是运动神经元依然被短路
### 2019-03-21, 1.0.2版, Commit:I'm hungry
在脑区添加Hungry删除随机运动的硬编码改成由Hungry区来驱动一旦frog能量小于10000,hungry区的所有脑神经元的input区激活如果这些神经元的输出区位于move区则作相应的移动。这是一个更随机一点的运动不再总是固定向一个方向。
### 2019-03-27, 1.0.3版, Commit:Shrink & Sperm
添加了"蛋+精子->受精蛋"的模拟,这是为了实现生物多样性。添加了每次添加一批随机神经元,但是只保留激活过的,如果某组神经元从没被用到(激活过),则有很大的可能不会将这组神经元添加到蛋中(用进废退规则)。
### 2019-03-29, Commit:Rainbow
更正一个小Bug,BrainStructure的zone显示的半径是实际的一半用彩虹色而不是随机数来表示CellGroup的细胞数量色彩越靠后表示细胞数越多。
Loading…
Cancel
Save