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
        private void boardPosPermTraverseTreePaths(TreeNode rootNode, List <AbstractPos> currPath, CandidateTileSeq candTileSeq, int currScore, List <CandidateTilePos> maxScorePosComboList)
        {
            if (rootNode.hasChildNodes())
            {
                List <TreeNode> childNodes = rootNode.getChildNodes();
                foreach (TreeNode childNode in childNodes)
                {
                    List <AbstractPos> newPath = currPath.listShallowClone();
                    AbstractPos        pos     = (AbstractPos)childNode.getValue();
                    newPath.Add(pos);
                    boardPosPermTraverseTreePaths(childNode, newPath, candTileSeq, currScore + pos.getScore(), maxScorePosComboList);
                }
            }
            else   // [SC] reached the final leaf; no more moves in the combo
            {
                if (currScore > 0)
                {
                    CandidateTilePos newCandTilePos = new CandidateTilePos(candTileSeq, currPath, currScore);

                    if (maxScorePosComboList.Count == 0)
                    {
                        maxScorePosComboList.Add(newCandTilePos);
                    }
                    else if (maxScorePosComboList[0].getTotalScore() == currScore)
                    {
                        maxScorePosComboList.Add(newCandTilePos);
                    }
                    else if (maxScorePosComboList[0].getTotalScore() < currScore)
                    {
                        maxScorePosComboList.Clear();
                        maxScorePosComboList.Add(newCandTilePos);
                    }
                }
            }
        }
Beispiel #3
0
 public void addCandTilePos(CandidateTilePos candTilePos)
 {
     candTilePosList.Add(candTilePos);
 }