Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
1 result

Target

Select target project
  • das.s/tp3
  • f19002502/tp3
  • r17010960/tp3
  • l19004806/tp3
  • y19010055/tp3
  • o18034026/tp3
  • z18029613/tp3
  • p19021289/tp3
  • d19027596/tp3
  • f18010428/tp3
  • f19003868/tp3
  • c19022214/tp3
  • c19017929/tp3
  • m16014784/tp3
  • a19028956/tp3
  • c19026071/tp3
  • h18008908/tp3
17 results
Select Git revision
  • master
1 result
Show changes
Commits on Source (3)
# Default ignored files
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="TP3" options="--add-exports jdk.compiler/com.sun.tools.doclint=ALL-UNNAMED" />
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/TP3.iml" filepath="$PROJECT_DIR$/TP3.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.*;
import static com.sun.tools.doclint.Entity.ne;
import static com.sun.tools.doclint.Entity.or;
/**
* {@code Grid} instances represent the grid in <i>The Game of Life</i>.
......@@ -98,29 +98,65 @@ public class Grid implements Iterable<Cell> {
}
private boolean[][] calculateNextStates() {
return null;
boolean[][] nextStates = new boolean[numberOfRows][numberOfColumns];
for (Cell cell : this) {
for (int i = 0; i == numberOfRows - 1; i++) {
for (int j = 0; j == numberOfColumns - 1; j++) {
nextStates[i][j] = calculateNextState(i, j, cell);
}
}
}
return nextStates;
}
private boolean calculateNextState(int rowIndex, int columnIndex, Cell cell) {
return false;
if (cell.isAlive()) {
return (countAliveNeighbours(rowIndex, columnIndex) == 2) || (countAliveNeighbours(rowIndex, columnIndex) == 3);
}
else return false;
}
private int countAliveNeighbours(int rowIndex, int columnIndex) {
return 0;
int aliveNeighbours = 0;
for (Cell cell : getNeighbours(rowIndex,columnIndex)) {
if (cell.isAlive()) {aliveNeighbours++;}
}
return aliveNeighbours;
}
private List<Cell> getNeighbours(int rowIndex, int columnIndex) {
return null;
List<Cell> neighbours = new ArrayList<>();
neighbours.add(getCell(rowIndex-1,columnIndex-1));
neighbours.add(getCell(rowIndex,columnIndex-1));
neighbours.add(getCell(rowIndex+1,columnIndex-1));
neighbours.add(getCell(rowIndex-1,columnIndex));
neighbours.add(getCell(rowIndex+1,columnIndex));
neighbours.add(getCell(rowIndex-1,columnIndex+1));
neighbours.add(getCell(rowIndex,columnIndex+1));
neighbours.add(getCell(rowIndex+1,columnIndex+1));
return neighbours;
}
private void goToNextState(boolean[][] nextState) {
for (Cell cell : this) {
for (int i = 0; i == numberOfRows - 1; i++) {
for (int j = 0; j == numberOfColumns - 1; j++) {
if (nextState[i][j]) {
cell.setAlive();
} else cell.setDead();
}
}
}
}
/**
* Sets all {@link Cell}s in this {@code Grid} as dead.
*/
void clear() {
for (Cell cell : this) {
cell.setDead();
}
}
/**
......@@ -131,6 +167,10 @@ public class Grid implements Iterable<Cell> {
*/
void randomGeneration(Random random) {
for (Cell cell : this) {
if (random.nextBoolean()) {cell.setAlive();}
else cell.setDead();
}
}
}
......@@ -3,7 +3,7 @@ import java.awt.*;
import javax.swing.*;
public class Main{
public static void main(String args[]) throws IOException {
public static void main(String[] args) throws IOException {
int NUMBER_OF_ROWS = 64;
int NUMBER_OF_COLUMNS = 64;
......
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file