Skip to content

Commit

Permalink
Clean up and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
drandarov-io committed Dec 30, 2018
1 parent bc58fe2 commit e4c527e
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 12 deletions.
33 changes: 33 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
= Playground-Game-of-Life
Dmitrij Drandarov <https://github.com/dmitrij-drandarov>
:imagesdir: img

== Authors

* Dmitrij Drandarov | link:https://github.com/dmitrij-drandarov[image:github.png[20px, 20px]] | link:https://twitter.com/drandarov_io[image:twitter.png[20px, 20px]] | link:https://www.xing.com/profile/Dmitrij_Drandarov[image:xing.png[20px, 20px]] | link:https://www.linkedin.com/in/dmitrij-drandarov/[image:linkedin.png[20px, 20px]]

== Demo
=== Kotlin-Functional-Processing-3D
image:gol_3D.png[3D Visualization (above), seperate layers (below)]

== Variants

=== link:/java-functional/src/main/java/io/drandarov/gol[Java-Functional]

=== link:/java-functional-3d/src/main/java/io/drandarov/gol[Java-Functional-3D (no GUI)]

=== link:/kotlin-converted-from-java-functional/src/main/java/io/drandarov/gol[Kotlin converted-from-Java-Functional]

=== link:/kotlin-functional/src/main/java/io/drandarov/gol[Kotlin-Functional]

=== link:/kotlin-functional-processing/src/main/java/io/drandarov/gol[Kotlin-Functional-Processing (GUI)]

- Right Arrow: Step

=== link:/kotlin-functional-processing-3d/src/main/java/io/drandarov/gol[Kotlin-Functional-Processing-3D (GUI)]

- Right Arrow: Step
- W, S: Zoom
- A, D: Rotate
- Q, E: Change cube gaps
- C : Show/Hide coordinate lines
Binary file added img/github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/gol_3D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/linkedin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/twitter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/xing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.drandarov.gol.functional
package io.drandarov.gol

typealias World = List<List<List<Boolean>>>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.drandarov.gol.functional
package io.drandarov.gol

import processing.core.PApplet

Expand All @@ -18,6 +18,7 @@ class GoLDemo : PApplet() {
val sliceWidth = world.width * (size + gap) + sliceGap
var sliceWidthSum = sliceWidth * world.depth - sliceGap
val sliceHeightSum = world.height * (size + gap)
var showCoords = true

var size3D = 20f
var gap3D = 0f
Expand Down Expand Up @@ -66,6 +67,8 @@ class GoLDemo : PApplet() {
gap3D += 2f
if (key == 'q')
gap3D = max(0f, gap3D - 2f)
if (key == 'c')
showCoords = !showCoords
}

override fun mouseClicked() {
Expand Down Expand Up @@ -103,10 +106,13 @@ class GoLDemo : PApplet() {
(world.depth - 1) * (size3D + gap3D))
rotateY(rotation)

stroke(200f, 0f, 0f)
line(-200f, 0f, 0f, 200f, 0f, 0f)
line(0f, -200f, 0f, 0f, 200f, 0f)
line(0f, 0f, -200f, 0f, 0f, 200f)
if (showCoords) {
val l = 10f * size3D
stroke(l, 0f, 0f)
line(-l, 0f, 0f, l, 0f, 0f)
line(0f, -l, 0f, 0f, l, 0f)
line(0f, 0f, -l, 0f, 0f, l)
}

world.forEachIndexed { z, slice ->
slice.forEachIndexed { y, row ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.drandarov.gol

import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test

class GoLTest {

companion object {
private val testWorld: World = createWorld(10, 12, 5)
.flipAt(1, 0, 0)
.flipAt(2, 1, 0)
.flipAt(0, 2, 0)
.flipAt(1, 2, 0)
.flipAt(2, 2, 0)
.flipAt(9, 14, 0)
}

@Test
fun neighborCountTest() {
assertEquals(1, testWorld.neighbourCount(1, 0, 0))
assertEquals(3, testWorld.neighbourCount(2, 1, 0))
assertEquals(1, testWorld.neighbourCount(0, 2, 0))
assertEquals(3, testWorld.neighbourCount(1, 2, 0))
assertEquals(2, testWorld.neighbourCount(2, 2, 0))
assertEquals(0, testWorld.neighbourCount(9, 11, 0))
}

@Test
fun isAliveTest() {
assertTrue(testWorld.isAliveNeighbor(0, 0, 0, 1, 0, 0))
assertTrue(testWorld.isAliveNeighbor(1, 1, 0, 2, 1, 0))
assertTrue(testWorld.isAliveNeighbor(1, 1, 0, 1, 2, 0))

assertFalse(testWorld.isAliveNeighbor(1, 0, 0, 0, -1, 0))
assertFalse(testWorld.isAliveNeighbor(-100, 5, 0, -101, 6, 0))
}

@Test
fun flipAtTest() {
assertTrue(testWorld.flipAt(8, 8, 0).isAlive(8, 8, 0))

assertFalse(testWorld.flipAt(2, 2, 0).isAlive(2, 2, 0))
assertFalse(testWorld.flipAt(1, 80, 0).isAlive(1, 80, 0))
}

}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.drandarov.gol.functional
package io.drandarov.gol

typealias World = List<List<Boolean>>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.drandarov.gol.functional
package io.drandarov.gol

import processing.core.PApplet

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.drandarov.gol.functional
package io.drandarov.gol

import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeAll
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.drandarov.gol.functional
package io.drandarov.gol

typealias World = List<List<Boolean>>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.drandarov.gol.functional
package io.drandarov.gol

fun main(args: Array<String>) {
var world: World = createWorld(10, 15)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.drandarov.gol.functional
package io.drandarov.gol

import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeAll
Expand Down

0 comments on commit e4c527e

Please sign in to comment.