From 7c4af9bef1df63c11bc0d225970d34d4ec7641ef Mon Sep 17 00:00:00 2001 From: drinkjava2 Date: Mon, 9 Sep 2019 16:43:51 -0700 Subject: [PATCH] Delete everything, only keep frame --- README.md | 1 - README_EN.md | 110 -------------- .../java/com/github/drinkjava2/frog/Env.java | 10 +- .../github/drinkjava2/frog/brain/Cell.java | 6 - .../github/drinkjava2/frog/brain/Input.java | 26 ---- .../github/drinkjava2/frog/brain/Organ.java | 13 -- .../github/drinkjava2/frog/brain/Output.java | 26 ---- .../frog/brain/group/RandomConnectGroup.java | 100 ------------- .../drinkjava2/frog/brain/organ/Active.java | 47 ------ .../drinkjava2/frog/brain/organ/Chance.java | 62 -------- .../drinkjava2/frog/brain/organ/Eat.java | 37 ----- .../drinkjava2/frog/brain/organ/Eye.java | 138 ------------------ .../drinkjava2/frog/brain/organ/Happy.java | 61 -------- .../drinkjava2/frog/brain/organ/Hungry.java | 73 --------- .../drinkjava2/frog/brain/organ/MoveDown.java | 28 ---- .../drinkjava2/frog/brain/organ/MoveLeft.java | 27 ---- .../frog/brain/organ/MoveRight.java | 29 ---- .../drinkjava2/frog/brain/organ/MoveUp.java | 28 ---- .../drinkjava2/frog/brain/organ/NewEye.java | 91 ------------ .../drinkjava2/frog/brain/organ/Pain.java | 70 --------- .../com/github/drinkjava2/frog/egg/Egg.java | 28 +--- .../github/drinkjava2/frog/egg/EggTool.java | 4 - eggs3d.ser | Bin 0 -> 1145 bytes 23 files changed, 3 insertions(+), 1012 deletions(-) delete mode 100644 README_EN.md delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/Input.java delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/Output.java delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/group/RandomConnectGroup.java delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Active.java delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Chance.java delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Eat.java delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Eye.java delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Happy.java delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Hungry.java delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveDown.java delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveLeft.java delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveRight.java delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveUp.java delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/NewEye.java delete mode 100644 core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Pain.java create mode 100644 eggs3d.ser diff --git a/README.md b/README.md index 684d9ab..c408551 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ ## Frog | 人工生命 -(Engish instruction see README_EN.md) 这是一个人工生命试验项目,最终目标是创建“有自我意识表现”的模拟生命体,技术架构基于02年提出的 [一个人工脑模型](一个人工脑模型.md)。 这个项目永远没有结束的时候,开始于模拟一个简单的生命体,然后是青蛙、狗......, 结束于有“自我意识表现”的人工脑,或者说,结束于被机器人代替人类的那一天。 diff --git a/README_EN.md b/README_EN.md deleted file mode 100644 index d331f33..0000000 --- a/README_EN.md +++ /dev/null @@ -1,110 +0,0 @@ -## Frog -This is an artificial life experiment project. The ultimate goal is to create a ¡°self-conscious performance¡± simulation of the living organism. The technical architecture is based on [an artificial brain model] (an artificial brain model.md) proposed in 2002. -When the project never ends, it begins with simulating a simple living body, then a frog, a dog... ending with an artificial brain with a ¡°self-consciousness,¡± or ending with being replaced by a robot. That day. - -## Origin -At present, the progress of artificial intelligence has solved the problem of pattern recognition quite perfectly. Face recognition and speech recognition are no weaker than human level, and this is the most confused piece I felt twenty years ago because of the poor foundation. And the computer at that time was slow. Pattern recognition is solved, and the remaining problems are much simpler. At present, the birth of artificial consciousness is only a shortcoming. It is how to "understand" these recognized contents and form feedback with humans on the basis of recognition. Therefore, the focus of this project is not on pattern recognition. On the basis of the results of pattern recognition, the neural network is trained to form conditioned reflexes, which show the strip reflection behavior of higher animals, and finally the behavior of "having self-awareness". . According to the principle that "consciousness is not a kind of existence, but a phenomenon", if a system exhibits self-awareness in the end, it can be considered as a human being and should acquire human rights. At present, some artificial intelligence research aims to make artificial intelligence solve some complex human social problems such as machine translation, which is a completely wrong goal and cannot be successful, because if a system cannot express self-awareness, it cannot It is impossible to have the ability to solve these problems by communicating with human beings. The phenomenon that is manifested is that "the machine does not make mistakes, and it is a big mistake once it is made." On the other hand, if a system exhibits self-aware behavior, it is fully capable of solving all the world's problems, including improving itself and eliminating humans (because he is the representative of advanced productivity). Therefore, the focus of artificial intelligence research should be on the construction of artificial life and theoretical research, rather than expecting short-term gains. It is dangerous to expect that humans can always enjoy artificial intelligence. The result of pattern recognition and deep learning is just a stumbling block to artificial life and a road sign. The "useful" application of artificial intelligence is probably only a short period of transition. It is not too happy to be too early. It may be too busy to make a wedding dress for the robot. Of course, the results of deep learning will be useful in the future. The organism has never been able to train a skill tens of thousands of times like a computer, reaching unprecedented coverage, even in the robot era, is also a useful technology. -To put it simply, the purpose of this project is to test and explore another direction of neural network development, that is, experiment-oriented, to simulate the process of life evolution, in accordance with the three principles of superiority, random variation, and use of retreat. Step by step to build artificial life from low to complex, in addition to the results of pattern recognition can be partially quoted, in principle does not require a lot of mathematical knowledge, because it is driven by experiments, rather than the algorithm to start building neural networks. At present, neural network research focuses on pattern recognition and algorithms, but it does not pay enough attention to the system. - -From single cell evolution to multi-cell evolution, from frog to human, this is a long, random evolutionary process, but running on a supercomputer may take a few days to get a pretty good brain model. Of course, the faster the computer speed, the larger the capacity, and the more realistic the environment simulation, the more complicated the brain structure formed after the victory and the wrong brain model are naturally eliminated. Starting from the algorithm, or starting from the simulation environment, this is the two major directions for creating artificial life. The first direction may go to a dead end because it does not have algorithmic self-improvement, mutation, and inheritance (encoding compression). The function, when the brain model is complex to a certain extent, may exceed the scope that the human brain can understand. The difficulty in simulating the environment is that the environment itself must be complex and correct. And it must be gradual and synchronized with the evolution of the brain. If a group of frogs are thrown into the monkey's simulated environment, all the frogs will be naturally eliminated, and the project will not be able to proceed. Another difficulty is that the computer must be very fast because it is Simulate parallelism in a serial manner and constantly try to go wrong. The current project only builds a framework, the language is Java, using the Swing mapping environment, constructing a virtual environment, and simulating the succession of a group of paramecium, to obtain an artificial life body with self-evolution function, the specific brain (ie The generation and evolutionary algorithms of computer-generated neural networks need to be added later. Students who are interested in neural networks are welcome to join this experimental project. Let's play together. This project does not require much mathematics and is practiced. - -## Short-term goals -Its first initial goal is to create a real artificial life: paramecium. It must have the following four characteristics: -* Brain structure is generated by computer: neural network is generated by computer algorithm, but computer algorithm is limited to simulation environment, instead of directly participating in building neural network, just as nature is only responsible for shooting unqualified life, it never actively participates in design brain. -* Brain structure can be inherited: similar to biological DNA, computer-generated brain structure (neural network), can be described by simple algorithm rules, and this algorithm rule can be compressed into shorter fragment storage and participate in the next generation of paramecium Construction. -* Brain structure can be mutated: algorithm rules can be mutated, and the next generation of paramecium is generally similar in brain structure to the previous generation, but there are some variations. -* Adapt to the environment: Paramecium survives in a simulated virtual environment with minimal changes in the environment, adapts to the environment, and inherits the ability to adapt to this environment from generation to generation. -* Use and retreat: This is a hypothesis. For creatures, there is a phenomenon in which many organs are used, which are prone to variability (for example, chewing betel nut often, which is prone to oral cancer). It is reasonable to believe that this is not accidental. Phenomenon, but a useful function of the organism in the process of evolution, in order to adapt to the environment more quickly, and it is likely that this mutation will affect the next generation through genetic cells. - -## Theory -Why is it a computer program? As long as you meet the above four characteristics, you can call it a "real" artificial life? I don't want to say more about it. You can know Baidu's "zhangrex artificial life". There is no such thing, consciousness is just a phenomenon. Wind blowing, tree movement, wind blowing, and dressing are just phenomena. Consciousness is essentially a phenomenon. In other words, as long as it shows the phenomenon of life, it can be called life, whether it is high or low. Wait, no matter what its material basis is. Twenty years ago, I began to think about this issue and put forward the slogan "I think I am not here." Please consider this point carefully. The study of intelligence and consciousness in philosophy and theory is very boring, equivalent to research. Nothing is what it is, no need to entangle in theory and algorithm. Yes, with the artificial neural network model obtained from the simulation environment, we really can't control how its algorithm is generated, but we know that this is in line with the law of nature's creation of life. - -## Architecture -This is a Java project, divided into three modules: Application, Env, and Frog: -Application module: Used to start and shut down the basic services of the project. In Windows environment, you can use run.bat to start it and view the demo. -Env module: Simulate a biological living area, using different shapes of graphic lattice to express and simulate objects such as food, natural enemies, obstacles, etc. This virtual space is fully controlled by the programmer and will continue to become more and more as Frog's brain evolves. The more complicated. -Frog: This is the main body of artificial life. It is now called Frog. It is called the same thing. It mainly has the following organs: -* Sports organs: Connected to motor neurons, there are only 4 movements: up, down, left and right. -* Eating organs: When Frog coincides with the coordinates of the food, the food will be removed from Env, and the energy value of Frog will be increased accordingly, and Frog's feeding sensory neurons will be activated. The energy will decrease with time, and the energy will be exhausted. death. -* Visual Organs: This is part of the brain model. In the experiment, a neuron area in the brain is randomly taken as a visual area. -* Brain Organs: This is the problem that programmers have to solve and the ultimate goal we want to achieve. The generation of the brain model is generated by the computer's superiority and cyclic iterative evolution. However, this evolutionary algorithm must be controlled by the programmer, step by step, that is, to prevent the virtual environment from being too complicated, and to avoid the brain model not adapting to the environment. All the living organisms were eliminated, causing the experiment to be interrupted and unable to proceed. - -## Technical details and ideas -* Simulate neural networks with arrays and serial loops to simulate parallel chip operation. Use Frog's energy to measure whether to eliminate it or allow it to produce offspring (the next egg) to participate in the next round of testing, because the purpose of this project is to acquire the agent, which is different from the general life game, not the fittest. Survival is over, but it must complete a set of goals set by the programmer, step by step, until it shows self-awareness. -* The brain model generation algorithm is completed by simple neuron connections. In principle, any form of hard coding is allowed (except for pattern recognition), because hard coding may destroy the life characteristic of "random variation". -* For the sake of simplicity, it is not considered to introduce GPU graphics chips for acceleration. -* Temporarily selected in Java language -* Some of the ideas and ideas of Miscellaneous Seven Pull are placed in "Development Ideas.md" and "An Artificial Brain Model.md". - -## The short-term and long-term goals to be achieved by the project -* Initial construction of the brain model and virtual environment [The brain model has just begun to build. The virtual environment is complete, click run.bat to view the demo] -* Make the brain model visually responsive, if there is food near it, it will stimulate natural conditioning, move to food, and get a reward for eating [not fully completed] -* Introduce off-the-shelf image recognition algorithms to make brain models have image recognition functions, distinguish food, poisons, and natural enemies according to shape [unfinished] -* If you eat toxic foods, it will stimulate natural conditioning, get punishment and deduct energy, and the natural pain zone is excited. [undone] -* If attacked by natural enemies, it will stimulate natural conditioning, get punishment and deduct energy, and the natural pain area is very excited. [undone] -* Training links the combat behavior to the painful excitatory area. [undone] -* Training will see the word "hit", which is linked to the action zone and the painful excitement zone. [undone] -* Train it to recite the common phrases that may be formed by all the Chinese characters in the 100 words, give it a word, and all the cell regions associated with the word are excited. [undone] -* Train it to see the words "food is coming" and come out from the nest to find food. [undone] -* Train it to understand "you", "I", "he" text, and only respond to "I" related instructions. [undone] -* Train it to recognize numbers and do four arithmetic operations [unfinished] -* Train it to recognize circles, rectangles, calculate area, learn to estimate and judge "big" and "small" [unfinished] -* Train it to know the coordinates and time, and act according to the instructions. If you see "You go to the upper right corner at 9:00, wait three minutes and then come back", you will follow the instructions. [undone] - -## Ultimate goal -* Expand its input grid and output grid size to expand the number of neurons -* Transfer to a super computer, let people communicate with it, enter new graphics and Chinese characters, correct the mistakes it says -* Migration to parallel chip hardware - -## Current progress and achievements -2019.03.11 The virtual environment has been built to simulate the inheritance, reproduction, mutation and evolution of lower life. However, it can only move in one direction, which is equivalent to one of the simplest single-celled creatures. It does not have visual ability. Have the ability to actively find food. -Run run.bat to view the demo (you need to install Java8 and Maven). Several important parameters in Env.java: -* SHOW_SPEED: Adjust the speed of the experiment (1~1000). The smaller the value, the slower. -* ENV_WIDTH: size of the virtual environment (100~1000) -* EGG_QTY: How many eggs are allowed under Frog each time, and each egg can hatch 4 frogs. Usually the egg lays between 10 and 1000. The eggs preserve the results of our tests. The ultimate goal of the experiment is to get an egg. -* FOOD_QTY: The number of foods, the more food, the higher the survival rate of Frog, the batch of Frog with the highest energy ranking can lay eggs, and the rest are eliminated. -The following is an animated screenshot of this test, if you are interested, you can try to run it yourself: -![result1](https://gitee.com/drinkjava2/frog/raw/master/result1.gif) -In addition, the result of each demonstration (egg) will be saved in the root directory of the root, named egg.ser, you can delete this file to start a new test from scratch. Because the brain model has not been built, it can be seen that some frogs run fast, which is the result of natural selection, because eating at the front is much more. This bug will be corrected in the future, so that the most intelligent, predatory Frog wins, rather than letting it run faster. -2019.03.21 Added a brain map to improve the random motion mode for the Hungry Zone driver. The brain structure can be visually observed from the brain map for easy debugging. -2019.04.01 Improve the display of brain map bugs, add random neurons each time Frog is generated, and simply implement the "egg + sperm -> fertilized eggs" algorithm to promote population diversity. -2019-04-12 Adding a simple eye (only four photoreceptors), the result of natural selection is that the eye is selected, but it is shorted to the motion zone, and it is not smart. However, the efficiency of finding food after eyesight has improved significantly, as shown in the following figure: -![resut2](https://gitee.com/drinkjava2/frog/raw/master/result2.gif) -2019-06-13 Some refactoring cleanups were added, plus two organs, Happy and Pain, which correspond to eating rewards and pain, respectively, which provoke near the border. Observing its performance, the painful effect took effect. Some Frogs did not move forward after they ran to the border, but slid down the border, but the Happy organ did not take effect, which is also obvious, because Happy is a complex eating conditional reflection. Part of the chain, before the introduction of memory organs (algorithms), there is no way to use the reward signal for survival of the fittest. See below: -![resut3](https://gitee.com/drinkjava2/frog/raw/master/result3.gif) -2019-06-26 The previous version of the food-seeking efficiency is too low, canceled the weight design, and returned to 4.12 to replace the weight with the number of connections, the artificially designed algorithm is still lost to random trial and error. -2019-07-28 -The following changes have been made: 1. A trap area trap is added in the middle of the Env area to add interest. The natural selection result is that the frog will automatically bypass the trap area. 2. Add an Active Organ, its role is to remain active, and found to be more efficient than the Hungry organ drive. 3. Add a Chance organ, its role is to introduce random disturbances, breaking the frog sometimes circling around a food is an instable cycle. At present, the reward signal for eating is not used, and it is wasted. -In addition, the Chance and Eye classes have once again applied the principle of random trial and error to determine the key parameters. The effect is not bad. If you are interested, you can take a look at the source code. -![resut4](https://gitee.com/drinkjava2/frog/raw/master/result4.gif) - -In addition, it is found that the current frog actually has a certain memory ability. The connection itself is a kind of memory, but it has no complicated pattern recognition ability, for example, it can not recognize the picture of a snake. Future work will focus on pattern recognition (of course, random connections may seem useful and may be retained in the future). The basic principle is to refer to the principle of wave propagation and holographic storage mentioned in the note, and reverse imaging in the thinking area. Moreover, the brain may be changed into a three-dimensional structure, and according to the principle of reverse imaging, all input and output organs are moved to the same side of the three-dimensional structure (ie, the thinking area). This will be a very big change. Below I simply drew a 3D diagram to illustrate the principle of pattern recognition and memory in my imagination. As for the wrong, I need to experiment to verify: -![3d-model](https://gitee.com/drinkjava2/frog/raw/master/3d-model.gif) -The top layer of this model represents the photoreceptor cells (or any input and output cells) of the eye, and is also the thinking area. Red indicates a long strip of graphics, and blue indicates a triangle graph. If these two graphs appear regularly at the same time, The nodes they share will be large, see the purple nodes. When the red graphic appears alone, the purple node will be strongly activated, and then the signal of the purple node will propagate back, and the triangle will be activated, and vice versa. This explains the principles of pattern recognition and memory (or recall) functions. A node can be shared by multiple photoreceptors, so its storage capacity is very strong. And perhaps this principle is more in line with the biological brain structure. Of course, in actual programming, the virtual neurons do not have to be arranged in a positive-cubic triangle, but may be discharged through indiscriminate discharge. Generally, it is enough to kill the master. In the end, it is necessary to rely on the computer to automatically and randomly discharge, and then use The survival of the fittest to screen. At present, there is a difficulty in how this memory function is imaged in the thinking area in an orderly manner and works in a serial manner. This problem is first put aside. - -2019-08-04 Updated a group test function. If the number of test frogs is too large, it can be tested in batches. The minimum number of frogs tested per round can be as few as one, which is time to change space. -2019-08-05 With the group test function, a demonstration of automatic balancing of the frog walking board is added. It only plays one frog at a time, including 100 tests per round, and runs about 90 rounds and half an hour. After slow), the following screen appears: -![result5](https://gitee.com/drinkjava2/frog/raw/master/result5_seesaw.gif) -The purpose of this version is to add a bit of fun, it seems that the frog is still a bit "useful", saving people to think that this project is not working, the frog will only find food. The brain structure of this version of the frog is basically the same as that of the frog. The difference is that the environment is different, that is, its performance changes with the environment. This is consistent with the concept of "general artificial intelligence", that is, the signal receptor is unified. (usually the eyes), but can perform different tasks according to different environments. The seesaw demonstration is the last version of the 2-dimensional brain. In the future, this project will be silent for a long time. I will work on reconstructing the frog brain into a 3D pyramidal brain structure (see above) because the shortcomings of this project are very Obviously, it does not have the ability to recognize patterns in 2-dimensional images. In a random trial and error manner, only very simple image signals appearing in fixed areas of the retina can be processed. -The frog's ability to find food and the ability to balance the balance of the raft are not optimized to the apex. Some of the complex organs in the concept, such as "and the door", "or gate" (don't doubt whether nature can evolve these complex organs), etc. In addition, the use of organs and the use of reward signals are not reflected, but I think these are not critical. The most urgent task at present should be to first model 3D brain structure so that frogs can have 2D graphics. The recognition (and recall) function, this large architecture reconstruction is the basis for its ability to process complex image information. Its image recognition capability is completely different from the usual working mode of training a picture with thousands of pictures. It is a universal method that automatically classifies and recognizes all images, more in line with the working mode of the animal brain, remembers and recalls an image (or a combination of arbitrary input signal scenes), and may only need to repeat this scene. Just a few times, it is a recognition mode that does not have external signal judgment and automatic classification. - -If you want to run a previous version of this project, you can use the gitk command and reference "version commit record.md" to revert to the previous version with the git reset command. - -2019-09-09 start to work on 3d brain - -## License -[Apache 2.0] (http://www.apache.org/licenses/LICENSE-2.0) - -## Futures -You are welcome to send us a better opinion or join the development team. In particular, students who have access to supercomputers are welcome to join. As the complexity of the virtual environment and the number of neurons increase, the requirements for computer speed will become higher and higher. - -## Author Other Open Source Projects | Other Projects -- [Java Persistence Layer Tool jSqlBox] (https://gitee.com/drinkjava2/jSqlBox) -- [Micro IOC/AOP tool jBeanBox] (https://gitee.com/drinkjava2/jBeanBox) -- [Front-end SQL tool GoSqlGo] (https://gitee.com/drinkjava2/gosqlgo) -- [MyBatis Enhancement Plugin MyFat] (https://gitee.com/drinkjava2/myfat) - -## Follow me | About Me -[Github] (https://github.com/drinkjava2) -[Code Cloud] (https://gitee.com/drinkjava2) -[WeChat] Yong99819981 \ No newline at end of file diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/Env.java b/core3d/src/main/java/com/github/drinkjava2/frog/Env.java index d1b43ab..41b47af 100644 --- a/core3d/src/main/java/com/github/drinkjava2/frog/Env.java +++ b/core3d/src/main/java/com/github/drinkjava2/frog/Env.java @@ -9,7 +9,6 @@ import java.util.List; import javax.swing.JPanel; -import com.github.drinkjava2.frog.brain.group.RandomConnectGroup; import com.github.drinkjava2.frog.egg.Egg; import com.github.drinkjava2.frog.egg.EggTool; import com.github.drinkjava2.frog.objects.Food; @@ -27,10 +26,10 @@ import com.github.drinkjava2.frog.util.RandomUtils; @SuppressWarnings("all") public class Env extends JPanel { /** Speed of test */ - public static final int SHOW_SPEED = 500; // 测试速度,-1000~1000,可调, 数值越小,速度越慢 + public static final int SHOW_SPEED = 5; // 测试速度,-1000~1000,可调, 数值越小,速度越慢 /** Delete eggs at beginning of each run */ - public static final boolean DELETE_EGGS = false;// 每次运行是否先删除保存的蛋 + public static final boolean DELETE_EGGS = true;// 每次运行是否先删除保存的蛋 public static final int EGG_QTY = 25; // 每轮下n个蛋,可调,只有最优秀的前n个青蛙们才允许下蛋 @@ -203,11 +202,6 @@ public class Env extends JPanel { Frog f = frogs.get(screen * FROG_PER_SCREEN + j); if (f.active(this)) allDead = false; - if (f.alive && RandomUtils.percent(0.2f)) {// 有很小的机率在青蛙活着时就创建新的器官 - RandomConnectGroup newConGrp = new RandomConnectGroup(); - newConGrp.initFrog(f); - f.organs.add(newConGrp); - } } if (SHOW_SPEED > 0 && i % SHOW_SPEED != 0) // 用画青蛙的方式来拖慢速度 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 fdae751..835768e 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 @@ -22,12 +22,6 @@ public class Cell { // this cell belong to frog's which organ public Organ organ; - // inputs of cell - public Input[] inputs; // 每个细胞有一组输入触突 - - // outputs of cell - public Output[] outputs; // 每个细胞有一组输出触突 - // energy of cell, energy got from food public float energy; // 每个细胞当前的能量值 diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/Input.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/Input.java deleted file mode 100644 index 78f16b4..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/Input.java +++ /dev/null @@ -1,26 +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; - -/** - * Input is the sensor of nerve cell - * - * @author Yong Zhu - * @since 1.0 - */ -@SuppressWarnings("serial") -public class Input extends Zone { - public Cell cell; // 这个输入触突属于哪个脑细胞 - - public Input(Zone z) { - super(z); - } -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/Organ.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/Organ.java index c26da8f..657ca17 100644 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/Organ.java +++ b/core3d/src/main/java/com/github/drinkjava2/frog/brain/Organ.java @@ -42,19 +42,6 @@ public class Organ extends Zone { } /** If active in this organ's zone? */ - public boolean outputActive(Frog f) { // 如果一个细胞能量>10,且它的输出触突位于这个器官内,则器官被激活 - for (Cell cell : f.cells) { - if (cell.energy > organActiveEnergy) - for (Output output : cell.outputs) { // - if (this.nearby(output)) { - cell.organ.fat++; - cell.energy -= 30;// - return true; - } - } - } - return false; - } /** Set X, Y, Radius, name of current Organ */ public Organ setXYRN(float x, float y, float r, String name) { diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/Output.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/Output.java deleted file mode 100644 index b794b93..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/Output.java +++ /dev/null @@ -1,26 +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; - -/** - * Output can active other nerve cell's input - * - * @author Yong Zhu - * @since 1.0 - */ -@SuppressWarnings("serial") -public class Output extends Zone { - public Cell cell; // 这个输出触突属于哪个脑细胞 - - public Output(Zone z) { - super(z); - } -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/group/RandomConnectGroup.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/group/RandomConnectGroup.java deleted file mode 100644 index ed223df..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/group/RandomConnectGroup.java +++ /dev/null @@ -1,100 +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 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.Cell; -import com.github.drinkjava2.frog.brain.Input; -import com.github.drinkjava2.frog.brain.Organ; -import com.github.drinkjava2.frog.brain.Output; -import com.github.drinkjava2.frog.brain.Zone; -import com.github.drinkjava2.frog.util.RandomUtils; - -/** - * RandomConnectGroup - * - * 这是一个随机方式连接两端的Group,它是从旧版的CellGroup改造过来,这是一种最简单的神经元排列方式,只有一组细胞,触突输入区和输出区分别位于Zone内的任意随机两点。 - * 至于是否合理则由frog的遗传进化来决定,不合理的RandomConnectGroup会被淘汰掉。 - * - * (还没改造完成,在不破坏原有外在表现的基础上,要平滑将它改造成一个标准Group的子类,也是第一个子类 ) - * - * @author Yong Zhu - * @since 1.0 - */ -public class RandomConnectGroup extends Group { - private static final long serialVersionUID = 1L; - - public Zone inputZone; // 输入触突区 - public Zone outputZone; // 输出触突区 - - @Override - public boolean allowBorrow() { // 是否允许在精子中将这个器官借出 - return true; - } - - @Override - public void initFrog(Frog f) { - if (!initilized) { - initilized = true; - // organWasteEnergy=.05f; - x = Env.FROG_BRAIN_WIDTH / 2; - y = Env.FROG_BRAIN_WIDTH / 2; - r = Env.FROG_BRAIN_WIDTH / 2; - inputZone = RandomUtils.randomPosInAnyFrogOrgan(f); - outputZone = RandomUtils.randomPosInAnyFrogOrgan(f); - } - - this.fat = 0;// 每次fat清0,因为遗传下来的fat不为0 - - Cell c = new Cell(); - Input in = new Input(inputZone); - in.cell = c; - c.inputs = new Input[] { in }; - - Output out = new Output(outputZone); - out.cell = c; - c.outputs = new Output[] { out }; - - c.organ = this; - f.cells.add(c); - } - - @Override - public Organ[] vary() { - if (fat <= 0)// 如果胖值为0,表示这个组的细胞没有用到,可以小概率丢掉它了 - if (RandomUtils.percent(30)) - return new Organ[] {}; - if (RandomUtils.percent(3)) // 有3%的几率丢掉它,防止这个器官数量只增不减 - return new Organ[] {}; - return new Organ[] { this }; - } - - @Override - public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来 - if (fat <= 0) - pic.setColor(Color.LIGHT_GRAY); // 没用到? 灰色 - else - pic.setColor(Color.red); // 用到了?红色 - pic.drawLine(inputZone, outputZone); - pic.drawZone(this); - pic.drawZone(inputZone); - pic.fillZone(outputZone); - if (fat > 0) { - pic.setColor(Color.red); - pic.drawCircle(outputZone); // 如果胖了,表示激活过了,下次下蛋少不了这一组 - } - } - -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Active.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Active.java deleted file mode 100644 index 6724647..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Active.java +++ /dev/null @@ -1,47 +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.Cell; -import com.github.drinkjava2.frog.brain.Input; -import com.github.drinkjava2.frog.brain.Organ; - -/** - * Active always keep active - * - * 这个器官永远激活 - */ -public class Active extends Organ {//以前的实验发现添加一个始终激活的区比用Hungry来驱动更能提高找食效率 - - private static final long serialVersionUID = 1L; - - @Override - public void initFrog(Frog f) { - if (!initilized) { - initilized = true; - organOutputEnergy = 2; - } - } - - @Override - public void active(Frog f) { - for (Cell cell : f.cells) { - if (cell.energy > 0) - cell.energy--; - if (cell.energy < Cell.MAX_ENERGY_LIMIT) - for (Input input : cell.inputs) - if (input.nearby(this)) // if input zone near by happy zone - cell.energy += organOutputEnergy; - } - } - -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Chance.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Chance.java deleted file mode 100644 index 8527363..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Chance.java +++ /dev/null @@ -1,62 +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.Cell; -import com.github.drinkjava2.frog.brain.Input; -import com.github.drinkjava2.frog.brain.Organ; -import com.github.drinkjava2.frog.util.RandomUtils; - -/** - * Chance is a random number generator - * - * 这个器官是一个随机数发生器,用来打乱青蛙的思维,防止它围着一个食物打转出不来 - */ -public class Chance extends Organ { // 至于这个器官能不能被选中,是另外一回事,听天由命了 - private static final long serialVersionUID = 1L; - public int percent; // 初始化的机率为5% - - @Override - public void initFrog(Frog f) { - if (!initilized) { - initilized = true; - percent = 5; - } - } - - @Override - public Organ[] vary() { - if (RandomUtils.percent(5)) { - percent = percent + 1 - 2 * RandomUtils.nextInt(2); - if (percent < 1) - percent = 1; - if (percent > 98) - percent = 98; - } - return new Organ[] { this }; - } - - @Override - public void active(Frog f) { - if (RandomUtils.percent(percent)) {// 如果靠近边界,痛苦信号生成 - for (Cell cell : f.cells) { - if (cell.energy > 0) - cell.energy--; - if (cell.energy < Cell.MAX_ENERGY_LIMIT) - for (Input input : cell.inputs) - if (input.nearby(this)) // if input zone nearby this zone - cell.energy += 30; - } - } - } - -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Eat.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Eat.java deleted file mode 100644 index 3b097d8..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Eat.java +++ /dev/null @@ -1,37 +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; -import com.github.drinkjava2.frog.Frog; -import com.github.drinkjava2.frog.brain.Organ; - -/** - * Eat food at current x, y position - */ -public class Eat extends Organ {// Eat这个类将食物转化为能量,能量小于0,则青蛙死掉 - private static final long serialVersionUID = 1L; - - @Override - public void active(Frog f) { - if (Env.foundAndAteFood(f.x, f.y)) { - f.ateFood++; - // 所有的硬编码都是bug,包括这个1000 - f.energy += 1000;// 如果青蛙的坐标与食物重合,吃掉food,能量境加 - - // 能量境加青蛙感觉不到,但是Happy区激活青蛙能感觉到,因为Happy区是一个脑器官 - - Organ o = f.organs.get(0); - ((Happy) o).happy += 2; // 找到食物有奖! - } - } - -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Eye.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Eye.java deleted file mode 100644 index 29d9686..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Eye.java +++ /dev/null @@ -1,138 +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.Application; -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.Cell; -import com.github.drinkjava2.frog.brain.Input; -import com.github.drinkjava2.frog.brain.Organ; -import com.github.drinkjava2.frog.brain.Zone; -import com.github.drinkjava2.frog.util.RandomUtils; - -/** - * Eye can only see 4 direction - * - * @author Yong Zhu - * @since 1.0 - */ -public class Eye extends Organ {// 这个Eye是老版的眼睛,只能看到四个方向,但它的调节距离会自动随机调整到一个最佳值,这就是随机试错算法的一个应用 - private static final long serialVersionUID = 1L; - public int seeDistance; // 眼睛能看到的距离 - - @Override - public void initFrog(Frog f) { // 仅在Frog生成时这个方法会调用一次 - if (!initilized) { - initilized = true; - organOutputEnergy = 30; - seeDistance = 8; - } - } - - @Override - public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来 - if (!Application.SHOW_FIRST_FROG_BRAIN) - return; - super.drawOnBrainPicture(f, pic); - float qRadius = r / 4; - float q3Radius = (float) (r * .75); - Zone seeUp = new Zone(x, y + q3Radius, qRadius); - Zone seeDown = new Zone(x, y - q3Radius, qRadius); - Zone seeLeft = new Zone(x - q3Radius, y, qRadius); - Zone seeRight = new Zone(x + q3Radius, y, qRadius); - pic.drawZone(seeUp); - pic.drawZone(seeDown); - pic.drawZone(seeLeft); - pic.drawZone(seeRight); - } - - @Override - public Organ[] vary() { - if (RandomUtils.percent(5)) { // 可视距离有5%的机率变异 - seeDistance = seeDistance + 1 - 2 * RandomUtils.nextInt(2); - if (seeDistance < 1) - seeDistance = 1; - if (seeDistance > 50) - seeDistance = 50; - } - return new Organ[] { this }; - } - - @Override - public void active(Frog f) { - // 第一个眼睛只能观察上、下、左、右四个方向有没有食物 - float qRadius = r / 4; - float q3Radius = (float) (r * .75); - Zone seeUp = new Zone(x, y + q3Radius, qRadius); - Zone seeDown = new Zone(x, y - q3Radius, qRadius); - Zone seeLeft = new Zone(x - q3Radius, y, qRadius); - Zone seeRight = new Zone(x + q3Radius, y, qRadius); - - boolean seeSomething = false; - boolean atUp = false; - boolean atDown = false; - boolean atLeft = false; - boolean atRight = false; - - for (int i = 1; i < seeDistance; i++) - if (Env.foundAnyThing(f.x, f.y + i)) { - seeSomething = true; - atUp = true; - break; - } - - for (int i = 1; i < seeDistance; i++) - if (Env.foundAnyThing(f.x, f.y - i)) { - seeSomething = true; - atDown = true; - break; - } - - for (int i = 1; i < seeDistance; i++) - if (Env.foundAnyThing(f.x - i, f.y)) { - seeSomething = true; - atLeft = true; - break; - } - - for (int i = 1; i < seeDistance; i++) - if (Env.foundAnyThing(f.x + i, f.y)) { - seeSomething = true; - atRight = true; - break; - } - - if (seeSomething) - for (Cell cell : f.cells) { - if (cell.energy < 100) - for (Input input : cell.inputs) { - if (input.nearby(this)) { - if (atUp && input.nearby(seeUp)) { - input.cell.energy += organOutputEnergy; - } - if (atDown && input.nearby(seeDown)) { - input.cell.energy += organOutputEnergy; - } - if (atLeft && input.nearby(seeLeft)) { - input.cell.energy += organOutputEnergy; - } - if (atRight && input.nearby(seeRight)) { - input.cell.energy += organOutputEnergy; - } - } - } - } - - } - -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Happy.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Happy.java deleted file mode 100644 index ad52bae..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Happy.java +++ /dev/null @@ -1,61 +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.Application; -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.Input; -import com.github.drinkjava2.frog.brain.Organ; - -/** - * Happy zone active after ate food - */ -public class Happy extends Organ { // Happy器官是进食后的产生的快感,痛苦和快感是条件反射形成的前题 - private static final long serialVersionUID = 1L; - public float happy = 0; // happy初始值为0, 进食后将由eat器官增加happy值 - - @Override - public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来 - if (!Application.SHOW_FIRST_FROG_BRAIN) - return; - if (happy > 0) { - pic.setColor(Color.red); - pic.fillZone(this); - } else { - pic.setColor(Color.white); - pic.fillZone(this); - pic.setColor(Color.BLACK); - pic.drawZone(this); - } - if (this.name != null) - pic.drawText(this, String.valueOf(this.name)); - } - - @Override - public void active(Frog f) { - if (happy > 0) { - happy--; - for (Cell cell : f.cells) { - if (cell.energy > 0) - cell.energy--; - if (cell.energy < Cell.MAX_ENERGY_LIMIT) - for (Input input : cell.inputs) - if (input.nearby(this)) // if input zone near by happy zone - cell.energy += happy / 10; // 所有的硬编码都是bug,包括这个2和10 - } - } - } - -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Hungry.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Hungry.java deleted file mode 100644 index ee51b61..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Hungry.java +++ /dev/null @@ -1,73 +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.Application; -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.Input; -import com.github.drinkjava2.frog.brain.Organ; - -/** - * Hungry will active cell's inputs, if frog's energy not enough - */ -public class Hungry extends Organ { - private static final long serialVersionUID = 1L; - - @Override - public void initFrog(Frog f) { // 仅在Frog生成时这个方法会调用一次,缺省啥也不干,通常用于Organ类的初始化 - if (!initilized) { - initilized = true; - // organWasteEnergy = 20f; - organOutputEnergy = 2; - } - } - - @Override - public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来 - if (!Application.SHOW_FIRST_FROG_BRAIN) - return; - if (f.energy < 10000) { - pic.fillZone(this); - } else { - pic.setColor(Color.white); - pic.fillZone(this); - pic.setColor(Color.BLACK); - pic.drawZone(this); - } - if (this.name != null) - pic.drawText(this, String.valueOf(this.name)); - } - - @Override - public Organ[] vary() { - // if (RandomUtils.percent(20)) // 有20机率权重变化 - // organOutputEnergy = RandomUtils.vary(organOutputEnergy); - return new Organ[] { this }; - } - - @Override - public void active(Frog f) { - if (f.energy < 10000)// 所有的硬编码都是bug - for (Cell cell : f.cells) { - if (cell.energy > 0) - cell.energy--; - if (cell.energy < Cell.MAX_ENERGY_LIMIT) - for (Input input : cell.inputs) - if (input.nearby(this)) // input zone near by hungry zone - cell.energy += 2; - } - } - -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveDown.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveDown.java deleted file mode 100644 index 62381d9..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveDown.java +++ /dev/null @@ -1,28 +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.Organ; - -/** - * Move down frog 1 unit if outputs of nerve cells active in this zone - */ -public class MoveDown extends Organ { - private static final long serialVersionUID = 1L; - - @Override - public void active(Frog f) { - if (outputActive(f)) - f.y++; - } - -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveLeft.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveLeft.java deleted file mode 100644 index 04e5f2e..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveLeft.java +++ /dev/null @@ -1,27 +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.Organ; - -/** - * Move left frog 1 unit if outputs of nerve cells active in this zone - */ -public class MoveLeft extends Organ { - private static final long serialVersionUID = 1L; - - @Override - public void active(Frog f) { - if (outputActive(f)) - f.x--; - } -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveRight.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveRight.java deleted file mode 100644 index 21c50c8..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveRight.java +++ /dev/null @@ -1,29 +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.Organ; - -/** - * Move right frog 1 unit if outputs of nerve cells active in this zone - */ -public class MoveRight extends Organ { - private static final long serialVersionUID = 1L; - - @Override - public void active(Frog f) { - if (outputActive(f)) - f.x++; - } - - -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveUp.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveUp.java deleted file mode 100644 index d02cd91..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/MoveUp.java +++ /dev/null @@ -1,28 +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.Organ; - -/** - * Move up frog 1 unit if outputs of nerve cells active in this zone - */ -public class MoveUp extends Organ { - private static final long serialVersionUID = 1L; - - @Override - public void active(Frog f) { - if (outputActive(f)) - f.y--; - } - -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/NewEye.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/NewEye.java deleted file mode 100644 index d9459ed..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/NewEye.java +++ /dev/null @@ -1,91 +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.Application; -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.Cell; -import com.github.drinkjava2.frog.brain.Input; -import com.github.drinkjava2.frog.brain.Organ; -import com.github.drinkjava2.frog.brain.Zone; -import com.github.drinkjava2.frog.util.RandomUtils; - -/** - * Eye is an organ can see environment, and active brain cells which inputs are - * located in eye range - * - * @author Yong Zhu - * @since 1.0 - */ -public class NewEye extends Organ {// 这个新版的眼睛有nxn个感光细胞,可以看到青蛙周围nxn网络内有没有食物 - private static final long serialVersionUID = 1L; - public int n = 3; // 眼睛有n x n个感光细胞, 用随机试错算法自动变异(加1或减1,最小是3x3) - - @Override - public void initFrog(Frog f) { // 仅在Frog生成时这个方法会调用一次,缺省啥也不干,通常用于Organ类的初始化 - if (!initilized) { - initilized = true; - organOutputEnergy = 30; - } - } - - @Override - public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来 - if (!Application.SHOW_FIRST_FROG_BRAIN) - return; - super.drawOnBrainPicture(f, pic); - float r2 = r / n; // r2是每个感光细胞的半径 - float x0 = x - r; - float y0 = y - r; // x0,y0是眼睛的左上角 - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - Zone cell = new Zone(x0 + i * 2 * r2 + r2, y0 + j * 2 * r2 + r2, r2); - if (Env.foundAnyThing(f.x - n / 2 + i, f.y - n / 2 + j)) - pic.fillZone(cell); - else - pic.drawZone(cell); - } - } - } - - @Override - public Organ[] vary() { - if (RandomUtils.percent(50)) { - n = n + 1 - 2 * RandomUtils.nextInt(2); - if (n < 3) - n = 3; - if (n > 12) - n = 12; - } - return new Organ[] { this }; - } - - @Override - public void active(Frog f) {// 如果看到食物就激活对应脑区的所有输入触突 - float r2 = r / n; // r2是每个感光细胞的半径 - float x0 = x - r; - float y0 = y - r; // x0,y0是眼睛的左上角 - 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)) { - Zone eyeCell = new Zone(x0 + i * 2 * r2 + r2, y0 + j * 2 * r2 + r2, r2); - for (Cell cell : f.cells) - for (Input input : cell.inputs) - if (input.nearby(eyeCell)) - input.cell.energy += organOutputEnergy; - } - } - } - } - -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Pain.java b/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Pain.java deleted file mode 100644 index bac4b18..0000000 --- a/core3d/src/main/java/com/github/drinkjava2/frog/brain/organ/Pain.java +++ /dev/null @@ -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.Application; -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.Cell; -import com.github.drinkjava2.frog.brain.Input; -import com.github.drinkjava2.frog.brain.Organ; - -/** - * Pain zone active after some bad thing happen like close to edge, hurt... - * - * 痛是一种惩罚,表示青蛙做错了什么,但是又不至严重到判其死亡的地步 - */ -public class Pain extends Organ { // Pain器官目前激活的条件是离边境20个单元之类,痛苦和快感是条件反射形成的前题 - - private static final long serialVersionUID = 1L; - - @Override - public void initFrog(Frog f) { - if (!initilized) { - initilized = true; - organOutputEnergy = 5; - } - } - - @Override - public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来 - if (!Application.SHOW_FIRST_FROG_BRAIN) - return; - if (Env.closeToEdge(f)) { - pic.fillZone(this); - } else { - pic.setColor(Color.white); - pic.fillZone(this); - pic.setColor(Color.BLACK); - pic.drawZone(this); - } - if (this.name != null) - pic.drawText(this, String.valueOf(this.name)); - } - - @Override - public void active(Frog f) { - if (Env.closeToEdge(f)) {// 如果靠近边界,痛苦信号生成 - for (Cell cell : f.cells) { - if (cell.energy > 0) - cell.energy--; - if (cell.energy < Cell.MAX_ENERGY_LIMIT) - for (Input input : cell.inputs) - if (input.nearby(this)) // if input zone nearby this zone - cell.energy += organOutputEnergy; - } - } - } - -} diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/egg/Egg.java b/core3d/src/main/java/com/github/drinkjava2/frog/egg/Egg.java index ac5128c..544bc71 100644 --- a/core3d/src/main/java/com/github/drinkjava2/frog/egg/Egg.java +++ b/core3d/src/main/java/com/github/drinkjava2/frog/egg/Egg.java @@ -17,18 +17,6 @@ import java.util.List; import com.github.drinkjava2.frog.Frog; import com.github.drinkjava2.frog.brain.Organ; import com.github.drinkjava2.frog.brain.group.Group; -import com.github.drinkjava2.frog.brain.organ.Active; -import com.github.drinkjava2.frog.brain.organ.Chance; -import com.github.drinkjava2.frog.brain.organ.Eat; -import com.github.drinkjava2.frog.brain.organ.Eye; -import com.github.drinkjava2.frog.brain.organ.Happy; -import com.github.drinkjava2.frog.brain.organ.Hungry; -import com.github.drinkjava2.frog.brain.organ.MoveDown; -import com.github.drinkjava2.frog.brain.organ.MoveLeft; -import com.github.drinkjava2.frog.brain.organ.MoveRight; -import com.github.drinkjava2.frog.brain.organ.MoveUp; -import com.github.drinkjava2.frog.brain.organ.NewEye; -import com.github.drinkjava2.frog.brain.organ.Pain; import com.github.drinkjava2.frog.util.RandomUtils; /** @@ -53,21 +41,7 @@ public class Egg implements Serializable { public List groups = new ArrayList<>(); public Egg() {// 无中生有,创建一个蛋,先有蛋,后有蛙 - organs.add(new Happy().setXYRN(600, 700, 60, "Happy")); // Happy必须第一个加入 - organs.add(new Hungry().setXYRN(300, 100, 60, "Hungry")); - organs.add(new MoveUp().setXYRN(800, 100, 60, "Up")); - organs.add(new MoveDown().setXYRN(800, 400, 60, "Down")); - organs.add(new MoveLeft().setXYRN(700, 250, 60, "Left")); - organs.add(new MoveRight().setXYRN(900, 250, 60, "Right")); - organs.add(new Eye().setXYRN(100, 300, 100, "Eye")); - organs.add(new NewEye().setXYRN(200, 700, 200, "NewEye")); - organs.add(new Pain().setXYRN(800, 700, 60, "Pain")); // 痛苦在靠近边界时触发 - organs.add(new Active().setXYRN(500, 100, 60, "Active")); // 永远激活 - organs.add(new Chance().setXYRN(650, 100, 60, "Chance")); // 永远激活 - - // 以上为11个, 就是FIXED_ORGAN_QTY值 - - organs.add(new Eat().setXYRN(0, 0, 0, "Eat")); // EAT不是感觉或输出器官,没有位置和大小 + } diff --git a/core3d/src/main/java/com/github/drinkjava2/frog/egg/EggTool.java b/core3d/src/main/java/com/github/drinkjava2/frog/egg/EggTool.java index e6a64ef..a96d539 100644 --- a/core3d/src/main/java/com/github/drinkjava2/frog/egg/EggTool.java +++ b/core3d/src/main/java/com/github/drinkjava2/frog/egg/EggTool.java @@ -22,8 +22,6 @@ import java.util.List; import com.github.drinkjava2.frog.Application; import com.github.drinkjava2.frog.Env; import com.github.drinkjava2.frog.Frog; -import com.github.drinkjava2.frog.brain.organ.Chance; -import com.github.drinkjava2.frog.brain.organ.Eye; import com.github.drinkjava2.frog.util.FrogFileUtils; /** @@ -54,8 +52,6 @@ public class EggTool { ObjectOutputStream so = new ObjectOutputStream(fo); so.writeObject(Env.eggs); so.close(); - System.out.print("\r1st frog has " + first.organs.size() + " organs, energy=" + first.energy + ", seeDist=" - + ((Eye) first.organs.get(6)).seeDistance + ", chance=" + ((Chance) first.organs.get(10)).percent); 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'"); } catch (IOException e) { diff --git a/eggs3d.ser b/eggs3d.ser new file mode 100644 index 0000000000000000000000000000000000000000..8efa45ade5622ec8089eff4acce57bb55db83aec GIT binary patch literal 1145 zcmZ4UmVvdnh(S0ju`E%qv?Mb}&#|Z|vC=2AxTK=-lI+amiF2757(E$SiZiQHD+(AG z7$nPCKqOF;QgVK-UV3IpMro2>N>OHBHpmboy|kkIbiLH{bUoMfbf8KQU}R!o@?l_0 zFUl`1C@x_T@ByjR2U({NvdJ1KmtT~gm{(lLP{+VrQ2?gFI>DAPRA3ii!Y+)Vaa0}l RfEo>#(QpCfxB*B96#&!}!{`72 literal 0 HcmV?d00001