Esempio n. 1
0
    /**
     * #function TripleBot::GetMove |
     * @author JavaComSci |
     * @desc gets the fit of a three 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)
    {
        try {
            CheckBlockValididty(allBotBlocks);
        } catch (Exception e) {
            throw e;
        }

        // get each of the bot's blocks
        List <Block> bot1Blocks = allBotBlocks[0];
        List <Block> bot2Blocks = allBotBlocks[1];
        List <Block> bot3Blocks = allBotBlocks[2];

        // 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 1 BOT 2");
        botInfoPrinter.PrintJaggedArr(bot2Blocks[0].data);
        Console.WriteLine("PIECE 1 BOT 3");
        botInfoPrinter.PrintJaggedArr(bot3Blocks[0].data);

        // get all the orientations
        List <Tuple <Block, Block, Block> > allOrientations = GenerateAllOrientations(allBotBlocks);

        if (allOrientations == null)
        {
            return(null);
        }
        // Console.WriteLine("ALL ORIENTATIONS");
        botInfoPrinter.PrintAllOrientationsThreeBlocksAsList(allOrientations);

        // get fit three blocks
        List <Tuple <CompatiblePiece, CompatiblePiece, CompatiblePiece> > allCompatiblePieces = GetFitThreeBlocks(board, allOrientations);

        if (allCompatiblePieces == null || allCompatiblePieces.Count == 0)
        {
            return(null);
        }
        Tuple <CompatiblePiece, CompatiblePiece, CompatiblePiece> bestPieces = GetBestFit(allCompatiblePieces);

        if (bestPieces == null || bestPieces.Item1 == null || bestPieces.Item2 == null || bestPieces.Item3 == null)
        {
            return(null);
        }

        // printing the info
        Console.WriteLine("BEST COMPATIBLE PIECES ON BOARD");
        List <Tuple <CompatiblePiece, CompatiblePiece, CompatiblePiece> > bestPiecesList = new List <Tuple <CompatiblePiece, 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 <Tuple <int, int> >         compatiblePiece3 = bestPieces.Item3.locationOnBoard;
        List <List <Tuple <int, int> > > allMoves         = new List <List <Tuple <int, int> > >();

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