Ejemplo n.º 1
0
        public MoveTracker Clone()
        {
            var mt = new MoveTracker();

            mt.Moves.AddRange(this.Moves);
            mt.FreshClone = true;

            return(mt);
        }
Ejemplo n.º 2
0
        public async Task <List <MoveTracker> > ProbePossibleMoves(CancellationToken ct)
        {
            await Task.CompletedTask;

            var mts = new List <MoveTracker>();
            var mt  = new MoveTracker();

            mts.Add(mt);

            while (ct.IsCancellationRequested == false)
            {
                if (this.MakeFirstPossibleMove(mts, mt) == false)
                {
                    if (mt.Moves.Any() == false)
                    {
                        mts.Remove(mt);
                        break; // no moves left to probe
                    }

                    var lastValidMove = mt.Moves.LastOrDefault();
                    if (mt.FreshClone == false)
                    {
                        mt = mt.Clone();
                        mts.Add(mt);
                    }

                    mt.Moves.Remove(lastValidMove);
                    this.RevertMove(lastValidMove.X, lastValidMove.Y, lastValidMove.Direction); // revert last move on current field

                    if (this.printEachStep)
                    {
                        this.Print();
                    }
                }
                else
                {
                    mt.FreshClone = false;

                    if (this.printEachStep)
                    {
                        var lastValidMove = mt.Moves.Last();
                        this.Print(lastValidMove);
                    }
                }
            }

            return(mts);
        }
Ejemplo n.º 3
0
        public bool MakeFirstPossibleMove(List <MoveTracker> mts, MoveTracker mt)
        {
            for (int y = 0; y < this.size; y++)
            {
                for (int x = 0; x < this.size; x++)
                {
                    foreach (Directions direction in Enum.GetValues(typeof(Directions)))
                    {
                        var m = new Move {
                            X = x, Y = y, Direction = direction, PreviousMove = mt.Moves.LastOrDefault(), Number = mt.Moves.Count + 1
                        };
                        if (this.CanMove(x, y, direction) && mts.Any(a => a.Moves.Any(b => b == m)) == false)
                        {
                            mt.Moves.Add(m);
                            this.MakeMove(x, y, direction);
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }