Esempio n. 1
0
        public MatrixNode aStartSearchMax()
        {
            MatrixNode newNode = new MatrixNode(StartMatrix, FinishMatrix);

            newNode.Sucesors.Add(newNode);
            AddChildren(newNode);
            bool       found   = false;
            MatrixNode minNode = null;
            int        index;

            while (!found)
            {
                lock (openList)
                {
                    index   = Convert.ToInt32(openList.Count * 0.75);
                    minNode = openList[index];  // Maximo
                }
                if (minNode.HeuristValue == 0 || Found)
                {
                    found = true;
                    Found = true;
                }
                else
                {
                    lock (openList)
                    {
                        openList.RemoveAt(index);
                        AddChildren(minNode);
                    }
                }
            }
            Console.WriteLine("Fin");
            return(minNode);
        }
Esempio n. 2
0
        /* A* algorithm */
        public MatrixNode aStartSearch()
        {
            MatrixNode newNode = new MatrixNode(StartMatrix, FinishMatrix);

            newNode.Sucesors.Add(newNode);
            AddChildren(newNode);
            bool       found   = false;
            MatrixNode minNode = null;

            while (!found)
            {
                lock (openList)
                {
                    minNode = openList[0];  // El minimo siempre es el primero: openList[0]
                }
                if (minNode.HeuristValue == 0 || Found)
                {
                    found = true;
                    Found = true;
                }
                else
                {
                    lock (openList)
                    {
                        openList.RemoveAt(0);
                        AddChildren(minNode);
                    }
                }
            }
            Console.WriteLine("Fin");
            return(minNode);
        }
Esempio n. 3
0
        public void AddChildren(MatrixNode node)
        {
            string opposite;

            if (node.Moves.Count > 0)
            {
                opposite = Movable.CalcOposite(node.Moves.Last());
            }
            else
            {
                opposite = "";
            }
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Movable aux = MovesFactory.GetInstance(i, j);
                    if (aux.IsValid(node.Matrix))
                    {
                        if (!opposite.Equals(aux.GetString()))
                        {
                            string[,] movedMatrix = aux.Move(node.Matrix);
                            MatrixNode child = new MatrixNode(movedMatrix, FinishMatrix);
                            child.Sucesors.AddRange(node.Sucesors);
                            child.Sucesors.Add(child);
                            child.Moves.AddRange(node.Moves);
                            child.Moves.Add(aux);
                            child.calculateEvaluationFunction();
                            AddInOrder(child);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public bool isUniquePosition(MatrixNode node, int i, int j)
        {
            List <MatrixNode> listOfSucesors = node.Sucesors;

            foreach (MatrixNode m in listOfSucesors)
            {
                if (m.Matrix.GetValue(i, j).ToString() == "X")
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 5
0
        public MatrixNode CalculateMin()
        {
            double     minValue = 999;
            MatrixNode minNode  = null;

            foreach (MatrixNode m in this.openList)
            {
                double value = 0;//m.calculateEvaluationFunction();
                if (value <= minValue)
                {
                    minValue = value;
                    minNode  = m;
                }
            }
            return(minNode);
        }
Esempio n. 6
0
        private void AddInOrder(MatrixNode child)
        {
            if (openList.Count == 0)
            {
                openList.Add(child);
                return;
            }
            double value = child.Value;

            if (value > openList[openList.Count - 1].Value)
            {
                openList.Add(child);
            }
            for (int i = 0; i < openList.Count; i++)
            {
                if (value < openList[i].Value)
                {
                    openList.Insert(i, child);
                    return;
                }
            }
            openList.Add(child);
        }