示例#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);
            }
        }
示例#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;
        }
示例#3
0
        public bool HasElementAt(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
            {
                return(false);
            }

            return(GetElementAt(point) == element);
        }
示例#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));
        }
示例#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());
        }
示例#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);
        }
示例#7
0
 public BoardElement GetElementAt(BoardPoint point)
 {
     return((BoardElement)BoardString[GetShiftByPoint(point)]);
 }
示例#8
0
文件: GameBoard.cs 项目: alhenk/snake
 private int GetShiftByPoint(BoardPoint point)
 {
     return point.Y * Size + point.X;
 }
示例#9
0
 private int GetShiftByPoint(BoardPoint point)
 {
     return(point.Y * Size + point.X);
 }
示例#10
0
文件: GameBoard.cs 项目: alhenk/snake
        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();
        }
示例#11
0
 public bool HasBarrierAt(BoardPoint point)
 {
     return(GetBarrierPositions().Contains(point));
 }
示例#12
0
文件: GameBoard.cs 项目: alhenk/snake
 public BoardElement GetElementAt(BoardPoint point)
 {
     return (BoardElement)BoardString[GetShiftByPoint(point)];
 }
示例#13
0
文件: GameBoard.cs 项目: alhenk/snake
 public bool HasBarrierAt(BoardPoint point)
 {
     return GetBarrierPositions().Contains(point);
 }
示例#14
0
 public bool HasElementAt(BoardPoint point, params BoardElement[] elements)
 {
     return(elements.Any(elem => HasElementAt(point, elem)));
 }
示例#15
0
文件: GameBoard.cs 项目: alhenk/snake
        public bool HasElementAt(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
            {
                return false;
            }

            return GetElementAt(point) == element;
        }
示例#16
0
文件: GameBoard.cs 项目: alhenk/snake
        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);
        }
示例#17
0
文件: GameBoard.cs 项目: alhenk/snake
 public bool HasElementAt(BoardPoint point, params BoardElement[] elements)
 {
     return elements.Any(elem => HasElementAt(point, elem));
 }