public PixelTreeNode(byte x, byte y, byte ifYes, byte ifNo, YesNoFinality finality, bool useAlpha = true) { ID = ID_COUNTER; ++ID_COUNTER; X = x; Y = y; IfYes = ifYes; IfNo = ifNo; Finality = finality; UseAlpha = useAlpha; }
public static byte GetNext(IEnumerable <Bitmap> images, int depth = 1, byte startingIndex = 0) { /*if (depth == 7 && startingIndex == 35) * { * var colors = images.Select(img => img.GetPixel(100, 100)); * }*/ int bestScore = Int32.MaxValue; Point bestScorePoint = new Point(1, 1); for (int x = 0; x < PERK_PX; ++x) { for (int y = 0; y < PERK_PX; ++y) { int yes = 0; int no = 0; foreach (var image in images) { var pixel = image.GetPixel(x, y); if (pixel.A == 0) { ++no; } else { ++yes; } } int score = Math.Abs(yes - no); if (score < bestScore && yes > 0 && no > 0) { bestScore = score; bestScorePoint = new Point(x, y); } } } bool useAlpha = true; List <Bitmap> yeses = new List <Bitmap>(); List <Bitmap> nos = new List <Bitmap>(); if (bestScore == Int32.MaxValue) { useAlpha = false; for (int x = 0; x < PERK_PX; ++x) { for (int y = 0; y < PERK_PX; ++y) { int yes = 0; int no = 0; foreach (var image in images) { var pixel = image.GetPixel(x, y); if (pixel.R != 0) { ++no; } else { ++yes; } } int score = Math.Abs(yes - no); if (score < bestScore && yes > 0 && no > 0) { bestScore = score; bestScorePoint = new Point(x, y); } } } foreach (var image in images) { if (image.GetPixel(bestScorePoint.X, bestScorePoint.Y).R != 0) { nos.Add(image); } else { yeses.Add(image); } } } else { foreach (var image in images) { if (image.GetPixel(bestScorePoint.X, bestScorePoint.Y).A == 0) { nos.Add(image); } else { yeses.Add(image); } } } if (bestScore == Int32.MaxValue) { int index = 0; foreach (var image in images) { image.Save(@"E:\Programming\Dead By Daylight\Icons\Problem Icons\Problem" + index.ToString() + ".png"); ++index; } } Debug.Assert(bestScore != Int32.MaxValue); Console.WriteLine(bestScorePoint.ToString() + " - " + bestScore.ToString()); YesNoFinality finality = YesNoFinality.None; byte yesID = 0; byte noID = 0; if (nos.Count == 1) { finality |= YesNoFinality.NoFinal; noID = (byte)Images.IndexOf(nos[0]); if (depth > ONotationMax) { ONotationMax = depth; } } else { noID = GetNext(nos, depth + 1, startingIndex); } if (yeses.Count == 1) { finality |= YesNoFinality.YesFinal; yesID = (byte)Images.IndexOf(yeses[0]); if (depth > ONotationMax) { ONotationMax = depth; } } else { yesID = GetNext(yeses, depth + 1, (byte)(startingIndex + nos.Count)); } var node = new PixelTreeNode( (byte)bestScorePoint.X, (byte)bestScorePoint.Y, yesID, noID, finality, useAlpha ); PointTree.Add(node.ID, node); return(node.ID); }