package edu.wright.hendrix11.conway.logic;

/**
 * @author Joe Hendrix
 */
public class Cell {
    private boolean alive = false;
    private Cell northernCell;
    private Cell southernCell;
    private Cell easternCell;
    private Cell westernCell;

    public Cell() {
    }

    public Cell(boolean alive) {
        this.alive = alive;
    }

    public void setEasternCell(Cell easternCell) {
        easternCell.westernCell = this;
        this.easternCell = easternCell;
    }

    public void setNorthernCell(Cell northernCell) {
        northernCell.southernCell = this;
        this.northernCell = northernCell;
    }

    public void setSouthernCell(Cell southernCell) {
        southernCell.northernCell = this;
        this.southernCell = southernCell;
    }

    public void setWesternCell(Cell westernCell) {
        westernCell.easternCell = this;
        this.westernCell = westernCell;
    }

    public Cell getEasternCell() {
        return easternCell;
    }

    public Cell getNorthernCell() {
        return northernCell;
    }

    public Cell getSouthernCell() {
        return southernCell;
    }

    public Cell getWesternCell() {
        return westernCell;
    }

    public void toggle() {
        alive = !alive;
    }

    public boolean isAlive() {
        return alive;
    }

    public int getNumberLivingNeighbors() {
        int count = 0;
        
        count += countCardinalLivingNeighbors();
        count += countDiagonalLivingNeighbors();
        
        return count;
    }
    
    private int countNorthernDiagonalLivingNeighbors() {
        int count = 0;
        
        if(northernCell != null) {
            
            if(northernCell.easternCell != null && northernCell.easternCell.isAlive()) {
                count++;
            }
            
            if(northernCell.westernCell != null && northernCell.westernCell.isAlive()) {
                count++;
            }
            
        } else {
            
            if(easternCell != null && easternCell.northernCell != null && easternCell.northernCell.isAlive()) {
                count++;
            }
            
            if(westernCell != null && westernCell.northernCell != null && westernCell.northernCell.isAlive()) {
                count++;
            }
        }
        
        return count;
    }
    
    private int countSouthernDiagonalLivingNeighbors() {
        int count = 0;
        
        if(southernCell != null) {
            
            if(southernCell.easternCell != null && southernCell.easternCell.isAlive()) {
                count++;
            }
            
            if(southernCell.westernCell != null && southernCell.westernCell.isAlive()) {
                count++;
            }
            
        } else {
            
            if(easternCell != null && easternCell.southernCell != null && easternCell.southernCell.isAlive()) {
                count++;
            }
            
            if(westernCell != null && westernCell.southernCell != null && westernCell.southernCell.isAlive()) {
                count++;
            }
        }
        
        return count;
    }
    
    private int countDiagonalLivingNeighbors() {
        int count = 0;
        
        count += countNorthernDiagonalLivingNeighbors;
        count += countSouthernDiagonalLivingNeighbors;
        
        return count;
    }
    
    private int countCardinalLivingNeighbors() {
        int count = 0;

        if(northernCell != null && northernCell.isAlive()) {
            count++;
        }

        if(southernCell != null && southernCell.isAlive()) {
            count++;
        }

        if(easternCell != null && easternCell.isAlive()) {
            count++;
        }

        if(westernCell != null && westernCell.isAlive()) {
            count++;
        }

        return count;
    }

    @Override
    public int hashCode() {
        return alive ? 1 : 0;
    }

    @Override
    public boolean equals(Object o) {
        return this == o;
    }
}

@@ -1179,32 +1179,1392 @@
 sternCell;%0A    %7D
+%0A    %0A    public Cell getNorthEasternCell() %7B%0A        Cell northEasternCell = null;%0A        %0A        if(northernCell != null) %7B%0A            northEasternCell = northernCell.easternCell;%0A        %7D else if(easternCell != null) %7B%0A            northEasternCell = easternCell.northernCell;%0A        %7D%0A        %0A        return northEasternCell;%0A    %7D%0A    %0A    public Cell getNorthWesternCell() %7B%0A        Cell northWesternCell = null;%0A        %0A        if(northernCell != null) %7B%0A            northWesternCell = northernCell.westernCell;%0A        %7D else if(westernCell != null) %7B%0A            northWesternCell = westernCell.northernCell;%0A        %7D%0A        %0A        return northWesternCell;%0A    %7D%0A    %0A    public Cell getSouthEasternCell() %7B%0A        Cell southEasternCell = null;%0A        %0A        if(southernCell != null) %7B%0A            southEasternCell = southernCell.easternCell;%0A        %7D else if(easternCell != null) %7B%0A            southEasternCell = easternCell.southernCell;%0A        %7D%0A        %0A        return southEasternCell;%0A    %7D%0A    %0A    public Cell getSouthWesternCell() %7B%0A        Cell southWesternCell = null;%0A        %0A        if(southernCell != null) %7B%0A            southWesternCell = southernCell.westernCell;%0A        %7D else if(westernCell != null) %7B%0A            southWesternCell = westernCell.southernCell;%0A        %7D%0A        %0A        return southWesternCell;%0A    %7D
 %0A%0A    public voi

Update Cell.java