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