package bagaturchess.bitboard.bughouse;


import bagaturchess.bitboard.impl1.BoardImpl;

import java.util.ArrayList;


public class BughousePositionsBuilder {

    /*

    Used primarily for generating FEN positions that represent bughouse moves. Since said positions is just manipulating
    with the FEN string, its all the builder needs to do.

    */


    final String[] first = {" "};
    final String[] second = {"1 ", " 1"};
    final String[] third = {"1 1", "2 ", " 2"};
    final String[] fourth = {"2 1", "1 2", "3 ", " 3"};
    final String[] fifth = {"3 1", "2 2", "1 3", "4 ", " 4"};
    final String[] sixth = {"4 1", "3 2", "1 4", "2 3", "5 ", " 5"};
    final String[] seventh = {"5 1", "4 2", "3 3", "1 5", "2 4", "6 ", " 6"};
    final String[] eight = {"6 1", "5 2", "4 3", "3 4", "2 5", "1 6", "7 ", " 7"};

    public BughousePositionsBuilder() {
    }

    public ArrayList<String> getBughouseDropMovesVariants(int number, char piece) {
        switch(number) {
            case 1:
                return buildPositions(first, piece);
            case 2:
                return buildPositions(second, piece);
            case 3:
                return buildPositions(third, piece);
            case 4:
                return buildPositions(fourth, piece);
            case 5:
                return buildPositions(fifth, piece);
            case 6:
                return buildPositions(sixth, piece);
            case 7:
                return buildPositions(seventh, piece);
            case 8:
                return buildPositions(eight, piece);
            default:
                return null;
        }
    }

    private ArrayList<String> buildPositions(String[] first, char piece) {
        ArrayList<String> result = new ArrayList<>();
        for (String current: first) {
            result.add(current.replace(' ', piece));
        }
        return result;
    }

    public boolean isCurrentPositionInCheck(String positionFEN) {
        BoardImpl currentBoard = new BoardImpl(positionFEN, null);
        return currentBoard.isInCheck();
    }

    public boolean isEndgame(String currentEvaluatedPosition) {
        BoardImpl currentBoard = new BoardImpl(currentEvaluatedPosition, null);
        if (currentBoard.isInCheck()) {
            if (!currentBoard.hasMoveInCheck()) {
                //Mate
                return true;
            }
        }
        return false;
    }

}
