public CrossPattern(int startX, int startY, int length, bool isHorizontal) { _startX = startX; _startY = startY; _length = length; AdjacentPatterns = new CrossPattern[_length]; _isHorizontal = isHorizontal; _pattern = Enumerable.Repeat('.', length).ToArray(); }
static void oldTest() { //prepare cross board ICrossBoard cb = new CrossBoard(); CreateCross(cb); var dict = new Dictionary("../../../dict/cz", cb.MaxWordLength); cb.Preprocess(dict); CrossPattern cp = cb.GetCrossPattern(32); CrossTransformation trans = cp.TryFill(null, "ADELAVOJTAHELA".AsSpan(), dict); //length 14 trans.Transform(cp); }
public void Preprocess(ICrossDictionary aDict) { _horizontalPatterns.Clear(); _startWords.Sort(new YXStartWordComparer()); //first create horizontal patterns int wordIdx = 0; for (int y = 0; y < _sizeY; y++) { int nextX = 0; while (wordIdx < _startWords.Count) { var sw = _startWords[wordIdx]; //Console.WriteLine("StartWord x:{0} y:{1} idx:{2}/cnt:{3}",sw.StartX,sw.StartY,wordIdx,_startWords.Count); if (sw.StartY == y) { if (sw.StartX - nextX >= MinPatternLength) { var cp = new CrossPattern(nextX, y, sw.StartX - nextX, true); //Console.WriteLine("SW pattern startX: {0} startY: {1} len: {2}",cp.StartX, cp.StartY, cp.Length); _horizontalPatterns.Add(cp); } nextX = sw.StartX + 1; wordIdx++; } else { break; } } if (_sizeX - nextX >= MinPatternLength) { var cp = new CrossPattern(nextX, y, _sizeX - nextX, true); //Console.WriteLine("EL pattern startX: {0} startY: {1} len: {2}",cp.StartX, cp.StartY, cp.Length); _horizontalPatterns.Add(cp); } } _verticalPatterns.Clear(); _startWords.Sort(new XYStartWordComparer()); //first create horizontal patterns wordIdx = 0; for (int x = 0; x < _sizeX; x++) { int nextY = 0; while (wordIdx < _startWords.Count) { var sw = _startWords[wordIdx]; //Console.WriteLine("StartWord x:{0} y:{1} idx:{2}/cnt:{3}",sw.StartX,sw.StartY,wordIdx,_startWords.Count); if (sw.StartX == x) { if (sw.StartY - nextY >= MinPatternLength) { var cp = new CrossPattern(x, nextY, sw.StartY - nextY, false); //Console.WriteLine("SW patternY startX: {0} startY: {1} len: {2}",cp.StartX, cp.StartY, cp.Length); _verticalPatterns.Add(cp); } nextY = sw.StartY + 1; wordIdx++; } else { break; } } if (_sizeY - nextY >= MinPatternLength) { var cp = new CrossPattern(x, nextY, _sizeY - nextY, false); //Console.WriteLine("EL patternY startX: {0} startY: {1} len: {2}",cp.StartX, cp.StartY, cp.Length); _verticalPatterns.Add(cp); } } BindAdjacentPatterns(); //set instantiation count int patternCount = GetPatternCount(); for (int i = 0; i < patternCount; i++) { var pattern = GetCrossPattern(i); pattern.InstantiationCount = aDict.GetWordOfLengthCount(pattern.Length); } }