@jlacar/

GoLCell

Java

Based on https://coderanch.com/t/80/700311/code-reviews/engineering/version-Conway-Game-Life

fork
loading
Files
  • Main.java

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.47933811281765015","path":"Main.java","file":{"path":"Main.java","content":{"asEncoding":{"base64":"Y2xhc3MgTWFpbiB7CiAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgc2hvd05leHQoQ2VsbC5ERUFEKTsKICAgIFN5c3RlbS5vdXQucHJpbnRsbigpOwogICAgc2hvd05leHQoQ2VsbC5BTElWRSk7CiAgfQoKICBwcml2YXRlIHN0YXRpYyB2b2lkIHNob3dOZXh0KENlbGwgY2VsbCkgewogICAgZm9yIChpbnQgaSA9IDA7IGkgPD0gODsgaSsrKSB7CiAgICAgIFN5c3RlbS5vdXQucHJpbnRmKCIlcy5uZXh0KCVkKSAtPiAlcyVuIiwgY2VsbCwgaSwgY2VsbC5uZXh0KGkpKTsKICAgIH0KICB9Cgp9CgplbnVtIENlbGwgewoKICAgIEFMSVZFIHsKICAgICAgQE92ZXJyaWRlIENlbGwgbmV4dChpbnQgbmVpZ2hib3JzKSB7CiAgICAgICAgcmV0dXJuIChuZWlnaGJvcnMgPT0gMiB8fCBuZWlnaGJvcnMgPT0gMykgCiAgICAgICAgICA/IHRoaXMgOiBERUFEOwogICAgICB9ICAKICAgIH0sIAogICAgCiAgICBERUFEIHsKICAgICAgQE92ZXJyaWRlIENlbGwgbmV4dChpbnQgbmVpZ2hib3JzKSB7CiAgICAgICAgcmV0dXJuIChuZWlnaGJvcnMgPT0gMykgPyBBTElWRSA6IHRoaXM7CiAgICAgIH0KICAgIH07CgogICAgYWJzdHJhY3QgQ2VsbCBuZXh0KGludCBuZWlnaGJvcnMpOwp9"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Main {
  public static void main(String[] args) {
    showNext(Cell.DEAD);
    System.out.println();
    showNext(Cell.ALIVE);
  }

  private static void showNext(Cell cell) {
    for (int i = 0; i <= 8; i++) {
      System.out.printf("%s.next(%d) -> %s%n", cell, i, cell.next(i));
    }
  }

}

enum Cell {

    ALIVE {
      @Override Cell next(int neighbors) {
        return (neighbors == 2 || neighbors == 3) 
          ? this : DEAD;
      }  
    }, 
    
    DEAD {
      @Override Cell next(int neighbors) {
        return (neighbors == 3) ? ALIVE : this;
      }
    };

    abstract Cell next(int neighbors);
}