Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <profiler>
  3.  
  4. #define ROUNDS 10
  5. #define TEAMS 3
  6. #define PLAYERS 32+1
  7. #define DETECTIVES 12
  8.  
  9. public void OnPluginStart()
  10. {
  11. RegConsoleCmd("sm_r2", Command_Random);
  12. }
  13.  
  14. public Action Command_Random(int iClient, int iArgs)
  15. {
  16. // For every test a new file (better overview)
  17. char path[PLATFORM_MAX_PATH];
  18. BuildPath(Path_SM, path, sizeof(path), "randomTest_%d.txt", GetTime());
  19.  
  20. File file = OpenFile(path, "w");
  21. if (file == INVALID_HANDLE)
  22. {
  23. LogError("Could not open spawn point file \"%s\" for writing.", path);
  24. return Plugin_Handled;
  25. }
  26.  
  27. Handle hProfile = CreateProfiler();
  28. StartProfiling(hProfile);
  29.  
  30. int iTeam[PLAYERS][TEAMS];
  31. int lastTeam[PLAYERS] = {-1, ...};
  32. bool wantDetective[PLAYERS] = {false, ...};
  33. int dCount = 0;
  34.  
  35. for (int client = 1; client <= PLAYERS-1; client++)
  36. {
  37. if (dCount == DETECTIVES)
  38. {
  39. break;
  40. }
  41.  
  42. wantDetective[client] = (GetRandomInt(0, 1) == 0);
  43. dCount++;
  44. }
  45.  
  46. // Rounds per Map
  47. for (int i = 1; i <= ROUNDS; i++)
  48. {
  49. file.WriteLine("Round: %d", i);
  50.  
  51. Handle hRoundProfil = CreateProfiler();
  52. StartProfiling(hRoundProfil);
  53.  
  54. int newTeam[PLAYERS];
  55.  
  56. // Player Count
  57. for (int client = 1; client <= PLAYERS-1; client++)
  58. {
  59. int tries = 0;
  60.  
  61. newTeam[client] = GetRandomInt(0, TEAMS-1);
  62. tries++;
  63.  
  64. // If anyone want detective
  65. while (newTeam[client] == 0 && !wantDetective[client])
  66. {
  67. newTeam[client] = GetRandomInt(0, TEAMS-1);
  68. tries++;
  69. break;
  70. }
  71.  
  72. // We don't want 2 times in the same team
  73. while (lastTeam[client] != -1 && newTeam[client] == lastTeam[client])
  74. {
  75. newTeam[client] = GetRandomInt(0, TEAMS-1);
  76. tries++;
  77. break;
  78. }
  79.  
  80. iTeam[client][newTeam[client]]++;
  81. file.WriteLine("Player: %d, Detective? %d, Tries: %d (LastTeam: %d), Team 1: %d, Team 2: %d, Team 3: %d", client, wantDetective[client], tries, lastTeam[client], iTeam[client][0], iTeam[client][1], iTeam[client][2]);
  82. lastTeam[client] = newTeam[client];
  83. }
  84.  
  85. // Round statistic
  86. int teams[TEAMS];
  87.  
  88. for (int client = 1; client <= PLAYERS-1; client++)
  89. {
  90. for (int x = 0; x <= TEAMS-1; x++)
  91. {
  92. if (newTeam[client] == x)
  93. {
  94. teams[x]++;
  95. }
  96. }
  97. }
  98.  
  99. file.WriteLine("Statistic for round %d: Team 1: %d, Team 2: %d, Team 3: %d", i, teams[0], teams[1], teams[2]);
  100.  
  101. StopProfiling(hRoundProfil);
  102. float fRoundTime = GetProfilerTime(hRoundProfil);
  103. file.WriteLine("Benchmark for round %d: %f", i, fRoundTime);
  104.  
  105. file.WriteLine("\n");
  106. }
  107.  
  108. StopProfiling(hProfile);
  109. float fTime = GetProfilerTime(hProfile);
  110. file.WriteLine("Benchmark all rounds: %f", fTime);
  111.  
  112. delete file;
  113. return Plugin_Continue;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement