private FilterResult Filter(PredictionCollection[] rowsPredictions, PredictionCollection[] columnsPredictions, Field field) { var anyChanged = false; bool PredictionFits(Line prediction, Line fieldLine) { for (int i = 0; i < fieldLine.Count; i++) { if (fieldLine[i] != Box.Empty && fieldLine[i] != prediction[i]) { return(false); } } return(true); } PredictionCollection FilterLine(PredictionCollection predictions, IEnumerable <Box> fieldLine) { var filteredPrediction = new PredictionCollection(predictions.Where(prediction => PredictionFits(prediction, new Line(fieldLine.ToArray())))); anyChanged = anyChanged || filteredPrediction.Count < predictions.Count; return(filteredPrediction); } for (int rowIndex = 0; rowIndex < rowsPredictions.Length; rowIndex++) { rowsPredictions[rowIndex] = FilterLine(rowsPredictions[rowIndex], field.GetRow(rowIndex)); } for (int columnIndex = 0; columnIndex < columnsPredictions.Length; columnIndex++) { columnsPredictions[columnIndex] = FilterLine(columnsPredictions[columnIndex], field.GetColumn(columnIndex)); } if (!anyChanged) { return(FilterResult.Unsolvable); } return(FilterResult.RequireMapping); }
private static Line PredictLine(PredictionCollection currentPredictions) { if (currentPredictions.Count == 1) { return(currentPredictions[0]); } var currentPrediction = currentPredictions[0].ToBoxArray(); foreach (var nextPrediction in currentPredictions.Skip(1)) { for (int i = 0; i < currentPrediction.Length; i++) { if (currentPrediction[i] != Box.Empty && currentPrediction[i] != nextPrediction[i]) { currentPrediction[i] = Box.Empty; } } } return(new Line(currentPrediction)); }