#include #include #define ROUNDS 10 #define TEAMS 3 #define PLAYERS 32+1 #define DETECTIVES 12 public void OnPluginStart() { RegConsoleCmd("sm_r2", Command_Random); } public Action Command_Random(int iClient, int iArgs) { // For every test a new file (better overview) char path[PLATFORM_MAX_PATH]; BuildPath(Path_SM, path, sizeof(path), "randomTest_%d.txt", GetTime()); File file = OpenFile(path, "w"); if (file == INVALID_HANDLE) { LogError("Could not open spawn point file \"%s\" for writing.", path); return Plugin_Handled; } Handle hProfile = CreateProfiler(); StartProfiling(hProfile); int iTeam[PLAYERS][TEAMS]; int lastTeam[PLAYERS] = {-1, ...}; bool wantDetective[PLAYERS] = {false, ...}; int dCount = 0; for (int client = 1; client <= PLAYERS-1; client++) { if (dCount == DETECTIVES) { break; } wantDetective[client] = (GetRandomInt(0, 1) == 0); dCount++; } // Rounds per Map for (int i = 1; i <= ROUNDS; i++) { file.WriteLine("Round: %d", i); Handle hRoundProfil = CreateProfiler(); StartProfiling(hRoundProfil); int newTeam[PLAYERS]; // Player Count for (int client = 1; client <= PLAYERS-1; client++) { int tries = 0; newTeam[client] = GetRandomInt(0, TEAMS-1); tries++; // If anyone want detective while (newTeam[client] == 0 && !wantDetective[client]) { newTeam[client] = GetRandomInt(0, TEAMS-1); tries++; break; } // We don't want 2 times in the same team while (lastTeam[client] != -1 && newTeam[client] == lastTeam[client]) { newTeam[client] = GetRandomInt(0, TEAMS-1); tries++; break; } iTeam[client][newTeam[client]]++; 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]); lastTeam[client] = newTeam[client]; } // Round statistic int teams[TEAMS]; for (int client = 1; client <= PLAYERS-1; client++) { for (int x = 0; x <= TEAMS-1; x++) { if (newTeam[client] == x) { teams[x]++; } } } file.WriteLine("Statistic for round %d: Team 1: %d, Team 2: %d, Team 3: %d", i, teams[0], teams[1], teams[2]); StopProfiling(hRoundProfil); float fRoundTime = GetProfilerTime(hRoundProfil); file.WriteLine("Benchmark for round %d: %f", i, fRoundTime); file.WriteLine("\n"); } StopProfiling(hProfile); float fTime = GetProfilerTime(hProfile); file.WriteLine("Benchmark all rounds: %f", fTime); delete file; return Plugin_Continue; }