|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Life() { |
|
|
public Life() { |
|
|
//nukeAll(); |
|
|
|
|
|
|
|
|
nukeAll(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public Life(String[] setup) { |
|
|
public Life(String[] setup) { |
|
|
|
|
|
|
|
|
printTable(board); |
|
|
printTable(board); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void printTable(String[] board) { //works |
|
|
|
|
|
|
|
|
private void printTable(String[] board) { |
|
|
for(int i = 0; i < board.length; i++) System.out.println(Arrays.toString(new String[]{board[i]})); |
|
|
for(int i = 0; i < board.length; i++) System.out.println(Arrays.toString(new String[]{board[i]})); |
|
|
System.out.println("________"); |
|
|
System.out.println("________"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void setAlive(int x, int y) { //works |
|
|
|
|
|
|
|
|
public void setAlive(int x, int y) { |
|
|
// TODO Auto-generated method stub |
|
|
// TODO Auto-generated method stub |
|
|
board[y] = board[y].substring(0, x) + '*' + board[y].substring(x+1); |
|
|
board[y] = board[y].substring(0, x) + '*' + board[y].substring(x+1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void setDead(int x, int y) { //works |
|
|
|
|
|
|
|
|
public void setDead(int x, int y) { |
|
|
// TODO Auto-generated method stub |
|
|
// TODO Auto-generated method stub |
|
|
board[y] = board[y].substring(0, x) + ' ' + board[y].substring(x+1); |
|
|
board[y] = board[y].substring(0, x) + ' ' + board[y].substring(x+1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean isAlive(int x, int y) { //works |
|
|
|
|
|
//char c = ; |
|
|
|
|
|
if(board[y].charAt(x) == '*'){ //-->Befehl falsch immer false!!! |
|
|
|
|
|
|
|
|
public boolean isAlive(int x, int y) { |
|
|
|
|
|
if(board[y].charAt(x) == '*'){ |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
else{ |
|
|
else{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public ILife nextGeneration() { |
|
|
public ILife nextGeneration() { |
|
|
System.out.println("next Generation"); |
|
|
|
|
|
|
|
|
//Problem mehrere steps auf einmal da gesetzer * bei nachfolgendem durchlauf mitberücksichtigt wird |
|
|
int alive; |
|
|
int alive; |
|
|
|
|
|
String[] nextBoard = new String[]{ " ", |
|
|
|
|
|
" ", |
|
|
|
|
|
" ", |
|
|
|
|
|
" ", |
|
|
|
|
|
" " }; |
|
|
|
|
|
|
|
|
for (int y = 0; y < board.length; y++){ |
|
|
for (int y = 0; y < board.length; y++){ |
|
|
for (int x = 0; x < board[y].length(); x++){ |
|
|
for (int x = 0; x < board[y].length(); x++){ |
|
|
alive=aliveNeighbours(x,y); //Problem immer 0 |
|
|
|
|
|
|
|
|
alive=aliveNeighbours(x,y); |
|
|
|
|
|
|
|
|
|
|
|
//A new Cell is born |
|
|
if(!isAlive(x,y) && alive == 3) { |
|
|
if(!isAlive(x,y) && alive == 3) { |
|
|
setAlive(x, y); |
|
|
|
|
|
|
|
|
nextBoard[y] = nextBoard[y].substring(0, x) + '*' + nextBoard[y].substring(x+1); |
|
|
|
|
|
} |
|
|
|
|
|
//Cell is lonely and dies |
|
|
|
|
|
else if(isAlive(x,y) && alive < 2){ |
|
|
|
|
|
nextBoard[y] = nextBoard[y].substring(0, x) + ' ' + nextBoard[y].substring(x+1); |
|
|
|
|
|
} |
|
|
|
|
|
else{ |
|
|
|
|
|
nextBoard[y] = nextBoard[y].substring(0, x) + board[y].charAt(x) + nextBoard[y].substring(x+1); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
board = nextBoard; |
|
|
|
|
|
System.out.println("next Generation"); |
|
|
printTable(board); |
|
|
printTable(board); |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private int aliveNeighbours(int x, int y) { //-->Problem wahrscheinlich Befehl substring siehe isAlive |
|
|
|
|
|
|
|
|
private int aliveNeighbours(int x, int y) { |
|
|
int neighbours = 0; |
|
|
int neighbours = 0; |
|
|
|
|
|
|
|
|
if(x>0 && y>0){ |
|
|
if(x>0 && y>0){ |