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); } }
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; }
public bool HasElementAt(BoardPoint point, BoardElement element) { if (point.IsOutOfBoard(Size)) { return(false); } return(GetElementAt(point) == element); }
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)); }
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()); }
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); }
public BoardElement GetElementAt(BoardPoint point) { return((BoardElement)BoardString[GetShiftByPoint(point)]); }
private int GetShiftByPoint(BoardPoint point) { return point.Y * Size + point.X; }
private int GetShiftByPoint(BoardPoint point) { return(point.Y * Size + point.X); }
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(); }
public bool HasBarrierAt(BoardPoint point) { return(GetBarrierPositions().Contains(point)); }
public BoardElement GetElementAt(BoardPoint point) { return (BoardElement)BoardString[GetShiftByPoint(point)]; }
public bool HasBarrierAt(BoardPoint point) { return GetBarrierPositions().Contains(point); }
public bool HasElementAt(BoardPoint point, params BoardElement[] elements) { return(elements.Any(elem => HasElementAt(point, elem))); }
public bool HasElementAt(BoardPoint point, BoardElement element) { if (point.IsOutOfBoard(Size)) { return false; } return GetElementAt(point) == element; }
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); }
public bool HasElementAt(BoardPoint point, params BoardElement[] elements) { return elements.Any(elem => HasElementAt(point, elem)); }