public void GetConflits() { Conflicts = 0; for (int i = 0; i < Queens.Count; i++) { var SubList = Queens.GetRange(i, Queens.Count - i); for (int j = 1; j < SubList.Count; j++) { // Check Columns if (SubList[0].X == SubList[j].X) { Queens[i].Conflicts.Add(SubList[j]); } // Check Rows if (SubList[0].Y == SubList[j].Y) { Queens[i].Conflicts.Add(SubList[j]); } // Check Descending Diagnonal if (SubList[0].X - SubList[0].Y == SubList[j].X - SubList[j].Y) { Queens[i].Conflicts.Add(SubList[j]); } // Check Ascending Diagonal if (SubList[0].X + SubList[0].Y == SubList[j].X + SubList[j].Y) { Queens[i].Conflicts.Add(SubList[j]); } } } Queens.ForEach(queen => Conflicts += queen.Conflicts.Count); }
public void PrintConflicts() { StringBuilder sb = new StringBuilder(); if (Conflicts > 0) { sb.Append("Conflicts: "); sb.Append(Conflicts); sb.AppendLine(); Queens.ForEach(queen => { if (queen.Conflicts.Any()) { sb.Append("Queen: "); sb.Append(queen.X); sb.Append("-"); sb.Append(queen.Y); sb.Append(", conflicts at:\n"); foreach (var conflict in queen.Conflicts) { sb.Append("\t"); sb.Append(conflict.X); sb.Append("-"); sb.Append(conflict.Y); sb.AppendLine(); } sb.AppendLine(); } }); } else { sb.Append("No Conflicts"); } Console.Write(sb); }