Exemple #1
0
        /// <summary>
        /// Enumerable de jugadas que devuelve todas las jugadas válidas para un estado del juego
        /// </summary>
        /// <returns></returns>
        public override IEnumerable <IPlay <TicTacToe> > PossiblesPlays()
        {
            List <TicTacToePlay> posiblesplays = new List <TicTacToePlay>();

            for (int i = 0; i < CountRows; i++)
            {
                for (int j = 0; j < CountColumns; j++)
                {
                    if (board[i, j] == null)
                    {
                        TicTacToePlay currentPlay = new TicTacToePlay(i, j);
                        posiblesplays.Add(currentPlay);
                    }
                }
            }
            return(posiblesplays);
        }
Exemple #2
0
        /// <summary>
        /// Método que le da valores a las jugadas según las ventajas que le puedan brindar a los jugadores realizarlas
        /// </summary>
        /// <param name="play"></param>
        /// <returns></returns>
        public override double PlayScore(IPlay <TicTacToe> play)
        {
            TicTacToePlay my_play = play as TicTacToePlay;
            int           row     = 0;
            int           column  = 0;
            int           count   = 0;
            bool          same    = true;

            for (int x = 0; x < board.GetLength(0); x++)
            {
                for (int i = 0; i < board.GetLength(1); i++)
                {
                    if (board[x, 0] != board[x, i])
                    {
                        row    = x;
                        column = i;
                        same   = false;
                    }
                    if (same)
                    {
                        count++;
                    }
                }
                if (count == board.GetLength(0) - 1)
                {
                    if (board[row, column] == null)
                    {
                        if (my_play.Row == row && my_play.Column == column)
                        {
                            return(4);
                        }
                    }
                }
            }
            count = 0;
            same  = true;
            for (int y = 0; y < board.GetLength(0); y++)
            {
                for (int i = 0; i < board.GetLength(1); i++)
                {
                    if (board[0, y] != board[i, y])
                    {
                        row    = i;
                        column = y;
                        same   = false;
                    }
                    if (same)
                    {
                        count++;
                    }
                }
                if (count == board.GetLength(1) - 1)
                {
                    if (board[row, column] == null)
                    {
                        if (my_play.Row == row && my_play.Column == column)
                        {
                            return(4);
                        }
                    }
                }
            }

            count = 0;
            same  = true;
            for (int x = 0; x < board.GetLength(0); x++)
            {
                for (int y = 0; y < board.GetLength(1); y++)
                {
                    if (x == y)
                    {
                        if (board[0, 0] != board[x, y])
                        {
                            row    = x;
                            column = y;
                            same   = false;
                        }
                        if (same)
                        {
                            count++;
                        }
                    }
                }
            }
            if (count == board.GetLength(1) - 1)
            {
                if (board[row, column] == null)
                {
                    if (my_play.Row == row && my_play.Column == column)
                    {
                        return(4);
                    }
                }
            }

            count = 0;
            same  = true;
            for (int x = 0; x < board.GetLength(0); x++)
            {
                for (int y = board.GetLength(1) - 1; y > 0; y--)
                {
                    if (x == y)
                    {
                        if (board[0, board.GetLength(0) - 1] != board[x, y])
                        {
                            row    = x;
                            column = y;
                            same   = false;
                        }
                        if (same)
                        {
                            count++;
                        }
                    }
                }
            }
            if (count == board.GetLength(1) - 1)
            {
                if (board[row, column] == null)
                {
                    if (my_play.Row == row && my_play.Column == column)
                    {
                        return(4);
                    }
                }
            }
            if (my_play.Row == 0 && my_play.Column == 0)//jugue en la esqina superior izquierda
            {
                return(2);
            }
            if (my_play.Row == 0 && my_play.Column == board.GetLength(1) - 1) //jugue en la esqina superior derecha
            {
                return(2);
            }
            if (my_play.Row == board.GetLength(0) - 1 && my_play.Column == board.GetLength(1) - 1)//jugue en la esqina inferior derecha
            {
                return(2);
            }
            if (my_play.Row == board.GetLength(0) - 1 && my_play.Column == 0)//jugue en la esqina inferior izquierda
            {
                return(2);
            }
            if (my_play.Column == 1 && my_play.Row == 1)//Juegue en el centro
            {
                return(3);
            }
            else
            {
                return(1);
            }
        }