private string GetNextWords(WordDirection direction) { StringBuilder sb = new StringBuilder(); if (direction == WordDirection.Forward) { startWord += clusterSize; if ((startWord + clusterSize) > words.Length) { startWord = 0; } } else if (direction == WordDirection.Reverse) { startWord -= clusterSize; if (startWord < 0) { startWord = words.Length - clusterSize; } } endWord = (startWord + clusterSize); for (int word = startWord; word < endWord; word++) { sb.Append(words[word]); sb.Append(" "); } return(sb.ToString()); }
private bool CheckCorrectWords(List <Letter> letters, WordDirection direction, List <Word> words) { foreach (var word in words) { if (word.IsComplete) { continue; } if (word.Direction != direction) { continue; } if (!letters.IsEqualTo(word.Letters)) { continue; } word.Complete(); FoundWords.Add(GetBounds(letters)); return(true); } return(false); }
private void SetWord(string word, Vector2Int position, WordDirection direction) { var currentPosition = position; foreach (var character in word) { var characterTile = GetTile(currentPosition); if (characterTile is null) { characterTile = Instantiate(characterTilePrefab, grid.transform); characterTile.name = $"{character.ToString().ToUpper()} [{currentPosition.x}|{currentPosition.y}]"; characterTile.Position = currentPosition; characterTile.transform.position = grid.CellToWorld((Vector3Int)currentPosition); _tiles.Add(characterTile); } else { if (characterTile.Character != character) { characterTile.PlayChangeCharacterAnimation(); } } characterTile.Character = character; currentPosition = direction == WordDirection.Vertical ? new Vector2Int(currentPosition.x, currentPosition.y - 1) : new Vector2Int(currentPosition.x + 1, currentPosition.y); } }
public SWord() { Name = ""; WordDirection = WordDirection.Vertical; X = 0; Y = 0; MatchCount = 0; LocationList = null; }
public SWord(SWord word, int matchCount) { Name = word.Name; WordDirection = word.WordDirection; X = word.X; Y = word.Y; MatchCount = matchCount; LocationList = word.LocationList; }
private Letter Next(Letter letter, WordDirection direction) { if (_location.ContainsKey(letter.transform.position + Next(direction))) { return(_location[letter.transform.position + Next(direction)]); } else { return(null); } }
string[] AddWord(WordDirection direction, string word, string[] result) { if (direction == WordDirection.Down) { return(AddWordDown(word, result)); } else { return(AddWordRight(word, result)); } }
// Itterates through board looking for potential letters where words can intersect private WordAndStartPositions FindWordAndPositions(int wordLength, WordDirection direction) { var startPosAttempts = 0; var word = String.Empty; var usedWords = new List <string>(_usedWords); var starPosList = new List <Tuple <int, int> > { }; var maxCounts = 25; // Attempt to find start positions while (startPosAttempts < maxCounts) { word = RetrieveWord(usedWords, wordLength); var wordCharCount = 0; // Attemps cycling through letters while (wordCharCount < word.Length) { var posList = CrosswordBoardMain.Instance().GetWordStartPositions(word, wordCharCount, direction); starPosList.AddRange(posList); wordCharCount++; } if (starPosList.Count > 0) { break; } usedWords.Add(word); startPosAttempts++; } // Return null of no position found if (starPosList.Count == 0) { Debug.WriteLine("____________failed to find startPos"); return(null); } var wordAndPosList = new WordAndStartPositions { StartPosList = new List <Tuple <int, int> >(starPosList), Word = word }; return(wordAndPosList); }
public bool IsNextTo(Letter letter, WordDirection wordDirection) { if (wordDirection == WordDirection.Horizontal) { return (Math.Abs(transform.position.x - (letter.transform.position.x + 1)) < 0.1f && Math.Abs(transform.position.y - letter.transform.position.y) < 0.1f); } else { return (Math.Abs(transform.position.x - letter.transform.position.x) < 0.1f && Math.Abs(transform.position.y - (letter.transform.position.y + 1)) < 0.1f); } }
public SWord(Word word) { Name = word.Name; WordDirection = word.Direction; X = (int)word.Letters[0].transform.position.x; Y = (int)word.Letters[0].transform.position.y; MatchCount = 0; LocationList = new List <Vector2>(); foreach (Letter letter in word.Letters) { LocationList.Add(letter.transform.position); } }
private bool IsStart(Letter letter, WordDirection direction) { // if next is empty return false if (!HasNextLetter(letter, direction)) { return(false); } if (!HasPreLetter(letter, direction)) { return(true); } return(!PreLetter(letter, direction).IsConnectedTo(letter)); }
// If word can be placed, it is public PlacedWord PlaceWord(string word, Tuple <int, int> startPos, WordDirection direction) { var canPlaceWord = CanWordBePlaced(word, startPos, direction); if (!canPlaceWord) { return(null); } else { BruteForcePlaceWord(word, startPos, direction); return(new PlacedWord { Word = word, StartPos = startPos, Direction = direction }); } }
// Check if word can be placed by doing horizontal and vertical checks public bool CanWordBePlaced(string word, Tuple <int, int> startPos, WordDirection direction) { if (startPos.Item1 < 0 || startPos.Item2 < 0) { return(false); } var wordLength = word.Length; // Scan word row and rows either side switch (direction) { case WordDirection.Horizontal: if (startPos.Item1 + wordLength > Width || startPos.Item2 >= Height) { return(false); } // Row (Actual Word) if (HorizontalWordScan(startPos, wordLength + 1, word, direction)) { return(false); } break; case WordDirection.Vertical: if (startPos.Item2 + wordLength > Height || startPos.Item1 >= Width) { return(false); } // Column (Actual Word) if (VerticalWordScan(startPos, wordLength + 1, word, direction)) { return(false); } break; } return(true); }
private List <List <Letter> > FindLettersList(Letter letter, WordDirection direction) { var lettersList = new List <List <Letter> >(); var letters = new List <Letter>(); while (letter != null) { letters.Add(letter); var next = Next(letter, direction); if (!letter.IsConnectedTo(next)) { lettersList.Add(new List <Letter>(letters)); } letter = next; } return(lettersList); }
// Is used to place word in grid arrays after checks have been done public void BruteForcePlaceWord(string word, Tuple <int, int> startPos, WordDirection direction) { var horizontalStart = startPos.Item1; var verticalStart = startPos.Item2; if (direction == WordDirection.Horizontal) { for (var i = horizontalStart; i < horizontalStart + word.Length; i++) { Board.Layout[startPos.Item2, i] = word[i - horizontalStart]; } } if (direction == WordDirection.Vertical) { for (var i = verticalStart; i < verticalStart + word.Length; i++) { Board.Layout[i, startPos.Item1] = word[i - verticalStart]; } } }
private void CheckErrorWords(List <Letter> letters, WordDirection direction, List <Word> words) { var charList = letters.Select(l => l.Char).ToList(); foreach (var word in words) { if (word.IsComplete) { continue; } if (word.Letters.Count != letters.Count) { continue; } if (!charList.IsEqualTo(word.Letters.Select(l => l.Char).ToList())) { continue; } FoundErrorWords.Add(GetBounds(letters)); } }
// Scan cells vertically and returns true if any cells are not empty, excludes the ignore cell private bool VerticalWordScan(Tuple <int, int> startPos, int length, string word, WordDirection direction) { var start = startPos.Item2; var end = start + length; for (var i = start; i < end; i++) { // Ignore if scan hits out of range cells if (i >= 0 && i < Height) { if (CheckVerticalIntersectionsAndPadding(i, startPos, word)) { return(true); } } } return(false); }
private static Vector3 Next(WordDirection direction) => direction == WordDirection.Horizontal ? Vector3.left : Vector3.down;
private bool HasNextLetter(Letter letter, WordDirection direction) { return(_location.ContainsKey(letter.transform.position + Next(direction))); }
// Sort placed words based on start postions. public List <PlacedWord> SortPlacedWordsByAxis(List <PlacedWord> placedWords, WordDirection direction) { var placedWordsSorted = new List <PlacedWord>(); // Sorted Horizontal or vertical if (direction == WordDirection.Horizontal) { placedWordsSorted = placedWords.Where(w => w.Direction == direction) .OrderBy(w => Convert.ToInt32(w.DefinitionIndex)).ToList(); } if (direction == WordDirection.Vertical) { placedWordsSorted = placedWords.Where(w => w.Direction == direction) .OrderBy(w => Convert.ToInt32(w.DefinitionIndex)).ToList(); } return(placedWordsSorted); }
private bool TryPlaceWord(string word, int i, int x, int y, WordDirection dir) { switch (dir) { case WordDirection.Down: if (y - i >= 0 && y + (word.Length - 1) - i < _h) { for (int j = 0; j < word.Length; j++) { if (_field[x + _w * (y - i + j)] != '\0' && _field[x + _w * (y - i + j)] != word[j]) { return(false); } } for (int j = 0; j < word.Length; j++) { _field[x + _w * (y - i + j)] = word[j]; } return(true); } break; case WordDirection.DownRight: if (y - i >= 0 && y + (word.Length - 1) - i < _h && x - i >= 0 && x + (word.Length - 1) - i < _w) { for (int j = 0; j < word.Length; j++) { if (_field[(x - i + j) + _w * (y - i + j)] != '\0' && _field[(x - i + j) + _w * (y - i + j)] != word[j]) { return(false); } } for (int j = 0; j < word.Length; j++) { _field[(x - i + j) + _w * (y - i + j)] = word[j]; } return(true); } break; case WordDirection.Right: if (x - i >= 0 && x + (word.Length - 1) - i < _w) { for (int j = 0; j < word.Length; j++) { if (_field[(x - i + j) + _w * y] != '\0' && _field[(x - i + j) + _w * y] != word[j]) { return(false); } } for (int j = 0; j < word.Length; j++) { _field[(x - i + j) + _w * y] = word[j]; } return(true); } break; case WordDirection.UpRight: if (y + i < _h && y - (word.Length - 1) + i >= 0 && x - i >= 0 && x + (word.Length - 1) - i < _w) { for (int j = 0; j < word.Length; j++) { if (_field[(x - i + j) + _w * (y + i - j)] != '\0' && _field[(x - i + j) + _w * (y + i - j)] != word[j]) { return(false); } } for (int j = 0; j < word.Length; j++) { _field[(x - i + j) + _w * (y + i - j)] = word[j]; } return(true); } break; case WordDirection.Up: if (y + i < _h && y - (word.Length - 1) + i >= 0) { for (int j = 0; j < word.Length; j++) { if (_field[x + _w * (y + i - j)] != '\0' && _field[x + _w * (y + i - j)] != word[j]) { return(false); } } for (int j = 0; j < word.Length; j++) { _field[x + _w * (y + i - j)] = word[j]; } return(true); } break; case WordDirection.UpLeft: if (y + i < _h && y - (word.Length - 1) + i >= 0 && x + i < _w && x - (word.Length - 1) + i >= 0) { for (int j = 0; j < word.Length; j++) { if (_field[(x + i - j) + _w * (y + i - j)] != '\0' && _field[(x + i - j) + _w * (y + i - j)] != word[j]) { return(false); } } for (int j = 0; j < word.Length; j++) { _field[(x + i - j) + _w * (y + i - j)] = word[j]; } return(true); } break; case WordDirection.Left: if (x + i < _w && x - (word.Length - 1) + i >= 0) { for (int j = 0; j < word.Length; j++) { if (_field[(x + i - j) + _w * y] != '\0' && _field[(x + i - j) + _w * y] != word[j]) { return(false); } } for (int j = 0; j < word.Length; j++) { _field[(x + i - j) + _w * y] = word[j]; } return(true); } break; case WordDirection.DownLeft: if (y - i >= 0 && y + (word.Length - 1) - i < _h && x + i < _w && x - (word.Length - 1) + i >= 0) { for (int j = 0; j < word.Length; j++) { if (_field[(x + i - j) + _w * (y - i + j)] != '\0' && _field[(x + i - j) + _w * (y - i + j)] != word[j]) { return(false); } } for (int j = 0; j < word.Length; j++) { _field[(x + i - j) + _w * (y - i + j)] = word[j]; } return(true); } break; } return(false); }
public PuzzleWord Copy() { return(new PuzzleWord(Word, ClueNumber, Clue, WordDirection.ToString(), StartColumn, StartRow)); }
public void SetWordPosition(SearchWord word, Vector2 position, WordDirection dir, SearchLetter[,] currentLetterArray) { int cordX; int cordY; switch (dir) { case WordDirection.Box: { int positionX = 16; foreach (SearchLetter l in word.Word) { l.Position = new Vector2(positionX, position.Y); positionX += 38; } break; } case WordDirection.Up: { cordX = BASE_POS_X + (int)position.X * POS_NEXT; cordY = BASE_POS_Y + (int)position.Y * POS_NEXT; for (int ii = 0; ii < word.Word.Count; ii++) { word.Word[ii].SetLetterPosition(new Vector2(cordX, cordY - (ii * POS_NEXT)), true); currentLetterArray[(int)position.X, (int)position.Y - ii] = word.Word[ii]; } break; } case WordDirection.Right: { cordX = BASE_POS_X + (int)position.X * POS_NEXT; cordY = BASE_POS_Y + (int)position.Y * POS_NEXT; for (int ii = 0; ii < word.Word.Count; ii++) { word.Word[ii].SetLetterPosition(new Vector2(cordX + (ii * POS_NEXT), cordY), true); currentLetterArray[(int)position.X + ii, (int)position.Y] = word.Word[ii]; } break; } case WordDirection.Down: { cordX = BASE_POS_X + (int)position.X * POS_NEXT; cordY = BASE_POS_Y + (int)position.Y * POS_NEXT; for (int ii = 0; ii < word.Word.Count; ii++) { word.Word[ii].SetLetterPosition(new Vector2(cordX, cordY + (ii * POS_NEXT)), true); currentLetterArray[(int)position.X, (int)position.Y + ii] = word.Word[ii]; } break; } case WordDirection.Left: { cordX = BASE_POS_X + (int)position.X * POS_NEXT; cordY = BASE_POS_Y + (int)position.Y * POS_NEXT; for (int ii = 0; ii < word.Word.Count; ii++) { word.Word[ii].SetLetterPosition(new Vector2(cordX - (ii * POS_NEXT), cordY), true); currentLetterArray[(int)position.X - ii, (int)position.Y] = word.Word[ii]; } break; } case WordDirection.Up_Right: { cordX = BASE_POS_X + (int)position.X * POS_NEXT; cordY = BASE_POS_Y + (int)position.Y * POS_NEXT; for (int ii = 0; ii < word.Word.Count; ii++) { word.Word[ii].SetLetterPosition(new Vector2(cordX + (ii * POS_NEXT), cordY - (ii * POS_NEXT)), true); currentLetterArray[(int)position.X + ii, (int)position.Y - ii] = word.Word[ii]; } break; } case WordDirection.Down_Right: { cordX = BASE_POS_X + (int)position.X * POS_NEXT; cordY = BASE_POS_Y + (int)position.Y * POS_NEXT; for (int ii = 0; ii < word.Word.Count; ii++) { word.Word[ii].SetLetterPosition(new Vector2(cordX + (ii * POS_NEXT), cordY + (ii * POS_NEXT)), true); currentLetterArray[(int)position.X + ii, (int)position.Y + ii] = word.Word[ii]; } break; } case WordDirection.Down_Left: { cordX = BASE_POS_X + (int)position.X * POS_NEXT; cordY = BASE_POS_Y + (int)position.Y * POS_NEXT; for (int ii = 0; ii < word.Word.Count; ii++) { word.Word[ii].SetLetterPosition(new Vector2(cordX - (ii * POS_NEXT), cordY + (ii * POS_NEXT)), true); currentLetterArray[(int)position.X - ii, (int)position.Y + ii] = word.Word[ii]; // } break; } case WordDirection.Up_Left: { cordX = BASE_POS_X + (int)position.X * POS_NEXT; cordY = BASE_POS_Y + (int)position.Y * POS_NEXT; for (int ii = 0; ii < word.Word.Count; ii++) { word.Word[ii].SetLetterPosition(new Vector2(cordX - (ii * POS_NEXT), cordY - (ii * POS_NEXT)), true); currentLetterArray[(int)position.X - ii, (int)position.Y - ii] = word.Word[ii]; } break; } } }
public CrosswordElement(CoordinateInfo[] coodrinatesInfo, Word word, WordDirection direction = WordDirection.Horizontal) { CoordinatesInfo = coodrinatesInfo; Word = word; Direction = direction; }
// Returns the word start positions public List <Tuple <int, int> > GetWordStartPositions(string word, int charIndex, WordDirection direction) { var potentialStartPositions = new List <Tuple <int, int> >(); var wordLength = word.Length; if (charIndex < 0 || charIndex > wordLength) { return(potentialStartPositions); } var letter = word[charIndex]; // Scan whole board for (var i = 0; i < Board.Layout.GetLength(0); i++) { for (var j = 0; j < Board.Layout.GetLength(1); j++) { // Find matching char (letter) if (Board.Layout[i, j] == letter) { if (direction == WordDirection.Horizontal) { // Horizontal Check if word is not too long and start of word fits on board if ((wordLength - charIndex) + j <= Width && j - charIndex >= 0) { potentialStartPositions.Add(new Tuple <int, int>(j - charIndex, i)); } } if (direction == WordDirection.Vertical) { // Vertical Check if word is not too long and start of word fits on board if ((wordLength - charIndex) + i <= Height && i - charIndex >= 0) { potentialStartPositions.Add(new Tuple <int, int>(j, i - charIndex)); } } } } } return(potentialStartPositions); }
private Letter PreLetter(Letter letter, WordDirection direction) { return(_location[letter.transform.position - Next(direction)]); }
public IEnumerator ValidateWordSet(List <List <Letter> > partitions, bool checkMoreThanOneSequence) { MgsCoroutine.Info += "\n Validating..."; #region initialize IsValid = false; _partitions = partitions; #region LetterToPartition dic // **************** initialize LetterToPartition dic if (_letterToPartition == null) { _letterToPartition = new Dictionary <Letter, List <Letter> >(); } else { _letterToPartition.Clear(); } foreach (var partition in _partitions) { foreach (Letter letter in partition) { _letterToPartition.Add(letter, partition); } } #endregion _usedPartitions.Clear(); #endregion #region check whole word in one partition // check whole word in one partition foreach (Word word in _wordComponents) { var partition = _letterToPartition[word.Letters[0]]; if (partition.Intersect(word.Letters).ToList().Count == word.Letters.Count) { yield break; } } #endregion #region Check for word with more than one sequence if (checkMoreThanOneSequence) { foreach (var word in _words) { _word = word; _foundSequence = 0; _wordDirection = WordDirection.Horizontal; yield return(FindSequence(0)); _wordDirection = WordDirection.Vertical; yield return(FindSequence(0)); if (_foundSequence != 1) { yield break; } } } #endregion IsValid = true; }
string[] AddWord(WordDirection direction, string word, string[] result) { if (direction == WordDirection.Down) return AddWordDown(word, result); else return AddWordRight(word, result); }