예제 #1
0
        public static void UpdateGame(this State st, BooleanState boolst)
        {
            var temp = st.GameState;

            for (int i = 0; i < st.Size; i++)
            {
                for (int j = 0; j < st.Size; j++)
                {
                    var box     = temp[i, j];
                    var boxbool = boolst.BooleanGame[i, j];
                    if ((!box.Down.IsDraw && boxbool.Down))
                    {
                        box.Down.DrawLine();
                        break;
                    }
                    else if ((!box.Up.IsDraw && boxbool.Up))
                    {
                        box.Up.DrawLine();
                        break;
                    }
                    else if ((!box.Left.IsDraw && boxbool.Left))
                    {
                        box.Left.DrawLine();
                        break;
                    }
                    else if ((!box.Right.IsDraw && boxbool.Right))
                    {
                        box.Right.DrawLine();
                        break;
                    }
                }
            }
        }
예제 #2
0
        private void MyCircle_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Ellipse clickdot = ((Ellipse)sender);

            if (!OnlyOneSelected)
            {
                PreviousEl = clickdot;
                if (!gameState.Jugador)//0 Max
                {
                    clickdot.Stroke = Brushes.Blue;
                }
                else
                {
                    clickdot.Stroke = Brushes.Red;//Min Rojo
                }
                clickdot.StrokeThickness = 3;
                TAGPrevious     = (TAGInfo)clickdot.Tag;
                OnlyOneSelected = true;
            }
            else
            {
                OnlyOneSelected = false;
                if (TAGPrevious.TAG == ((TAGInfo)clickdot.Tag).TAG)
                {
                    clickdot.Stroke          = Brushes.Black;
                    clickdot.StrokeThickness = 1;
                }
                else
                {
                    double  x1 = TAGPrevious.X + 10;
                    double  x2 = ((TAGInfo)clickdot.Tag).X + 10;
                    double  y1 = TAGPrevious.Y + 10;
                    double  y2 = ((TAGInfo)clickdot.Tag).Y + 10;
                    DotLine linetodraw;
                    //Sirve para izquierda a derecha y arriba hacia abajo
                    linetodraw = gameState.ItemsLine.Where(x => (x.X1 == x1 && x.Y1 == y1 && x.X2 == x2 && x.Y2 == y2) ||
                                                           (x.X1 == x2 && x.Y1 == y2 && x.X2 == x1 && x.Y2 == y1)).SingleOrDefault();
                    linetodraw?.DrawLine();
                    PreviousEl.Stroke          = Brushes.Black;
                    PreviousEl.StrokeThickness = 1;



                    //Dibujar rectangulito
                    Thread.Sleep(10);
                    DrawBox();
                    while (gameState.Jugador)
                    {
                        //Hacer jugada por parte de la maquina

                        var          tem = Alg.MaxValue(gameState.BooleanRepresentation(), float.MinValue + 1, float.MaxValue - 1, 4);
                        BooleanState t   = Alg.Result;
                        gameState.UpdateGame(t);
                        DrawBox();
                    }
                }
            }
        }
예제 #3
0
 public static void Print(this BooleanState te)
 {
     Console.WriteLine("Filas");
     te.BoolRow.PrintMatrix();
     Console.WriteLine("Colummnas");
     te.BoolColumn.PrintMatrix();
     Console.WriteLine("Cajas");
     te.GetBoolBoxes().PrintMatrix();
 }
예제 #4
0
        public int EvalHeuristic(BooleanState state)
        {
            //20x1+5x2-10x3
            var temp = state.getData();
            int X1   = temp.X1;
            int X2   = temp.X2;
            int X3   = temp.X3;

            return(30 * X1 + 5 * X2 - 10 * X3);
        }
