Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging wjl_derp into master #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions com/laboon/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ public State iterate(int numNeighbors) {
* @return Character representation of the cell's state
*/

public char getStateRep() {
char toReturn = ' ';
if (_state == State.DEAD) {
toReturn = '.';
} else if (_state == State.ALIVE) {
toReturn = '*';
} else {
toReturn = ' ';
public char getStateRep() {
char toReturn = ' ';
if (_state == State.DEAD) {
toReturn = ' ';
} else if (_state == State.ALIVE) {
toReturn = '*';
} else {
toReturn = ' ';
}
return toReturn;
}
return toReturn;
}
Expand Down
34 changes: 18 additions & 16 deletions com/laboon/JavaLife.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

public class JavaLife {

/**
* This is the main part.
*
* @param size Size of world
* @param seed Random number seed
* @param percent Percent of cells alive at beginning
* @param maxIterations Maximum number of iterations
*/
/**
*
* @param size Size of a world
* @param seed Random number seed for RNG
* @param percent Percent of cells alive at beginning
* @param maxIterations Maximum number of iterations
*/

public JavaLife(int size, int seed, int percent, int maxIterations) {
World w = new World(size, seed, percent);
System.out.println("Initial Configuration:");
System.out.println(w.toString());
for (int j=0; j < maxIterations; j++) {
w = w.iterate();
System.out.println("Iteration " + (j + 1) + ":");
System.out.println(w.toString());
public JavaLife(int size, int seed, int percent, int maxIterations) {
World w = new World(size, seed, percent);
System.out.println("Initial Configuration:");
System.out.println( w.toString() );
for (int j=0; j < maxIterations; j++) {
w = w.iterate();
System.out.println("Iteration " + (j + 1) + ":");
System.out.println(w.toString());
}


}

}
Expand Down
41 changes: 21 additions & 20 deletions com/laboon/World.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.laboon;

import java.util.Random;
import java.lang.StringBuilder;

public class World {

Expand Down Expand Up @@ -109,26 +110,26 @@ public World iterate() {
return new World(newCells, _rng);
}

/**
* Convert this World to a string for display.
* @return String representation of world
*/

public String toString() {
String toReturn = " ";
for (int j= 0; j < _size; j++) {
toReturn += String.valueOf(j % 10);
}
toReturn += "\n";
for (int j = 0; j < _size; j++ ) {
toReturn += String.valueOf(j % 10) + " ";
for (int k = 0; k < _size; k++) {
toReturn += (_world[j][k].getStateRep());
}
toReturn += "\n";
}
return toReturn;
}
/**
* Convert this World to a string for display.
* @return String representation of world
*/

public String toString() {
StringBuilder toReturn = new StringBuilder(" ");
for (int j= 0; j < _size; j++) {
toReturn.append(String.valueOf(j % 10));
}
toReturn.append("\n");
for (int j = 0; j < _size; j++ ) {
toReturn.append(String.valueOf(j % 10) + " ");
for (int k = 0; k < _size; k++) {
toReturn.append(_world[j][k].getStateRep());
}
toReturn.append("\n");
}
return toReturn.toString();
}

/**
* Generate initial game board.
Expand Down