public void CalculateFitnessTest(string input, int expeceted) { var matrix = input.StringToByteMatrix(4); var weights = new TsitsiklisWeights(1, 3); var algorithm = new Tsitsiklis(weights); Assert.AreEqual(expeceted, algorithm.CalculateFitness(matrix, null, 0, 0)); }
public void GetBestMoveTest(string input, Color color1, Color color2, int expeceted) { var matrix = input.StringToByteMatrix(10); var weights = new TsitsiklisWeights(1, 3); var algorithm = new Tsitsiklis(weights); var manager = new BoardManager(matrix); manager.SpawnPill(color1, color2); var engine = new AiEngine(algorithm); var bestMove = engine.GetNextMove(manager); Assert.AreEqual(expeceted, bestMove.Fitness); }
public void GetBestMoveTest(string input, BlockType newBlockType, int expeceted) { var boolMatrix = input.StringToBoolMatrix(10); var weights = new TsitsiklisWeights(1, 3); var algorithm = new Tsitsiklis(weights); var manager = new BoardManager(boolMatrix); manager.SpawnBlock(newBlockType); var engine = new Engine(algorithm); var bestMove = engine.GetNextMove(manager); Assert.AreEqual(expeceted, bestMove.Fitness); }
public void MovesAreCorrect(string input, BlockType newBlockType, Move[] expeceted) { var boolMatrix = input.StringToBoolMatrix(8); var weights = new TsitsiklisWeights(1, 3); var algorithm = new Tsitsiklis(weights); var manager = new BoardManager(boolMatrix); manager.SpawnBlock(newBlockType); var engine = new Engine(algorithm); var bestMove = engine.GetNextMove(manager); var moves = bestMove.Moves; Assert.IsTrue(bestMove.IsValid); Assert.That(bestMove.Fitness, Is.AtMost(1), "Fitness"); Assert.AreEqual(expeceted.Where(x => x == Move.Right).Count(), moves.Where(x => x == Move.Right).Count()); Assert.AreEqual(expeceted.Where(x => x == Move.Left).Count(), moves.Where(x => x == Move.Left).Count()); Assert.AreEqual(expeceted.Where(x => x == Move.RotateLeft).Count(), moves.Where(x => x == Move.RotateLeft).Count()); Assert.AreEqual(expeceted.Where(x => x == Move.RotateRight).Count(), moves.Where(x => x == Move.RotateRight).Count()); }