<commit_before>package ru.napadovskiuB.board;

import  ru.napadovskiuB.figure.*;

public class Board{
    private final Figure[][] board = new Figure[8][8];

    public Figure[][] getBoard(){
        return this.board;
    }

    /**
     *Method fills the board with pawns
     */
    public void fillPawn(boolean isWhite){
        int firstLine = 1;
        if(!isWhite){
            firstLine = 6;
        }
        for(int i=0; i<8; i++){
            Figure pawn = new Pawn(firstLine,i,isWhite);
            this.setFigureByPosition(pawn);
        }
    }

    /**
     *Method fills the board with figurs
     */
    public void fillFigure(boolean isWhite){
        int firstLine = 0;
        if(!isWhite){
            firstLine =7;
        }
        this.setFigureByPosition(new Rook(firstLine,0,isWhite));
        this.setFigureByPosition(new Rook(firstLine,7,isWhite));
        this.setFigureByPosition(new Horse(firstLine,1,isWhite));
        this.setFigureByPosition(new Horse(firstLine,6,isWhite));
        this.setFigureByPosition(new Elephant(firstLine,2,isWhite));
        this.setFigureByPosition(new Elephant(firstLine,5,isWhite));
        this.setFigureByPosition(new Queen(firstLine,3,isWhite));
        this.setFigureByPosition(new King(firstLine,4,isWhite));
    }

    /**
     *Method fills the board
     */
    public void fillBoard(boolean isWhite){
        this.fillPawn(isWhite);
        this.fillFigure(isWhite);
    }

    /**
     *Method return figure
     *@param y
     *@param x
     *@return figure
     */
    public Figure getFigureByPosition (int y, int x){
        return  this.board[y][x];
    }

    /**
     *Method clear position of the board
     *@param y
     *@param x
     */
    public void clearPosition(int y, int x){
        this.board[y][x] = null;
    }

    /**
     *Method sets the figure to the position of board
     *@param figure
     */
    public void setFigureByPosition(Figure figure){
        this.board[figure.getPositionY()][figure.getPositionX()] = figure;

    }

    /**
     *Method clears the position on the board
     *@param figure
     *@param positionY
     *@param positionX
     */
    private boolean occupiedCell(Figure figure, int positionY,int positionX){
        boolean result = true;
        if (!(figure instanceof Horse)){
            if(this.getFigureByPosition(positionY,positionX)!=null){
                result =false;
            }
        }
        return result;
    }

    /**
     *Method takes shape
     *@param newY
     *@param newX
     */
    private void takeShape(Figure newFigure, int newY, int newX){
        if(this.getFigureByPosition(newY,newX) !=null){
           if (newFigure.getColorFigure() != this.getFigureByPosition(newY,newX).getColorFigure()){
               clearPosition(newY,newX);
           }
        }
    }

    /**
     *Method checks the possibility of move
     *@param figure
     *@param newY
     *@param newX
     */
    private boolean canMoveFigure(Figure figure,int newY, int newX){
        boolean result = false;
        Position[] allAvailableMoves = figure.getAvailableMoves();
        for (int i=0; i < allAvailableMoves.length; i++){
            if (allAvailableMoves[i] == null){
                continue;
            }
            if(!occupiedCell(figure,allAvailableMoves[i].getPositionY(),allAvailableMoves[i].getPositionX())){
                result =false;
                break;
            }
            if (allAvailableMoves[i].getPositionY() == newY && allAvailableMoves[i].getPositionX() == newX){
                result=true;
                break;
            }
        }
        return result;
    }

    /**
     *Method move figure on the board
     *@param figure
     *@param newPositionY
     *@param newPositionX
     */<commit_msg>add new method check color<commit_after>package ru.napadovskiuB.board;

import  ru.napadovskiuB.figure.*;

public class Board{
    private final Figure[][] board = new Figure[8][8];

    public Figure[][] getBoard(){
        return this.board;
    }

