From 2e9764cb452054d503a20f91eeaeea3c7d03a1c5 Mon Sep 17 00:00:00 2001 From: neumeiermo84285 Date: Fri, 17 Dec 2021 10:19:08 +0100 Subject: [PATCH] LifeTest first step passed --- .../GameOfLifeAssignment/Simulation.class | Bin 2659 -> 0 bytes src/Simulation.java | 113 ------------------ 2 files changed, 113 deletions(-) delete mode 100644 out/production/GameOfLifeAssignment/Simulation.class delete mode 100644 src/Simulation.java diff --git a/out/production/GameOfLifeAssignment/Simulation.class b/out/production/GameOfLifeAssignment/Simulation.class deleted file mode 100644 index 2229ce09949d0f338eab1661741e598e301d6414..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2659 zcma)8-%}G;6#j0q$tKG}Fc=gQ)K*Xk0ySEy0#=2hXb@X0R`Ca$WDN@;%Os0GW;*Rd zdFpc?I_*O(CS1KGXj+;h)8-*Wg`y*but4jgan~3u8Rg>ObZ*hiI|AVmt86)^1cE)ivr$A4RiWuGmlE}KjS@z)NidA-IoQi2I4@Z!qL4SY0hP~LQV!w_z@TNf9 zHpT+#iac6kw22TuW`^cPM!}&a9BW*v1(*!K*u275{MK{f-xMEg!D{K_D;&pjERi|RCOqtGtU8u&w zxTfJc=2YB})pApytB%|%-?f*_L5~2hfF_K*V^>JTmyM<48+uO98|6aDtafE>duerL zcq^m^&8CA_9;}$#m^Y&KT6(y5tBWzCRGP6IlkId{ARq=JAmD&VN068AkD2bta@nkm zm5gfDtg5&p(7grgb`Vr>ChYxhQ;rD_FMBt_P62}aaK!KlIY-<#X9nL9wi7F#&(oBO zw3N0T>1Pn>^h25{EVMU;On(6F1AoTYZZ=LBOI zr$l$|<-%Rb>jS)wedJ&I2W5qOx4uUrp4>oZa3q=j0nO`}h#!~=p6aBauA`f;cxNU# z@D-X5KSwt(^%xpgy4O2ctEaw^bG;Kaa5;u`@k);{wE?T}v6hYda#01VUehn9CuM-h*__!yz zP9Xdens^0W#RZWHzd-0uUL)je@!@CbNOG=8e925onXZ#8zfZv6qNKD=tX3mda|4l= zYVP%t*zCW04sP*$fS$Ylw`Yz}Kjz<%uZ4%q?E!2`sbz4uvF$7g+l7J3H7xl zkIugq8kX{?uYbaOypl^3B{&!YOnHn+*n>Vw{m5Vdqm1nWjxbpn9mMJV_rMJYw8*_Hfk4ao4ky7D^WINhCK zb&W8*QC7|A270?|p>)?m>GngB)e`0}2hqggF27E^V8jV}mz}mImoM%!l@LTpG(PxQy3YYkIl^t{wmvIL( zDB%h!w7t(WpI{E3;fBl2G2-jRB&~HOtOK|G?ux#~tKG^3{pxE5uZ^ zikFD;(<7Q9Eicf-F5^FI`!e45bNV@5%U;U-gvhnlNaPugW&1**4ZPDAcAu*I+`vf= zi&1`R?|L_S^>>@Y%wPyP0?#u9li-USM;1XWu^N|Ig|-W<-MbMV5WJkfhe*IU;|a1# gWlhhL9`LtY5Fb%{%YDwf&m5~(_Ozh)B0YEf0}zt*-v9sr diff --git a/src/Simulation.java b/src/Simulation.java deleted file mode 100644 index 299d91a..0000000 --- a/src/Simulation.java +++ /dev/null @@ -1,113 +0,0 @@ -public class Simulation { - - int width; - int height; - int[][] board; - - public Simulation(int width, int height) { - this.width = width; - this.height = height; - this.board = new int[width][height]; - } - - public void printBoard() { - System.out.println("---"); - for (int y = 0; y < height; y++) { - String line = "|"; - for (int x = 0; x < width; x++) { - if (this.board[x][y] == 0) { - line += "."; - } else { - line += "*"; - } - } - line += "|"; - System.out.println(line); - } - System.out.println("---\n"); - } - - public void setAlive(int x, int y) { - this.board[x][y] = 1; - } - - public void setDead(int x, int y) { - this.board[x][y] = 0; - } - - public int countAliveNeighbours(int x, int y) { - int count = 0; - - count += getState(x - 1, y - 1); - count += getState(x, y - 1); - count += getState(x + 1, y - 1); - - count += getState(x - 1, y); - count += getState(x + 1, y); - - count += getState(x - 1, y + 1); - count += getState(x, y + 1); - count += getState(x + 1, y + 1); - - return count; - } - - public int getState(int x, int y) { - if (x < 0 || x >= width) { - return 0; - } - - if (y < 0 || y >= height) { - return 0; - } - - return this.board[x][y]; - } - - public void step() { - int[][] newBoard = new int[width][height]; - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - int aliveNeighbours = countAliveNeighbours(x, y); - - if (getState(x, y) == 1) { - if (aliveNeighbours < 2) { - newBoard[x][y] = 0; - } else if (aliveNeighbours == 2 || aliveNeighbours == 3) { - newBoard[x][y] = 1; - } else if (aliveNeighbours > 3) { - newBoard[x][y] = 0; - } - } else { - if (aliveNeighbours == 3) { - newBoard[x][y] = 1; - } - } - - } - } - - this.board = newBoard; - } - - public static void main(String[] args) { - Simulation simulation = new Simulation(8, 5); - - simulation.setAlive(2, 2); - simulation.setAlive(3, 2); - simulation.setAlive(4, 2); - - simulation.printBoard(); - - simulation.step(); - - simulation.printBoard(); - - simulation.step(); - - simulation.printBoard(); - - } - -} \ No newline at end of file