예제 #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
파일: GameBoard.cs 프로젝트: evoyager/snake
        public bool HasElementAt(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
            {
                return(false);
            }

            return(GetElementAt(point) == element);
        }
예제 #4
0
파일: GameBoard.cs 프로젝트: evoyager/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));
        }
예제 #5
0
파일: GameBoard.cs 프로젝트: evoyager/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());
        }
예제 #6
0
파일: GameBoard.cs 프로젝트: evoyager/snake
        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
파일: GameBoard.cs 프로젝트: evoyager/snake
 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
파일: GameBoard.cs 프로젝트: evoyager/snake
 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
파일: GameBoard.cs 프로젝트: evoyager/snake
 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
파일: GameBoard.cs 프로젝트: evoyager/snake
 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));
 }