private static void ShowPaths(HexBoardViewModel boardViewModel) { PathLengthBase pathLength = new PathLengthAStar(boardViewModel.Board); List <Location> playerXPath = pathLength.GetCleanPath(true); List <Location> playerYPath = pathLength.GetCleanPath(false); foreach (HexCellViewModel cell in boardViewModel.Cells) { bool onXPath = playerXPath.Contains(cell.Location); cell.DebugData.OnShortestPathForPlayerX = onXPath.ToVisibilityCollapsed(); bool onYPath = playerYPath.Contains(cell.Location); cell.DebugData.OnShortestPathForPlayerY = onYPath.ToVisibilityCollapsed(); } }
public void SpeedTest() { const int RandSeed = 24; const int BoardCount = 100; const int BoardSize = 12; Random rands = new Random(RandSeed); HexBoard[] boards = new HexBoard[BoardCount]; // make some boards for (int loopIndex = 0; loopIndex < BoardCount; loopIndex++) { boards[loopIndex] = RandomBoard(BoardSize, 10 + loopIndex, rands); } // time it the old way DateTime oldStart = DateTime.Now; foreach (HexBoard board in boards) { PathLengthLoop oldPath = new PathLengthLoop(board); oldPath.PlayerScore(true); oldPath.PlayerScore(false); } DateTime oldEnd = DateTime.Now; // and the new way DateTime newStart = DateTime.Now; foreach (HexBoard board in boards) { PathLengthAStar newPath = new PathLengthAStar(board); newPath.PlayerScore(true); newPath.PlayerScore(false); } DateTime newEnd = DateTime.Now; TimeSpan oldDuration = oldEnd - oldStart; TimeSpan newDuration = newEnd - newStart; double ratio = newDuration.Milliseconds / (double)oldDuration.Milliseconds; Assert.IsTrue(ratio < 1.0); }
private static double GetRatio(int cellFilledCount) { const int RandSeed = 24; const int BoardCount = 50; const int BoardSize = 12; Random rands = new Random(RandSeed + cellFilledCount); HexBoard[] boards = new HexBoard[BoardCount]; // make some boards for (int loopIndex = 0; loopIndex < BoardCount; loopIndex++) { boards[loopIndex] = RandomBoard(BoardSize, cellFilledCount, rands); } // time it the old way DateTime oldStart = DateTime.Now; foreach (HexBoard board in boards) { PathLengthLoop oldPath = new PathLengthLoop(board); oldPath.PlayerScore(true); oldPath.PlayerScore(false); } DateTime oldEnd = DateTime.Now; // and the new way DateTime newStart = DateTime.Now; foreach (HexBoard board in boards) { PathLengthAStar newPath = new PathLengthAStar(board); newPath.PlayerScore(true); newPath.PlayerScore(false); } DateTime newEnd = DateTime.Now; TimeSpan oldDuration = oldEnd - oldStart; TimeSpan newDuration = newEnd - newStart; double ratio = newDuration.Milliseconds / (double)oldDuration.Milliseconds; return(ratio); }
private static void CheckPathLength(HexBoard board, int boardIndex) { // first do it with the old path length PathLengthLoop oldPath = new PathLengthLoop(board); int oldX = oldPath.PlayerScore(true); int oldY = oldPath.PlayerScore(false); // now the new PathLengthAStar newPath = new PathLengthAStar(board) { UseNeighbours2 = false }; int newX = newPath.PlayerScore(true); int newY = newPath.PlayerScore(false); Assert.AreEqual(oldX, newX, "X not equal at board index" + boardIndex); Assert.AreEqual(oldY, newY, "Y not equal at board index" + boardIndex); }