Esempio n. 1
0
        public DepthFirst(Cuadrilla grid) : base(grid)
        {
            NombreAlgoritmo = "Depth-First Search";

            // Add the first node to the stack
            _stack.Push(new Node(Id++, null, Origen, 0, 0));
        }
        public AEstrella(Cuadrilla grid) : base(grid)
        {
            NombreAlgoritmo = "A*";
            _Vecinos        = new List <Coord>();

            // origen a la lista abierta
            _ListaAbierta.Add(new Node(Id++, null, Origen, 0, GetH(Origen, Destino)));
        }
Esempio n. 3
0
 protected AlgoritmoBase(Cuadrilla grid)
 {
     Cuadrilla  = grid;
     Cerrada    = new List <Node>();
     Origen     = Cuadrilla.GetStart().Coord;
     Destino    = Cuadrilla.GetEnd().Coord;
     Operations = 0;
     Id         = 1;
 }
Esempio n. 4
0
 protected AlgoritmoBase(Cuadrilla cuadrilla)
 {
     Cuadrilla = cuadrilla;
     Cerrado   = new List <Nodo>();
     Origen    = Grid.GetStart().Coord;
     Destino   = Grid.GetEnd().Coord;
     Operacion = 0;
     Id        = 1;
 }
Esempio n. 5
0
 public DibujarLaberinto(PictureBox pb, int seed = 0)
 {
     _pb       = pb;
     Cuadrilla = new Cuadrilla(Horizontales, Verticales);
     if (seed == 0)
     {
         seed = (int)DateTime.Now.Ticks;
     }
     Seed = seed;
     Cuadrilla.Randomize(seed);
 }
        /// <summary>
        /// Método que inserta un nuevo registro a la tabla de xxxxx
        /// </summary>
        /// <param name="iCuadrilla"></param>
        public static string Insertar(Cuadrilla iCuadrilla)
        {
            try
            {
                //1. Configurar la conexión y el tipo de comando
                SqlConnection sqlcConectar = new SqlConnection(ConfigurationManager.ConnectionStrings["OSEF"].ConnectionString);
                SqlCommand    sqlcComando  = new SqlCommand();
                sqlcComando.Connection  = sqlcConectar;
                sqlcComando.CommandType = CommandType.StoredProcedure;
                sqlcComando.CommandText = "web_spI_InsertarCuadrilla";

                //2. Declarar los parametros
                SqlParameter sqlpID = new SqlParameter();
                sqlpID.ParameterName = "@ID";
                sqlpID.SqlDbType     = SqlDbType.Char;
                sqlpID.Value         = iCuadrilla.ID;
                sqlpID.Size          = 10;
                sqlpID.Direction     = ParameterDirection.Output;

                SqlParameter sqlpNombre = new SqlParameter();
                sqlpNombre.ParameterName = "@Nombre";
                sqlpNombre.SqlDbType     = SqlDbType.Char;
                sqlpNombre.Value         = iCuadrilla.Nombre;

                SqlParameter sqlpDescripcion = new SqlParameter();
                sqlpDescripcion.ParameterName = "@Descripcion";
                sqlpDescripcion.SqlDbType     = SqlDbType.Char;
                sqlpDescripcion.Value         = iCuadrilla.Descripcion;


                //3. Agregar los parametros al comando
                sqlcComando.Parameters.Add(sqlpID);
                sqlcComando.Parameters.Add(sqlpNombre);
                sqlcComando.Parameters.Add(sqlpDescripcion);

                //4. Abrir la conexión
                sqlcComando.Connection.Open();

                //5. Ejecutar la instrucción INSERT que regresa un dato que es el ID
                int result = Convert.ToInt32(sqlcComando.ExecuteScalar());

                //6. Cerrar la conexión
                sqlcComando.Connection.Close();

                //7. Regresar el resultado
                return(sqlcComando.Parameters["@ID"].Value.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("Error capa de datos (public static int Insertar(Cuadrilla " + iCuadrilla.ID + ")): " + ex.Message);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string strcookieEditarCuadrilla = Cookies.GetCookie("cookieEditarCuadrilla").Value;

            if (!strcookieEditarCuadrilla.Equals("Nuevo"))
            {
                Cuadrilla cu = new Cuadrilla();
                cu = CuadrillaBusiness.ObtenerCuadrillaPorID(strcookieEditarCuadrilla);
                txtID.SetValue(cu.ID);
                txtNombre.SetValue(cu.Nombre);
                txtDescripcion.SetValue(cu.Descripcion);
            }
        }
        /// <summary>
        /// Método que modifica un registro a la tabla de xxxxx
        /// </summary>
        /// <param name="iCuadrilla"></param>
        public static int Modificar(Cuadrilla iCuadrilla)
        {
            try
            {
                //1. Configurar la conexión y el tipo de comando
                SqlConnection sqlcConectar = new SqlConnection(ConfigurationManager.ConnectionStrings["OSEF"].ConnectionString);
                SqlCommand    sqlcComando  = new SqlCommand();
                sqlcComando.Connection  = sqlcConectar;
                sqlcComando.CommandType = CommandType.StoredProcedure;
                sqlcComando.CommandText = "web_spU_ActualizarCuadrilla";

                //2. Declarar los parametros
                SqlParameter sqlpID = new SqlParameter();
                sqlpID.ParameterName = "@ID";
                sqlpID.SqlDbType     = SqlDbType.Char;
                sqlpID.Value         = iCuadrilla.ID;

                SqlParameter sqlpNombre = new SqlParameter();
                sqlpNombre.ParameterName = "@Nombre";
                sqlpNombre.SqlDbType     = SqlDbType.Char;
                sqlpNombre.Value         = iCuadrilla.Nombre;

                SqlParameter sqlpDescripcion = new SqlParameter();
                sqlpDescripcion.ParameterName = "@Descripcion";
                sqlpDescripcion.SqlDbType     = SqlDbType.Char;
                sqlpDescripcion.Value         = iCuadrilla.Descripcion;


                //3. Agregar los parametros al comando
                sqlcComando.Parameters.Add(sqlpID);
                sqlcComando.Parameters.Add(sqlpNombre);
                sqlcComando.Parameters.Add(sqlpDescripcion);


                //4. Abrir la conexión
                sqlcComando.Connection.Open();

                //5. Ejecutar la instrucción UPDATE que no regresa filas
                int result = sqlcComando.ExecuteNonQuery();

                //6. Cerrar la conexión
                sqlcComando.Connection.Close();

                //7. Regresar el resultado
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("Error capa de datos (public static int Modificar(Cuadrilla " + iCuadrilla.ID + ")): " + ex.Message);
            }
        }
Esempio n. 9
0
 protected override DetallesBusqueda detallesBusqueda()
 {
     return(new DetallesBusqueda
     {
         Ruta = ruta?.ToArray(),
         CostoRuta = GetPathCost(),
         UltimoNodo = NodoActual,
         DistanciaDesdeNodoActual = NodoActual == null ? 0 : GetManhattenDistance(NodoActual.Coord, Destino),
         TamañoListaAbierta = _stack.Count,
         TamañoListaCerrada = Cerrada.Count,
         TamañoListaSinExplorar = Cuadrilla.GetCountOfType(Enums.CellType.Vacio),
         Operaciones = Operations++
     });
 }
Esempio n. 10
0
        /// <summary>
        /// Obtener un registro de Cuadrilla por su ID
        /// </summary>
        /// <param name="strID"></param>
        /// <returns></returns>
        public static Cuadrilla ObtenerCuadrillaPorID(string strID)
        {
            try
            {
                //1. Configurar la conexión y el tipo de comando
                SqlConnection sqlcConectar = new SqlConnection(ConfigurationManager.ConnectionStrings["OSEF"].ConnectionString);
                SqlCommand    sqlcComando  = new SqlCommand();
                sqlcComando.Connection  = sqlcConectar;
                sqlcComando.CommandType = CommandType.StoredProcedure;
                sqlcComando.CommandText = "web_spS_ObtenerCuadrillaPorID";

                //2. Declarar los parametros
                SqlParameter sqlpID = new SqlParameter();
                sqlpID.ParameterName = "@ID";
                sqlpID.SqlDbType     = SqlDbType.Char;

                if (strID == null)
                {
                    sqlpID.Value = DBNull.Value;
                }
                else
                {
                    sqlpID.Value = strID;
                }



                //3. Agregar los parametros al comando
                sqlcComando.Parameters.Add(sqlpID);

                //4. Abrir la conexión
                sqlcComando.Connection.Open();

                //5. Ejecutar la instrucción SELECT que regresa filas
                SqlDataReader reader = sqlcComando.ExecuteReader();

                //6. Asignar la Cuadrilla
                Cuadrilla result = LibraryGenerics <Cuadrilla> .ConvertDataSetToList(reader).FirstOrDefault();

                //7. Cerrar la conexión
                sqlcComando.Connection.Close();

                //8. Regresar el resultado
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("Error capa de datos (public static Cuadrilla ObtenerCuadrillaPorID(string " + strID + ")): " + ex.Message);
            }
        }
Esempio n. 11
0
        public override DetallesBusqueda MarcarRuta()
        {
            // Check the next node on the stack to see if it is the destination
            NodoActual = _stack.Peek();
            if (CoordsMatch(NodoActual.Coord, Destino))
            {
                // All the items on the stack will be the path so add them and reverse the order
                ruta = new List <Coord>();
                foreach (var item in _stack)
                {
                    ruta.Add(item.Coord);
                }

                ruta.Reverse();

                return(detallesBusqueda());
            }

            // Get all the neighbours that haven't been visited
            var neighbours = GetNeighbours(NodoActual).Where(x => !AlreadyVisited(new Coord(x.X, x.Y))).ToArray();

            if (neighbours.Any())
            {
                foreach (var neighbour in neighbours)
                {
                    Cuadrilla.SetCell(neighbour.X, neighbour.Y, Enums.CellType.Abierto);
                }

                // Take this neighbour and add it the stack
                var next    = neighbours.First();
                var newNode = new Node(Id++, null, next.X, next.Y, 0, 0);
                _stack.Push(newNode);
                Cuadrilla.SetCell(newNode.Coord.X, newNode.Coord.Y, Enums.CellType.Actual);
            }
            else
            {
                // Remove this unused node from the stack and add it to the closed list
                var abandonedCell = _stack.Pop();
                Cuadrilla.SetCell(abandonedCell.Coord.X, abandonedCell.Coord.Y, Enums.CellType.Cerrado);
                Cerrada.Add(abandonedCell);
            }

            return(detallesBusqueda());
        }
Esempio n. 12
0
        /// <summary>
        /// Evento de clic del botón Guardar
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void imgbtnGuardar_Click(object sender, DirectEventArgs e)
        {
            //1. Obtener datos de la Forma y saber si es edición o nuevo
            string strRegistro = e.ExtraParams["registro"];

            //2. Por cada elemento del submit de la Forma detectar el campo y asignarlo al objeto correspondiente
            Dictionary <string, string> dRegistro = JSON.Deserialize <Dictionary <string, string> >(strRegistro);
            Cuadrilla cu = new Cuadrilla();

            foreach (KeyValuePair <string, string> sd in dRegistro)
            {
                switch (sd.Key)
                {
                case "txtID":
                    cu.ID = sd.Value;
                    break;

                case "txtNombre":
                    cu.Nombre = sd.Value;
                    break;

                case "txtDescripcion":
                    cu.Descripcion = sd.Value;
                    break;
                }
            }
            string strcookieEditarCuadrilla = Cookies.GetCookie("cookieEditarCuadrilla").Value;

            if (strcookieEditarCuadrilla.Equals("Nuevo"))
            {
                //3. Insertar en la base de datos
                cu.ID = CuadrillaBusiness.Insertar(cu);
                //4. Mandar mensaje con el código de la cuadrilla
                e.ExtraParamsResponse.Add(new Ext.Net.Parameter("data", cu.ID, ParameterMode.Value));
            }
            else
            {
                CuadrillaBusiness.Modificar(cu);
                cu.ID = strcookieEditarCuadrilla;
                e.ExtraParamsResponse.Add(new Ext.Net.Parameter("data", cu.ID, ParameterMode.Value));
            }
        }
Esempio n. 13
0
        public void Dibujar()
        {
            _cellWidth  = _pb.Width / Horizontales;
            _cellHeight = _pb.Height / Verticales;

            var image = new Bitmap(_pb.Width, _pb.Height);

            using (var g = Graphics.FromImage(image))
            {
                var background = new Rectangle(0, 0, image.Width, image.Height);
                g.FillRectangle(new SolidBrush(Color.White), background);

                for (var x = 0; x < Horizontales; x++)
                {
                    for (var y = 0; y < Verticales; y++)
                    {
                        var cell = Cuadrilla.GetCell(x, y);
                        switch (cell.Tipo)
                        {
                        case CellType.Vacio:
                            switch (cell.Valor)
                            {
                            case 2: g.FillRectangle(Brushes.White, GetRectangle(x, y)); break;

                            case 3: g.FillRectangle(Brushes.White, GetRectangle(x, y)); break;
                            }
                            break;

                        case CellType.Solido:
                            g.FillRectangle(Brushes.Black, GetRectangle(x, y));
                            break;

                        case CellType.Camino:
                            g.FillRectangle(Brushes.Red, GetRectangle(x, y));
                            break;

                        case CellType.Abierto:
                            g.FillRectangle(Brushes.LightSkyBlue, GetRectangle(x, y));
                            break;

                        case CellType.Cerrado:
                            g.FillRectangle(Brushes.LightSeaGreen, GetRectangle(x, y));
                            break;

                        case CellType.Actual:
                            g.FillRectangle(Brushes.Red, GetRectangle(x, y));
                            break;

                        case CellType.A:
                            g.DrawString("->", GetFont(), Brushes.Red, GetPoint(x, y));
                            break;

                        case CellType.B:
                            g.DrawString("->", GetFont(), Brushes.Red, GetPoint(x, y));
                            break;

                        default:
                            throw new ArgumentOutOfRangeException("Unknown cell type: " + cell);
                        }

                        g.DrawRectangle(Pens.Black, GetRectangle(x, y));
                    }
                }

                _pb.Image = image;
            }
        }
Esempio n. 14
0
        public override DetallesBusqueda MarcarRuta()
        {
            if (NodoActual == null)
            {
                if (!_ListaAbierta.Any())
                {
                    return(detallesBusqueda());
                }

                // utilizar el nodo actual de la lista abierta para examinarlo
                NodoActual = _ListaAbierta.OrderBy(x => x.F).ThenBy(x => x.H).First();

                // mover a la lista cerrada para no ser examinado de nuevo
                _ListaAbierta.Remove(NodoActual);
                Cerrada.Add(NodoActual);
                Cuadrilla.SetCell(NodoActual.Coord, Enums.CellType.Cerrado);

                _Vecinos.AddRange(GetNeighbours(NodoActual));
            }

            if (_Vecinos.Any())
            {
                Cuadrilla.SetCell(NodoActual.Coord, Enums.CellType.Actual);

                var vecinoDestino = _Vecinos.First();
                _Vecinos.Remove(vecinoDestino);

                // si el vecino es el destino
                if (CoordsMatch(vecinoDestino, Destino))
                {
                    // construir ruta en base a lista cerrada si se llego al destino
                    ruta = new List <Coord> {
                        vecinoDestino
                    };
                    int?Idpariente = NodoActual.Id;
                    while (Idpariente.HasValue)
                    {
                        var NodoSiguiente = Cerrada.First(x => x.Id == Idpariente);
                        ruta.Add(NodoSiguiente.Coord);
                        Idpariente = NodoSiguiente.ParentId;
                    }

                    // reordenar la ruta desde el origen al destino
                    ruta.Reverse();

                    return(detallesBusqueda());
                }

                // costo del nodo actual + el valor del paso anterior y heuristica
                var Hn          = GetH(vecinoDestino, Destino);
                var CostoCelda  = Cuadrilla.GetCell(vecinoDestino.X, vecinoDestino.Y).Valor;
                var CostoVecino = NodoActual.G + CostoCelda + Hn;

                // el nodo con menor valor en la lista abierta
                var ItemListaAbierta = _ListaAbierta.FirstOrDefault(x => x.Id == GetExistingNode(true, vecinoDestino));
                if (ItemListaAbierta != null && ItemListaAbierta.F > CostoVecino)
                {
                    // utilizo el nodo con menor costo en la lista para crear ruta
                    ItemListaAbierta.F        = CostoVecino;
                    ItemListaAbierta.ParentId = NodoActual.Id;
                }


                var itemListaCerrada = Cerrada.FirstOrDefault(x => x.Id == GetExistingNode(false, vecinoDestino));
                if (itemListaCerrada != null && itemListaCerrada.F > CostoVecino)
                {
                    //menor costo en lista cerrada
                    itemListaCerrada.F        = CostoVecino;
                    itemListaCerrada.ParentId = NodoActual.Id;
                }


                if (ItemListaAbierta != null || itemListaCerrada != null)
                {
                    return(detallesBusqueda());
                }
                _ListaAbierta.Add(new Node(Id++, NodoActual.Id, vecinoDestino, NodoActual.G + CostoCelda, Hn));
                Cuadrilla.SetCell(vecinoDestino.X, vecinoDestino.Y, Enums.CellType.Abierto);
            }
            else
            {
                Cuadrilla.SetCell(NodoActual.Coord, Enums.CellType.Cerrado);
                NodoActual = null;
                return(MarcarRuta());
            }

            return(detallesBusqueda());
        }
Esempio n. 15
0
 /// <summary>
 /// Método que Modifica una Cuadrilla por su ID
 /// </summary>
 /// <param name="dID"></param>
 public static int Modificar(Cuadrilla dID)
 {
     return(CuadrillaDataAccess.Modificar(dID));
 }
Esempio n. 16
0
 /// <summary>
 /// Método que borrar una Cuadrilla por su ID
 /// </summary>
 /// <param name="dID"></param>
 public static string Insertar(Cuadrilla dID)
 {
     return(CuadrillaDataAccess.Insertar(dID));
 }
Esempio n. 17
0
 public void Reset()
 {
     Cuadrilla.Randomize(Seed);
 }