///////////////////////////////////////////////////////////////// ////// 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 }
////// 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."); } }