Beispiel #1
0
        ////// END: hard ai functionality
        /////////////////////////////////////////////////////////////////

        /////////////////////////////////////////////////////////////////
        ////// START: very hard ai functionality
        #region very hard AI
        public void invokeVeryHardAI()
        {
            CandidateTilePos selectedPosCombo = calculateMoves(true, true, false);

            if (selectedPosCombo == null)   // [SC] no tiles to put on a board
            // [SC] dropping a random tile
            {
                setSelectedTile(playerTiles.getRandomElement());
                game.dropPlayerTile(playerIndex);
            }
            else if (getCanMove())
            {
                CandidateTileSeq tileSeq = selectedPosCombo.getCandidateTileSeq();
                int totalMoveCount       = selectedPosCombo.getComboLength();
                int currMoveCount        = 0;

                while (currMoveCount < totalMoveCount)
                {
                    AbstractPos abstrPos  = selectedPosCombo.getAbstrPosAt(currMoveCount);
                    int         rowIndex  = abstrPos.getRowIndex();
                    int         colIndex  = abstrPos.getColIndex();
                    int         tileIndex = abstrPos.getTileIndex();

                    TileZeroTile tile = tileSeq.getTileAt(tileIndex);

                    setSelectedTile(tile);

                    game.setSelectedCell(rowIndex, colIndex, playerIndex);

                    game.placePlayerTileOnBoard(playerIndex);

                    currMoveCount++;
                }
            }
        }
Beispiel #2
0
        /////////////////////////////////////////////////////////////////
        ////// START: A code for creating all possible permutations of board positions
        ////// of tiles in given list, starting from left-most tile in the array

        private void boardPosPermAddChildNodes(CandidateTileSeq candTileSeq, int currTileIndex, TreeNode parentNode, TileZeroTile[,] tileArray, VirtualBoard virtualBoard)
        {
            if (currTileIndex >= candTileSeq.getTileCount())
            {
                return;
            }

            TileZeroTile tile = candTileSeq.getTileAt(currTileIndex);

            for (int currRowIndex = 0; currRowIndex < tileArray.GetLength(0); currRowIndex++)
            {
                for (int currColIndex = 0; currColIndex < tileArray.GetLength(1); currColIndex++)
                {
                    int resultScore = virtualBoard.isValidMove(currRowIndex, currColIndex, tile, true, tileArray, false);

                    if (resultScore != Cfg.NONE)
                    {
                        TileZeroTile[,] newTileArray = Cfg.createBoardCopy(tileArray);
                        virtualBoard.addTile(currRowIndex, currColIndex, tile, false, newTileArray);
                        TreeNode childNode = parentNode.addChildNodeValue(new AbstractPos(currTileIndex, currRowIndex, currColIndex, resultScore));
                        boardPosPermAddChildNodes(candTileSeq, currTileIndex + 1, childNode, newTileArray, virtualBoard);
                    }
                }
            }

            boardPosPermAddChildNodes(candTileSeq, currTileIndex + 1, parentNode, tileArray, virtualBoard); // [SC][2016.12.08] new code
        }
Beispiel #3
0
 public bool isOrderedSubsetOf(CandidateTileSeq cts)
 {
     if (getTileCount() > cts.getTileCount())
     {
         return(false);
     }
     else
     {
         for (int tileIndex = 0; tileIndex < getTileCount(); tileIndex++)
         {
             if (!getTileAt(tileIndex).sameVisTile(cts.getTileAt(tileIndex)))
             {
                 return(false);
             }
         }
         return(true);
     }
 }