public void Step()
        {
            //if (StartField.Equals(FinalField)) return;
            Cell        freeCell       = StartField.Cells.First(x => x.Content == null);
            List <Move> availableMoves = StartField.Moves.Where(x => x.HasCell(freeCell)).ToList();

            AllPathes = availableMoves.Select(x => new List <Move> {
                x
            }).ToList();

            while (AllPathes.Count > 0)
            {
                Path = AllPathes[0];
                AllPathes.RemoveAt(0);
                InitPath();
                if (StartField.Equals(FinalField))
                {
                    return;
                }
                freeCell       = StartField.Cells.First(x => x.Content == null);
                availableMoves = StartField.Moves.Where(x => x.HasCell(freeCell)).ToList();
                var moves = new List <Move>();
                foreach (var move in availableMoves)
                {
                    if (move.Checker.Moves.Exists(x => x.Equals(move)))
                    {
                        continue;
                    }
                    moves.Add(move);
                }
                availableMoves = moves;
                AllPathes.AddRange(availableMoves.Select(x =>
                {
                    var path = Path.ToList();
                    path.Add(x);
                    return(path);
                }).ToList());
            }

            Path.Clear();
            AllPathes.Clear();
        }
예제 #2
0
        public void Step()
        {
            if (StartField.Equals(FinalField))
            {
                return;
            }
            Cell        freeCell       = StartField.Cells.First(x => x.Content == null);
            List <Move> availableMoves = StartField.Moves.Where(x => x.HasCell(freeCell)).ToList();

            foreach (var move in availableMoves)
            {
                if (move.Checker.Moves.Exists(x => x.Equals(move)))
                {
                    continue;
                }
                Path.Add(move);
                move.Transfer();

                if (StartField.Equals(FinalField))
                {
                    return;
                }
                #region Rollback
                if (Path.Count > 15)
                {
                    Path.RemoveAt(Path.Count - 1);
                    move.RollBack();
                    return;
                }
                #endregion
                Step();
                if (StartField.Equals(FinalField))
                {
                    return;
                }
                Path.RemoveAt(Path.Count - 1);
                move.RollBack();
            }
        }