Exemple #1
0
 public void ReplaceLetters(LetterRack rack)
 {
     for (int i = rack.Letters.Count; i < letterRackSize; i++)
     {
         rack.Letters.Add(GetRandomLetter());
     }
 }
Exemple #2
0
        public LetterRack GetInitialLetterRack()
        {
            LetterRack rack = new LetterRack()
            {
                Letters = new List <Letter>()
            };

            ReplaceLetters(rack);

            return(rack);
        }
Exemple #3
0
    public void OnClick()
    {
        LetterSlot letterSlot = transform.parent.GetComponent <LetterSlot>();

        if (letterSlot != null)
        {
            Debug.Log("Letter Slot => " + letterSlot.name);
            LetterRack letterRack = letterSlot.LetterRack;
            if (letterRack != null)
            {
                Debug.Log("Letter Rack => " + letterRack.name);
                letterRack.LetterButtonTapped(this);
            }
        }
    }
Exemple #4
0
        public List <List <Letter> > GenerateAllPossiblePermutations(LetterRack rack, int permutationLength)
        {
            HashSet <string>      usedWords         = new HashSet <string>();
            List <List <Letter> > permutations      = Permutate(rack.Letters, permutationLength);
            List <List <Letter> > finalPermutations = new List <List <Letter> >();

            foreach (var permutation in permutations)
            {
                string word = new string(permutation.Select(x => x.Character).ToArray());

                if (!usedWords.Contains(word))
                {
                    finalPermutations.Add(permutation);
                    usedWords.Add(word);
                }
            }

            return(finalPermutations);
        }
Exemple #5
0
        /// <summary>
        /// Calculates list of potential turns to make
        /// </summary>
        /// <param name="board"></param>
        /// <param name="rack"></param>
        /// <returns>The list of potential turns</returns>
        public async Task <List <PotentialTurn> > CalculateTurnAsync(GameBoard board, LetterRack rack, ProgressReport progress)
        {
            progress.TotalCells            = CountTotalFilledCells(board);
            progress.CellsChecked          = 0;
            progress.WordsChecked          = 0;
            progress.IsProgressInitialized = true;

            Dictionary <int, List <List <Letter> > > letterRackPermutations = new Dictionary <int, List <List <Letter> > >();

            // generate the list of potential turns for each possible length of string
            for (var length = 1; length <= rack.Letters.Count(); length++)
            {
                List <List <Letter> > words = letterRackLogic.GenerateAllPossiblePermutations(rack, length);

                letterRackPermutations.Add(length, words);
            }

            List <List <BoardCell> > columns = gameBoardLogic.GetColumnsFromRows(board);

            Task <List <PotentialTurn> > rowTurns    = CalculateTurnsForCellListsAsync(board.Cells, columns, letterRackPermutations, progress);
            Task <List <PotentialTurn> > columnTurns = CalculateTurnsForCellListsAsync(columns, board.Cells, letterRackPermutations, progress);

            List <PotentialTurn> potentialTurns = await rowTurns;

            potentialTurns.AddRange(await columnTurns);

            return(potentialTurns.OrderByDescending(x => x.Points).ToList());
        }