public void TwoBeatMoves() { string jsonData = @"{ 'team': 'w', 'field': [ ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', 'b', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', 'b', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['W', '.', '.', '.', '.', '.', '.', '.'] ] }"; var boardModel = JsonConvert.DeserializeObject <BoardModel>(jsonData); board = boardModel.ConvertToArray(); var move = new List <Move> { new Move { StartingPoint = new Cell { X = 0, Y = 7 }, EndingPoint = new Cell { X = 3, Y = 4 } }, new Move { StartingPoint = new Cell { X = 3, Y = 4 }, EndingPoint = new Cell { X = 5, Y = 2 } }, }; var newBoard = board.UpdateFromMoves(move); string expectedNewBoard = @"{ 'team': 'w', 'field': [ ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', 'W', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'] ] }"; var expectedBoard = JsonConvert.DeserializeObject <BoardModel>(expectedNewBoard).ConvertToArray(); CollectionAssert.AreEqual(expectedBoard, newBoard); }
public void SeveralBeatsMoves() { string jsonData = @"{ 'team': 'w', 'field': [ ['.', 'b', '.', 'b', '.', 'b', '.', 'b'], ['b', '.', 'b', '.', 'b', '.', 'b', '.'], ['.', 'b', '.', 'b', '.', 'b', '.', 'b'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', 'b', '.', 'b', '.', '.'], ['w', '.', 'w', '.', 'w', '.', '.', '.'], ['.', 'w', '.', 'w', '.', 'w', '.', 'w'], ['w', '.', 'w', '.', 'w', '.', 'w', '.'] ] }"; var boardModel = JsonConvert.DeserializeObject <BoardModel>(jsonData); board = boardModel.ConvertToArray(); var move = new List <Move> { new Move { StartingPoint = new Cell { X = 2, Y = 5 }, EndingPoint = new Cell { X = 4, Y = 3 } }, new Move { StartingPoint = new Cell { X = 4, Y = 3 }, EndingPoint = new Cell { X = 6, Y = 5 } } }; var newBoard = board.UpdateFromMoves(move); string expectedNewBoard = @"{ 'team': 'w', 'field': [ ['.', 'b', '.', 'b', '.', 'b', '.', 'b'], ['b', '.', 'b', '.', 'b', '.', 'b', '.'], ['.', 'b', '.', 'b', '.', 'b', '.', 'b'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['w', '.', '.', '.', 'w', '.', 'w', '.'], ['.', 'w', '.', 'w', '.', 'w', '.', 'w'], ['w', '.', 'w', '.', 'w', '.', 'w', '.'] ] }"; var expectedBoard = JsonConvert.DeserializeObject <BoardModel>(expectedNewBoard).ConvertToArray(); CollectionAssert.AreEqual(expectedBoard, newBoard); }
public void OnlyItemsWithSetDepthAreStored() { var move = new List <Move> { new Move { StartingPoint = new Cell { X = 7, Y = 6 }, EndingPoint = new Cell { X = 6, Y = 5 } } }; var node = new PredictionNode { Depth = 0, InitialMoves = move, NextBoard = board.UpdateFromMoves(move), NextTeam = It.IsAny <Team>() }; var prediction = _predictionBuilder.GetDepthwisePrediction(node, It.IsAny <Team>(), 2, It.IsAny <CancellationToken>()); Assert.That(prediction.Count, Is.EqualTo(4)); Assert.That(prediction.FindAll(pr => pr.Depth == 2).Count, Is.EqualTo(4)); }
public List <Move> GetCalculatedNextMoves(CellState[,] board, Team team, List <List <Move> > beats, List <List <Move> > moves, CancellationToken token) { var firstPredictions = new List <PredictionNode>(); try { var predictions = new List <PredictionNode>(); foreach (var beat in beats) { if (beat.Count > 0) { var updatedBoard = board.UpdateFromMoves(beat); if (updatedBoard.CountEnemies(team) == 0) { return(beat); } var ranking = _getMoveWeight.CalculateMoveWeight(beat, board, updatedBoard, team, true); var node = new PredictionNode { InitialMoves = beat, NextTeam = team.GetNextTeam(), NextBoard = updatedBoard, Depth = 0, AccumulatedWeight = ranking.weight, StatsForPlayer = ranking.stats }; firstPredictions.Add(node); predictions.AddRange(_predictionBuilder.GetDepthwisePrediction(node, team, 3, token)); } } foreach (var move in moves) { if (token.IsCancellationRequested) { throw new TaskCanceledException(); } var updatedBoard = board.UpdateFromMoves(move); var ranking = _getMoveWeight.CalculateMoveWeight(move, board, updatedBoard, team); var node = new PredictionNode { InitialMoves = move, NextTeam = team.GetNextTeam(), NextBoard = updatedBoard, Depth = 0, AccumulatedWeight = ranking.weight, StatsForPlayer = ranking.stats }; firstPredictions.Add(node); predictions.AddRange(_predictionBuilder.GetDepthwisePrediction(node, team, 3, token)); } return(GetBestForRandom(predictions)); } catch (TaskCanceledException) { Console.WriteLine("Task cancelled"); } return(GetBestForRandom(firstPredictions)); }