Work on ABCD Test

pull/1/head
drinkjava2 5 years ago
parent 91cd4ad128
commit 9135b664ad

@ -77,11 +77,12 @@ Frog: 这是人工生命的主体,目前起名叫青蛙(Frog),其实叫什
2019-08-05 有了分组测试功能后,顺手加上了一个青蛙走跷跷板自动平衡的演示,它每次只出场一个青蛙, 每轮包括100场测试大约跑90多轮半个小时(电脑慢)后,出现了下面的画面: 2019-08-05 有了分组测试功能后,顺手加上了一个青蛙走跷跷板自动平衡的演示,它每次只出场一个青蛙, 每轮包括100场测试大约跑90多轮半个小时(电脑慢)后,出现了下面的画面:
![result5](https://gitee.com/drinkjava2/frog/raw/master/result5_seesaw.gif) ![result5](https://gitee.com/drinkjava2/frog/raw/master/result5_seesaw.gif)
这个版本的目的是为了增加一点趣味性,显得青蛙还是有点"用处"的,省得让人以为这个项目不务正业,青蛙只会找食。这个版本青蛙的脑结构和找食版的青蛙基本相同,区别只是在于环境不同,也就是说它的表现随着环境而变化,这符合"通用人工智能"的概念,即信号感受器官是统一的(通常是眼睛)但能根据不同的环境完成不同的任务。走跷跷板演示是最后一个2维脑的版本今后这个项目将沉寂一段较长时间我将致力于将青蛙脑重构为3D金字塔形脑结构(见上文)因为这个项目的缺点已经很明显它不具备对2维图像的模式识别能力用随机试错的方式只能处理非常简单的、信号在视网膜的固定区域出现的图像信号。 这个版本的目的是为了增加一点趣味性,显得青蛙还是有点"用处"的,省得让人以为这个项目不务正业,青蛙只会找食。这个版本青蛙的脑结构和找食版的青蛙基本相同,区别只是在于环境不同,也就是说它的表现随着环境而变化,这符合"通用人工智能"的概念,即信号感受器官是统一的(通常是眼睛)但能根据不同的环境完成不同的任务。走跷跷板演示是最后一个2维脑的版本今后这个项目将沉寂一段较长时间我将致力于将青蛙脑重构为3D金字塔形脑结构(见上文)因为这个项目的缺点已经很明显它不具备对2维图像的模式识别能力用随机试错的方式只能处理非常简单的、信号在视网膜的固定区域出现的图像信号。
青蛙的找食效率以及走跷跷板平衡的能力都没有优化到顶点,一些构想中的复杂的器官如“与门”、“或门”(不要怀疑大自然能否进化出这些复杂器官)等都没加上器官的用进废退、奖励信号的利用都没反映但我认为这些还不关键目前最急迫的任务应该是先进行3D脑结构建模让青蛙能具备2维图形的模式识别(和回忆)功能,这个大的架构重构是它能处理复杂图像信息的立足之本,它的图像识别能力和通常的用上千张图片来训练识别一个图片这种工作模式完全不同,它是一种通用的,可自动分类识别所有图像的模式,更符合动物脑的工作模式,记住并回忆出某个图像(或任意输入信号场景的组合),可能只需要这种场景重复出现过几次即可,它是一种无外界信号判定,自动分类的识别模式。 青蛙的找食效率以及走跷跷板平衡的能力都没有优化到顶点,一些构想中的复杂的器官如“与门”、“或门”(不要怀疑大自然能否进化出这些复杂器官)等都没加上器官的用进废退、奖励信号的利用都没反映但我认为这些还不关键目前最急迫的任务应该是先进行3D脑结构建模让青蛙能具备2维图形的模式识别(和回忆)功能,这个大的架构重构是它能处理复杂图像信息的立足之本,它的图像识别能力和通常的用上千张图片来训练识别一个图片这种工作模式完全不同,它是一种通用的,可自动分类识别所有图像的模式,更符合动物脑的工作模式,记住并回忆出某个图像(或任意输入信号场景的组合),可能只需要这种场景重复出现过几次即可,它是一种无外界信号判定,自动分类的识别模式。
如果想要运行这个项目的以前版本可以结合gitk命令和参考"版本提交记录.md"的介绍用git reset命令回复到以前任一个版本例如用: 如果想要运行这个项目的以前版本可以结合gitk命令和参考"版本提交记录.md"的介绍用git reset命令回复到以前任一个版本例如用:
git reset --hard ae34b07e 可以转回到上一个分组测试的找食版本。 git reset --hard ae34b07e 可以转回到上一个分组测试的找食版本。
2019-09-09 开始3D脑的构建任务又回到原点找食从静止的青蛙要能进化到吃光所有食物。目前只是搭建空的开发环境还未涉及3D脑模型编程。新的工作存放在core3d目录原有的旧core目录保留相应地批处理文件也分为普通版run.bat和3d版run3d.bat,蛋文件也分为普通版eggs.ser和3d版eggs3d.ser。 2019-09-09 开始3D脑的构建任务又回到原点找食从静止的青蛙要能进化到吃光所有食物。目前只是搭建空的3D框架还未涉及3D脑模型编程。新的工作存放在core3d目录原有的旧core目录保留相应地批处理文件也分为普通版run.bat和3d版run3d.bat,蛋文件也分为普通版eggs.ser和3d版eggs3d.ser。
脑的3D版要引入模式识别功能第一个编程任务是要用这个3D脑模拟出体全息存贮现象也就等价于模式识别功能用字母的点阵图像激活它的视觉区并同时激活一个随意指定的脑区作为字母识别区然后只激活视觉区的图像再检查这个随意指定的字母区是否会被激活而其它字母区基本不激活例如同时训练字母A、B、C、D一段时间然后只激活字母A的图像区即在视网膜区产生光子)其它三个BCD字母区应该没有A字母区活跃(即其它字母区收到的光子数或总能量少于A字母区),这是从从二维图像识别出对应的文字,比较好检测并利用检测结果来进行生存竟争,从大量随机生成的脑细胞播种器官中挑选出有用的器官,注意在同一个脑空间(cube),可以同时存在多个不同器官播种出来的脑细胞(cell。体全息存贮在物理上很难实现因为光和材料受物理特性制约但在虚拟脑中不存在这个物理限制让虚拟的光子反射、拐弯、增强、拆分都可轻易模拟出。
反之如果对应A字母的脑区兴奋也要能激活一个模糊的A的像素点阵图像脑内某个区(与视网膜重合或下层)这不好检测但可以变通一下比如同时训练C和O两个字母然后只激活C字母区并检测O字母区是否有较强的信号也就是说C字母区会在脑内成像区生成一个C的像素点阵然后这个像素点阵又会倒过来激活与C图像相似的O字母区(以及所有类似C图像的其它脑区),这是第二步的编程任务,它反映了脑的联想机制。如果说第一步是信息的存贮,是体全息存贮原理的简单实现,这第二步就是信息的检索和联想,相比与普通的体全息存贮,它多了一个联想功能,这个联想功能以后会用到,由痛苦、愉快等奖惩机制来调节这个联想过程一直永无止歇地进行下去。
## 重要参数 | Parameters ## 重要参数 | Parameters
在Env.java类中以下有以下可调整参数请手工修改这些参数进行不同的测试前5个参数很重要: 在Env.java类中以下有以下可调整参数请手工修改这些参数进行不同的测试前5个参数很重要:

@ -27,7 +27,7 @@ public class Application {
} }
public static JFrame mainFrame = new JFrame(); public static JFrame mainFrame = new JFrame();
public static Env env = new Env(); public static Env env = new Env();
public static BrainPicture brainPic = new BrainPicture(Env.ENV_WIDTH + 5, 0, Env.FROG_BRAIN_RADIUS, public static BrainPicture brainPic = new BrainPicture(Env.ENV_WIDTH + 5, 0, Env.FROG_BRAIN_XSIZE,
Env.FROG_BRAIN_DISP_WIDTH); Env.FROG_BRAIN_DISP_WIDTH);
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {

@ -11,10 +11,8 @@ import javax.swing.JPanel;
import com.github.drinkjava2.frog.egg.Egg; 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.Food;
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.Object;
import com.github.drinkjava2.frog.objects.Trap;
import com.github.drinkjava2.frog.util.RandomUtils; import com.github.drinkjava2.frog.util.RandomUtils;
/** /**
@ -26,7 +24,7 @@ import com.github.drinkjava2.frog.util.RandomUtils;
@SuppressWarnings("all") @SuppressWarnings("all")
public class Env extends JPanel { public class Env extends JPanel {
/** Speed of test */ /** Speed of test */
public static final int SHOW_SPEED = 3; // 测试速度,-1000~1000,可调, 数值越小,速度越慢 public static final int SHOW_SPEED = 10; // 测试速度,-1000~1000,可调, 数值越小,速度越慢
/** Delete eggs at beginning of each run */ /** Delete eggs at beginning of each run */
public static final boolean DELETE_EGGS = true;// 每次运行是否先删除保存的蛋 public static final boolean DELETE_EGGS = true;// 每次运行是否先删除保存的蛋
@ -54,8 +52,10 @@ public class Env extends JPanel {
/** Steps of one test round */ /** Steps of one test round */
public static final int STEPS_PER_ROUND = 50000;// 每轮测试步数,可调 public static final int STEPS_PER_ROUND = 50000;// 每轮测试步数,可调
/** Frog's brain radius */ /** Frog's x radius, brain volume = XSIZE * YSIZE * ZSIZE */
public static final float FROG_BRAIN_RADIUS = 20; // frog的脑半径先固定为20个单元 public static final int FROG_BRAIN_XSIZE = 50; // frog的脑在X方向长度
public static final int FROG_BRAIN_YSIZE = 25; // frog的脑在Y方向长度
public static final int FROG_BRAIN_ZSIZE = 15; // frog的脑在Z方向长度
public static final int FOOD_QTY = 100; // 食物数量, 可调 public static final int FOOD_QTY = 100; // 食物数量, 可调
@ -67,7 +67,7 @@ public class Env extends JPanel {
public static List<Egg> eggs = new ArrayList<>(); // 这里存放从磁盘载入或上轮下的蛋每个蛋可能生成1~n个青蛙 public static List<Egg> eggs = new ArrayList<>(); // 这里存放从磁盘载入或上轮下的蛋每个蛋可能生成1~n个青蛙
public static Object[] things = new Object[] { }; public static Object[] things = new Object[] {};
static { static {
System.out.println("唵缚悉波罗摩尼莎诃!"); // 杀生前先打印往生咒见码云issue#IW4H8 System.out.println("唵缚悉波罗摩尼莎诃!"); // 杀生前先打印往生咒见码云issue#IW4H8
@ -234,7 +234,7 @@ public class Env extends JPanel {
} }
for (int j = 0; j < FROG_PER_SCREEN; j++) { for (int j = 0; j < FROG_PER_SCREEN; j++) {
Frog f = frogs.get(screen * FROG_PER_SCREEN + j); Frog f = frogs.get(screen * FROG_PER_SCREEN + j);
f.cells.clear(); f.cubes = new Object[1][1][1];
} }
Application.brainPic.drawBrainPicture(firstFrog); Application.brainPic.drawBrainPicture(firstFrog);
Application.mainFrame.setTitle(new StringBuilder("Round: ").append(round).append(", screen:") Application.mainFrame.setTitle(new StringBuilder("Round: ").append(round).append(", screen:")

@ -18,7 +18,6 @@ import java.util.List;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Organ; import com.github.drinkjava2.frog.brain.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;
@ -34,7 +33,7 @@ import com.github.drinkjava2.frog.objects.Material;
public class Frog { public class Frog {
/** brain cells */ /** brain cells */
public List<Cell> cells = new ArrayList<>(); public Object[][][] cubes;
/** organs */ /** organs */
public List<Organ> organs = new ArrayList<>(); public List<Organ> organs = new ArrayList<>();
@ -63,7 +62,7 @@ public class Frog {
public void initOrgans() { public void initOrgans() {
for (Organ org : organs) for (Organ org : organs)
org.initFrog(this);// 每个新器官初始化如果是Group类它们会生成许多脑细胞 org.init(this);// 每个新器官初始化如果是Group类它们会生成许多脑细胞
} }
public boolean active(Env v) { public boolean active(Env v) {

@ -23,6 +23,8 @@ import com.github.drinkjava2.frog.Frog;
/** /**
* BrainPicture show first frog's brain structure, for debug purpose only * BrainPicture show first frog's brain structure, for debug purpose only
* *
* 3
*
* @author Yong Zhu * @author Yong Zhu
* @since 1.0 * @since 1.0
*/ */
@ -33,18 +35,15 @@ public class BrainPicture extends JPanel {
float scale; // brain scale float scale; // brain scale
int xOffset = 0; // brain display x offset compare to screen int xOffset = 0; // brain display x offset compare to screen
int yOffset = 0; // brain display y offset compare to screen int yOffset = 0; // brain display y offset compare to screen
// float xAngle = (float) (Math.PI / 4); // brain rotate on x axis float xAngle = (float) (Math.PI / 2.5); // brain rotate on x axis
// float yAngle = (float) (Math.PI / 4); // brain rotate on y axis float yAngle = -(float) (Math.PI / 8); // brain rotate on y axis
// float zAngle = (float) (Math.PI / 4);// brain rotate on z axis
float xAngle = 0; // brain rotate on x axis
float yAngle = 0; // brain rotate on y axis
float zAngle = 0;// brain rotate on z axis float zAngle = 0;// brain rotate on z axis
public BrainPicture(int x, int y, float brainWidth, int brainDispWidth) { public BrainPicture(int x, int y, float brainWidth, int brainDispWidth) {
super(); super();
this.setLayout(null);// 空布局 this.setLayout(null);// 空布局
this.brainDispWidth = brainDispWidth; this.brainDispWidth = brainDispWidth;
scale = 0.6f * brainDispWidth / brainWidth; scale = 0.7f * brainDispWidth / brainWidth;
this.setBounds(x, y, brainDispWidth + 1, brainDispWidth + 1); this.setBounds(x, y, brainDispWidth + 1, brainDispWidth + 1);
MouseAction act = new MouseAction(this); MouseAction act = new MouseAction(this);
this.addMouseListener(act); this.addMouseListener(act);
@ -56,30 +55,24 @@ public class BrainPicture extends JPanel {
float x = c.x; float x = c.x;
float y = c.y; float y = c.y;
float z = c.z; float z = c.z;
float xr = c.xr; float xe = c.xe;
float yr = c.yr; float ye = c.ye;
float zr = c.zr; float ze = c.ze;
setColor(Color.BLUE); drawTopViewLine(x, y, z, x + xe, y, z);// 画立方体的下面边
drawTopViewLine(x - xr, y - yr, z - zr, x - xr, y + yr, z - zr);// 画立方体的下面边 drawTopViewLine(x + xe, y, z, x + xe, y + ye, z);
drawTopViewLine(x - xr, y + yr, z - zr, x + xr, y + yr, z - zr); drawTopViewLine(x + xe, y + ye, z, x, y + ye, z);
drawTopViewLine(x + xr, y + yr, z - zr, x + xr, y - yr, z - zr); drawTopViewLine(x, y + ye, z, x, y, z);
drawTopViewLine(x + xr, y - yr, z - zr, x - xr, y - yr, z - zr);
drawTopViewLine(x, y, z, x, y, z + ze);// 画立方体的中间边
setColor(Color.green); drawTopViewLine(x + xe, y, z, x + xe, y, z + ze);
drawTopViewLine(x - xr, y - yr, z + zr, x - xr, y - yr, z - zr);// 画立方体的中间边 drawTopViewLine(x + xe, y + ye, z, x + xe, y + ye, z + ze);
setColor(Color.YELLOW); drawTopViewLine(x, y + ye, z, x, y + ye, z + ze);
drawTopViewLine(x + xr, y - yr, z + zr, x + xr, y - yr, z - zr);
setColor(Color.YELLOW); drawTopViewLine(x, y, z + ze, x + xe, y, z + ze);// 画立方体的上面边
drawTopViewLine(x + xr, y + yr, z + zr, x + xr, y + yr, z - zr); drawTopViewLine(x + xe, y, z + ze, x + xe, y + ye, z + ze);
setColor(Color.green); drawTopViewLine(x + xe, y + ye, z + ze, x, y + ye, z + ze);
drawTopViewLine(x - xr, y + yr, z + zr, x - xr, y + yr, z - zr); drawTopViewLine(x, y + ye, z + ze, x, y, z + ze);
setColor(Color.red);
drawTopViewLine(x - xr, y - yr, z + zr, x - xr, y + yr, z + zr); // 画立方体的上面边
drawTopViewLine(x - xr, y + yr, z + zr, x + xr, y + yr, z + zr);
drawTopViewLine(x + xr, y + yr, z + zr, x + xr, y - yr, z + zr);
drawTopViewLine(x + xr, y - yr, z + zr, x - xr, y - yr, z + zr);
} }
/*- /*-
@ -94,8 +87,18 @@ public class BrainPicture extends JPanel {
x.cosθ-y.sinθ, x.sinθ+y.consθ, z x.cosθ-y.sinθ, x.sinθ+y.consθ, z
-*/ -*/
private void drawTopViewLine(float px1, float py1, float pz1, float px2, float py2, float pz2) { private void drawTopViewLine(float px1, float py1, float pz1, float px2, float py2, float pz2) {
double x1 = px1 * scale, y1 = py1 * scale, z1 = pz1 * scale, x2 = px2 * scale, y2 = py2 * scale, double x1 = px1 - Env.FROG_BRAIN_XSIZE / 2;
z2 = pz2 * scale; double y1 = -py1 + Env.FROG_BRAIN_YSIZE / 2;// 屏幕的y坐标是反的显示时要正过来
double z1 = pz1 - Env.FROG_BRAIN_ZSIZE / 2;
double x2 = px2 - Env.FROG_BRAIN_XSIZE / 2;
double y2 = -py2 + Env.FROG_BRAIN_YSIZE / 2;// 屏幕的y坐标是反的显示时要正过来
double z2 = pz2 - Env.FROG_BRAIN_ZSIZE / 2;
x1 = x1 * scale;
y1 = y1 * scale;
z1 = z1 * scale;
x2 = x2 * scale;
y2 = y2 * scale;
z2 = z2 * scale;
double x, y, z; double x, y, z;
y = y1 * cos(xAngle) - z1 * sin(xAngle);// 绕x轴转 y = y1 * cos(xAngle) - z1 * sin(xAngle);// 绕x轴转
z = y1 * sin(xAngle) + z1 * cos(xAngle); z = y1 * sin(xAngle) + z1 * cos(xAngle);
@ -148,15 +151,16 @@ public class BrainPicture extends JPanel {
if (!Application.SHOW_FIRST_FROG_BRAIN) if (!Application.SHOW_FIRST_FROG_BRAIN)
return; return;
Graphics g = this.getGraphics(); Graphics g = this.getGraphics();
g.setColor(Color.WHITE); g.setColor(Color.WHITE);// 先清空旧图
g.fillRect(0, 0, brainDispWidth, brainDispWidth); g.fillRect(0, 0, brainDispWidth, brainDispWidth);
g.setColor(Color.black); g.setColor(Color.black); // 画边框
g.drawRect(0, 0, brainDispWidth, brainDispWidth); g.drawRect(0, 0, brainDispWidth, brainDispWidth);
for (Organ organ : frog.organs) for (Organ organ : frog.organs)// 每个器官负责画出自已在脑图中的位置和形状
organ.drawOnBrainPicture(frog, this); // each organ draw itself organ.drawOnBrainPicture(frog, this); // each organ draw itself
} }
// getters & setters
public float getScale() { public float getScale() {
return scale; return scale;
} }

@ -0,0 +1,47 @@
/*
* 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.util.Arrays;
/**
* Cube include 0~n cells and 0~n photons
*
* @author Yong Zhu
* @since 1.0
*/
public class Cube {
Cell[] cells = new Cell[] {};
Photon[] photons = new Photon[] {};
public void addCell(Cell cell) {// 每个方格空间可以存在多个脑细胞
cells = Arrays.copyOf(cells, cells.length + 1);
cells[cells.length - 1] = cell;
}
public void addPhoton(Photon p) {// 每个方格空间可以存在多个光子
for (Photon old : photons)
if (old.energy < 0.01 && p.energy > -0.01) {// 如果能量没有了,用新的代替空位
old.x = p.x;
old.y = p.y;
old.z = p.z;
old.energy = p.energy;
return;
}
photons = Arrays.copyOf(photons, photons.length + 1);// 否则追加新光子到未尾
photons[cells.length - 1] = p;
}
public void removePhoton(int i) {// 清除光子
photons[i].energy = 0;
}
}

@ -12,8 +12,6 @@ package com.github.drinkjava2.frog.brain;
import java.io.Serializable; import java.io.Serializable;
import com.github.drinkjava2.frog.Env;
/** /**
* Cuboid represents a rectangular prism zone in brain * Cuboid represents a rectangular prism zone in brain
* *
@ -23,52 +21,33 @@ import com.github.drinkjava2.frog.Env;
public class Cuboid implements Serializable { public class Cuboid implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public float x; public int x;// x,y,z是长方体的左下角坐标
public float y; public int y;
public float z; public int z;
public float xr;// xr为这个矩形体x边长的一半 public int xe;// xe,ye,ze分别是长方体三边长
public float yr;// yr为这个矩形体y边长的一半 public int ye;
public float zr;// zr为这个矩形体z边长的一半 public int ze;
public Cuboid() { public Cuboid() {
// 空构造器不能省 // 空构造器不能省
} }
public Cuboid(float x, float y, float z, float r) {// 用x,y,z,r来构造 public Cuboid(int x, int y, int z, int xe, int ye, int ze) {// 用x,y,z,r来构造
this.x = x;
this.y = y;
this.z = z;
this.xr = r;
this.yr = r;
this.zr = r;
if (this.x < 0)
this.x = 0;
if (this.y < 0)
this.y = 0;
if (this.x > Env.FROG_BRAIN_RADIUS)
this.x = Env.FROG_BRAIN_RADIUS;
if (this.y > Env.FROG_BRAIN_RADIUS)
this.y = Env.FROG_BRAIN_RADIUS;
if (this.z > Env.FROG_BRAIN_RADIUS)
this.z = Env.FROG_BRAIN_RADIUS;
}
public Cuboid(float x, float y, float z, float xr, float yr, float zr) {// 用x,y,z,r来构造
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.xr = xr; this.xe = xe;
this.yr = yr; this.ye = ye;
this.zr = zr; this.ze = ze;
} }
public Cuboid(Cuboid c) {// 用另一个Cube来构造 public Cuboid(Cuboid c) {// 用另一个Cube来构造
this.x = c.x; this.x = c.x;
this.y = c.y; this.y = c.y;
this.z = c.z; this.z = c.z;
this.xr = c.xr; this.xe = c.xe;
this.yr = c.yr; this.ye = c.ye;
this.zr = c.zr; this.ze = c.ze;
} }
public static void copyXYZ(Cuboid from, Cuboid to) { public static void copyXYZ(Cuboid from, Cuboid to) {
@ -77,13 +56,13 @@ public class Cuboid implements Serializable {
to.z = from.z; to.z = from.z;
} }
public static void copyXYZR(Cuboid from, Cuboid to) { public static void copyXYZE(Cuboid from, Cuboid to) {
to.x = from.x; to.x = from.x;
to.y = from.y; to.y = from.y;
to.z = from.z; to.z = from.z;
to.xr = from.xr; to.xe = from.xe;
to.xr = from.xr; to.xe = from.xe;
to.xr = from.xr; to.xe = from.xe;
} }
} }

@ -7,10 +7,12 @@ import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener; import java.awt.event.MouseWheelListener;
/** /**
* BrainPicture show first frog's brain structure, for debug purpose only * MouseAction
*
*
* *
* @author Yong Zhu * @author Yong Zhu
* @since 1.0 * @since 2.0.2
*/ */
public class MouseAction implements MouseListener, MouseWheelListener, MouseMotionListener { public class MouseAction implements MouseListener, MouseWheelListener, MouseMotionListener {
private BrainPicture brainPic; private BrainPicture brainPic;
@ -23,10 +25,10 @@ public class MouseAction implements MouseListener, MouseWheelListener, MouseMoti
} }
@Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {// 记录当前鼠标点
if (e.getButton() == 1) if (e.getButton() == 1)// 旋转
buttonPressed = 1; buttonPressed = 1;
else if (e.getButton() == 2) else if (e.getButton() == 2)// 缩放
buttonPressed = 2; buttonPressed = 2;
else else
buttonPressed = 0; buttonPressed = 0;
@ -40,7 +42,7 @@ public class MouseAction implements MouseListener, MouseWheelListener, MouseMoti
} }
@Override @Override
public void mouseWheelMoved(MouseWheelEvent e) { public void mouseWheelMoved(MouseWheelEvent e) {// 缩放
if (e.getWheelRotation() < 0) if (e.getWheelRotation() < 0)
brainPic.scale *= 1.1; brainPic.scale *= 1.1;
else else
@ -48,7 +50,7 @@ public class MouseAction implements MouseListener, MouseWheelListener, MouseMoti
} }
@Override @Override
public void mouseDragged(MouseEvent e) {// do nothing public void mouseDragged(MouseEvent e) {// 旋转
if (buttonPressed == 1) { if (buttonPressed == 1) {
if (e.getX() > x && e.getY() > y) if (e.getX() > x && e.getY() > y)
brainPic.zAngle -= .00f; brainPic.zAngle -= .00f;
@ -67,7 +69,7 @@ public class MouseAction implements MouseListener, MouseWheelListener, MouseMoti
x = e.getX(); x = e.getX();
y = e.getY(); y = e.getY();
} }
if (buttonPressed == 2) { if (buttonPressed == 2) {// 平移
if (e.getX() > x) if (e.getX() > x)
brainPic.xOffset++; brainPic.xOffset++;
if (e.getX() < x) if (e.getX() < x)

@ -33,7 +33,7 @@ public class Organ extends Cuboid {
} }
/** Only call once when frog created , Child class can override this method */ /** Only call once when frog created , Child class can override this method */
public void initFrog(Frog f) { // 仅在Frog生成时这个方法会调用一次缺省啥也不干通常用于在这一步播种脑细胞 public void init(Frog f) { // 仅在Frog生成时这个方法会调用一次缺省啥也不干通常用于在这一步播种脑细胞
} }
/** Each loop step call active method, Child class can override this method */ /** Each loop step call active method, Child class can override this method */
@ -56,7 +56,7 @@ public class Organ extends Cuboid {
} catch (Exception e) { } catch (Exception e) {
throw new UnknownError("Can not make new Organ copy for " + this); throw new UnknownError("Can not make new Organ copy for " + this);
} }
copyXYZR(this, newOrgan); copyXYZE(this, newOrgan);
newOrgan.fat = this.fat; newOrgan.fat = this.fat;
return new Organ[] { newOrgan }; return new Organ[] { newOrgan };
} }

@ -0,0 +1,37 @@
/*
* 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;
/**
* Photon has direction and strength
*
* x,y,zstep
* Cell
*
* @author Yong Zhu
* @since 2.0.2
*/
public class Photon {
public float x;// 用 x,y,z长度来表示矢量的方向便于今后计算
public float y;
public float z;
public float energy;
public Photon() { // 缺省构造器
}
public Photon(float x, float y, float z, float energy) { // 缺省构造器
this.x = x;
this.y = y;
this.z = z;
this.energy = energy;
}
}

@ -11,26 +11,29 @@
package com.github.drinkjava2.frog.brain.organ; package com.github.drinkjava2.frog.brain.organ;
import com.github.drinkjava2.frog.Env; import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Organ; import com.github.drinkjava2.frog.brain.Organ;
/** /**
* BrainFrame one used to drawing the brain frame in BrainPicture * A means A
* *
* @author Yong Zhu * @author Yong Zhu
*/ */
public class BrainFrame extends Organ { public class A extends Organ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public BrainFrame() { public A() {
x = 0; x = 30;
y = 0; y = 10;
z = 0; z = Env.FROG_BRAIN_ZSIZE - 1;
xr = Env.FROG_BRAIN_RADIUS / 2; xe = 3;
yr = xr; ye = 3;
zr = xr; ze = 1;
} }
public boolean allowBorrow() { // 是否允许在精子中将这个器官借出 @Override
return false; public void active(Frog f) {
} }
} }

@ -11,26 +11,29 @@
package com.github.drinkjava2.frog.brain.organ; package com.github.drinkjava2.frog.brain.organ;
import com.github.drinkjava2.frog.Env; import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Organ; import com.github.drinkjava2.frog.brain.Organ;
/** /**
* PictureEye can only see the picture in env * B means B
* *
* @author Yong Zhu * @author Yong Zhu
*/ */
public class PictureEye extends Organ { public class B extends Organ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public PictureEye() { public B() {
x = 0; x = 30;
y = 0; y = 15;
z = Env.FROG_BRAIN_RADIUS / 2 - .5f; z = Env.FROG_BRAIN_ZSIZE - 1;
xr = Env.FROG_BRAIN_RADIUS / 4; xe = 3;
yr = xr; ye = 3;
zr = 0.5f; ze = 1;
} }
public boolean allowBorrow() { // 是否允许在精子中将这个器官借出 @Override
return false; public void active(Frog f) {
} }
} }

@ -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.organ;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Cube;
import com.github.drinkjava2.frog.brain.Organ;
/**
* Brain one used to define the brain position and size
*
*
* cells3
*
*
*
* Cubecube00()
* (Photon) ))
*
* 穿cell
* 0,
*
* @author Yong Zhu
*/
public class Brain extends Organ {
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;
}
@Override
public void init(Frog f) {
f.cubes = new Cube[Env.FROG_BRAIN_XSIZE][Env.FROG_BRAIN_YSIZE][Env.FROG_BRAIN_ZSIZE];
}
}

@ -8,23 +8,32 @@
* OF ANY KIND, either express or implied. See the License for the specific * OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License. * language governing permissions and limitations under the License.
*/ */
package com.github.drinkjava2.frog.brain; 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;
/** /**
* Point has x, y, z value * C means C
* *
* @author Yong Zhu * @author Yong Zhu
* @since 2.0.2
*/ */
@SuppressWarnings("all") public class C extends Organ {
public class Point {
public float x; private static final long serialVersionUID = 1L;
public float y;
public float z;
public Point(float x, float y, float z) { public C() {
this.x = x; x = 35;
this.y = y; y = 10;
this.z = z; z = Env.FROG_BRAIN_ZSIZE - 1;
xe = 3;
ye = 3;
ze = 1;
} }
@Override
public void active(Frog f) {
}
} }

@ -0,0 +1,39 @@
/*
* 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;
/**
* D means D
*
* @author Yong Zhu
*/
public class D extends Organ {
private static final long serialVersionUID = 1L;
public D() {
x = 35;
y = 15;
z = Env.FROG_BRAIN_ZSIZE - 1;
xe = 3;
ye = 3;
ze = 1;
}
@Override
public void active(Frog f) {
}
}

@ -0,0 +1,53 @@
/*
* 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;
/**
* Eye can only see env material
*
* @author Yong Zhu
*/
public class Eye extends Organ {//这个眼睛有nxn个感光细胞可以看到青蛙周围nxn网络内有没有食物
private static final long serialVersionUID = 1L;
public int n = 13; // 眼睛有n x n个感光细胞 用随机试错算法自动变异(加1或减1最小是3x3)
@Override
public void init(Frog f) { // 仅在Frog生成时这个方法会调用一次缺省啥也不干通常用于Organ类的初始化
if (!initilized) {
initilized = true;
}
}
public Eye() {
x = 10;
y = 10;
z = Env.FROG_BRAIN_ZSIZE - 1;
xe = 10;
ye = xe;
ze = 1;
}
@Override
public void active(Frog f) {// 如果看到食物就在视网膜所在位置的cube上产生一些光子
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)) {
}
}
}
}
}

@ -16,8 +16,12 @@ import java.util.List;
import com.github.drinkjava2.frog.Frog; import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Organ; import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.brain.organ.BrainFrame; import com.github.drinkjava2.frog.brain.organ.A;
import com.github.drinkjava2.frog.brain.organ.PictureEye; import com.github.drinkjava2.frog.brain.organ.B;
import com.github.drinkjava2.frog.brain.organ.Brain;
import com.github.drinkjava2.frog.brain.organ.C;
import com.github.drinkjava2.frog.brain.organ.D;
import com.github.drinkjava2.frog.brain.organ.Eye;
import com.github.drinkjava2.frog.util.RandomUtils; import com.github.drinkjava2.frog.util.RandomUtils;
/** /**
@ -38,8 +42,13 @@ public class Egg implements Serializable {
public List<Organ> organs = new ArrayList<>(); public List<Organ> organs = new ArrayList<>();
public Egg() {// 无中生有,创建一个蛋,先有蛋,后有蛙 public Egg() {// 无中生有,创建一个蛋,先有蛋,后有蛙
organs.add(new BrainFrame()); // BrainCube是固有的用来画一个脑的立方什么都不做 organs.add(new Brain()); // BrainCube是固有的用来画一个脑的立方什么都不做
organs.add(new PictureEye()); // BrainCube是固有的用来画一个脑的立方什么都不做 organs.add(new Eye()); // BrainCube是固有的用来画一个脑的立方什么都不做
organs.add(new A());
organs.add(new B());
organs.add(new C());
organs.add(new D());
} }
/** Create egg from frog */ /** Create egg from frog */

@ -11,29 +11,28 @@
package com.github.drinkjava2.frog.objects; package com.github.drinkjava2.frog.objects;
/** /**
* Object means some thing in Env * LetterTester used to test A, B , C, D letter recognition
*
* (AA
* BB...) ,
*
* *
* @author Yong Zhu * @author Yong Zhu
* @since 1.0 * @since 1.0
*/ */
public class Pictures implements Object { public class LetterTester implements Object {
@Override @Override
public void build() { public void build() { // do nothing
// TODO Auto-generated method stub
} }
@Override @Override
public void destory() { public void destory() {// do nothing
// TODO Auto-generated method stub
} }
@Override @Override
public void active(int screen) { public void active(int screen) {
} }
} }

@ -19,15 +19,14 @@ import java.awt.Color;
* @since 1.0 * @since 1.0
*/ */
public class Material { public class Material {
public static final byte VISIBLE = 10; // if>=10 will visible to frog public static final byte NO = 0; // nothing
public static final byte KILLFROG = 20; // if>=20 will kill frog
public static final byte NO = 0;
public static final byte SEESAW_BASE = 1; // 1~9 is invisible to frog public static final byte SEESAW_BASE = 1; // 1~9 is invisible to frog
public static final byte VISIBLE = 10; // if>=10 will visible to frog
public static final byte FOOD = VISIBLE + 1; public static final byte FOOD = VISIBLE + 1;
public static final byte SEESAW = VISIBLE + 2; public static final byte SEESAW = VISIBLE + 2;
public static final byte KILLFROG = 20; // if>=20 will kill frog
public static final byte BRICK = KILLFROG + 1;// brick will kill frog public static final byte BRICK = KILLFROG + 1;// brick will kill frog
public static final byte TRAP = KILLFROG + 2; // trap will kill frog public static final byte TRAP = KILLFROG + 2; // trap will kill frog

@ -0,0 +1,75 @@
/* Copyright 2018-2020 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.util;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;
/**
* StringPixelUtils used to get pixel array from a given string
*
* boolean[][]
*
* @author Yong Zhu
* @since 2.0.2
*/
public class StringPixelUtils {
private static final Map<String, boolean[][]> lettersMap = new HashMap<>();
public static boolean[][] getSanserif12Pixels(String s) {
return getStringPixels(Font.SANS_SERIF, Font.PLAIN, 12, s);
}
/* 在内存 BufferedImage里输出文本并获取它的像素点 */
public static boolean[][] getStringPixels(String fontName, int fontStyle, int fontSize, String s) {
String key = new StringBuilder(fontName).append("_").append(fontStyle).append("_").append(fontSize).append("_")
.append(s).toString();
if (lettersMap.containsKey(key))
return lettersMap.get(key);
Font font = new Font(fontName, fontStyle, fontSize);
BufferedImage bi = new BufferedImage(fontSize * 8, fontSize * 50, BufferedImage.TYPE_INT_RGB);
Graphics g = bi.getGraphics();
Graphics2D g2d = (Graphics2D) g;
g2d.setFont(font);
FontMetrics fm = g2d.getFontMetrics();
int strHeight = fm.getAscent() + fm.getDescent() - 3;
int strWidth = fm.stringWidth(s);
g2d.drawString(s, 0, fm.getAscent() - fm.getLeading() - 1);
boolean[][] b = new boolean[strHeight][strWidth];
for (int y = 0; y < strHeight; y++)
for (int x = 0; x < strWidth; x++)
if (bi.getRGB(x, y) == -1)
b[y][x] = true;
else
b[y][x] = false;
lettersMap.put(key, b);
return b;
}
public static void main(String[] args) {
boolean[][] c = getStringPixels(Font.SANS_SERIF, Font.PLAIN, 10, "∮ABCD中国人");
for (int y = 0; y < c.length; y++) {
boolean[] line = c[y];
for (int x = 0; x < line.length; x++)
if (c[y][x])
System.out.print("*");
else
System.out.print(" ");
System.out.println();
}
}
}

@ -1,9 +1,9 @@
这个捐款记录的目的是为了让收支透明化,万一项目做大了,收到码云平台外的捐款也可以在这里记录下来。本记录按时间顺序记录捐款人和当前总额,不记具体数额,这样即体现了不鼓励金额攀比、自愿随意的原则,也能通过历史记录查询出每笔的具体数额。在此衷心地感谢每一位捐款、点赞、及关注这个项目的同学! 这个捐款记录的目的是为了让收支透明化,万一项目做大了,收到码云平台外的捐款也可以在这里记录下来。本记录按时间顺序记录捐款人和当前总额,不记具体数额,这样即体现了不鼓励金额攀比、自愿随意的原则,也能通过历史记录查询出每笔的具体数额。在此衷心地感谢每一位捐款、点赞、及关注这个项目的同学!
捐款人(按时间顺序): 捐款人(按时间顺序):
wangtao wangtao
dotao dotao
LongFer LongFer
目前收入总额:48.88元 目前收入总额:48.88元

Loading…
Cancel
Save