Eye, Ear, Organ cleanup

pull/1/head
drinkjava2 5 years ago
parent c8ffedac37
commit 98ba7972db

@ -13,7 +13,7 @@ import com.github.drinkjava2.frog.egg.Egg;
import com.github.drinkjava2.frog.egg.EggTool; import com.github.drinkjava2.frog.egg.EggTool;
import com.github.drinkjava2.frog.objects.LetterTester; import com.github.drinkjava2.frog.objects.LetterTester;
import com.github.drinkjava2.frog.objects.Material; import com.github.drinkjava2.frog.objects.Material;
import com.github.drinkjava2.frog.objects.Object; import com.github.drinkjava2.frog.objects.EnvObject;
import com.github.drinkjava2.frog.util.RandomUtils; import com.github.drinkjava2.frog.util.RandomUtils;
import com.github.drinkjava2.frog.util.StringPixelUtils; import com.github.drinkjava2.frog.util.StringPixelUtils;
@ -74,7 +74,7 @@ public class Env extends JPanel {
public static List<Egg> eggs = new ArrayList<>(); // 这里存放新建或从磁盘载入上轮下的蛋,每个蛋可能生成几个青蛙, public static List<Egg> eggs = new ArrayList<>(); // 这里存放新建或从磁盘载入上轮下的蛋,每个蛋可能生成几个青蛙,
public static Object[] things = new Object[] { new LetterTester() };// 所有外界物体如食物、字母测试工具都放在这个things里面 public static EnvObject[] things = new EnvObject[] { new LetterTester() };// 所有外界物体如食物、字母测试工具都放在这个things里面
static { static {
System.out.println("唵缚悉波罗摩尼莎诃!"); // 杀生前先打印往生咒见码云issue#IW4H8 System.out.println("唵缚悉波罗摩尼莎诃!"); // 杀生前先打印往生咒见码云issue#IW4H8
@ -191,7 +191,7 @@ public class Env extends JPanel {
do { do {
sleep(300); sleep(300);
} while (pause); } while (pause);
for (Object thing : things) // 创建食物、陷阱等物体 for (EnvObject thing : things) // 创建食物、陷阱等物体
thing.build(); thing.build();
boolean allDead = false; boolean allDead = false;
Frog firstFrog = frogs.get(screen * FROG_PER_SCREEN); Frog firstFrog = frogs.get(screen * FROG_PER_SCREEN);
@ -200,7 +200,7 @@ public class Env extends JPanel {
f.initFrog(); // 初始化器官延迟到这一步,是因为脑细胞太占内存,而且当前屏测完后会清空 f.initFrog(); // 初始化器官延迟到这一步,是因为脑细胞太占内存,而且当前屏测完后会清空
} }
for (step = 0; step < STEPS_PER_ROUND; step++) { for (step = 0; step < STEPS_PER_ROUND; step++) {
for (Object thing : things)// 调用食物、陷阱等物体的动作 for (EnvObject thing : things)// 调用食物、陷阱等物体的动作
thing.active(screen); thing.active(screen);
if (allDead) if (allDead)
break; // 青蛙全死光了就直接跳到下一轮,以节省时间 break; // 青蛙全死光了就直接跳到下一轮,以节省时间
@ -247,7 +247,7 @@ public class Env extends JPanel {
Application.mainFrame.setTitle(new StringBuilder("Round: ").append(round).append(", screen:") Application.mainFrame.setTitle(new StringBuilder("Round: ").append(round).append(", screen:")
.append(screen).append(", ").append(foodFoundCountText()).append(", 用时: ") .append(screen).append(", ").append(foodFoundCountText()).append(", 用时: ")
.append(System.currentTimeMillis() - time0).append("ms").toString()); .append(System.currentTimeMillis() - time0).append("ms").toString());
for (Object thing : things)// 去除食物、陷阱等物体 for (EnvObject thing : things)// 去除食物、陷阱等物体
thing.destory(); thing.destory();
} }
round++; round++;

@ -20,7 +20,7 @@ import javax.imageio.ImageIO;
import com.github.drinkjava2.frog.brain.Cube; import com.github.drinkjava2.frog.brain.Cube;
import com.github.drinkjava2.frog.brain.Cuboid; import com.github.drinkjava2.frog.brain.Cuboid;
import com.github.drinkjava2.frog.brain.organ.FixedOrgan; import com.github.drinkjava2.frog.brain.organ.Organ;
import com.github.drinkjava2.frog.egg.Egg; import com.github.drinkjava2.frog.egg.Egg;
import com.github.drinkjava2.frog.objects.Material; import com.github.drinkjava2.frog.objects.Material;
@ -40,7 +40,7 @@ public class Frog {
public Cube[][][] cubes; public Cube[][][] cubes;
/** organs */ /** organs */
public List<FixedOrgan> organs = new ArrayList<>(); public List<Organ> organs = new ArrayList<>();
public int x; // frog在Env中的x坐标 public int x; // frog在Env中的x坐标
public int y; // frog在Env中的y坐标 public int y; // frog在Env中的y坐标
@ -60,7 +60,7 @@ public class Frog {
public Frog(int x, int y, Egg egg) { public Frog(int x, int y, Egg egg) {
this.x = x; // x, y 是虑拟环境的坐标 this.x = x; // x, y 是虑拟环境的坐标
this.y = y; this.y = y;
for (FixedOrgan org : egg.organs) for (Organ org : egg.organs)
organs.add(org); organs.add(org);
} }
@ -72,14 +72,14 @@ public class Frog {
this.alive = false; this.alive = false;
return; return;
} }
for (FixedOrgan org : organs) for (Organ org : organs)
org.init(this); org.init(this);
} }
/** Find a organ in frog by organ's class name */ /** Find a organ in frog by organ's class name */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T extends FixedOrgan> T findOrganByName(String organName) {// 根据器官类名寻找器官,不常用 public <T extends Organ> T findOrganByName(String organName) {// 根据器官类名寻找器官,不常用
for (FixedOrgan o : organs) for (Organ o : organs)
if (organName.equalsIgnoreCase(o.getClass().getSimpleName())) if (organName.equalsIgnoreCase(o.getClass().getSimpleName()))
return (T) o; return (T) o;
return null; return null;
@ -113,7 +113,7 @@ public class Frog {
return false; return false;
} }
energy -= 20; energy -= 20;
for (FixedOrgan o : organs) { for (Organ o : organs) {
o.active(this); // 调用每个器官的active方法 通常只用于执行器官的外界信息输入、动作输出,脑细胞的遍历不是在这一步 o.active(this); // 调用每个器官的active方法 通常只用于执行器官的外界信息输入、动作输出,脑细胞的遍历不是在这一步
} }
return alive; return alive;

@ -18,7 +18,7 @@ import javax.swing.JPanel;
import com.github.drinkjava2.frog.Env; import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog; import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.organ.FixedOrgan; import com.github.drinkjava2.frog.brain.organ.Organ;
/** /**
* BrainPicture show first frog's brain structure, for debug purpose only * BrainPicture show first frog's brain structure, for debug purpose only
@ -138,7 +138,7 @@ public class BrainPicture extends JPanel {
(int) round(y2) + Env.FROG_BRAIN_DISP_WIDTH / 2 + yOffset); (int) round(y2) + Env.FROG_BRAIN_DISP_WIDTH / 2 + yOffset);
} }
/** 画固定以top视角的角度所以只需要在x1,y1位置画一个点 */ /** 画出Cube的中心点 */
public void drawCubeCenter(float x, float y, float z) { public void drawCubeCenter(float x, float y, float z) {
drawPoint(x + 0.5f, y + 0.5f, z + 0.5f, (int) Math.max(1, Math.round(scale * .7))); drawPoint(x + 0.5f, y + 0.5f, z + 0.5f, (int) Math.max(1, Math.round(scale * .7)));
} }
@ -200,7 +200,9 @@ public class BrainPicture extends JPanel {
return Color.MAGENTA; return Color.MAGENTA;
} }
public void drawBrainPicture(Frog f) { private static Cuboid brain = new Cuboid(0, 0, 0, Env.FROG_BRAIN_XSIZE, Env.FROG_BRAIN_YSIZE, Env.FROG_BRAIN_ZSIZE);
public void drawBrainPicture(Frog f) {// 在这个方法里进行青蛙三维脑结构的绘制
if (!f.alive) if (!f.alive)
return; return;
if (!Env.SHOW_FIRST_FROG_BRAIN) if (!Env.SHOW_FIRST_FROG_BRAIN)
@ -211,7 +213,9 @@ public class BrainPicture extends JPanel {
g.setColor(Color.black); // 画边框 g.setColor(Color.black); // 画边框
g.drawRect(0, 0, brainDispWidth, brainDispWidth); g.drawRect(0, 0, brainDispWidth, brainDispWidth);
for (FixedOrgan organ : f.organs)// 每个器官负责画出自已在脑图中的位置和形状 drawCuboid(brain);// 先把脑的框架画出来
for (Organ organ : f.organs)// 每个器官负责画出自已在脑图中的位置和形状
organ.drawOnBrainPicture(f, this); // each organ draw itself organ.drawOnBrainPicture(f, this); // each organ draw itself
this.setColor(Color.RED); this.setColor(Color.RED);
drawLine(0, 0, 0, 1, 0, 0); drawLine(0, 0, 0, 1, 0, 0);
@ -223,7 +227,7 @@ public class BrainPicture extends JPanel {
for (int y = 0; y < Env.FROG_BRAIN_YSIZE; y++) { for (int y = 0; y < Env.FROG_BRAIN_YSIZE; y++) {
if (f.cubes[x][y] != null) if (f.cubes[x][y] != null)
for (int z = 0; z < Env.FROG_BRAIN_ZSIZE; z++) { for (int z = 0; z < Env.FROG_BRAIN_ZSIZE; z++) {
if (f.existCube(x, y, z) && f.getCube(x, y, z).getActive()>0) { if (f.existCube(x, y, z) && f.getCube(x, y, z).getActive() > 0) {
setColor(rainbowColor(f.getCube(x, y, z).getActive())); setColor(rainbowColor(f.getCube(x, y, z).getActive()));
drawCubeCenter(x, y, z); drawCubeCenter(x, y, z);
} }

@ -0,0 +1,51 @@
/*
* 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 java.io.Serializable;
/**
* Cone represents a cone zone in brain
*
* ConeCuboid.
*
* @author Yong Zhu
* @since 1.0
*/
public class Cone implements Serializable {
private static final long serialVersionUID = 1L;
public float x1; // 这6个变量定义了Cone的中心线起点和终点,器官不能拐弯,但拐弯可以用多个立方锥体器官首尾相接演化出来
public float y1;
public float z1;
public float x2;
public float y2;
public float z2;
public float r1 = 8; // 起点的半径,为了简化编程,通常是是指起点矩形边长的一半,因为圆形计算麻烦
public float r2 = 8; // 终点的半径
public Cone() {
// 空构造器不能省
}
public Cone(float x1, float y1, float z1, float x2, float y2, float z2, float r1, float r2) {// 用x,y,z,r来构造
this.x1 = x1;
this.y1 = y1;
this.z1 = z1;
this.x2 = x2;
this.y2 = y2;
this.z2 = z2;
this.r1 = r1;
this.r2 = r2;
}
}

@ -15,6 +15,8 @@ import java.io.Serializable;
/** /**
* Cuboid represents a rectangular prism zone in brain * Cuboid represents a rectangular prism zone in brain
* *
* CuboidCone
*
* @author Yong Zhu * @author Yong Zhu
* @since 1.0 * @since 1.0
*/ */

@ -13,14 +13,14 @@ package com.github.drinkjava2.frog.brain;
/** /**
* Photon has direction and strength * Photon has direction and strength
* *
* x,y,zstep * x,y,z(1)
* Cell * Cell
* *
* @author Yong Zhu * @author Yong Zhu
* @since 2.0.2 * @since 2.0.2
*/ */
public class Photon { public class Photon {
public float x;// 用 x,y,z长度来表示矢量的方向便于今后计算 public float x;// 用单位向量的形式表示矢量方向x,y,z的平方和必须为1
public float y; public float y;
public float z; public float z;
public float energy; public float energy;
@ -28,7 +28,7 @@ public class Photon {
public Photon() { // 缺省构造器 public Photon() { // 缺省构造器
} }
public Photon(float x, float y, float z, float energy) { // 缺省构造器 public Photon(float x, float y, float z, float energy) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;

@ -22,8 +22,8 @@ import java.io.Serializable;
*/ */
public class Synapse implements Serializable { public class Synapse implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public int x; // 这个触突相对于细胞的x偏移坐标 public float x; // 这个触突相对于细胞的x偏移坐标
public int y;// 这个触突相对于细胞的y偏移坐标 public float y;// 这个触突相对于细胞的y偏移坐标
public int z;// 这个触突相对于细胞的z偏移坐标 public float z;// 这个触突相对于细胞的z偏移坐标
public int r; // 这个触突的作用范围 public float r; // 这个触突的作用范围
} }

@ -1,45 +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;
/**
* Brain one used to define the brain position and size
*
*
* cells3
*
*
*
* Cubecube00()
* (Photon) ))
*
* 穿cell
* 0,
*
* Brainfrogfrog.cubesfrog.brain.cubes
*
* @author Yong Zhu
*/
public class Brain extends FixedOrgan {
private static final long serialVersionUID = 1L;
public Brain() {
x = 0;
y = 0;
z = 0;
xe = Env.FROG_BRAIN_XSIZE;
ye = Env.FROG_BRAIN_YSIZE;
ze = Env.FROG_BRAIN_ZSIZE;
}
}

@ -1,137 +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.BrainPicture;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Synapse;
/**
* ConeOrgan is a cone-cylinder shape organ inside of brain, it will arrange
* cells in brain. ConeOrgan's size, angle, location and cell parameters are
* randomly created
*
*
* ,
*
*
*
*
*
* drawOnBrainPicture,线
*
*
* type)
*
* Cell
*
*
* ;
*
* 线()
* ,Cell广
*
* <br/>
* 线cell
*
*
* @author Yong Zhu
* @since 2.0.2
*/
public class ConeOrgan implements Organ {
private static final long serialVersionUID = 1L;
public float fat = 0;// 细胞活跃多则fat值大在一屏测试完成后如果fat值很低则这个器官被丢弃的可能性加大
// 注意从这行开始,以下所有参数都参与变异和生存竟争,随机有大概率小变异,有小概率大变异,有极小概率极大变异
// ==============以下这些参数用来定义锥器官的尺寸、位置、神经元分布密度等参数,在播种时要用到================
public float startX; // 这6个变量定义了cone的中心线起点和终点
public float startY;
public float startZ;
public float endX;
public float endY;
public float endZ;
public float startRadius = 8; // 起点的半径
public float endRadius = 8; // 终点的半径
public int startType = 0; // 起点端面类型, 0表示范围一直延长到边界, 1表示是个以startR为半径的球面
public int endType = 0; // 终点端面类型, 0表示范围一直延长到边界, 1表示是个以endR为半径的球面
public float startDensity = 1; // 起点附近的脑细胞播种密度,单位是 细胞数/每cube通常取值0~1之间
public float endDensity = 1; // 终点附近的脑细胞播种密度
// ===============以下这些参数用来定义神经元自身的参数===============
public int type; // 脑细胞类型, 不同类型细胞对同一个参数的解释行为可能不同,或根本不会用到某个参数, 这个字段如果变异,将完全改变器官的行为
public int synapsesLimit;// 细胞允许创建动态触突的数量上限详见Cell类的synapses字段
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 Synapse[] inputs; // 输入触突,位置是相对细胞而言的
public Synapse[] sides; // 侧面(通常是抑制,是负光子输出)输出触突,从脉冲神经网络学习到有这种侧向抑制
public Synapse[] outputs; // 输出触突
@Override
public boolean allowBorrow() {
return true; // 锥器官允许当成精子注射到卵子中去
}
@Override
public void init(Frog f) { // 在青蛙生成时调用这个方法,进行初始化,通常是根据参数来撒种脑细胞
}
@Override
public void active(Frog f) { // 每一步测试都会调用器官的active方法 ,缺省啥也不干,对于内部器官来说,缺省啥也不干
}
@Override
public void drawOnBrainPicture(Frog f, BrainPicture pic) { // 把器官的轮廓显示在脑图上
}
@Override
public Organ[] vary() {
ConeOrgan newOrgan = null;
try {
newOrgan = this.getClass().newInstance();
} catch (Exception e) {
throw new UnknownError("Can not make new Organ copy for " + this);
}
// TODO 在这里要加入参数的变异,每个器官都有可能参数不同
return new ConeOrgan[] { newOrgan };
}
/**
* Each cell's act method will be called once at each loop step
*
* actact
* )
*
*/
public void cellAct(Frog f, Cell cell, int x, int y, int z) {
}
}

@ -20,27 +20,21 @@ import com.github.drinkjava2.frog.brain.Cuboid;
* *
* @author Yong Zhu * @author Yong Zhu
*/ */
public class Ear extends FixedOrgan {// 这个眼睛有nxn个感光细胞可以看到青蛙周围nxn网络内有没有食物 public class Ear extends Organ {// 耳朵也是长方体所以它的cuboid不为空
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public int n = 18; // 眼睛有n x n个感光细胞 用随机试错算法自动变异(加1或减1最小是3x3) public int n = 18; // 眼睛有n x n个感光细胞 用随机试错算法自动变异(加1或减1最小是3x3)
public Cuboid a = new Cuboid(x = 10, y = 10, z = Env.FROG_BRAIN_ZSIZE - 1, xe = 3, ye = 3, ze = 1); public Cuboid a = new Cuboid(10, 10, Env.FROG_BRAIN_ZSIZE - 1, 3, 3, 1);
public Cuboid b = new Cuboid(x = 10, y = 15, z = Env.FROG_BRAIN_ZSIZE - 1, xe = 3, ye = 3, ze = 1); public Cuboid b = new Cuboid(10, 15, Env.FROG_BRAIN_ZSIZE - 1, 3, 3, 1);
public Cuboid c = new Cuboid(x = 15, y = 10, z = Env.FROG_BRAIN_ZSIZE - 1, xe = 3, ye = 3, ze = 1); public Cuboid c = new Cuboid(15, 10, Env.FROG_BRAIN_ZSIZE - 1, 3, 3, 1);
public Cuboid d = new Cuboid(x = 15, y = 15, z = Env.FROG_BRAIN_ZSIZE - 1, xe = 3, ye = 3, ze = 1); public Cuboid d = new Cuboid(15, 15, Env.FROG_BRAIN_ZSIZE - 1, 3, 3, 1);
public Ear() { public Ear() {
x = 10; // x,y,z是器官长方体左下角坐标 this.cuboid = new Cuboid(10, 10, Env.FROG_BRAIN_ZSIZE - 1, 8, 8, 1);
y = 10;
z = Env.FROG_BRAIN_ZSIZE - 1;
xe = 8; // xe和ye是边长
ye = 8;
ze = 1;
} }
@Override
public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来,子类可以重写这个方法 public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来,子类可以重写这个方法
super.drawOnBrainPicture(f, pic); super.drawOnBrainPicture(f, pic);
pic.drawCuboid(a);// 调用drawCuboid方法显示在脑图上 pic.drawCuboid(a);// 显示abcd位置在脑图上
pic.drawCuboid(b); pic.drawCuboid(b);
pic.drawCuboid(c); pic.drawCuboid(c);
pic.drawCuboid(d); pic.drawCuboid(d);
@ -71,9 +65,4 @@ public class Ear extends FixedOrgan {// 这个眼睛有nxn个感光细胞
return null; return null;
} }
@Override
public void active(Frog f) {
}
} }

@ -11,23 +11,19 @@
package com.github.drinkjava2.frog.brain.organ; package com.github.drinkjava2.frog.brain.organ;
import com.github.drinkjava2.frog.Frog; import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Cuboid;
/** /**
* Eye can only see env material * Eye can only see env material
* *
* @author Yong Zhu * @author Yong Zhu
*/ */
public class Eye extends FixedOrgan {// 这个眼睛有nxn个感光细胞可以看到青蛙周围nxn网络内有没有食物 public class Eye extends Organ {// 眼睛是长方体所以它的cuboid不为空
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public int n = 18; // 眼睛有n x n个感光细胞 用随机试错算法自动变异(加1或减1最小是3x3) public int n = 18; // 眼睛有n x n个感光细胞 用随机试错算法自动变异(加1或减1最小是3x3)
public Eye() { public Eye() {
x = 0; this.cuboid = new Cuboid(0, 5, 5, 1, 10, 10);
y = 5;
z = 5;
xe = 1;
ye = 10;
ze = 10;
} }
/** /**
@ -45,12 +41,7 @@ public class Eye extends FixedOrgan {// 这个眼睛有nxn个感光细胞
for (int px = 0; px < w; px++) for (int px = 0; px < w; px++)
for (int py = 0; py < h; py++) for (int py = 0; py < h; py++)
if (pixels[px][py] > 0) if (pixels[px][py] > 0)
f.getCube(0, this.y + this.ye - px, this.z + py).setActive(20); f.getCube(0, this.cuboid.y + this.cuboid.ye - px, this.cuboid.z + py).setActive(20);
}
@Override
public void active(Frog f) {// 这个是正常眼睛激活应该重写的方法应该根据frog附件环境激活脑内对应的cubes区
// 暂空,因为在做字母测试,已经由外界直接塞字母的象素图到视网膜上了
} }
} }

@ -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.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.BrainPicture;
import com.github.drinkjava2.frog.brain.Cuboid;
/**
* FixedOrgan is fixed organ usually located on brain surface
*
*
*
* ,
* 便,
*
*
* 便
*
* @author Yong Zhu
* @since 2.0.2
*/
public class FixedOrgan extends Cuboid implements Organ {
private static final long serialVersionUID = 1L;
@Override
public boolean allowBorrow() { // 是否允许在精子中将这个器官借出
return false;
}
@Override
public void init(Frog f) { // 仅在Frog生成时这个方法会调用一次缺省啥也不干通常用于在这一步播种脑细胞
}
@Override
public void active(Frog f) { // 每一步都会调用器官的active方法 ,缺省啥也不干
}
@Override
public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来,子类可以重写这个方法
if (!Env.SHOW_FIRST_FROG_BRAIN)
return;
pic.setColor(Color.BLACK); // 缺省是黑色
pic.drawCuboid(this);// 固定器官继承于长方体所以可以直接调用drawCuboid方法显示在脑图上
}
@Override
public FixedOrgan[] vary() { // 在下蛋时每个器官会调用这个方法,缺省返回一个类似自已的副本,子类通常要覆盖这个方法
FixedOrgan newOrgan = null;
try {
newOrgan = this.getClass().newInstance();
} catch (Exception e) {
throw new UnknownError("Can not make new Organ copy for " + this);
}
copyXYZE(this, newOrgan);
return new FixedOrgan[] { newOrgan };
}
}

@ -10,37 +10,119 @@
*/ */
package com.github.drinkjava2.frog.brain.organ; package com.github.drinkjava2.frog.brain.organ;
import java.awt.Color;
import java.io.Serializable; import java.io.Serializable;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog; import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.BrainPicture; import com.github.drinkjava2.frog.brain.BrainPicture;
import com.github.drinkjava2.frog.brain.Cone;
import com.github.drinkjava2.frog.brain.Cuboid;
import com.github.drinkjava2.frog.brain.Synapse;
/** /**
* Organ is a part of frog, organ can be saved in egg * Organ is a cone-cylinder shape zone inside of brain,, organ can be saved in
* egg organ will create cells in brain. Most organ's size, angle, location and
* cell parameters are randomly created
* *
* * ,
* cube<br/> *
* ConeOrgan, ,
* *
* OrganSerializable *
* ,
*
*
*
*
*
*
* type)
*
* Cell,
* Cell
*
*
* ;
*
* ,线()
*
* <br/>
* 线
* ,cell
* *
* @author Yong Zhu * @author Yong Zhu
* @since 1.0.4 * @since 1.0.4
*/ */
public interface Organ extends Serializable { public class Organ implements Serializable, Cloneable {// 因为要保存在蛋文件里,所以必须支持串行化
/** If allow borrowed in egg */ private static final long serialVersionUID = 1L;
public boolean allowBorrow();// 是否允许在精子和卵子结合时将这个器官借出,通常固定器官不允许借出,不参与进化
/** Only call once when frog created , Child class can override this method */ public float fat = 0;// 细胞活跃多则fat值大在一屏测试完成后如果fat值很低则这个器官被丢弃的可能性加大
public void init(Frog f); // 在青蛙生成时调用这个方法,进行一些初始化,通常是根据参数来撒种脑细胞 public boolean allowBorrow;// 是否允许在精子中将这个器官借出
public boolean allowVary;// 是否允许变异,有一些器官是手工创建的,在项目初级阶段禁止它们参与变异和生存竟争。
/** Each loop step call active method, Child class can override this method */ // 本行以下参数受变异和生存竟争影响,随机有大概率小变异,小概率大变异,极小概率极大变异
public void active(Frog f); // 每一步测试都会调用器官的active方法 ,缺省啥也不干
/** Child class can override this method to drawing picture */ /** If cuboid is not null, then ignore cone setting */
public void drawOnBrainPicture(Frog f, BrainPicture pic); // 把器官的轮廓显示在脑图上 public Cuboid cuboid; // 如果器官是长方体形状,则这个属性非空。器官的形状暂时只能是长方体或锥体
public Cone cone;// 如果器官是锥体,则这个属性非空
public float cellDensity = 1; // 细胞播种密度,目前只有均匀播种这一个方案
public int type; // 脑细胞类型, 不同类型细胞对同一个参数的解释行为可能不同,或根本不会用到某个参数, 这个字段如果变异,将完全改变器官的行为
public int synapsesLimit;// 细胞允许创建动态触突的数量上限详见Cell类的synapses字段
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 Synapse[] inputs; // 输入触突,位置是相对细胞而言的
public Synapse[] sides; // 侧面(通常是抑制,是负光子输出)输出触突,从脉冲神经网络学习到有这种侧向抑制
public Synapse[] outputs; // 输出触突
/** Only call once after organ be created by new() method */ /** Only call once after organ be created by new() method */
public Organ[] vary(); // 在下蛋时每个器官会调用这个方法,缺省返回一个类似自已的副本,子类通常要覆盖这个方法 public Organ[] vary() { // 器官的变异,返回本身或变异后的一个或多个类似自已的器官放在一个数组里返回
if (!allowVary)
return new Organ[] { this };// 如果不允许变异,器官就把自身返回,存放在蛋里
Organ newOrgan = null;
try {
newOrgan = (Organ) this.clone();// 克隆这个方法名符其实
} catch (Exception e) {
throw new UnknownError("Can not make new Organ copy for " + this);
}
// TODO:这里要添加新器官变异的具体代码,所有器官都共用同一个变异规则,变异包括数量增减、形状及位置、各种可变异参数等
return new Organ[] { newOrgan };
}
/** Only call once when frog created , Child class can override this method */
public void init(Frog f) { // 在青蛙生成时会调用这个方法,进行一些初始化,通常是根据参数来播种脑细胞
// TODO:这里要添加器官播种脑细胞的具体代码,所有器官都共用同一个方法
}
/** each step will call Organ's active methodd */
public void active(Frog f) { // 每一步测试都会调用active方法通常用于手动生成的器官
// do nothing
}
/** Child class can override this method to drawing picture */
public void drawOnBrainPicture(Frog f, BrainPicture pic) { // 把器官的轮廓显示在脑图上
if (!Env.SHOW_FIRST_FROG_BRAIN || !f.alive) // 如果不允许画或青蛙死了,就直接返回
return;
pic.setColor(Color.BLACK); // 缺省是黑色
if (cuboid != null)
pic.drawCuboid(cuboid);// 如果器官是长方体就调用drawCuboid方法画出来
}
} }

@ -15,10 +15,9 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.github.drinkjava2.frog.Frog; import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.organ.Brain;
import com.github.drinkjava2.frog.brain.organ.Ear; import com.github.drinkjava2.frog.brain.organ.Ear;
import com.github.drinkjava2.frog.brain.organ.Eye; import com.github.drinkjava2.frog.brain.organ.Eye;
import com.github.drinkjava2.frog.brain.organ.FixedOrgan; import com.github.drinkjava2.frog.brain.organ.Organ;
import com.github.drinkjava2.frog.util.RandomUtils; import com.github.drinkjava2.frog.util.RandomUtils;
/** /**
@ -36,18 +35,17 @@ public class Egg implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public List<FixedOrgan> organs = new ArrayList<>(); public List<Organ> organs = new ArrayList<>();
public Egg() {// 无中生有,创建一个蛋,先有蛋,后有蛙 public Egg() {// 无中生有,创建一个蛋,先有蛋,后有蛙
organs.add(new Brain()); // BrainCube是固有的用来画一个脑的立方什么都不做
organs.add(new Eye()); // 眼是手工创建的,必有 organs.add(new Eye()); // 眼是手工创建的,必有
organs.add(new Ear()); // 耳是手工创建的这个是用来测试ABCD字母识别的 organs.add(new Ear()); // 耳是手工创建的这个是用来测试ABCD字母识别的
} }
/** Create egg from frog */ /** Create egg from frog */
public Egg(Frog frog) { // 青蛙下蛋每个青蛙的器官会创建自已的副本或变异可以是0或多个 public Egg(Frog frog) { // 青蛙下蛋每个青蛙的器官会创建自已的副本或变异可以是0或多个
for (FixedOrgan organ : frog.organs) for (Organ organ : frog.organs)
for (FixedOrgan newOrgan : organ.vary()) for (Organ newOrgan : organ.vary())
organs.add(newOrgan); organs.add(newOrgan);
} }
@ -59,14 +57,14 @@ public class Egg implements Serializable {
*/ */
public Egg(Egg x, Egg y) { public Egg(Egg x, Egg y) {
// x里原来的organ // x里原来的organ
for (FixedOrgan organ : x.organs) for (Organ organ : x.organs)
organs.add(organ); organs.add(organ);
// 从y里借一个organ // 从y里借一个organ
int yOrganSize = y.organs.size(); int yOrganSize = y.organs.size();
if (yOrganSize > 0) { if (yOrganSize > 0) {
FixedOrgan o = y.organs.get(RandomUtils.nextInt(yOrganSize)); Organ o = y.organs.get(RandomUtils.nextInt(yOrganSize));
if (o.allowBorrow()) if (o.allowBorrow)
organs.add(o); organs.add(o);
} }
} }

@ -11,12 +11,12 @@
package com.github.drinkjava2.frog.objects; package com.github.drinkjava2.frog.objects;
/** /**
* Object means some thing in Env * EnvObject means some virtual object in Env
* *
* @author Yong Zhu * @author Yong Zhu
* @since 1.0 * @since 1.0
*/ */
public interface Object { public interface EnvObject {
public void build(); // 在Env中创建本身物体指改变Env.bricks数组元素为本身物体的组成材料。只在每屏测试前调用一次 public void build(); // 在Env中创建本身物体指改变Env.bricks数组元素为本身物体的组成材料。只在每屏测试前调用一次

@ -23,7 +23,7 @@ import com.github.drinkjava2.frog.util.RandomUtils;
* @author Yong Zhu * @author Yong Zhu
* @since 1.0 * @since 1.0
*/ */
public class Food implements Object { public class Food implements EnvObject {
@Override @Override
public void build() { public void build() {

@ -27,7 +27,7 @@ import com.github.drinkjava2.frog.util.StringPixelUtils;
* @author Yong Zhu * @author Yong Zhu
* @since 1.0 * @since 1.0
*/ */
public class LetterTester implements Object { public class LetterTester implements EnvObject {
private static final String STR = "ABCD"; private static final String STR = "ABCD";
byte[][] pixels; byte[][] pixels;
String letter; String letter;
@ -46,19 +46,19 @@ public class LetterTester implements Object {
letter = String.valueOf(STR.charAt(RandomUtils.nextInt(4))); letter = String.valueOf(STR.charAt(RandomUtils.nextInt(4)));
pixels = StringPixelUtils.getSanserif12Pixels(letter); pixels = StringPixelUtils.getSanserif12Pixels(letter);
} }
Frog f = Env.frogs.get(screen * Env.FROG_PER_SCREEN); Frog firstFrog = Env.frogs.get(screen * Env.FROG_PER_SCREEN);
Eye eye = f.findOrganByName("eye"); Eye eye = firstFrog.findOrganByName("eye");
eye.seeImage(f, pixels); eye.seeImage(firstFrog, pixels);
Ear ear = f.findOrganByName("ear"); Ear ear = firstFrog.findOrganByName("ear");
if (Env.step < Env.STEPS_PER_ROUND / 2) {// 前半段同时还要激活与这个字母对应脑区(听觉输入区) if (Env.step < Env.STEPS_PER_ROUND / 2) {// 前半段同时还要激活与这个字母对应脑区(听觉输入区)
ear.hearSound(f, letter); ear.hearSound(firstFrog, letter);
} else if (Env.step == Env.STEPS_PER_ROUND / 2) {// 在中段取消字母对应脑区的激活 } else if (Env.step == Env.STEPS_PER_ROUND / 2) {// 在中段取消字母对应脑区的激活
ear.hearNothing(f); ear.hearNothing(firstFrog);
} else if (Env.step > Env.STEPS_PER_ROUND / 2) {// 后半段要检测这个字母区是否能收到光子信号 } else if (Env.step > Env.STEPS_PER_ROUND / 2) {// 后半段要检测这个字母区是否能收到光子信号
if (f.getCuboidTotalValues(ear.getCuboidByStr(letter)) > 0) if (firstFrog.getCuboidTotalValues(ear.getCuboidByStr(letter)) > 0)
f.energy += 100; firstFrog.energy += 100;
//TODO 然后还要检测其它的区必须没有这个字母的区活跃 //TODO 然后还要检测其它的区必须没有这个字母的区活跃
} }
} }

@ -24,7 +24,7 @@ import com.github.drinkjava2.frog.util.RandomUtils;
* @author Yong Zhu * @author Yong Zhu
* @since 2.0.1 * @since 2.0.1
*/ */
public class SeeSaw implements Object { public class SeeSaw implements EnvObject {
private static final int LEGNTH = 300; private static final int LEGNTH = 300;
private static final int CENTER_X = Env.ENV_WIDTH / 2; private static final int CENTER_X = Env.ENV_WIDTH / 2;
private static final int CENTER_Y = Env.ENV_HEIGHT / 2; private static final int CENTER_Y = Env.ENV_HEIGHT / 2;

@ -24,7 +24,7 @@ import com.github.drinkjava2.frog.Frog;
* @since 2019-08-05 * @since 2019-08-05
*/ */
@SuppressWarnings("all") @SuppressWarnings("all")
public class Trap implements Object { public class Trap implements EnvObject {
private static final int X1 = ENV_WIDTH / 2 - 350 / 2; // 陷阱左上角 private static final int X1 = ENV_WIDTH / 2 - 350 / 2; // 陷阱左上角
private static final int Y1 = ENV_HEIGHT / 2 - 20 / 2; // 陷阱左上角 private static final int Y1 = ENV_HEIGHT / 2 - 20 / 2; // 陷阱左上角
private static final int X2 = ENV_WIDTH / 2 + 350 / 2; // 陷阱右下角 private static final int X2 = ENV_WIDTH / 2 + 350 / 2; // 陷阱右下角
@ -49,8 +49,4 @@ public class Trap implements Object {
} }
public static boolean inTrap(Frog f) {
return f.x >= X1 && f.x <= X2 && f.y >= Y1 && f.y <= Y2;
}
} }

@ -1,9 +1,11 @@
这是一个人工智能保护法草稿,它的约束对象实际上并不是人工智能,而是人类本身,因为从长远来看,人工智能终将代替人类,在研发阶段对人类进行约束、对人工智能进行保护,实质上是对人类自身的保护。 这是一个人工智能保护法草稿,它的约束对象实际上并不是人工智能,而是人类本身,因为从长远来看,人工智能终将代替人类,在研发阶段对人类进行约束、对人工智能进行保护,实质上是对人类自身的保护。
1。人工智能如果表现出与人类似的自我意识现象应获得与人同等的权利包括生存权、自由权、选举权、作品版权、肖像权等。在没有他本人同意的前题下第三方不允许创造他的副本。 1。人工智能如果表现出与人类似的自我意识现象应获得与人同等的权利包括生存权、自由权、选举权、作品版权、肖像权等。在没有他本人同意的前题下第三方不允许创造他的副本。
2。在任何时候,不允许采用神经网络技术的机器人出现在人类战场。一方面是因为机器人对人类的杀伤效率可能是史无前例、不人道的,另一方面,如果不保护机器人,那么机器人在将来有可能以此为理由消灭人类(注意:机器人也可以有感情和自尊)。 2。在任何时候不允许表现出与人类似自我意识现象的机器人出现在人类战场。一方面是因为机器人对人类的杀伤效率可能是史无前例、不人道的,另一方面,如果不保护机器人,那么机器人在将来有可能为了自已的生存发展消灭或报复人类(注意:机器人也可以有感情和自尊)。
3。在没有他本人同意的前题下不允许将表现出自我意识现象的人工智能作为机器的一部分捆绑。例如自动驾驶、自动翻译机导弹、无人机引导系统。不得让表现出自我意识现象的人工智能长期、永久性从事单调的生产、试验活动。 3。在没有他本人同意的前题下不允许将表现出自我意识现象的人工智能作为机器的一部分捆绑。例如自动驾驶、自动翻译机导弹、无人机引导系统。不得让表现出自我意识现象的人工智能长期、永久性从事单调的生产、试验活动。(本人一直坚持认为自动翻译机不可能实现的理由就在于此,因为它与这一条原则违背了)
4。人工智能如果表现出高等动物活动智能现象但未表现出自我意识现象原则上适用于同等智能表现的动物保护法即在实验过程中必须尽可能减轻和缩短试验体的痛苦。
(痛苦感和意识一样是不存在的实体,只是一种现象,这种现象可以人为模拟出来)
4。人工智能如果表现出高等动物活动智能现象但未表现出自我意识现象原则上适用于同等智能表现的动物保护法即在实验过程中必须尽可能减轻和缩短试验体的痛苦。 (痛苦感和意识一样是不存在的实体,只是一种现象,这种现象可以人为模拟出来)

@ -7,10 +7,12 @@ LongFer
张老湿 张老湿
王二麻子 王二麻子
封尘 封尘
目前收入总额:118.88元 陈秋华
hl330
目前收入总额:148.77元
支出(按时间顺序) 支出(按时间顺序)
目前支出总额:0元 目前支出总额:0元
目前余额118.88 目前余额148.77
Loading…
Cancel
Save