From db02ef0f7d3abebac09fa1f2dff65842c9197468 Mon Sep 17 00:00:00 2001 From: Yong Zhu Date: Thu, 10 Oct 2019 07:18:17 -0600 Subject: [PATCH] Add CellTemplate --- README.md | 2 +- core/pom.xml | 15 +++++ core/run.sh | 2 + core3d/pom.xml | 17 ++++- core3d/run.sh | 2 + .../drinkjava2/frog/brain/BrainPicture.java | 10 ++- .../github/drinkjava2/frog/brain/Cell.java | 10 ++- .../drinkjava2/frog/brain/CellTemplate.java | 59 ++++++++++++++++++ .../drinkjava2/frog/brain/MouseAction.java | 17 +++-- .../github/drinkjava2/frog/brain/Synapse.java | 29 +++++++++ .../frog/util/StringPixelUtils.java | 10 +-- eggs3d.ser | Bin 7145 -> 0 bytes 捐款记录.md | 3 +- 13 files changed, 154 insertions(+), 22 deletions(-) create mode 100644 core/run.sh create mode 100644 core3d/run.sh create mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/CellTemplate.java create mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/Synapse.java delete mode 100644 eggs3d.ser diff --git a/README.md b/README.md index 9ec92fc..e675569 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## Frog | 人工生命 +## Frog | 人工生命 这是一个人工生命试验项目,最终目标是创建“有自我意识表现”的模拟生命体,技术架构基于02年提出的 [一个人工脑模型](一个人工脑模型.md)。 这个项目永远没有结束的时候,开始于模拟一个简单的生命体,然后是青蛙、狗......, 结束于有“自我意识表现”的人工脑,或者说,结束于被机器人代替人类的那一天。 diff --git a/core/pom.xml b/core/pom.xml index 8ab49e7..4f24670 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -78,6 +78,21 @@ UTF-8 + + org.apache.maven.plugins + maven-jar-plugin + 3.1.2 + + + + true + false + lib/ + com.github.drinkjava2.frog.Application + + + + diff --git a/core/run.sh b/core/run.sh new file mode 100644 index 0000000..836c941 --- /dev/null +++ b/core/run.sh @@ -0,0 +1,2 @@ +mvn clean package +java -jar target/frog-*.jar diff --git a/core3d/pom.xml b/core3d/pom.xml index f26c722..a22c879 100644 --- a/core3d/pom.xml +++ b/core3d/pom.xml @@ -78,10 +78,25 @@ UTF-8 + + org.apache.maven.plugins + maven-jar-plugin + 3.1.2 + + + + true + false + lib/ + com.github.drinkjava2.frog.Application + + + + - + \ No newline at end of file diff --git a/core3d/run.sh b/core3d/run.sh new file mode 100644 index 0000000..836c941 --- /dev/null +++ b/core3d/run.sh @@ -0,0 +1,2 @@ +mvn clean package +java -jar target/frog-*.jar diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/BrainPicture.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/BrainPicture.java index 9fe8044..795dc5b 100644 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/BrainPicture.java +++ b/core3d/src/main/java/com/github/drinkjava2/frog/brain/BrainPicture.java @@ -32,7 +32,6 @@ public class BrainPicture extends JPanel { Color color = Color.red; int brainDispWidth; // screen display piexls width float scale; // brain scale - int pointDia; // point size int xOffset = 0; // brain display x offset compare to screen int yOffset = 0; // brain display y offset compare to screen float xAngle = (float) (Math.PI / 2.5); // brain rotate on x axis @@ -44,7 +43,6 @@ public class BrainPicture extends JPanel { this.setLayout(null);// 空布局 this.brainDispWidth = brainDispWidth; scale = 0.7f * brainDispWidth / brainWidth; - pointDia = Math.max(Math.round(scale), 1); this.setBounds(x, y, brainDispWidth + 1, brainDispWidth + 1); MouseAction act = new MouseAction(this); this.addMouseListener(act); @@ -141,7 +139,7 @@ public class BrainPicture extends JPanel { /** 画点,固定以top视角的角度,所以只需要在x1,y1位置画一个点 */ public void drawCubeCenter(float x, float y, float z) { - drawPoint(x + 0.5f, y + 0.5f, z + 0.5f, pointDia); + drawPoint(x + 0.5f, y + 0.5f, z + 0.5f, (int) Math.max(1, Math.round(scale * .7))); } /** 画点,固定以top视角的角度,所以只需要在x1,y1位置画一个点 */ @@ -183,7 +181,7 @@ public class BrainPicture extends JPanel { return rainbow[nextColor++]; } - public static Color rainboColor(float i) { + public static Color rainbowColor(float i) { if (i == 0) return Color.black; if (i == 1) @@ -224,8 +222,8 @@ public class BrainPicture extends JPanel { for (int y = 0; y < Env.FROG_BRAIN_YSIZE; y++) { if (f.cubes[x][y] != null) for (int z = 0; z < Env.FROG_BRAIN_ZSIZE; z++) { - if (f.existCube(x, y, z)) { - setColor(rainboColor(f.getCube(x, y, z).getActive())); + if (f.existCube(x, y, z) && f.getCube(x, y, z).getActive()>0) { + setColor(rainbowColor(f.getCube(x, y, z).getActive())); drawCubeCenter(x, y, z); } } diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/Cell.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/Cell.java index 1efa13b..281a8cf 100644 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/Cell.java +++ b/core3d/src/main/java/com/github/drinkjava2/frog/brain/Cell.java @@ -13,14 +13,18 @@ package com.github.drinkjava2.frog.brain; /** * Cell is the basic unit of frog's brain * + * Cell这个类只保存很少的信息,而不是直接定义成对象,这样可方便它的参数变异。它的触突分布参数、对信号(即光子)的处理行为由CellTemplate + * 中的type来完成。 Cell的排布由器官来完成,一个器官通常会撒布一群相同类型的细胞。 + * * @author Yong Zhu - * @since 1.0 + * @since 2.0.2 */ public class Cell { - public byte cellType; // 这个细胞的类型 + public int type; // 这个细胞的类型,见CellTemplate类中的type // energy of cell, energy got from food public float energy; // 每个细胞当前的能量值 - public float tire; // 每个细胞的疲劳值 + + public float tire; // 每个细胞的疲劳值,只取决于最近的激活频率 } diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/CellTemplate.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/CellTemplate.java new file mode 100644 index 0000000..e0c8deb --- /dev/null +++ b/core3d/src/main/java/com/github/drinkjava2/frog/brain/CellTemplate.java @@ -0,0 +1,59 @@ +/* + * 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; + +import com.github.drinkjava2.frog.Frog; + +/** + * CellTemplate is the cell template, a group of CellTemplate be saved in egg + * + * CellTemplate描述细胞的形状和行为,其中触突数量和参数是有可能随机变异的。行为则是硬编码不可以变异,模拟单个神经元的逻辑,不同的细胞有不同的 + * 行为,通过cellType来区分,虽然行为不可以变异,但是可以写出尽可能多种不同的行为,由生存竟争来筛选。 + * CellTemplate是可串行化的,一组CellTemplate实例会保存在蛋里面。 + * 每个脑细胞都指向某个type类型,CellTemplate本身都是单例,不占内存,从命名上可以看出它只是个模板,它是无状态的,只影响 cell处理 + * 信息(光子)的逻辑 + * + * + * @author Yong Zhu + * @since 2.0.2 + */ +public class CellTemplate implements Serializable { + private static final long serialVersionUID = 1L; + public int type; // 当创建CellType实例 + public Synapse[] inputs; // 输入触突,位置是相对细胞而言的 + public Synapse[] sides; // 侧面(通常是抑制,是负光子输出)输出触突们,才从脉冲神经网络了解到有这种侧向抑制 + public Synapse[] outputs; // 输出触突 + + /** + * Each cell's act method will be called once at each loop step + * + * 在轮循时,每个细胞的act方法都会被调用一次,这个方法针对不同的细胞类型有不同的行为逻辑,这是硬编码,要 多尝试各种不同的行为,然后抛给电脑去筛选。 + * + */ + public void act(Frog f, Cell cell, int x, int y, int z) { + switch (type) { // TODO 待添加细胞的行为,这是硬编码 + case 0: + break; + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + break; + default: + break; + } + } +} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/MouseAction.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/MouseAction.java index b06d7c4..73d8ead 100644 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/MouseAction.java +++ b/core3d/src/main/java/com/github/drinkjava2/frog/brain/MouseAction.java @@ -43,10 +43,15 @@ public class MouseAction implements MouseListener, MouseWheelListener, MouseMoti @Override public void mouseWheelMoved(MouseWheelEvent e) {// 缩放 - if (e.getWheelRotation() < 0) + if (e.getWheelRotation() < 0) { brainPic.scale *= 1.1; - else + brainPic.xOffset *= 1.1; + brainPic.yOffset *= 1.1; + } else { brainPic.scale /= 1.1; + brainPic.xOffset /= 1.1; + brainPic.yOffset /= 1.1; + } } @Override @@ -71,13 +76,13 @@ public class MouseAction implements MouseListener, MouseWheelListener, MouseMoti } if (buttonPressed == 2) {// 平移 if (e.getX() > x) - brainPic.xOffset+=6; + brainPic.xOffset += 6; if (e.getX() < x) - brainPic.xOffset-=6; + brainPic.xOffset -= 6; if (e.getY() > y) - brainPic.yOffset+=6; + brainPic.yOffset += 6; if (e.getY() < y) - brainPic.yOffset-=6; + brainPic.yOffset -= 6; x = e.getX(); y = e.getY(); } diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/Synapse.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/Synapse.java new file mode 100644 index 0000000..43edd1b --- /dev/null +++ b/core3d/src/main/java/com/github/drinkjava2/frog/brain/Synapse.java @@ -0,0 +1,29 @@ +/* + * 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; + +/** + * Synapse can be input, output, side synapse + * + * 触突 + * + * @author Yong Zhu + * @since 2.0.2 + */ +public class Synapse implements Serializable { + private static final long serialVersionUID = 1L; + public int x; // 这个触突相对于细胞的x偏移坐标 + public int y;// 这个触突相对于细胞的y偏移坐标 + public int z;// 这个触突相对于细胞的z偏移坐标 + public int r; // 这个触突的作用范围 +} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/util/StringPixelUtils.java b/core3d/src/main/java/com/github/drinkjava2/frog/util/StringPixelUtils.java index d79dcea..a5af27e 100644 --- a/core3d/src/main/java/com/github/drinkjava2/frog/util/StringPixelUtils.java +++ b/core3d/src/main/java/com/github/drinkjava2/frog/util/StringPixelUtils.java @@ -53,21 +53,22 @@ public class StringPixelUtils { for (int y = 0; y < strHeight; y++) for (int x = 0; x < strWidth; x++) if (bi.getRGB(x, y) == -1) - b[x][strHeight-y-1] = 1; + b[x][strHeight - y - 1] = 1; else - b[x][strHeight-y-1] = 0; + b[x][strHeight - y - 1] = 0; lettersMap.put(key, b); return b; } + /*- 这个是测试输出,平时不需要用 public static void main(String[] args) { byte[][] c = getStringPixels(Font.SANS_SERIF, Font.PLAIN, 12, "Test点阵输出"); int w = c.length; int h = c[0].length; - + for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { - if (c[x][h-y-1]>0) + if (c[x][h - y - 1] > 0) System.out.print("*"); else System.out.print(" "); @@ -75,4 +76,5 @@ public class StringPixelUtils { System.out.println(); } } + */ } diff --git a/eggs3d.ser b/eggs3d.ser deleted file mode 100644 index a2d6f975f9aff4fd7b8ad8c76683f3e8ffd6ea3b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7145 zcmeHL%}&BV5T5c=6JnI07Y};ypvIUb@#+bX1BS%Aw<4vkKP|RJw;W7-3=h76@8R9| z@Ex34T4{k4qSt9scEW!1&Ft67OyT1j%7G7Cx7L#-MxneH4d1t-t_(u;`nCJ^X}uT0 z=s+ouV_OXYVCT6+pXjuI?L7!bhBu?0==;*WBa%}w@I6P^jw9NRgGjoJ0vKH|J>Rk1 zAcSg{kaY@Ir$}dN7(Bv@hMJn*MEa8)`krq|S7<)bBwPFHK%jg$Sn7I7sZ5;;7f>8n z;T2S*D={rRY#(_Jm-4hmJx}(hL}mvJ)q#St(TLE9$QYv$%SX_?7{5KU0^qTam&TkN zyB*oFJE@C7TtynLC12uN#=DYQ<1K(1#yMIsP9yfhDDWGBSc`Zk>lWHZ4AiGsmAx4| zEo9%sO^Who_SPcyg!SLKpXaeBQL?!!UFU_lYNsb>#&kK=K`=_2E|NRv0TXl`A;~F| zHJgu4WFrMzoVJEl5teM{u+>tq1fC7bBA`Sp0*inOum~)|L;noegLG)3V;9r diff --git a/捐款记录.md b/捐款记录.md index 3b5d690..540aa2b 100644 --- a/捐款记录.md +++ b/捐款记录.md @@ -5,6 +5,7 @@ wangtao dotao LongFer ʪ + -Ŀǰܶ:98.88Ԫ +Ŀǰܶ:108.88Ԫ Ŀǰ֧ܶ:0Ԫ \ No newline at end of file