<commit_before>package tp.pr4.logic;

import tp.pr4.logic.Counter;

public class Board implements ReadOnlyBoard {
	private int width, 
				height, 
				occupiedCells;
	private boolean full;
	private Counter [][] board;
	
	// Constructor with two parameters for Board
	
	public Board(int tx, int ty) {
		this.width = tx; // Row
		this.height = ty;  // column
		
		if ((tx < 1) || (ty < 1)) { /* Creates a 1x1 board if dimensions are wrong */
			width = 1;
			height = 1;
		}
		board = new Counter[height][width];
		emptyCells(); // restart the board
		occupiedCells = 0;
	}

	// Getters and setters for private attributes
	
	public int getWidth() { return this.width; }
	public int getHeight() { return this.height; } 
	
	public Counter getPosition(int x, int y) {
		Counter color = Counter.EMPTY; 
		if ((x >= 1 && x <= width) && (y >= 1 && y <= height)) 
			color = board[y - 1][x - 1];
		return color;		
	}
	
	// Setters for private attributes

	public void setFull(Boolean full) {
		this.full = full; // indicates if a board is full or not.
	}
	
	public void emptyCells() {
		for (int y = 0; y < height; y++) 
			for (int x = 0; x < width; x++) 
				board[y][x] = Counter.EMPTY; // Reset the board with empty Cells
	}
		
	public void setPosition(int tx, int ty, Counter counter) {
		
		//DEBUG
		System.out.println("tx" + (tx-1));
		System.out.println("ty" + (ty-1));
		System.out.println("dimX" + width);
		System.out.println("dimY" + height);
		
		
		if ((tx >= 1 && tx <= width) && (ty >= 1 && ty <= height)) 
			if (board[tx-1][ty-1] == Counter.EMPTY && counter != Counter.EMPTY)
				occupiedCells++;
			else if (board[tx-1][ty-1] != Counter.EMPTY && counter == Counter.EMPTY)
				occupiedCells--;
			board[ty - 1][tx - 1] = counter;
	}
	
	// Methods for checking if a board neither column is full or not.
	
	public boolean isFull() {
		int boardDim = width * height; 
		return occupiedCells == boardDim;
	}
	
	public boolean isFullColumn(int Column) {
		int i = 1, j = Column;
		boolean fullColumn = true;

		while ((i <= height) && (fullColumn)) {
			if (getPosition(i, j) == Counter.EMPTY) {
				fullColumn = false;
			}			
			i++;
		}
		return fullColumn;
	}<commit_msg>No exceptions in connect4<commit_after>package tp.pr4.logic;

import tp.pr4.logic.Counter;

public class Board implements ReadOnlyBoard {
	private int width, 
				height, 
				occupiedCells;
	private boolean full;
	private Counter [][] board;
	
	// Constructor with two parameters for Board
	
	public Board(int tx, int ty) {
		this.width = tx; // Row
		this.height = ty;  // column
		
		if ((tx < 1) || (ty < 1)) { /* Creates a 1x1 board if dimensions are wrong */
			width = 1;
			height = 1;
		}
		board = new Counter[height][width];
		emptyCells(); // restart the board
		occupiedCells = 0;
	}

	// Getters and setters for private attributes
	
	public int getWidth() { return this.width; }
	public int getHeight() { return this.height; } 
	
	public Counter getPosition(int x, int y) {
		Counter color = Counter.EMPTY; 
		if ((x >= 1 && x <= width) && (y >= 1 && y <= height)) 
			color = board[y - 1][x - 1];
		return color;		
	}
	
	// Setters for private attributes

	public void setFull(Boolean full) {
		this.full = full; // indicates if a board is full or not.
	}
	
	public void emptyCells() {
		for (int y = 0; y < height; y++) 
			for (int x = 0; x < width; x++) 
				board[y][x] = Counter.EMPTY; // Reset the board with empty Cells
	}
		
	public void setPosition(int tx, int ty, Counter counter) {
		
		//DEBUG
		System.out.println("tx" + (tx));
		System.out.println("ty" + (ty));
		System.out.println("dimX" + width);
		System.out.println("dimY" + height);
		
		
		if ((tx >= 1 && tx <= width) && (ty >= 1 && ty <= height)) 
			if (board[ty-1][tx-1] == Counter.EMPTY && counter != Counter.EMPTY) {
				occupiedCells++;
				board[ty - 1][tx - 1] = counter;//cambiado x por y
			}
			else if (board[ty-1][tx-1] != Counter.EMPTY && counter == Counter.EMPTY) {
				occupiedCells--;
				board[ty - 1][tx - 1] = counter;//cambiado x por y
			}
	}
	
	// Methods for checking if a board neither column is full or not.
	
	public boolean isFull() {
		int boardDim = width * height; 
		return occupiedCells == boardDim;
	}
	
	public boolean isFullColumn(int Column) {
		int i = 1, j = Column;
		boolean fullColumn = true;

		while ((i <= height) && (fullColumn)) {
			if (getPosition(i, j) == Counter.EMPTY) {
				fullColumn = false;
			}			
			i++;
		}
		return fullColumn;
	}
{'fraction_non_alphanumeric': 0.14894571556751907, 'fraction_numerical': 0.011888739344997757, 'mean_word_length': 2.7981260647359454, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 11, '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': '5420745', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1488, 'n_words': 485}