    /**
     *Method fills the board with pawns
     */
    public void fillPawn(boolean isWhite){
        int firstLine = 1;
        if(!isWhite){
            firstLine = 6;
        }
        for(int i=0; i<8; i++){
            Figure pawn = new Pawn(firstLine,i,isWhite);
            this.setFigureByPosition(pawn);
        }
    }

    /**
     *Method fills the board with figurs
     */
    public void fillFigure(boolean isWhite){
        int firstLine = 0;
        if(!isWhite){
            firstLine =7;
        }
        this.setFigureByPosition(new Rook(firstLine,0,isWhite));
        this.setFigureByPosition(new Rook(firstLine,7,isWhite));
        this.setFigureByPosition(new Horse(firstLine,1,isWhite));
        this.setFigureByPosition(new Horse(firstLine,6,isWhite));
        this.setFigureByPosition(new Elephant(firstLine,2,isWhite));
        this.setFigureByPosition(new Elephant(firstLine,5,isWhite));
        this.setFigureByPosition(new Queen(firstLine,3,isWhite));
        this.setFigureByPosition(new King(firstLine,4,isWhite));
    }

    /**
     *Method fills the board
     */
    public void fillBoard(boolean isWhite){
        this.fillPawn(isWhite);
        this.fillFigure(isWhite);
    }

    /**
     *Method return figure
     *@param y
     *@param x
     *@return figure
     */
    public Figure getFigureByPosition (int y, int x){
        return  this.board[y][x];
    }

    /**
     *Method clear position of the board
     *@param y
     *@param x
     */
    public void clearPosition(int y, int x){
        this.board[y][x] = null;
    }

    /**
     *Method sets the figure to the position of board
     *@param figure
     */
    public void setFigureByPosition(Figure figure){
        this.board[figure.getPositionY()][figure.getPositionX()] = figure;

    }

    /**
     *Method clears the position on the board
     *@param figure
     *@param positionY
     *@param positionX
     */
    private boolean occupiedCell(Figure figure, int positionY,int positionX){
        boolean result = true;
        if (!(figure instanceof Horse)){
            if(this.getFigureByPosition(positionY,positionX)!=null){
                result =false;
            }
        }
        return result;
    }

    /**
     *Method takes shape
     *@param newY
     *@param newX
     */
    private void takeShape(Figure newFigure, int newY, int newX){
        if(this.getFigureByPosition(newY,newX) !=null){
           if (newFigure.getColorFigure() != this.getFigureByPosition(newY,newX).getColorFigure()){
               clearPosition(newY,newX);
           }
        }
    }


    /**
     *Method chek color of figure on the new position
     *@param figure
     *@param y
     *@param x
     */

    private boolean checkNewPosition(Figure figure, int y,int x){
        boolean result = false;
        if (this.getFigureByPosition(y,x)!=null && figure.getColorFigure() != this.getFigureByPosition(y,x).getColorFigure()){
            result = true;
        }
        return result;
    }

    /**
     *Method checks the possibility of move
     *@param figure
     *@param newY
     *@param newX
     */
    private boolean canMoveFigure(Figure figure,int newY, int newX){
        boolean result = false;
        Position[] allAvailableMoves = figure.getAvailableMoves();
        if (checkNewPosition(figure,newY,newX)) {

            for (int i = 0; i < allAvailableMoves.length; i++) {
                if (allAvailableMoves[i] == null) {
                    continue;
                }
                if (!occupiedCell(figure, allAvailableMoves[i].getPositionY(), allAvailableMoves[i].getPositionX())) {
                    result = false;
                    break;
                }

                if (allAvailableMoves[i].getPositionY() == newY && allAvailableMoves[i].getPositionX() == newX) {
                    result = true;
                    break;
                }
            }
        }
        return result;
    }

    /**
     *Method move figure on the board
     *@param figure
     *@param newPositionY
     *@param newPositionX
     */
{'fraction_non_alphanumeric': 0.11307550644567219, 'fraction_numerical': 0.004174340085942296, 'mean_word_length': 2.0463724756918475, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '1686861', 'n_tokens_mistral': 2427, 'n_tokens_neox': 2360, 'n_words': 546}