Exemplo n.º 1
0
        private void CalculateNextStepBoardPoints()
        {
            if (!BoardPoints.Any())
            {
                return;
            }


            var maxPossibility       = BoardPoints.Max(x => x.ChopperPossibility);
            var maxPossibilityPoints = BoardPoints.Where(x => x.ChopperPossibility == maxPossibility).ToList();

            var possibility = maxPossibilityPoints.Count > 1 ? 30 : 50;

            foreach (var maxPossibilityPoint in maxPossibilityPoints)
            {
                var nextStepPoint = maxPossibilityPoint.GetNearPoint(maxPossibilityPoint.ChopperMovePosition);

                var boardPoint = new BoardPoint(nextStepPoint)
                {
                    ChopperPossibility   = possibility,
                    ChopperMoveDirection = maxPossibilityPoint.ChopperMoveDirection,
                    ChopperMovePosition  = maxPossibilityPoint.ChopperMovePosition
                };

                BoardPoints.Add(boardPoint);
            }
        }
Exemplo n.º 2
0
        public void InitBoardPoints()
        {
            BoardPoints.Clear();

            var coefficients = new List <Tuple <int, int, MoveDirection> >();
            var result       = new List <BoardPoint>();

            if (IsUnknownPossibleDirection)
            {
                for (var i = 0; i < _nextTickPoints.Count; i++)
                {
                    var point = _nextTickPoints[i];

                    if (Global.Board.IsAnyOfAt(point.Item2, CanNotMoveThrought))
                    {
                        continue;
                    }

                    coefficients.Add(new Tuple <int, int, MoveDirection>(i, _nextTickMaxPossibility, _nextTickMoveDirectionMap[i]));
                }
            }
            else
            {
                for (int i = 0; i < _nextTickPoints.Count; i++)
                {
                    var point = _nextTickPoints[i];

                    if (Global.Board.IsAnyOfAt(point.Item2, CanNotMoveThrought))
                    {
                        continue;
                    }

                    var coefficient = _nextTickPointMovePossibilities[_nextTickMoveDirectionMap[i]];
                    coefficients.Add(new Tuple <int, int, MoveDirection>(i, coefficient, _nextTickMoveDirectionMap[i]));
                }
            }

            var coefficientsSum = coefficients.Select(x => x.Item2).Sum();

            foreach (var coefficient in coefficients)
            {
                var point = _nextTickPoints[coefficient.Item1];

                var boardPoint = new BoardPoint(point.Item2)
                {
                    ChopperPossibility   = coefficient.Item2 * 100 / coefficientsSum,
                    ChopperMoveDirection = coefficient.Item3,
                    ChopperMovePosition  = point.Item1
                };

                result.Add(boardPoint);
            }

            BoardPoints.AddRange(result);

            CalculateNextStepBoardPoints();

            //Console.WriteLine(string.Join(" | ", BoardPoints.Select(x => x.Point + " " + x.ChopperPossibility)));
            //return result;
        }
Exemplo n.º 3
0
        public bool HasElementAt(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
            {
                return(false);
            }

            return(GetElementAt(point) == element);
        }
Exemplo n.º 4
0
        public bool IsNearToElement(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
            {
                return(false);
            }

            return(HasElementAt(point.ShiftBottom(), element) ||
                   HasElementAt(point.ShiftTop(), element) ||
                   HasElementAt(point.ShiftLeft(), element) ||
                   HasElementAt(point.ShiftRight(), element));
        }
Exemplo n.º 5
0
        public int GetCountElementsNearToPoint(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
            {
                return(0);
            }

            //GetHashCode() in classic MS.NET for bool returns 1 for true and 0 for false;
            return(HasElementAt(point.ShiftLeft(), element).GetHashCode() +
                   HasElementAt(point.ShiftRight(), element).GetHashCode() +
                   HasElementAt(point.ShiftTop(), element).GetHashCode() +
                   HasElementAt(point.ShiftBottom(), element).GetHashCode());
        }
Exemplo n.º 6
0
        public List <BoardPoint> FindAllElements(BoardElement element)
        {
            List <BoardPoint> result = new List <BoardPoint>();

            for (int i = 0; i < Size * Size; i++)
            {
                BoardPoint pt = GetPointByShift(i);

                if (HasElementAt(pt, element))
                {
                    result.Add(pt);
                }
            }

            return(result);
        }
Exemplo n.º 7
0
 public BoardElement GetElementAt(BoardPoint point)
 {
     return((BoardElement)BoardString[GetShiftByPoint(point)]);
 }
Exemplo n.º 8
0
 private int GetShiftByPoint(BoardPoint point)
 {
     return point.Y * Size + point.X;
 }
Exemplo n.º 9
0
 private int GetShiftByPoint(BoardPoint point)
 {
     return(point.Y * Size + point.X);
 }
Exemplo n.º 10
0
        public int GetCountElementsNearToPoint(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
                return 0;

            //GetHashCode() in classic MS.NET for bool returns 1 for true and 0 for false;
            return HasElementAt(point.ShiftLeft(), element).GetHashCode() +
                   HasElementAt(point.ShiftRight(), element).GetHashCode() +
                   HasElementAt(point.ShiftTop(), element).GetHashCode() +
                   HasElementAt(point.ShiftBottom(), element).GetHashCode();
        }
Exemplo n.º 11
0
 public bool HasBarrierAt(BoardPoint point)
 {
     return(GetBarrierPositions().Contains(point));
 }
Exemplo n.º 12
0
 public BoardElement GetElementAt(BoardPoint point)
 {
     return (BoardElement)BoardString[GetShiftByPoint(point)];
 }
Exemplo n.º 13
0
 public bool HasBarrierAt(BoardPoint point)
 {
     return GetBarrierPositions().Contains(point);
 }
Exemplo n.º 14
0
 public bool HasElementAt(BoardPoint point, params BoardElement[] elements)
 {
     return(elements.Any(elem => HasElementAt(point, elem)));
 }
Exemplo n.º 15
0
        public bool HasElementAt(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
            {
                return false;
            }

            return GetElementAt(point) == element;
        }
Exemplo n.º 16
0
        public bool IsNearToElement(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
                return false;

            return HasElementAt(point.ShiftBottom(), element)
                   || HasElementAt(point.ShiftTop(), element)
                   || HasElementAt(point.ShiftLeft(), element)
                   || HasElementAt(point.ShiftRight(), element);
        }
Exemplo n.º 17
0
 public bool HasElementAt(BoardPoint point, params BoardElement[] elements)
 {
     return elements.Any(elem => HasElementAt(point, elem));
 }