//METHODS private bool[,] makeArray() { int columnCount = _placement.GetSpaceList().Count; int rowCount = _tray.Length; bool[,] returnArray = new bool[columnCount, rowCount]; int primaryWordIndex = 0; for (int x = 0; x < columnCount; x++) { //check skip over anchors while (PrimaryWordSpaces[primaryWordIndex].IsOccupied()) { primaryWordIndex++; if (PrimaryWordSpaces.Count == primaryWordIndex) { break; } } for (int y = 0; y < rowCount; y++) { if (_tray[y] == '?') { var tempList = from t in ExclusionTuples where t.Item1 == primaryWordIndex select t; if (tempList.Distinct().Count() > 25) { returnArray[x, y] = false; } else { returnArray[x, y] = true; } } else if (ExclusionTuples.Contains(Tuple.Create(primaryWordIndex, _tray[y]))) { returnArray[x, y] = false; } else { returnArray[x, y] = true; } } primaryWordIndex++; } return(returnArray); }
//CONSTRUCTOR public PlacementMatrix(Placement placement) { if (placement.IsSingle()) { throw new ArgumentException("An PlacementMatrix is not appropriate for single tile placements"); } _placement = placement; Game = _placement.Game; _tray = Game.GetTrayString(); PrimaryWordSpaces = new List <Space>(); PrimaryWordSpaces.AddRange(_placement.Anchors); PrimaryWordSpaces.AddRange(_placement.GetSpaceList()); PrimaryWordSpaces.Sort(SpaceComparer.Instance); AnchorTuples = GetAnchorTuples(); ExclusionTuples = GetExclusionTuples(); ExclusionArray = makeArray(); }
//METHODS public List <SubWord> GetSubWords() { SubWord[] subwords = new SubWord[_playList.Count + 1]; //Single tile placements are a special case //Essentially, single tile placements have no primary SubWord //And instead have two secondary words. Or at least that's how I'll approach them. if (_placement.IsSingle()) { //Get Horizontal SubWord SubWord horizontal = _game.SingleSubWord(_playList[0], "horizontal"); //Get Vertical SubWord SubWord vertical = _game.SingleSubWord(_playList[0], "vertical"); //return subwords if (vertical == null) { subwords[0] = horizontal; subwords[1] = vertical; } else if (horizontal == null) { subwords[0] = vertical; subwords[1] = horizontal; } else if (horizontal.ExtractWord().Length >= vertical.ExtractWord().Length) { subwords[0] = horizontal; subwords[1] = vertical; } else { subwords[0] = vertical; subwords[1] = horizontal; } return(subwords.Where(x => x.ExtractWord().Length > 1).ToList()); } List <Tuple <Space, Tile> > mainWord = _playList.ToList(); List <Space> anchors = _placement.Anchors; foreach (Space anchor in anchors) { mainWord.Add(Tuple.Create(anchor, anchor.GetTile())); } SubWord primaryWord = new SubWord(mainWord, _game); subwords[0] = primaryWord; List <Space> playSpaces = _placement.GetSpaceList(); if (_placement.IsHorizontal()) { //Build a vertical subword for each space in the Play for (int i = 1; i < subwords.Length; i++) { subwords[i] = _game.SingleSubWord(_playList[i - 1], "vertical"); } } if (_placement.IsVertical()) { //Build a horizontal subword for each space in the Play for (int i = 1; i < subwords.Length; i++) { subwords[i] = _game.SingleSubWord(_playList[i - 1], "horizontal"); } } return(subwords.Where(x => x.ExtractWord().Length > 1).ToList()); }