From 4a1c0fd63039ea0f88360d23436b7bae0e490b12 Mon Sep 17 00:00:00 2001 From: Yong Zhu Date: Sun, 24 Feb 2019 17:51:58 -0700 Subject: [PATCH] Work on first step --- core/.classpath | 11 --- core/.project | 14 ---- core/.settings/org.eclipse.jdt.core.prefs | 9 --- core/{frog_up.png => frog.png} | Bin core/frog_down.png | Bin 1347 -> 0 bytes core/frog_left.png | Bin 1351 -> 0 bytes core/frog_right.png | Bin 1350 -> 0 bytes .../github/drinkjava2/env/Application.java | 19 ++--- .../java/com/github/drinkjava2/env/Env.java | 57 +++++++++++---- .../java/com/github/drinkjava2/frog/Frog.java | 11 ++- .../java/com/github/drinkjava2/frog/Leg.java | 69 ------------------ .../com/github/drinkjava2/frog/Mouth.java | 27 ------- .../github/drinkjava2/frog/brain/Cell.java | 31 +++----- .../com/github/drinkjava2/frog/brain/Eye.java | 24 ------ .../github/drinkjava2/frog/brain/Gene.java | 24 ------ .../github/drinkjava2/frog/brain/Zone.java | 22 ------ core/src/main/resources/frog.jpg | Bin 2283 -> 0 bytes temp.txt | 17 +++++ 18 files changed, 83 insertions(+), 252 deletions(-) delete mode 100644 core/.classpath delete mode 100644 core/.project delete mode 100644 core/.settings/org.eclipse.jdt.core.prefs rename core/{frog_up.png => frog.png} (100%) delete mode 100644 core/frog_down.png delete mode 100644 core/frog_left.png delete mode 100644 core/frog_right.png delete mode 100644 core/src/main/java/com/github/drinkjava2/frog/Leg.java delete mode 100644 core/src/main/java/com/github/drinkjava2/frog/Mouth.java delete mode 100644 core/src/main/java/com/github/drinkjava2/frog/brain/Eye.java delete mode 100644 core/src/main/java/com/github/drinkjava2/frog/brain/Gene.java delete mode 100644 core/src/main/java/com/github/drinkjava2/frog/brain/Zone.java delete mode 100644 core/src/main/resources/frog.jpg create mode 100644 temp.txt diff --git a/core/.classpath b/core/.classpath deleted file mode 100644 index e4311e2..0000000 --- a/core/.classpath +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/core/.project b/core/.project deleted file mode 100644 index c237dfe..0000000 --- a/core/.project +++ /dev/null @@ -1,14 +0,0 @@ - - - frog - An artificial life test project. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. - - - - org.eclipse.jdt.core.javabuilder - - - - org.eclipse.jdt.core.javanature - - \ No newline at end of file diff --git a/core/.settings/org.eclipse.jdt.core.prefs b/core/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index beea4c9..0000000 --- a/core/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,9 +0,0 @@ -#Tue Feb 19 07:51:10 MST 2019 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -eclipse.preferences.version=1 -encoding/src/main/java=UTF-8 -org.eclipse.jdt.core.compiler.source=1.8 -encoding/src/test/resources=UTF-8 -encoding/src/main/resources=UTF-8 -encoding/src/test/java=UTF-8 -org.eclipse.jdt.core.compiler.compliance=1.8 diff --git a/core/frog_up.png b/core/frog.png similarity index 100% rename from core/frog_up.png rename to core/frog.png diff --git a/core/frog_down.png b/core/frog_down.png deleted file mode 100644 index 4fa1cd36e4c722ef8a1e2389b7aa6d27b19c1060..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1347 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyjKx9jPK-BC>eK@{oCO|{#S9F5 zM?jcysy3fA0|S#lfKP}kP;wNEh5$SSUOkq&0_1Ec3GxeO;MrJGwt?H~c+dY+OIcVq zEk0`=b@Sel@0>r6-n|{pBq}Bz`LbU@apJQG#=1WrKgT8h&X;RFyuxeAyOw3m?-%+? z+<)R=`_$)zq)<8En_>^ClQz59J_w3@+rQ`2nOUw~yVYuBc3SYh{bIIV|Et- z>3`Q9ODlZ5z&IPZ!6KiaBd1{tOoi6gjScQYpUW2+N`=s?iN|Ryy{0 zdFLu`J~OLhi<9x%4vmdRy}Y75eYCfp&DnZ)TKz`zM-O?N?Mr{nv&?_@z1H5i_`S`d z{~A{pEy`JVE#tq?>#nZ`Q!;v%9bKCCqWd&ggQ~{%h{WhsTa#~o;tF}z%D4RV)3`v^ zH8HMRs(2rK+!d?0T%Uc-+GiCTxL>PmmwRCGVa|i|jHZkW%9xv^&2#luuD-u%D`RQc zf_;YUQ%rMLFL_%aaxgDb=z)16du4f4QSUpa4D&$dS>Ho8{*3zeu6WVZjC$#&n|~Pi zW_7q6UbtaZ+P~&ohbJoYZM)1j_ldN1-=;Zzsj*?l1yfgNJd1gAO|o$FR&Mnt&95)& z+Dcn`USZbPu6ADTQ?%fF$=a-c@8>Rzu+%T9cV>lswpF6n*KubA^Dh%KSz&gdY_W*>VrN;AFFf~m`Ib*OWxsp(4)^bu z56@$FQC13MTYT#B+vCn=FHST`AKnqQu#hEX$FqqHtt`KjB`^F;S>(E~^W+R3jvKwF zDEAtl>irwdKI3jat@()LouAM4%|Fjr1WK5UWd%I>|vYD%K c=6_^8L$yz#Rb}6VQ=mld>FVdQ&MBb@0Q(Ag3;+NC diff --git a/core/frog_left.png b/core/frog_left.png deleted file mode 100644 index f4ea107d930e5a670711bbab7306ec6c96d30642..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1351 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyjKx9jPK-BC>eK@{oCO|{#S9F5 zM?jcysy3fA0|S#lfKP}kP;wNEh5$SSUOkq&0_1Ec3GxeO@cR6Jy9M*JJ^43xOR#8!iVW);{G4e&YxF*OtQbkEBWN3*mM@I-?b^< z!v%8r%3{{_zMXYA%1ZFszK)Z}YEJn&tcW~rAoSs756{`Hg|V{tHr@y=FIjTLebu|T z{-sIWEeg_koHEOPMK>#M@>u@ned5H$+fIiSFFaZxa@Y0tm4n^;ZTTC|$ItyTwXM%s z>Zx+m8Xf1fM|*dAnz=9smH^YWh^LEVNX4Ae$v?w`97T@nzwg#O#l2yY*CCOmPH(p+ z*eVP8W(1n(=3I2yaKh+TX7FYm-&?1@)o!l+DL(u7V_DfxcjceW*?Ir`nVHq^%R6=$ za2PzBSa;^MzJchX6Kl9TKI^)KMSo<9O?tRUNa=Ty&PC>Fi>9pYOD&kDtN(l{S9oCR z)Y)NcVwMWb%L@0^UB13;OPcP6yuD|mk8hJUb6PilZNAgg{LS^=%zqdwv?3M>9^$$1 z1!iHw3F>HSRTC^D6i4jjN7Y4s&;(+{iw0-QM3%{#qi^U<#PLd1W-*`}{ASroRUbcz`e=QSI%b}q zn3(5%=-!JthG(oJT+(I)v9N66+1OILEpbXk|3pU4A0GlgXc_p?kXexvXeK@{oCO|{#S9F5 zM?jcysy3fA0|S#lfKP}kP;wNEh5$SSUOkq&0_1Ec3GxeOFx&S3lc(6u+l70dF0pEHlQ*ev!~k_t@M!k#XUAr*6KC%=pqN)$PoFQa`{VhN+q28S3Wtr=3h zN4*v-I?JrWTH|p$JokRi`}jAhZIwwUUe@h=|9Rg1GsVx&>~(21 z^=_YZb4g_Jvqf8S;(pfX#-5kd>geIF;JwSTxphTR;#HrdrB{=jOW$2|jj$0;D8FKn zU0fAg%dA_dTdKcWd(-j6pIp~$;}V~0IppLV$}&|ra6GD*o5eory2Z6mZfkyP-@e7f zA=KIvvHxIiugEbqC2h0(o3q%r9X!4@|NV_d4|UeXD$HAo#mkPX*ve_@K4*~lCU8_B ztifdy_g$e0hvF8f=iWbl?suUBBcIY@V{eBWH5?W>wnEbz;#e)Jdfs0?DJNC%=ZNQ= zSK-Wm4rG>`I3W2^=c+}~^wtBGCcMw~E1iwIXXoO2pwdL!GDS~-*ZM!Jo|eO@`cA#> zk4g)~A9=`09GklOxnhglfpuJKKKSe`I}*C&ljKUDbW!>ifXtoOE==QozWcdgO5ax(6{)Tw1RA3k1w ze##s#-`#4VR;~NK-2PzdzU7g0=9Th492 frogs = new ArrayList(); public List foods = new ArrayList(); - public Env() { super(); this.setLayout(null);// 空布局 + this.setBounds(100, 100, XSIZE, YSIZE); Random rand = new Random(); for (int i = 0; i < frogAmount; i++) frogs.add(new Frog(rand.nextInt(Env.XSIZE - 3), rand.nextInt(Env.YSIZE - 3))); @@ -37,13 +38,43 @@ public class Env extends JPanel { foods.add(new Food(rand.nextInt(Env.XSIZE - 3), rand.nextInt(Env.YSIZE - 3))); } - @Override - public void paint(Graphics g) { - super.paint(g); - for (Frog frog : frogs) - frog.show(g); - for (Food food : foods) - food.show(g); + public void eatFoods() { + eating = true; + for (Frog frog : frogs) { + int j = foods.size() - 1; + for (int i = j; i >= 0; i--) { + Food food = foods.get(i); + if (frog.x == food.x && frog.y == food.y) + foods.remove(i); + } + } + eating = false; + } + + static boolean eating = true; + + public void run() throws InterruptedException { + Random r = new Random(); + int count = 0; + do { + count++; + for (Frog frog : frogs) { + frog.x += r.nextInt(3) - 1; + frog.y += r.nextInt(3) - 1; + } + eatFoods(); + if (count % 50 != 0) + continue; + Image buffImg = createImage(this.getWidth(), this.getHeight()); + Graphics g = buffImg.getGraphics(); + for (Frog frog : frogs) + frog.show(g); + for (Food food : foods) + food.show(g); + Graphics g2 = this.getGraphics(); + g2.drawImage(buffImg, 0, 0, this); + Thread.sleep(10); + } while (true); } } diff --git a/core/src/main/java/com/github/drinkjava2/frog/Frog.java b/core/src/main/java/com/github/drinkjava2/frog/Frog.java index 2ab530c..073e24d 100644 --- a/core/src/main/java/com/github/drinkjava2/frog/Frog.java +++ b/core/src/main/java/com/github/drinkjava2/frog/Frog.java @@ -19,7 +19,6 @@ import java.util.Random; import javax.imageio.ImageIO; import com.github.drinkjava2.frog.brain.Brain; -import com.github.drinkjava2.frog.brain.Eye; /** * Frog = brain + body(mouth, eye, leg) @@ -34,25 +33,25 @@ public class Frog { public int move = 0; // 0: stop 1:up 2:right 3:down 4:left 5:right turn 6 left turn public long energy = 10000; - static Image frog_up; + static Image frogImg; static { try { - frog_up = ImageIO.read(new FileInputStream(new File("").getAbsolutePath() + "/frog_up.png")); + frogImg = ImageIO.read(new FileInputStream(new File("").getAbsolutePath() + "/frog.png")); } catch (Exception e) { e.printStackTrace(); } } Brain brain; - Eye eye; public Frog(int x, int y) { this.x = x; this.y = y; } - public void show(Graphics g) { - g.drawImage(frog_up, x - 16, y - 16, 32, 32, null); + public void show(Graphics g) { + g.drawLine(x, y-2, x, y+2); + g.drawImage(frogImg, x - 16, y - 16, 32, 32, null); } } diff --git a/core/src/main/java/com/github/drinkjava2/frog/Leg.java b/core/src/main/java/com/github/drinkjava2/frog/Leg.java deleted file mode 100644 index 115b457..0000000 --- a/core/src/main/java/com/github/drinkjava2/frog/Leg.java +++ /dev/null @@ -1,69 +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; - -/** - * Leg of frog, frog only have 1 leg, Leg is a output device of frog , Leg's - * drive cells are located inside of brain - * - * Leg used to move frog, has 4 directions, i.e., have 4 output cells in brain - * - * @author Yong Zhu - * @since 1.0.0 - */ -public class Leg { - int up; - int down; - int left; - int right; - int stop; - - public int getUp() { - return up; - } - - public void setUp(int up) { - this.up = up; - } - - public int getDown() { - return down; - } - - public void setDown(int down) { - this.down = down; - } - - public int getLeft() { - return left; - } - - public void setLeft(int left) { - this.left = left; - } - - public int getRight() { - return right; - } - - public void setRight(int right) { - this.right = right; - } - - public int getStop() { - return stop; - } - - public void setStop(int stop) { - this.stop = stop; - } - -} diff --git a/core/src/main/java/com/github/drinkjava2/frog/Mouth.java b/core/src/main/java/com/github/drinkjava2/frog/Mouth.java deleted file mode 100644 index c2ab619..0000000 --- a/core/src/main/java/com/github/drinkjava2/frog/Mouth.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; - -/** - * Mouth of frog, Mouth is a output device of frog , mouth's input cells are - * located inside of brain - * - * @author Yong Zhu - * @since 1.0.0 - */ -public class Mouth { - /** - * when eat, cost 1 energy, if eat success, come cells in brain will active - */ - public void eat() { - } - -} diff --git a/core/src/main/java/com/github/drinkjava2/frog/brain/Cell.java b/core/src/main/java/com/github/drinkjava2/frog/brain/Cell.java index 57a095c..1d8b62a 100644 --- a/core/src/main/java/com/github/drinkjava2/frog/brain/Cell.java +++ b/core/src/main/java/com/github/drinkjava2/frog/brain/Cell.java @@ -10,29 +10,22 @@ */ package com.github.drinkjava2.frog.brain; -import java.util.List; - /** - * Cell represents a nerve cell, this is the basic unit of brain + * Cell represents a brain nerve cell, this is the basic unit of brain * * @author Yong Zhu * @since 1.0.0 */ public class Cell { - /** x location in brain */ - public int x = 0; - - /** y location in brain */ - public int y = 0; - - /** z location in brain */ - public int z = 0; - - public int active = 0; - - // cell type, 0:normal 1:xxx 2:xxx 3:xxx ... - public int type = 0; - - /** Connected other cells */ - List connects; + public int x; + public int y; + public int active; + public int drop; + public int inX; + public int inY; + public int inSize; + public int outX; + public int outY; + public int outSize; + public int fat; } diff --git a/core/src/main/java/com/github/drinkjava2/frog/brain/Eye.java b/core/src/main/java/com/github/drinkjava2/frog/brain/Eye.java deleted file mode 100644 index b08b678..0000000 --- a/core/src/main/java/com/github/drinkjava2/frog/brain/Eye.java +++ /dev/null @@ -1,24 +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; - -/** - * Eye of frog, each frog has 1 eye, eye is the input device of frog, eye's feel - * cells are located inside of brain - * - * @author Yong Zhu - * @since 1.0.0 - */ -public class Eye { - private int xSize = 30; - - private int ySize = 30; -} diff --git a/core/src/main/java/com/github/drinkjava2/frog/brain/Gene.java b/core/src/main/java/com/github/drinkjava2/frog/brain/Gene.java deleted file mode 100644 index 63d3069..0000000 --- a/core/src/main/java/com/github/drinkjava2/frog/brain/Gene.java +++ /dev/null @@ -1,24 +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; - -/** - * Gene is not a real thing, it represents the structure of brain, gene can be - * stored to file or database, used to build next generation. - * - * Gene is consisted by Zones. - * - * @author Yong Zhu - * @since 1.0.0 - */ -public class Gene { - -} diff --git a/core/src/main/java/com/github/drinkjava2/frog/brain/Zone.java b/core/src/main/java/com/github/drinkjava2/frog/brain/Zone.java deleted file mode 100644 index bdff58b..0000000 --- a/core/src/main/java/com/github/drinkjava2/frog/brain/Zone.java +++ /dev/null @@ -1,22 +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; - -/** - * Zone is not a real thing, it represents a kind of function zone in brain, may - * be consisted with same or bound of different cells - * - * @author Yong Zhu - * @since 1.0.0 - */ -public class Zone { - -} diff --git a/core/src/main/resources/frog.jpg b/core/src/main/resources/frog.jpg deleted file mode 100644 index 1b86c2ae3942ce6116a2d18f249a3c479b97055e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2283 zcmbV~c~p|=9>-q<1aS+uOs&Qx9TXy!v{j}u4Xx`?xujy_E+%^1$x*m!S?;N&M%Pet z$-3I;xQ|QbHkyq=<^s8ZWr;1g#9*Qf%*>fN=l*r?{XWm{Jm2@czvnsM&-1?0N$DK0 z&B=k_0DwRs;5*p>q&&d$B$XTl0B6ns<^TY|0Vo&*KxGajDnhffT?HsG=+qLRr?(v`rQt3|5eZg+gSwpd{IQ0D^>S7+M}v)Fk@Cj3TwH zlJm;o#>eY>w9m4HCf0sYDM|>P?YcYk_L!P|jWWmWx3N8N@X!hSlMarj2u|nDySll1 zT=4V{2n-4iA%{lC#Ky%_FDIm4xtezEdU{5F!OdHRMa8!n<@YKotE%tUJZSi_v8lPG zwXOY0Z(skw;Lk(D>=$D%$0sJII6VIR>o*H;-z^H3S60_Pi+&Zaf01*60Pr7Jf06wM z7gENhAo~Uon4Alw5HBk*5&|`}RMa>|g!x8l8d)X7wT|bN)%PeFTb~tb`$e%3Iwm;Y zo@F`O?_~cSSjzuJ_7~XSTpU0}_G2m_!AJlPY%({Sx+xJbT2D8ue3_ZWAAf|2*st4o zM_JW$%B*8-Zw0|*<;4h^<<&`>CHBy zE|eDqTeaov`tq)ttySd1_xun3qEr!B7U!DSQ8X$H%qiZVWP?vna4S%qxZapa4M>}Q z4ROT0Ol=EjYak=q30nDDIs8{=-VA-^^u@dz2#bB@B|1IUfqj^0vusnzbI}aZF(c#> zn>LQLXmZvq2Uw$8^&M9CAlVrmf$(_{!v@j%_1C$C8#m2%PpkOm0lG7BMB?YVbvWW&AF(HtzE=}5$FiD%9^3* zYL6vWo`J@R2ZR7<-=YCRPX{)VbISkQCFN%ZOw5uLfZ^0rUIa|7+99ZthwRO|x zwnLH$hFX`XHbVPze{n9cFs4~O8krr=-jOl7>s-{&noD>wYEYtOy1Jz_C4AazXVfgz znz3;~F2PQrzlu>F-&=Ns_mo)uYgZ2GJQOM z$vm`V$+@;YzK~IOZ71PuwsRE9wv$a~plK}QJ|6>dTauPr{q&?4>6hSUtJK&x`xIw~ z(0t34TbRyd4!*NLYP()q{k$3bL!uGK`IW%!QH^rRX{Y9z&@K=3aoTDmnFm0RdL8JG zVd`($OkX+_DbD1V_B}+)u~OYBX8Up=4N}jfVF{akRUUd$yI1v7x*36@vP(N71VX z+wCGT`AwUctsy2NcK1J}Ktp#g9xPbB;4PR@5mptI`8*AJFIpMB6s)Cz3mg9Tw+$MV zw+N5`a6hf=@n`c6+`JjJy1GD6%O2;x9TP>h*)ZM((Z-ndF1_kpM|*aR6iD~czSc(! zIoCPBwDR$uBzaojzo2c_oPW?hTtO$7HfT98QZaCqhTZI<&lPT=e%!oDgGkBDCtv_w3uJNC*PeeQ0tXdXM#1|lntBcD{CdFAmojUd?J&d-n zX=$l>cfL%iih1sFmkPZHEFo^hN>qg{eRO2vcg!b+Gw9~6$rmxELVlHIFYZy6-*6U$=|IpMZ*}NEq;_=?Q;u;UnPNr_Dt}W9u zjs%tq@H^L-YGkImaaw$r@QPHjMYybcN diff --git a/temp.txt b/temp.txt new file mode 100644 index 0000000..5ea9f2e --- /dev/null +++ b/temp.txt @@ -0,0 +1,17 @@ +Cell Ӿ extends Cell +int x x, y dzڹ̶ +int y Ԫͼε +int active +int last +int inputX +int inputY +int inSize ˶ extends Cell +int outputX x, y dzڹ̶ +int outputY ʹfrog˶ +int outSize +int fat + + + +һԪһ +Ԫfatֵ