Пример #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 <FourInLine> > PossiblesPlays()
        {
            List <FourInLinePlay> posiblesplays = new List <FourInLinePlay>();

            for (int j = 0; j < CountColumns; j++)
            {
                if (board[board.GetLength(0) - 1, j] == null)
                {
                    FourInLinePlay currentPlay = new FourInLinePlay(j);
                    posiblesplays.Add(currentPlay);
                }
            }
            return(posiblesplays);
        }
Пример #2
0
        /// <summary>
        /// Método que le da valores a las jugadas según las ventajas que le puedan brindar a los jugadores realizarlas (mientras más fichas haya
        /// del jugador que realiza la jugada en esa fila, columna o diagonales; más vale la jugada)
        /// </summary>
        /// <param name="play"></param>
        /// <returns></returns>
        public override double PlayScore(IPlay <FourInLine> play)
        {
            FourInLinePlay myPlay = play as FourInLinePlay;
            int            y      = myPlay.Column;
            int            x      = board.GetLength(0);

            for (int i = 0; i < board.GetLength(0); i++)
            {
                if (board[i, y] == null)
                {
                    x = i;
                }
            }

            int currentY = y;
            int currentX = x;
            int count1   = 0;
            int count2   = 0;
            int count3   = 0;
            int count4   = 0;

            while (currentY < board.GetLength(1) && board[x, y] == board[currentX, currentY])
            {
                currentY++;
                count1++;
            }

            currentX = x;
            currentY = y;
            while (currentY >= 0 && board[x, y] == board[currentX, currentY])
            {
                currentY--;
                count1++;
            }

            currentX = x;
            currentY = y;
            while (currentY >= 0 && board[x, y] == board[currentX, currentY])
            {
                currentY--;
                count2++;
            }

            currentX = x;
            currentY = y;
            while (currentY < board.GetLength(1) && currentX >= 0 && board[x, y] == board[currentX, currentY])
            {
                currentX--;
                currentY++;
                count3++;
            }

            currentX = x;
            currentY = y;
            while (currentY >= 0 && currentX < board.GetLength(0) && board[x, y] == board[currentX, currentY])
            {
                currentX++;
                currentY--;
                count3++;
            }

            currentX = x;
            currentY = y;
            while (currentY <= 0 && currentX <= 0 && board[x, y] == board[currentX, currentY])
            {
                currentX--;
                currentY--;
                count4++;
            }

            currentX = x;
            currentY = y;
            while (currentY < board.GetLength(1) && currentX >= board.GetLength(0) && board[x, y] == board[currentX, currentY])
            {
                currentX++;
                currentY++;
                count4++;
            }
            return(Math.Max(Math.Max(count1, count2), Math.Max(count3, count4)));
        }