コード例 #1
0
        private void Fila_Cero(object sender, MouseButtonEventArgs e)
        {
            if (IniciarJuego4())
            {
                for (int i = 5; i >= 0; i--)
                {
                    if (nodo_Juego.Estado[i * 7] == ' ')
                    {
                        nodo_Juego.Estado[i * 7] = 'J';

                        int result = nodo_Juego.minimax(3, true);

                        if (nodo_Juego.Fichas == null)
                        {
                            MessageBox.Show("Juego terminado");
                            this.Close();
                            return;
                        }

                        Border b = GenerarTablero_Fichas();
                        b.Background = Brushes.Red;
                        grdTablero.Children.RemoveAt(i * 7);
                        grdTablero.Children.Insert(i * 7, b);

                        NodoJuego nodo = (nodo_Juego.Fichas.FirstOrDefault(x => x.Valor == result)) as NodoJuego;
                        for (int j = 0; j < 42; j++)
                        {
                            if (nodo_Juego.Estado[j] != nodo.Estado[j])
                            {
                                nodo_Juego.Estado[j] = nodo.Estado[j];
                                Border b2 = GenerarTablero_Fichas();
                                b2.Background = Brushes.Yellow;
                                grdTablero.Children.RemoveAt(j);
                                grdTablero.Children.Insert(j, b2);
                                nodo_Juego.Fichas = null;

                                return;
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("No se ha inicializado una partida");
            }
        }
コード例 #2
0
        public override void GenerarFicha(bool esTurnoPC)
        {
            char c = esTurnoPC ? 'C' : 'J';

            for (int i = 0; i < Estado.Length; i++)
            {
                if (i <= 34)
                {
                    if (Estado[i] == ' ' && Estado[i + 7] != ' ')
                    {
                        if (Fichas == null)
                        {
                            Fichas = new List <Algoritmo>();
                        }
                        NodoJuego n = new NodoJuego();
                        n.Estado    = (char[])Estado.Clone();
                        n.Estado[i] = c;

                        Fichas.Add(n);
                    }
                }
                else
                {
                    if (Estado[i] == ' ')
                    {
                        if (Fichas == null)
                        {
                            Fichas = new List <Algoritmo>();
                        }

                        NodoJuego n = new NodoJuego();
                        n.Estado    = (char[])Estado.Clone();
                        n.Estado[i] = c;

                        Fichas.Add(n);
                    }
                }
            }
        }