public Cell GetCell(string code) { var position = positionParser.TryParse(code); if (!position.HasValue) { return(null); } return(GetCell(position.Value)); }
public ValueOrError <bool> MakeMove(string move) { if (move == "pass") { CurrentColor = CurrentColor.Opposite(); return(ValueOrError.FromValue <bool>(true)); } var position = parser.TryParse(move); if (!position.HasValue) { return(ValueOrError.FromError <bool>($"Wrong code: {move}")); } if (possibleMovesFinder.GetPossibleMoves(Field).Any(possibleMove => possibleMove.Color == CurrentColor && possibleMove.Position == position.Value)) { var result = Field.MakeMove(move, CurrentColor); if (result.HasValue) { CurrentColor = CurrentColor.Opposite(); } return(result); } return(ValueOrError.FromError <bool>($"Move {move} is impossible for {CurrentColor}")); }
public void ParserShouldParsePosition(string input, Position?result) { Assert.That(parser.TryParse(input), Is.EqualTo(result)); }