Ejemplo n.º 1
0
        public void ResetGame()
        {
            for (byte i = 0; i < 3; i++)
            {
                for (byte j = 0; j < 3; j++)
                {
                    Game[i, j] = null;
                }
            }

            AI    = new TicTacToeMinimax();
            State = Result.Game;
            move  = 0;
        }
Ejemplo n.º 2
0
        public void HandleTap(TappedRoutedEventArgs e)
        {
            if (State != Result.Game)
            {
                return;
            }

            // Get Bounds
            Rect bounds    = ApplicationView.GetForCurrentView().VisibleBounds;
            Rect imgBounds = Grid.Bounds;

            // Get Startingpoint & Ratio
            float   ratio      = GetRatio(bounds, imgBounds);
            Vector2 startPoint = GetStartPoint(bounds, imgBounds, ratio);
            Point   tapped     = e.GetPosition(Canvas);

            // Tapped outside of grid
            if ((tapped.X < startPoint.X) || (tapped.Y < startPoint.Y))
            {
                return;
            }

            for (byte i = 1; i <= 3; i++)
            {
                for (byte j = 1; j <= 3; j++)
                {
                    Vector2 location = startPoint + new Vector2(i * ratio * 166, j * ratio * 166);
                    if ((tapped.X < location.X) && (tapped.Y < location.Y))
                    {
                        if (Game[i - 1, j - 1] == null)
                        {
                            Game[i - 1, j - 1] = move++;
                            AI.goTo((byte)(i - 1), (byte)(j - 1));
                            State = TicTacToeMinimax.Evaluate(Game);

                            // If game continues, get oponent move
                            if (State == Result.Game)
                            {
                                (byte x, byte y)o = AI.getMove();
                                Game[o.x, o.y]    = move++;
                                State             = TicTacToeMinimax.Evaluate(Game);
                            }
                        }
                        return;
                    }
                }
            }
        }