Conway's Game of Life example

3 years ago by the_ocs to c/kotlin

I've had a long time fascination with Conway's Game of Life, and with the Sigbla APIs starting to stabilize I thought it would be fun to play around a bit and implement it as an example.

You can find the Conway example code here, and it should hopefully, even if you're unfamiliar with Sigbla, be fairly straight forward to understand.

It's using various core features, such as views, batching, transformers and cloning, with about 100 lines of code to get it all working. It's not really what I would envision Sigbla being used for, but it's a fun little example..

Conway's Game of Life in Sigbla

breadsmasher 4 points 3 years ago

interesting! Hadnt seen sigbla before - nice use.

Just curious,


// Add some logic to detect when we're stuck in a loop
boards.add(conway.map { true in it }.toList().hashCode())

… 

    if (boards.size < 5) {
        // Stuck in loop, add some randomness

What do you mean with stuck in a loop? Is it where the game reaches a state where its cycling continuously through the same variations repeatedly?

path: 0 8731029, hotness: undefined, score: 4, children: 1
the_ocs 2 points 3 years ago

Yep, exactly that.

path: 0 8731029 8731103, hotness: undefined, score: 2, children: 0
lthlnkso 2 points 3 years ago path: 0 8733791, hotness: undefined, score: 2, children: 0
kotlin
kotlin

@programming.dev

login for more options
808
109
11

Kotlin is a statically typed programming language for the JVM, Android, JavaScript, and native.

Subreddit rules:

  • Be civil
  • No spam
  • Stay on-topic
  • No fluff

Resources:

go to feed...