예제 #5
0
        internal List <BooleanState> GetSuccessors()
        {
            List <BooleanState> myStates = new List <BooleanState>();
            int Estado = 0;

            //Comenzamos por las filas (Cambio en una fila, un nuevo estado)
            for (int i = 0; i < Size + 1; i++)
            {
                for (int j = 0; j < Size; j++)
                {
                    if (!BoolRow[i, j])//Si no hay linea dibujada, supondremos que se ha dibujado
                    {
                        //            Estado++;
                        //            Console.WriteLine("--------------------------------------------------------------Estado: " + Estado);
                        BooleanState NewChild = new BooleanState();
                        bool         t        = !BoolRow[i, j];
                        bool[,] boolRow2    = (bool[, ])BoolRow.Clone();
                        boolRow2[i, j]      = t;
                        NewChild.Size       = Size;
                        NewChild.BoolRow    = boolRow2;
                        NewChild.BoolColumn = (bool[, ])BoolColumn.Clone();
                        NewChild.Player     = Player;
                        NewChild.CreateBoxMatrix();
                        //NewChild.Print();
                        myStates.Add(NewChild);
                    }
                    if (!BoolColumn[i, j])//Si no hay linea dibujada, supondremos que se ha dibujado
                    {
                        //            Estado++;
                        //         Console.WriteLine("--------------------------------------------------------------Estado: " + Estado);
                        BooleanState NewChild = new BooleanState();
                        bool         t        = !BoolColumn[i, j];
                        bool[,] boolRow2          = (bool[, ])BoolRow.Clone();
                        NewChild.BoolColumn       = (bool[, ])BoolColumn.Clone();
                        NewChild.BoolColumn[i, j] = t;
                        NewChild.BoolRow          = boolRow2;
                        NewChild.Player           = Player;
                        NewChild.Size             = Size;
                        NewChild.CreateBoxMatrix();
                        //NewChild.Print();
                        myStates.Add(NewChild);
                    }
                }
            }

            return(myStates);
        }
예제 #6
0
 public static void CreateBoxMatrix(this BooleanState te)
 {
     BooleanBox[,] gmstate = new BooleanBox[te.Size, te.Size];
     for (int i = 0; i < te.Size; i++)
     {
         for (int j = 0; j < te.Size; j++)
         {
             bool up    = te.BoolRow[i, j];
             bool down  = te.BoolRow[i + 1, j];
             bool left  = te.BoolColumn[j, i];
             bool right = te.BoolColumn[j + 1, i];
             gmstate[i, j] = new BooleanBox {
                 Up = up, Left = left, Right = right, Down = down
             };
         }
     }
     te.BooleanGame = gmstate;
 }
예제 #7
0
        private float MinValue(BooleanState state, float Alpha, float Beta, int Depth)
        {
            if (Depth == 0)
            {
                return(EvalHeuristic(state));
            }
            List <BooleanState> Successors = state.GetSuccessors();

            foreach (BooleanState s in Successors)
            {
                Beta = Math.Min(Beta, MaxValue(s, Alpha, Beta, Depth - 1));
                if (Beta <= Alpha)
                {
                    break;
                }
            }

            return(Beta);
        }
예제 #8
0
        internal BooleanState BooleanRepresentation()
        {
            //Se arma el equivalente booleano
            BooleanState myState = new BooleanState();

            bool[,] rows    = new bool[Size + 1, Size];
            bool[,] columns = new bool[Size + 1, Size];
            for (int i = 0; i < Size + 1; i++)
            {
                for (int j = 0; j < Size; j++)
                {
                    rows[i, j]    = Rows[i][j].IsDraw;
                    columns[i, j] = Columns[i][j].IsDraw;
                }
            }
            BooleanState Temp = new BooleanState {
                BoolColumn = columns, BoolRow = rows, Player = Jugador, Size = Size
            };

            Temp.CreateBoxMatrix();
            return(Temp);
        }
예제 #9
0
        public float MaxValue(BooleanState state, float Alpha, float Beta, int Depth)
        {
            if (Depth == 0)
            {
                return(EvalHeuristic(state));
            }
            List <BooleanState> Successors = state.GetSuccessors();

            foreach (BooleanState s in Successors)
            {//Bug inside the successors list
                Alpha = Math.Max(Alpha, MinValue(s, Alpha, Beta, Depth - 1));
                if (Depth == 4 && Alpha >= my)
                {
                    Result = s;
                    my     = Alpha;
                }
                if (Beta <= Alpha)
                {
                    break;
                }
            }
            return(Alpha);
        }