Esempio n. 1
0
        /// <summary>
        /// Метод проверяет координаты оппонента в спорной ситуации.
        /// </summary>
        /// <param name="coordinatesOfMove"></param>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <param name="priority"></param>
        private void CheckOpponentPoints(ref CoordinatesOfMove coordinatesOfMove, int i, int j, int priority)
        {
            Random randForEqualPriority = new Random();

            if (_cell[i, j].OpponentPoints > _cell[coordinatesOfMove.Y, coordinatesOfMove.X].OpponentPoints)
            {
                SetNewCoordinates(ref coordinatesOfMove, i, j, priority);
            }
            else if (_cell[i, j].OpponentPoints == _cell[coordinatesOfMove.Y, coordinatesOfMove.X].OpponentPoints && randForEqualPriority.Next(0, 100) > 50)
            {
                SetNewCoordinates(ref coordinatesOfMove, i, j, priority);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Ход компьютера
        /// </summary>
        /// <returns></returns>
        public override string Move()
        {
            Console.ForegroundColor = PlayerColor;
            Console.WriteLine($"Игрок №{Number}({Sign}) думает!");
            Console.ResetColor();
            CoordinatesOfMove coordinatesOfMove = new CoordinatesOfMove();

            HorizontalAnalysis();
            VerticalAnalysis();
            LeftDiagonalAnalysis();
            RightDiagonalAnalysis();
            PriorityAssessment(ref coordinatesOfMove);
            Thread.Sleep(1000);
            return(ConvertToCoordinate(coordinatesOfMove.Y, coordinatesOfMove.X));
        }
Esempio n. 3
0
        /// <summary>
        /// Метод вычисляет приоритетные координаты
        /// </summary>
        /// <param name="coordinatesOfMove"></param>
        private void PriorityAssessment(ref CoordinatesOfMove coordinatesOfMove)
        {
            for (int i = 0; i < _numberOfLines; i++)
            {
                for (int j = 0; j < _numberOfColumns; j++)
                {
                    if (_cell[i, j].MyLine == 5)
                    {
                        SetNewCoordinates(ref coordinatesOfMove, i, j, priority: 8);
                    }

                    else if (coordinatesOfMove.Priority < 7 && _cell[i, j].OpponentLine == 5)
                    {
                        SetNewCoordinates(ref coordinatesOfMove, i, j, priority: 7);
                    }

                    else if (coordinatesOfMove.Priority < 6 && _cell[i, j].MyLine == 4)
                    {
                        SetNewCoordinates(ref coordinatesOfMove, i, j, priority: 6);
                    }
                    else if (coordinatesOfMove.Priority == 6 && _cell[i, j].MyLine == _cell[coordinatesOfMove.Y, coordinatesOfMove.X].MyLine)
                    {
                        CheckMyPoints(ref coordinatesOfMove, i, j, 6);
                    }

                    else if (coordinatesOfMove.Priority < 5 && _cell[i, j].OpponentLine == 4)
                    {
                        SetNewCoordinates(ref coordinatesOfMove, i, j, priority: 5);
                    }
                    else if (coordinatesOfMove.Priority == 5 && _cell[i, j].OpponentLine == _cell[coordinatesOfMove.Y, coordinatesOfMove.X].OpponentLine)
                    {
                        CheckOpponentPoints(ref coordinatesOfMove, i, j, 5);
                    }

                    else if (coordinatesOfMove.Priority < 4 && _cell[i, j].MyLine == 3)
                    {
                        SetNewCoordinates(ref coordinatesOfMove, i, j, priority: 4);
                    }
                    else if (coordinatesOfMove.Priority == 4 && _cell[i, j].MyLine == _cell[coordinatesOfMove.Y, coordinatesOfMove.X].MyLine)
                    {
                        CheckMyPoints(ref coordinatesOfMove, i, j, 4);
                    }

                    else if (coordinatesOfMove.Priority < 3 && _cell[i, j].OpponentLine == 3)
                    {
                        SetNewCoordinates(ref coordinatesOfMove, i, j, priority: 3);
                    }
                    else if (coordinatesOfMove.Priority == 3 && _cell[i, j].OpponentLine == _cell[coordinatesOfMove.Y, coordinatesOfMove.X].OpponentLine)
                    {
                        CheckOpponentPoints(ref coordinatesOfMove, i, j, 3);
                    }

                    else if (coordinatesOfMove.Priority < 2 && _cell[i, j].MyLine == 2)
                    {
                        SetNewCoordinates(ref coordinatesOfMove, i, j, priority: 2);
                    }
                    else if (coordinatesOfMove.Priority == 2 && _cell[i, j].MyLine == _cell[coordinatesOfMove.Y, coordinatesOfMove.X].MyLine)
                    {
                        CheckMyPoints(ref coordinatesOfMove, i, j, 2);
                    }

                    else if (coordinatesOfMove.Priority < 1 && _cell[i, j].OpponentLine == 2)
                    {
                        SetNewCoordinates(ref coordinatesOfMove, i, j, priority: 1);
                    }
                    else if (coordinatesOfMove.Priority == 1 && _cell[i, j].OpponentLine == _cell[coordinatesOfMove.Y, coordinatesOfMove.X].OpponentLine)
                    {
                        CheckOpponentPoints(ref coordinatesOfMove, i, j, 1);
                    }
                    else if (coordinatesOfMove.Priority == 0)
                    {
                        coordinatesOfMove.Y = 7;
                        coordinatesOfMove.X = 7;
                    }
                }
            }
            ClearPointBoard();
        }
Esempio n. 4
0
 /// <summary>
 /// Метод устанавливает новые координаты.
 /// </summary>
 /// <param name="coordinatesOfMove"></param>
 /// <param name="i"></param>
 /// <param name="j"></param>
 /// <param name="priority"></param>
 private static void SetNewCoordinates(ref CoordinatesOfMove coordinatesOfMove, int i, int j, int priority)
 {
     coordinatesOfMove.Y        = i;
     coordinatesOfMove.X        = j;
     coordinatesOfMove.Priority = priority;
 }