Esempio n. 1
0
    /**
     * #function DoubleBot::GetMove |
     * @author JavaComSci |
     * @desc gets the fit of a both block onboard |
     * @header public override List<Tuple<int, int>> GetMove(Board board, List<List<Block>> allBotBlocks, bool allRotations = false)  |
     * @param Board board: board to do placing on |
     * @param List<List<Block>> allBotBlocks: blocks to be placed|
     * @returns List<List<Tuple<int, int>>> : contains position for both blocks |
     */
    public override List <List <Tuple <int, int> > > GetMove(Board board, List <List <Block> > allBotBlocks, bool allRotations = false)
    {
        // get each of the bot's blocks
        List <Block> bot1Blocks = allBotBlocks[0];
        List <Block> bot2Blocks = allBotBlocks[1];

        // check to make sure that each block is valid
        bool blockValid1 = bot1Blocks[0].CheckValidity();

        // block is invalid
        if (!blockValid1)
        {
            throw new Exception("Shape formation is incorrect");
        }
        bool blockValid2 = bot2Blocks[0].CheckValidity();

        // block is invalid
        if (!blockValid2)
        {
            throw new Exception("Shape formation is incorrect");
        }

        // get the max height of each column of the baord
        board.FindMaxHeights();

        // print the information
        // Console.WriteLine("BOARD");
        botInfoPrinter.PrintMultiDimArr(board.board);
        // Console.WriteLine("PIECE 1 BOT 1");
        botInfoPrinter.PrintJaggedArr(bot1Blocks[0].data);
        // Console.WriteLine("PIECE 2 BOT 2");
        botInfoPrinter.PrintJaggedArr(bot2Blocks[0].data);


        // all orientations of the 2 blocks in each one going first on the board
        List <Tuple <Block, Block, int> > allOrientations = GetAllOrientations(bot1Blocks[0], bot2Blocks[0]);

        if (allOrientations == null)
        {
            return(null);
        }

        // Console.WriteLine("ALL ORIENTATIONS");
        botInfoPrinter.PrintAllOrientationsAsList(allOrientations);

        // get the best fit of blocks
        List <Tuple <CompatiblePiece, CompatiblePiece> > allCompatiblePieces = GetFitBothBlocks(board, allOrientations);

        if (allCompatiblePieces == null || allCompatiblePieces.Count == 0)
        {
            // Console.WriteLine("I AM RETURING WITH NO PIECES");
            return(null);
        }

        Tuple <CompatiblePiece, CompatiblePiece> bestPieces = GetBestFit(allCompatiblePieces);

        // Console.WriteLine("BEST FIETS " + bestPieces);
        if (bestPieces == null || bestPieces.Item1 == null || bestPieces.Item2 == null)
        {
            return(null);
        }

        // printing the info
        // Console.WriteLine("BEST COMPATIBLE PIECES ON BOARD");
        List <Tuple <CompatiblePiece, CompatiblePiece> > bestPiecesList = new List <Tuple <CompatiblePiece, CompatiblePiece> >();

        bestPiecesList.Add(bestPieces);
        botInfoPrinter.PrintAllCompatiblePieces(board.board, bestPiecesList);


        // return setup
        List <Tuple <int, int> >         compatiblePiece1 = bestPieces.Item1.locationOnBoard;
        List <Tuple <int, int> >         compatiblePiece2 = bestPieces.Item2.locationOnBoard;
        List <List <Tuple <int, int> > > allMoves         = new List <List <Tuple <int, int> > >();

        allMoves.Add(compatiblePiece1);
        allMoves.Add(compatiblePiece2);
        if (compatiblePiece1 == null || compatiblePiece2 == null)
        {
            return(null);
        }
        return(allMoves);
    }