private Move TryMove(Position position, QuoridorPlayer currentPlayer) { if (MoveValidator.IsValid(GetBoardArray(), currentPlayer.CurrentPosition, Players.Select(p => p.CurrentPosition), position)) { //if (changeAllowed) { MovePlayer(currentPlayer, position); } return(new Move { Destination = position }); } return(null); }
public void MovePlayer(QuoridorPlayer player, Move move) { if (!Players.Contains(player)) { throw new ArgumentException(); } if (move.IsMove) { var position = TranslatePlayerPosition(player, move.Destination); #if _USE_ADDITIONAL_VALIDATION if (!MoveValidator.IsValid(GetBoardArray(), player.CurrentPosition, Players.Select(p => p.CurrentPosition), position)) { //this is kind of second time validation - we dont neceserry need it in production throw new ArgumentException(); } #endif var playerBoardElement = this[player.CurrentPosition]; this[player.CurrentPosition] = BoardElementType.Empty; BoardMatrix[player.CurrentPosition.Y][player.CurrentPosition.X].Player = null; player.CurrentPosition = position; this[player.CurrentPosition] = playerBoardElement; BoardMatrix[player.CurrentPosition.Y][player.CurrentPosition.X].Player = player; } else if (move.IsWallPlacement) { var positions = move.WallPlacementPositions.Select(p => TranslatePlayerPosition(player, p)); #if _USE_ADDITIONAL_VALIDATION if (!WallValidator.AreValid(GetBoardArray(), Players, player, positions.ToArray())) { //this is kind of second time validation - we dont neceserry need it in production throw new ArgumentException(); } #endif foreach (var position in positions) { this[position] = BoardElementType.Wall; } } else { throw new ArgumentException(); } }
public override async Task <Move> GetMove() { Move newMove = null; await Task.Run(() => { var boardCopy = board.GetBoardArray(); do { RollNewPosition(); if (random.NextDouble() <= _probabilityOfWallPlacement && NumberOfWallsAvalaible > 0 && WallValidator.AreValid(boardCopy, board.Players, this, wallPositions)) { newMove = new Move() { IsWallPlacement = true, WallPlacementPositions = wallPositions }; } else if (MoveValidator.IsValid(boardCopy, CurrentPosition, board.PlayersPositions, movePosition)) { newMove = new Move() { Destination = movePosition }; } } while (newMove == null); System.Threading.Tasks.Task.Delay(500).Wait();//AI is thinking :D if (newMove.IsWallPlacement) { NumberOfWallsAvalaible--; } }); return(newMove); }
public void ValidatesInput(string input, bool expectedValidity) { Assert.AreEqual(expectedValidity, MoveValidator.IsValid(input)); }