Exemple #1
0
        private List <NodeMove> GetInitialMoves()
        {
            var moves       = new List <NodeMove>();
            var tuplesMoves = GetPossibleMoves(Root);

            foreach (var newPosition in tuplesMoves)
            {
                var newNode = new NodeMove(newPosition);
                AddNode(Root, newNode, newPosition);
                moves.Add(newNode);
            }

            return(moves);
        }
Exemple #2
0
        private void TraceAllMoves(NodeMove currentPosition, NodeMove previousPosition)
        {
            var previousCoordinates = new Tuple <int, int>(previousPosition.Id.Item1, previousPosition.Id.Item2);
            var tuplesMoves         = GetPossibleMoves(currentPosition);

            tuplesMoves.RemoveWhere(x => x.Equals(previousCoordinates));

            foreach (var newPosition in tuplesMoves)
            {
                var nodeToAdd = new NodeMove(newPosition);

                if (AddNode(currentPosition, nodeToAdd, newPosition))
                {
                    TraceAllMoves(nodeToAdd, currentPosition);
                }
            }
        }
Exemple #3
0
        private HashSet <Tuple <int, int> > GetPossibleMoves(NodeMove node)
        {
            var possibleMoves = new HashSet <Tuple <int, int> >();

            var x1 = node.Id.Item1;
            var y1 = node.Id.Item2;

            if (x1 + KnightRangeA <= NMinus)
            {
                if (y1 + KnightRangeB <= NMinus)
                {
                    possibleMoves.Add(new Tuple <int, int>(x1 + KnightRangeA, y1 + KnightRangeB));
                    possibleMoves.Add(new Tuple <int, int>(y1 + KnightRangeB, x1 + KnightRangeA));
                }

                if (y1 - KnightRangeB >= 0)
                {
                    possibleMoves.Add(new Tuple <int, int>(x1 + KnightRangeA, y1 - KnightRangeB));
                    possibleMoves.Add(new Tuple <int, int>(y1 - KnightRangeB, x1 + KnightRangeA));
                }
            }

            if (x1 - KnightRangeA >= 0)
            {
                if (y1 + KnightRangeB <= NMinus)
                {
                    possibleMoves.Add(new Tuple <int, int>(x1 - KnightRangeA, y1 + KnightRangeB));
                    possibleMoves.Add(new Tuple <int, int>(y1 + KnightRangeB, x1 - KnightRangeA));
                }

                if (y1 - KnightRangeB >= 0)
                {
                    possibleMoves.Add(new Tuple <int, int>(x1 - KnightRangeA, y1 - KnightRangeB));
                    possibleMoves.Add(new Tuple <int, int>(y1 - KnightRangeB, x1 - KnightRangeA));
                }
            }

            return(possibleMoves);
        }
Exemple #4
0
        private bool AddNode(NodeMove parentNode, NodeMove nodeToAdd, Tuple <int, int> coordinates)
        {
            if (Graph.ContainsKey(coordinates))
            {
                var existingNode = Graph[coordinates];
                parentNode.Parents.Add(existingNode);
                existingNode.Parents.Add(parentNode);

                return(false);
            }

            nodeToAdd.Parents.Add(parentNode);
            parentNode.Parents.Add(nodeToAdd);
            Graph.Add(coordinates, nodeToAdd);

            if (coordinates.Item1 == coordinates.Item2 && coordinates.Item2 == NMinus)
            {
                IsCornerVisited = true;
                Endpoint        = nodeToAdd;
                return(false);
            }

            return(true);
        }