Beispiel #1
0
        ////// END: very easy ai functionality
        /////////////////////////////////////////////////////////////////

        /////////////////////////////////////////////////////////////////
        ////// START: easy ai functionality
        #region easy AI
        public void invokeEasyAI()
        {
            VirtualBoard virtualBoard = game.getVirtualBoard();
            int          rowCount     = virtualBoard.getRowCount();
            int          colCount     = virtualBoard.getColCount();

            // [SC] using copy since indices in playerTiles may change due to removed tiles
            List <TileZeroTile> tempPlayerTiles = playerTiles.listShallowClone();

            bool tilePlacedFlag = false;
            bool shouldDropFlag = true;

            foreach (TileZeroTile tile in tempPlayerTiles)
            {
                // [SC] check if the tile is playable
                if (!tile.getPlayable())
                {
                    continue;
                }

                // [SC] add some daly before making next move
                if (tilePlacedFlag)
                {
                    tilePlacedFlag = false;
                }

                for (int currRowIndex = 0; currRowIndex < rowCount && !tilePlacedFlag; currRowIndex++)
                {
                    for (int currColIndex = 0; currColIndex < colCount; currColIndex++)
                    {
                        int resultScore = virtualBoard.isValidMove(currRowIndex, currColIndex, tile, true, null, false);

                        if (resultScore != Cfg.NONE)
                        {
                            setSelectedTile(tile);
                            game.setSelectedCell(currRowIndex, currColIndex, playerIndex);
                            game.placePlayerTileOnBoard(playerIndex);
                            tilePlacedFlag = true;
                            shouldDropFlag = false;
                            break;
                        }
                    }
                }
            }

            if (shouldDropFlag)
            {
                // [SC] dropping a random tile
                setSelectedTile(playerTiles.getRandomElement());
                game.dropPlayerTile(playerIndex);
                //Cfg.showMsg(getPlayerName() + " dropped a tile.");
            }
        }
Beispiel #2
0
        // [2016.12.01]
        protected void putStartingTiles()
        {
            int startCol = virtualBoard.getColCount() / 2 - Cfg.START_TILE_COUNT / 2;
            int startRow = virtualBoard.getRowCount() / 2;

            for (int counter = 0; counter < Cfg.START_TILE_COUNT; counter++)
            {
                int          currCol = startCol + counter;
                TileZeroTile tile    = (TileZeroTile)tileBag.ElementAt(0);

                int result = putTileOnBoard(startRow, currCol, tile, false);

                // [TODO] need to terminate the game
                if (result == Cfg.NONE)
                {
                    Cfg.log("Error putting starting tiles");
                    break;
                }

                tileBag.Remove(tile);
                ++playedTileCount;
            }
        }