public int NextMove(int[,] gameSurrond) { _currentSurrond = gameSurrond; if (_isFirstMove) { _sizeOfTable = gameSurrond.GetUpperBound(0) + 1; InitPositionsOfPlayers(gameSurrond); _isFirstMove = false; } // ValidateCurrentPosition(); Interface.Move nextMove = GetSafeMove(20); RecalculateNextPositionAndDirection(nextMove); return((int)nextMove); }
private bool GetIfMoveIsSafe(Point currentPosition, Interface.Direction currentDirection, Interface.Move move, int numberOfSafeMoves) { if (numberOfSafeMoves == 0) { return(true); } Interface.Direction absoluteDirection = GetAbsoluteDirection(currentDirection, move); Point nextPoint = GetNextPoint(currentPosition, absoluteDirection); if (nextPoint.X >= _sizeOfTable || nextPoint.X < 0 || nextPoint.Y >= _sizeOfTable || nextPoint.Y < 0) { return(false); } if (_currentSurrond[nextPoint.X, nextPoint.Y] != 0) { return(false); } if (IsCrossColision(nextPoint, absoluteDirection)) { return(false); } numberOfSafeMoves--; foreach (var nextMove in _moveList) { if (GetIfMoveIsSafe(nextPoint, absoluteDirection, nextMove, numberOfSafeMoves)) { return(true); } } return(false); }
private Interface.Direction GetAbsoluteDirection(Interface.Direction direction, Interface.Move move) { if (move == Interface.Move.Left) { if (direction == Interface.Direction.Top) { return(Interface.Direction.TopLeft); } return(direction - 1); } if (move == Interface.Move.Right) { if (direction == Interface.Direction.TopLeft) { return(Interface.Direction.Top); } return(direction + 1); } return(direction); }
private void RecalculateNextPositionAndDirection(Interface.Move move) { _myCurrentDirection = GetAbsoluteDirection(_myCurrentDirection, move); MyCurrentPosition = GetNextPoint(MyCurrentPosition, _myCurrentDirection); }