Done 3d frame show

pull/1/head
drinkjava2 5 years ago
parent 7c4af9bef1
commit 91cd4ad128

@ -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_WIDTH, public static BrainPicture brainPic = new BrainPicture(Env.ENV_WIDTH + 5, 0, Env.FROG_BRAIN_RADIUS,
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 {
@ -38,8 +38,8 @@ public class Application {
mainFrame.add(brainPic); mainFrame.add(brainPic);
JButton button = new JButton("Show first frog's brain"); JButton button = new JButton("Show brain");
int buttonWidth = 180; int buttonWidth =100;
int buttonHeight = 22; int buttonHeight = 22;
int buttonXpos = Env.ENV_WIDTH / 2 - buttonWidth / 2; int buttonXpos = Env.ENV_WIDTH / 2 - buttonWidth / 2;
button.setBounds(buttonXpos, Env.ENV_HEIGHT + 8, buttonWidth, buttonHeight); button.setBounds(buttonXpos, Env.ENV_HEIGHT + 8, buttonWidth, buttonHeight);
@ -48,13 +48,13 @@ public class Application {
public void actionPerformed(ActionEvent arg0) { public void actionPerformed(ActionEvent arg0) {
SHOW_FIRST_FROG_BRAIN = !SHOW_FIRST_FROG_BRAIN; SHOW_FIRST_FROG_BRAIN = !SHOW_FIRST_FROG_BRAIN;
if (SHOW_FIRST_FROG_BRAIN) { if (SHOW_FIRST_FROG_BRAIN) {
button.setText("Hide first frog's brain"); button.setText("Hide brain");
int y = Env.ENV_HEIGHT + 100; int y = Env.ENV_HEIGHT + 100;
if (Env.FROG_BRAIN_DISP_WIDTH + 41 > y) if (Env.FROG_BRAIN_DISP_WIDTH + 41 > y)
y = Env.FROG_BRAIN_DISP_WIDTH + 41; y = Env.FROG_BRAIN_DISP_WIDTH + 41;
mainFrame.setSize(Env.ENV_WIDTH + Env.FROG_BRAIN_DISP_WIDTH + 25, y); mainFrame.setSize(Env.ENV_WIDTH + Env.FROG_BRAIN_DISP_WIDTH + 25, y);
} else { } else {
button.setText("Show first frog's brain"); button.setText("Show brain");
mainFrame.setSize(Env.ENV_WIDTH + 20, Env.ENV_HEIGHT + 100); mainFrame.setSize(Env.ENV_WIDTH + 20, Env.ENV_HEIGHT + 100);
} }
} }

@ -26,7 +26,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 = 5; // 测试速度,-1000~1000,可调, 数值越小,速度越慢 public static final int SHOW_SPEED = 3; // 测试速度,-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;// 每次运行是否先删除保存的蛋
@ -35,12 +35,12 @@ public class Env extends JPanel {
public static final int FROG_PER_EGG = 4; // 每个蛋可以孵出几个青蛙 public static final int FROG_PER_EGG = 4; // 每个蛋可以孵出几个青蛙
public static final int SCREEN = 1; // 分几屏测完 public static final int SCREEN = 4; // 分几屏测完
public static final int FROG_PER_SCREEN = EGG_QTY * FROG_PER_EGG / SCREEN; // 每屏上显示几个青蛙,这个数值由上面三个参数计算得来 public static final int FROG_PER_SCREEN = EGG_QTY * FROG_PER_EGG / SCREEN; // 每屏上显示几个青蛙,这个数值由上面三个参数计算得来
/** Draw first frog's brain after some steps */ /** Draw first frog's brain after some steps */
public static int DRAW_BRAIN_AFTER_STEPS = 50; // 以此值为间隔动态画出脑图设为0则关闭这个动态脑图功能只显示一个静态、不闪烁的脑图 public static int DRAW_BRAIN_AFTER_STEPS = 20; // 以此值为间隔动态画出脑图设为0则关闭这个动态脑图功能只显示一个静态、不闪烁的脑图
/** Environment x width, unit: pixels */ /** Environment x width, unit: pixels */
public static final int ENV_WIDTH = 400; // 虚拟环境的宽度, 可调 public static final int ENV_WIDTH = 400; // 虚拟环境的宽度, 可调
@ -52,12 +52,12 @@ public class Env extends JPanel {
public static final int FROG_BRAIN_DISP_WIDTH = 400; // Frog的脑图在屏幕上的显示大小,可调 public static final int FROG_BRAIN_DISP_WIDTH = 400; // Frog的脑图在屏幕上的显示大小,可调
/** Steps of one test round */ /** Steps of one test round */
public static final int STEPS_PER_ROUND = 2000;// 每轮测试步数,可调 public static final int STEPS_PER_ROUND = 50000;// 每轮测试步数,可调
/** Frog's brain width, fixed to 1000 unit */ /** Frog's brain radius */
public static final float FROG_BRAIN_WIDTH = 1000; // frog的脑宽度固定为1000,不要随便调整,因为器官的相对位置和大小是按脑大小设定的 public static final float FROG_BRAIN_RADIUS = 20; // frog的脑半径先固定为20个单元
public static final int FOOD_QTY = 1500; // 食物数量, 可调 public static final int FOOD_QTY = 100; // 食物数量, 可调
public static boolean pause = false; // 暂停按钮按下将暂停测试 public static boolean pause = false; // 暂停按钮按下将暂停测试
@ -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[] { new Food(), new Trap() }; public static Object[] things = new Object[] { };
static { static {
System.out.println("唵缚悉波罗摩尼莎诃!"); // 杀生前先打印往生咒见码云issue#IW4H8 System.out.println("唵缚悉波罗摩尼莎诃!"); // 杀生前先打印往生咒见码云issue#IW4H8

@ -41,7 +41,7 @@ public class Frog {
public int x; // frog在Env中的x坐标 public int x; // frog在Env中的x坐标
public int y; // frog在Env中的y坐标 public int y; // frog在Env中的y坐标
public long energy = 100000; // 青蛙的能量为0则死掉 public long energy = 10000000; // 青蛙的能量为0则死掉
public boolean alive = true; // 设为false表示青蛙死掉了将不参与计算和显示以节省时间 public boolean alive = true; // 设为false表示青蛙死掉了将不参与计算和显示以节省时间
public int ateFood = 0; public int ateFood = 0;

@ -0,0 +1,89 @@
/*
* 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.Env;
/**
* Cuboid represents a rectangular prism zone in brain
*
* @author Yong Zhu
* @since 1.0
*/
public class Cuboid implements Serializable {
private static final long serialVersionUID = 1L;
public float x;
public float y;
public float z;
public float xr;// xr为这个矩形体x边长的一半
public float yr;// yr为这个矩形体y边长的一半
public float zr;// zr为这个矩形体z边长的一半
public Cuboid() {
// 空构造器不能省
}
public Cuboid(float x, float y, float z, float r) {// 用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.y = y;
this.z = z;
this.xr = xr;
this.yr = yr;
this.zr = zr;
}
public Cuboid(Cuboid c) {// 用另一个Cube来构造
this.x = c.x;
this.y = c.y;
this.z = c.z;
this.xr = c.xr;
this.yr = c.yr;
this.zr = c.zr;
}
public static void copyXYZ(Cuboid from, Cuboid to) {
to.x = from.x;
to.y = from.y;
to.z = from.z;
}
public static void copyXYZR(Cuboid from, Cuboid to) {
to.x = from.x;
to.y = from.y;
to.z = from.z;
to.xr = from.xr;
to.xr = from.xr;
to.xr = from.xr;
}
}

@ -0,0 +1,99 @@
package com.github.drinkjava2.frog.brain;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
/**
* BrainPicture show first frog's brain structure, for debug purpose only
*
* @author Yong Zhu
* @since 1.0
*/
public class MouseAction implements MouseListener, MouseWheelListener, MouseMotionListener {
private BrainPicture brainPic;
private int buttonPressed = 0;
private int x;
private int y;
public MouseAction(BrainPicture brainPic) {
this.brainPic = brainPic;
}
@Override
public void mousePressed(MouseEvent e) {
if (e.getButton() == 1)
buttonPressed = 1;
else if (e.getButton() == 2)
buttonPressed = 2;
else
buttonPressed = 0;
x = e.getPoint().x;
y = e.getPoint().y;
}
@Override
public void mouseReleased(MouseEvent e) {
buttonPressed = 0;
}
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getWheelRotation() < 0)
brainPic.scale *= 1.1;
else
brainPic.scale /= 1.1;
}
@Override
public void mouseDragged(MouseEvent e) {// do nothing
if (buttonPressed == 1) {
if (e.getX() > x && e.getY() > y)
brainPic.zAngle -= .00f;
else if (e.getX() < x && e.getY() < y)
brainPic.zAngle += .00f;
else {
if (e.getX() > x)
brainPic.yAngle += .02f;
if (e.getX() < x)
brainPic.yAngle -= .02f;
if (e.getY() > y)
brainPic.xAngle -= .02f;
if (e.getY() < y)
brainPic.xAngle += .02f;
}
x = e.getX();
y = e.getY();
}
if (buttonPressed == 2) {
if (e.getX() > x)
brainPic.xOffset++;
if (e.getX() < x)
brainPic.xOffset--;
if (e.getY() > y)
brainPic.yOffset++;
if (e.getY() < y)
brainPic.yOffset--;
x = e.getX();
y = e.getY();
}
}
@Override
public void mouseClicked(MouseEvent e) {// do nothing
}
@Override
public void mouseEntered(MouseEvent e) {// do nothing
}
@Override
public void mouseExited(MouseEvent e) {// do nothing
}
@Override
public void mouseMoved(MouseEvent e) { // do nothing
}
}

@ -18,36 +18,26 @@ import com.github.drinkjava2.frog.Frog;
/** /**
* Organ is a part of frog, organ can be saved in egg * Organ is a part of frog, organ can be saved in egg
* *
* *
* *
* @author Yong Zhu * @author Yong Zhu
* @since 1.0.4 * @since 1.0.4
*/ */
public class Organ extends Zone { public class Organ extends Cuboid {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public String name; // 显示在脑图上的器官名称,可选
public long fat = 0; // 如果活跃多fat值高则保留及变异的可能性大反之则很可能丢弃掉 public long fat = 0; // 如果活跃多fat值高则保留及变异的可能性大反之则很可能丢弃掉
// public float organWasteEnergy = 0.05f; //
// 器官在每个测试循环中需要消耗青蛙多少能量,可以通过调节这个参数抑制器官数量无限增长
public float organActiveEnergy = 1; // 输出器官激活需要消耗每个脑细胞多少能量
public float organOutputEnergy = 2; // 感觉器官激活会给每个脑细胞增加多少能量
public boolean initilized; // 通过这个标记判断是否需要手工给定它的参数初值 public boolean initilized; // 通过这个标记判断是否需要手工给定它的参数初值
public boolean allowBorrow() { // 是否允许在精子中将这个器官借出 public boolean allowBorrow() { // 是否允许在精子中将这个器官借出
return false; return false;
} }
/** Each loop step call active method, Child class can override this method */ /** Only call once when frog created , Child class can override this method */
public void active(Frog f) { // 每一步都会调用器官的active方法 ,缺省啥也不干 public void initFrog(Frog f) { // 仅在Frog生成时这个方法会调用一次缺省啥也不干通常用于在这一步播种脑细胞
} }
/** If active in this organ's zone? */ /** Each loop step call active method, Child class can override this method */
public void active(Frog f) { // 每一步都会调用器官的active方法 ,缺省啥也不干
/** Set X, Y, Radius, name of current Organ */
public Organ setXYRN(float x, float y, float r, String name) {
this.setXYR(x, y, r);
this.name = name;
return this;
} }
/** Child class can override this method to drawing picture */ /** Child class can override this method to drawing picture */
@ -55,13 +45,7 @@ public class Organ extends Zone {
if (!Application.SHOW_FIRST_FROG_BRAIN) if (!Application.SHOW_FIRST_FROG_BRAIN)
return; return;
pic.setColor(Color.BLACK); // 缺省是黑色 pic.setColor(Color.BLACK); // 缺省是黑色
pic.drawZone(this); pic.drawCube(this);
if (this.name != null)
pic.drawText(this, String.valueOf(this.name));
}
/** Only call once when frog created , Child class can override this method */
public void initFrog(Frog f) { // 仅在Frog生成时这个方法会调用一次缺省啥也不干通常用于Group子类的初始化
} }
/** Only call once after organ be created by new() method */ /** Only call once after organ be created by new() method */
@ -72,8 +56,7 @@ public class Organ extends Zone {
} 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);
} }
copyXYR(this, newOrgan); copyXYZR(this, newOrgan);
newOrgan.name = this.name;
newOrgan.fat = this.fat; newOrgan.fat = this.fat;
return new Organ[] { newOrgan }; return new Organ[] { newOrgan };
} }

@ -0,0 +1,30 @@
/*
* 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;
/**
* Point has x, y, z value
*
* @author Yong Zhu
* @since 2.0.2
*/
@SuppressWarnings("all")
public class Point {
public float x;
public float y;
public float z;
public Point(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
}

@ -1,84 +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;
import java.io.Serializable;
import com.github.drinkjava2.frog.Env;
/**
* Zone represents a rectangle zone in brain
*
* @author Yong Zhu
* @since 1.0
*/
public class Zone implements Serializable {
private static final long serialVersionUID = 1L;
public float x;
public float y;
public float r;// r为这个矩形区边长的一半
public Zone() {
// 空构造器不能省
}
public Zone(float x, float y, float r) {// 用x,y,r来构造
this.x = x;
this.y = y;
this.r = r;
if (this.x < 0)
this.x = 0;
if (this.y < 0)
this.y = 0;
if (this.x > Env.FROG_BRAIN_WIDTH)
this.x = Env.FROG_BRAIN_WIDTH;
if (this.y > Env.FROG_BRAIN_WIDTH)
this.y = Env.FROG_BRAIN_WIDTH;
}
public Zone(Zone z) {// 用另一个Zone来构造
this.x = z.x;
this.y = z.y;
this.r = z.r;
}
public boolean nearby(Zone z) {
float dist = r + z.r;
return (Math.abs(x - z.x) < dist && Math.abs(y - z.y) < dist);
}
public int roundX() {
return Math.round(x);
}
public int roundY() {
return Math.round(y);
}
public static void copyXY(Zone from, Zone to) {
to.x = from.x;
to.y = from.y;
}
public static void copyXYR(Zone from, Zone to) {
to.x = from.x;
to.y = from.y;
to.r = from.r;
}
public void setXYR(float x, float y, float r) {
this.x = x;
this.y = y;
this.r = r;
}
}

@ -1,34 +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 com.github.drinkjava2.frog.brain.Organ;
/**
* Group presents a rectangle organ zone, Group only arranges a group of cells
*
* 2.0CellGroup线2.0Group,Group
*
* CellGroupGroupGroup,
* Group Group
* Group Group
*
* GroupGroup,fatGroup
* GroupGroup"播种机"
* Group()Group
*
* @author Yong Zhu
* @since 1.0
*/
public abstract class Group extends Organ {
private static final long serialVersionUID = 1L;
}

@ -0,0 +1,36 @@
/*
* 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.brain.Organ;
/**
* BrainFrame one used to drawing the brain frame in BrainPicture
*
* @author Yong Zhu
*/
public class BrainFrame extends Organ {
private static final long serialVersionUID = 1L;
public BrainFrame() {
x = 0;
y = 0;
z = 0;
xr = Env.FROG_BRAIN_RADIUS / 2;
yr = xr;
zr = xr;
}
public boolean allowBorrow() { // 是否允许在精子中将这个器官借出
return false;
}
}

@ -0,0 +1,36 @@
/*
* 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.brain.Organ;
/**
* PictureEye can only see the picture in env
*
* @author Yong Zhu
*/
public class PictureEye extends Organ {
private static final long serialVersionUID = 1L;
public PictureEye() {
x = 0;
y = 0;
z = Env.FROG_BRAIN_RADIUS / 2 - .5f;
xr = Env.FROG_BRAIN_RADIUS / 4;
yr = xr;
zr = 0.5f;
}
public boolean allowBorrow() { // 是否允许在精子中将这个器官借出
return false;
}
}

@ -16,12 +16,13 @@ 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.group.Group; import com.github.drinkjava2.frog.brain.organ.BrainFrame;
import com.github.drinkjava2.frog.brain.organ.PictureEye;
import com.github.drinkjava2.frog.util.RandomUtils; import com.github.drinkjava2.frog.util.RandomUtils;
/** /**
* Egg is the static structure description of frog, can save as text file, to * Egg is the static structure description of frog, can save as file, to build a
* build a frog, first need build a egg.<br/> * frog, first need build a egg.<br/>
* *
* Frog,FrogFrogFrog"永生"egg * Frog,FrogFrogFrog"永生"egg
* *
@ -30,19 +31,15 @@ import com.github.drinkjava2.frog.util.RandomUtils;
* @since 1.0 * @since 1.0
*/ */
public class Egg implements Serializable { public class Egg implements Serializable {
// 为了缩短时间,这个程序随机生成的联结将只落在固定的器官上而不是漫天撒网(见4.12提交),这是程序的优化,实现的逻辑和随机漫天撒网定是相同的。
// 但是这个优化带来的问题是这是一个硬编码逻辑,不利于器官的优胜劣汰, 而且下面这个 FIXED_ORGAN_QTY必须每次手工设定以后需要重构这块的代码
public static int FIXED_ORGAN_QTY = 11; public static int FIXED_ORGAN_QTY = 11;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public List<Organ> organs = new ArrayList<>(); public List<Organ> organs = new ArrayList<>();
public List<Group> groups = new ArrayList<>();
public Egg() {// 无中生有,创建一个蛋,先有蛋,后有蛙 public Egg() {// 无中生有,创建一个蛋,先有蛋,后有蛙
organs.add(new BrainFrame()); // BrainCube是固有的用来画一个脑的立方什么都不做
organs.add(new PictureEye()); // BrainCube是固有的用来画一个脑的立方什么都不做
} }
/** Create egg from frog */ /** Create egg from frog */

@ -52,8 +52,9 @@ public class EggTool {
ObjectOutputStream so = new ObjectOutputStream(fo); ObjectOutputStream so = new ObjectOutputStream(fo);
so.writeObject(Env.eggs); so.writeObject(Env.eggs);
so.close(); so.close();
System.out.print("Fist frog has " + first.organs.size() + " organs, energy=" + first.energy);
System.out.println(", Last frog has " + last.organs.size() + " organs, energy=" + last.energy); 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'"); System.out.println("Saved " + Env.eggs.size() + " eggs to file '" + Application.CLASSPATH + "eggs3d.ser'");
} catch (IOException e) { } catch (IOException e) {
System.out.println(e); System.out.println(e);
} }

@ -26,10 +26,10 @@ public class Material {
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 FOOD = VISIBLE + 1; public static final byte FOOD = VISIBLE + 1;
public static final byte SEESAW = VISIBLE + 2; // if <0 will not cause frog die public static final byte SEESAW = VISIBLE + 2;
public static final byte BRICK = KILLFROG + 1; public static final byte BRICK = KILLFROG + 1;// brick will kill frog
public static final byte TRAP = KILLFROG + 2; public static final byte TRAP = KILLFROG + 2; // trap will kill frog
public static Color color(byte material) { public static Color color(byte material) {
if (material == TRAP) if (material == TRAP)

@ -0,0 +1,39 @@
/* 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.objects;
/**
* Object means some thing in Env
*
* @author Yong Zhu
* @since 1.0
*/
public class Pictures implements Object {
@Override
public void build() {
// TODO Auto-generated method stub
}
@Override
public void destory() {
// TODO Auto-generated method stub
}
@Override
public void active(int screen) {
}
}

@ -40,7 +40,7 @@ public class SeeSaw implements Object {
@Override @Override
public void destory() { public void destory() {
// do nothing
} }
@Override @Override

@ -12,10 +12,6 @@ package com.github.drinkjava2.frog.util;
import java.util.Random; import java.util.Random;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Zone;
import com.github.drinkjava2.frog.egg.Egg;
/** /**
* Random Utilities used in this project * Random Utilities used in this project
* *
@ -32,28 +28,7 @@ public class RandomUtils {
public static float nextFloat() { public static float nextFloat() {
return rand.nextFloat(); return rand.nextFloat();
} }
/** Return a random zone inside of a zone */
public static Zone randomZoneInZone(Zone z) { // 在一个区内随机取一个小小区
return new Zone(z.x - z.r + z.r * 2 * rand.nextFloat(), z.y - z.r + z.r * 2 * rand.nextFloat(),
z.r * rand.nextFloat() * .04f);
}
/** Return a random zone inside of frog's random organ */
public static Zone randomPosInAnyFrogOrgan(Frog f) {
if (f.organs == null || f.organs.size() == 0)
throw new IllegalArgumentException("Can not call randomPosInRandomOrgan method when frog has no organ");
return randomZoneInZone(f.organs.get(RandomUtils.nextInt(Egg.FIXED_ORGAN_QTY)));
}
/** Return a random zone inside of frog's random organ */
public static Zone randomPosMostInNewEye(Frog f) {
if (f.organs == null || f.organs.size() == 0)
throw new IllegalArgumentException("Can not call randomPosInRandomOrgan method when frog has no organ");
if (RandomUtils.percent(95))
return randomZoneInZone(f.organs.get(7));// 这是一个硬编码大部分新联接建立在newEye中
return randomZoneInZone(f.organs.get(RandomUtils.nextInt(Egg.FIXED_ORGAN_QTY)));
}
public static boolean percent(float percent) { public static boolean percent(float percent) {
return rand.nextFloat() * 100 < percent; return rand.nextFloat() * 100 < percent;

Binary file not shown.
Loading…
Cancel
Save