<commit_before>import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by GozdeDogan on 14.11.2016.
 * Implemented by YasinTulumen on 14.11.2016
 *
 */
public class King extends Pieces {
    @Override
    public List<Cell> checkMove(ArrayList<ArrayList<Cell>> board, int x, int y) {
        List<Cell> moves = new LinkedList<>();
        int i, j;
        //Ilk olarak secili tasin rengini kiyaslama yapmak icin tutuyorum
        boolean curColor = board.get(x).get(y).getPiece().getColor() ;

        //Sol tarafina dogru hareket edebilirligine bakarak gidiyorum. Ilk bakacagim
        //yer olarak i ye x-1 atadim. Yani tasin hemen soluna bakicam ilk
        i = x-1;
        if(i >= 0){
            //Eger tasin solu bos ise moves listeme ekleyerek devam ederim
            if(board.get(i).get(y).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(i).get(y)));
            }
            //Eger bi tas varsa ve ayni renk deilse yiyebilecegim icin move listesine ekliyorum
            else if(board.get(i).get(y).getPiece().getColor() != curColor){
                moves.add(new Cell(board.get(i).get(y)));
            }
        }
        j = y-1;
        if((i>= 0) && (j >= 0)){
            //Eger tasin solu bos ise moves listeme ekleyerek devam ederim
            if(board.get(i).get(j).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(i).get(j)));
            }
            //Eger bi tas varsa ve ayni renk deilse yiyebilecegim icin move listesine ekliyorum
            //fakat yemekten oteye gecemedigimden hemen ardindan dongumu sonlandiriyorum
            else if(board.get(i).get(j).getPiece().getColor() != curColor){
                moves.add(new Cell(board.get(i).get(j)));
            }
        }
        //Ayni islemleri saga dogru bakiyorum
        i = x+1;
        if(i <= 7){
            if(board.get(i).get(y).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(i).get(y)));
            }
            else if(board.get(i).get(y).getPiece().getColor() != curColor){
                moves.add(new Cell(board.get(i).get(y)));
            }
        }
        //Ayni islemleri sag alta dogru bakiyorum
        j = y-1;
        if((i <= 7) && (j >= 0)){
            if(board.get(i).get(j).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(i).get(j)));
            }
            else if(board.get(i).get(j).getPiece().getColor() != curColor) {
                moves.add(new Cell(board.get(i).get(j)));
            }
        }
        //Asagiya ve
        if(j >= 0){
            if(board.get(x).get(j).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(x).get(j)));
            }
            else if(board.get(x).get(j).getPiece().getColor() != curColor){
                moves.add(new Cell(board.get(x).get(j)));
            }
        }

        //Sag uste ve
        j = y+1;
        if((i <= 7) && (j <= 7)){
            if(board.get(i).get(j).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(i).get(j)));
            }
            else if(board.get(i).get(j).getPiece().getColor() != curColor){
                moves.add(new Cell(board.get(i).get(j)));
            }
        }
        //Yukariya dogru da ayni islemler gecerli
        if(j <= 7){
            if(board.get(x).get(j).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(x).get(j)));
            }
            else if(board.get(i).get(y).getPiece().getColor() != curColor){
                moves.add(new Cell(board.get(x).get(j)));
            }
        }
        //Sol uste dogru da ayni islemler gecerli
        i = x-1;
        if((i >= 0) && (j <= 7)){
            if(board.get(i).get(j).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(i).get(j)));
            }
            else if(board.get(i).get(j).getPiece().getColor() != curColor){
                moves.add(new Cell(board.get(i).get(j)));
            }
        }
        //Kalenin her yone dogru oynayabilecegi hamleleri move listesine atadik ve donduruyoruz
        return moves;
    }

    public boolean inDanger(ArrayList<ArrayList<Cell>> board)
    {
        for (int i=0 ; i<7 ; ++i)
        {
            for (int j=0 ; j<7 ; ++j)
            {
                if (!(board.get(i).get(j).getPiece() instanceof NoPiece))
                {
                    if (getColor() != board.get(i).get(j).getPiece().getColor())
                    {
                        List<Cell> moves = new LinkedList<>();

                        moves = board.get(i).get(j).getPiece().checkMove(board,i,j);

<<<<<<< HEAD
                        if(kingInList(moves))
=======
                        if(true)
>>>>>>> master
                        {
                            return true;
                        }
                    }
                }
            }
        }

        return false;
    }

    public boolean kingInList(List<Cell> moves)
    {
        for (int i=0 ; i<moves.size() ; ++i)
        {
            if(moves.get(i).getPiece() instanceof King)<commit_msg>Fixed<commit_after>import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by GozdeDogan on 14.11.2016.
 * Implemented by YasinTulumen on 14.11.2016
 *
 */
public class King extends Pieces {
    @Override
    public List<Cell> checkMove(ArrayList<ArrayList<Cell>> board, int x, int y) {
        List<Cell> moves = new LinkedList<>();
        int i, j;
        //Ilk olarak secili tasin rengini kiyaslama yapmak icin tutuyorum
        boolean curColor = board.get(x).get(y).getPiece().getColor() ;

        //Sol tarafina dogru hareket edebilirligine bakarak gidiyorum. Ilk bakacagim
        //yer olarak i ye x-1 atadim. Yani tasin hemen soluna bakicam ilk
        i = x-1;
        if(i >= 0){
            //Eger tasin solu bos ise moves listeme ekleyerek devam ederim
            if(board.get(i).get(y).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(i).get(y)));
            }
            //Eger bi tas varsa ve ayni renk deilse yiyebilecegim icin move listesine ekliyorum
            else if(board.get(i).get(y).getPiece().getColor() != curColor){
                moves.add(new Cell(board.get(i).get(y)));
            }
        }
        j = y-1;
        if((i>= 0) && (j >= 0)){
            //Eger tasin solu bos ise moves listeme ekleyerek devam ederim
            if(board.get(i).get(j).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(i).get(j)));
            }
            //Eger bi tas varsa ve ayni renk deilse yiyebilecegim icin move listesine ekliyorum
            //fakat yemekten oteye gecemedigimden hemen ardindan dongumu sonlandiriyorum
            else if(board.get(i).get(j).getPiece().getColor() != curColor){
                moves.add(new Cell(board.get(i).get(j)));
            }
        }
        //Ayni islemleri saga dogru bakiyorum
        i = x+1;
        if(i <= 7){
            if(board.get(i).get(y).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(i).get(y)));
            }
            else if(board.get(i).get(y).getPiece().getColor() != curColor){
                moves.add(new Cell(board.get(i).get(y)));
            }
        }
        //Ayni islemleri sag alta dogru bakiyorum
        j = y-1;
        if((i <= 7) && (j >= 0)){
            if(board.get(i).get(j).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(i).get(j)));
            }
            else if(board.get(i).get(j).getPiece().getColor() != curColor) {
                moves.add(new Cell(board.get(i).get(j)));
            }
        }
        //Asagiya ve
        if(j >= 0){
            if(board.get(x).get(j).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(x).get(j)));
            }
            else if(board.get(x).get(j).getPiece().getColor() != curColor){
                moves.add(new Cell(board.get(x).get(j)));
            }
        }

        //Sag uste ve
        j = y+1;
        if((i <= 7) && (j <= 7)){
            if(board.get(i).get(j).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(i).get(j)));
            }
            else if(board.get(i).get(j).getPiece().getColor() != curColor){
                moves.add(new Cell(board.get(i).get(j)));
            }
        }
        //Yukariya dogru da ayni islemler gecerli
        if(j <= 7){
            if(board.get(x).get(j).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(x).get(j)));
            }
            else if(board.get(i).get(y).getPiece().getColor() != curColor){
                moves.add(new Cell(board.get(x).get(j)));
            }
        }
        //Sol uste dogru da ayni islemler gecerli
        i = x-1;
        if((i >= 0) && (j <= 7)){
            if(board.get(i).get(j).getPiece() instanceof NoPiece){
                moves.add(new Cell(board.get(i).get(j)));
            }
            else if(board.get(i).get(j).getPiece().getColor() != curColor){
                moves.add(new Cell(board.get(i).get(j)));
            }
        }
        //Kalenin her yone dogru oynayabilecegi hamleleri move listesine atadik ve donduruyoruz
        return moves;
    }

    public boolean inDanger(ArrayList<ArrayList<Cell>> board)
    {
        for (int i=0 ; i<7 ; ++i)
        {
            for (int j=0 ; j<7 ; ++j)
            {
                if (!(board.get(i).get(j).getPiece() instanceof NoPiece))
                {
                    if (getColor() != board.get(i).get(j).getPiece().getColor())
                    {
                        List<Cell> moves = new LinkedList<>();

                        moves = board.get(i).get(j).getPiece().checkMove(board,i,j);

                        if(kingInList(moves))

                        {
                            return true;
                        }
                    }
                }
            }
        }

        return false;
    }

    public boolean kingInList(List<Cell> moves)
    {
        for (int i=0 ; i<moves.size() ; ++i)
        {
            if(moves.get(i).getPiece() instanceof King)
{'fraction_non_alphanumeric': 0.14955183164458302, 'fraction_numerical': 0.00779423226812159, 'mean_word_length': 1.5856423173803527, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 42, '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': '2302155', 'n_tokens_mistral': 3527, 'n_tokens_neox': 3426, 'n_words': 654}