static void ClearCharColumn(Column column, CharPosition @char, List <CharPosition> startPositions) { foreach (var item in startPositions. Where(x => x.Index > @char.Index)) { MoveToColumn(item, ((IEnumerable <Column>)Enum.GetValues(typeof(Column))).FirstOrDefault(x => x != column && x != @char.Column)); } }
static Column MoveNext(CharPosition item) { char nextColumnChar = (char)item.Column; nextColumnChar = (char)(nextColumnChar + 1); Column nextColumn = columnList.Contains(nextColumnChar) ? (Column)nextColumnChar : item.Column - 1; Console.WriteLine($"{item.Character} bloğu {(char)item.Column} kolonundan {(char)nextColumn} kolonuna hareket etti"); item.Column = nextColumn; return(nextColumn); }
static void Main(string[] args) { List <CharPosition> startPositions = new List <CharPosition>(); List <CharPosition> endPositions = new List <CharPosition>(); Return1: Console.WriteLine("Başlangıç durumu için 2-9 arasında blok sayısı seçin."); int blockCount = new int(); if (!int.TryParse(Console.ReadLine(), out blockCount) || blockCount < 2 || blockCount > 9) { goto Return1; } SetStartPosition(startPositions, blockCount); SetEndPosition(endPositions, blockCount); Console.WriteLine(""); Console.WriteLine("İlk durum"); foreach (var item in startPositions.OrderBy(x => x.Character)) { Console.WriteLine(item.ToString()); } Console.WriteLine(""); List <CharPosition> result = new List <CharPosition>(); while (startPositions.Count > 0) { foreach (var column in columnList) { foreach (var endPosition in endPositions.Where(x => x.Column == (Column)column).OrderBy(x => x.Index)) { bool search = true; while (search) { var startPosition = startPositions.FirstOrDefault(x => x.Column == endPosition.Column && x.Character == endPosition.Character && x.Index == endPosition.Index); if (startPosition != null) { Console.WriteLine(startPosition.Character + " bitiş pozisyonunda"); result.Add(startPosition); startPositions.Remove(startPosition); search = false; } else { CharPosition @char = startPositions.FirstOrDefault(x => x.Character == endPosition.Character); ClearTargetColumn(endPosition, @char, startPositions); ClearCharColumn(endPosition.Column, @char, startPositions); MoveToColumn(@char, endPosition.Column); result.Add(@char); startPositions.Remove(@char); search = false; } } } } } Console.WriteLine(""); Console.WriteLine("İstenen"); foreach (var item in endPositions.OrderBy(x => x.Character)) { Console.WriteLine(item.ToString()); } Console.WriteLine("--------------------------"); Console.WriteLine("--------------------------"); Console.WriteLine("Sonuç"); foreach (var item in result.OrderBy(x => x.Character)) { Console.WriteLine(item.ToString()); } Console.ReadKey(); }
static void MoveToColumn(CharPosition @char, Column column) { Console.WriteLine($"{@char.Character} bloğu {(char)@char.Column} kolonundan {(char)column} kolonuna hareket etti"); @char.Column = column; }