<commit_before>package simulationObjects;

import controller.Grid;

/**
 * Patch that Simulates GameOfLife
 *
 * @author <NAME>
 *
 */
public class LifePatch extends Patch {

    // TODO Comment everything
    // Need to load this through the XML...
    // Edit from Constructor
    private int comfortableAmount = 3;
    private int baselineAmount = 2;

    public LifePatch() {
	super();
    }

    public LifePatch(int x, int y, Grid m) {
	super(x, y, m);

    }

    @Override
    public void prepareToUpdate() {
	processNeighborsAndUpdateState();
    }

    /**
     * Special rules for Game of Life
     */
    public void processNeighborsAndUpdateState() {
	int occupiedNeighbors = countNeighbors();

	if (occupiedNeighbors == comfortableAmount && isEmpty()) {
	    myState = State.GENERATING;
	} else if ((occupiedNeighbors > comfortableAmount || occupiedNeighbors < baselineAmount)
		&& !isEmpty()) {
	    myState = State.EMPTYING;
	}
    }

    public int countNeighbors() {
	int occupiedNeighbors = 0;
	for (Patch p : myNeighbors) {
	    if (!p.isEmpty()) {
		occupiedNeighbors++;
	    }
	}
	return occupiedNeighbors;
    }

    // TODO Update this
    // talk to Kevin about this switch
    // some duplicated code.
    @Override
    public void update() {
	// Update this
	switch (myState) {
	case OCCUPIED:
	    myCell.setFill(myCell.infoSheet.getColor("CELL"));
	    break;
	case GENERATING:
	    Cell generated = new LifeCell(xCoord, yCoord);
	    addCell(generated);
	    myState = State.OCCUPIED;
	    break;
	case EMPTYING:
	    removeCell();
	    break;
	default:
	    break;
	}
    }
}<commit_msg>enable toggle cell in game of life<commit_after>package simulationObjects;

import controller.Grid;

/**
 * Patch that Simulates GameOfLife
 *
 * @author <NAME>
 *
 */
public class LifePatch extends Patch {

    // TODO Comment everything
    // Need to load this through the XML...
    // Edit from Constructor
    private int comfortableAmount = 3;
    private int baselineAmount = 2;

    public LifePatch() {
	super();
    }

    public LifePatch(int x, int y, Grid m) {
	super(x, y, m);

    }

    @Override
    public void prepareToUpdate() {
	processNeighborsAndUpdateState();
    }

    /**
     * Special rules for Game of Life
     */
    public void processNeighborsAndUpdateState() {
	int occupiedNeighbors = countNeighbors();

	if (occupiedNeighbors == comfortableAmount && isEmpty()) {
	    myState = State.GENERATING;
	} else if ((occupiedNeighbors > comfortableAmount || occupiedNeighbors < baselineAmount)
		&& !isEmpty()) {
	    myState = State.EMPTYING;
	}
    }

    public int countNeighbors() {
	int occupiedNeighbors = 0;
	for (Patch p : myNeighbors) {
	    if (!p.isEmpty()) {
		occupiedNeighbors++;
	    }
	}
	return occupiedNeighbors;
    }

    // TODO Update this
    // talk to Kevin about this switch
    // some duplicated code.
    @Override
    public void update() {
	// Update this
	switch (myState) {
	case OCCUPIED:
	    myCell.setFill(myCell.infoSheet.getColor("CELL"));
	    break;
	case GENERATING:
	    Cell generated = new LifeCell(xCoord, yCoord);
	    addCell(generated);
	    myState = State.OCCUPIED;
	    break;
	case EMPTYING:
	    removeCell();
	    break;
	default:
	    break;
	}
    }
    
    @Override
    public void toggleCellState() {
	switch (myState){
	case OCCUPIED:
	    removeCell();
	    break;
	case EMPTY:
	    Cell generated = new LifeCell(xCoord, yCoord);
	    addCell(generated);
	    myState = State.OCCUPIED;
	    break;
	    
	}
    }
}
{'fraction_non_alphanumeric': 0.10805445263754963, 'fraction_numerical': 0.0017016449234259785, 'mean_word_length': 2.740190880169671, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2254644', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1095, 'n_words': 301}