Guest User

Untitled

a guest
May 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using System.Collections.Generic;
  5.  
  6. namespace MonsterTest
  7. {
  8. class MainClass
  9. {
  10. public static void Main (string[] args)
  11. {
  12. // Open a file for the results.
  13. Monster.Rng = new Random();
  14. const int numDudes = 100;
  15.  
  16. using(FileStream resStream = File.Open("outdata.csv", FileMode.OpenOrCreate))
  17. {
  18. AppendValue(resStream, "Strength, Mojo, Soak, Willpower, Reflex, Intelligence\r\n");
  19.  
  20. // Create some monsters
  21. List<Monster> monsters = new List<Monster>();
  22. for (int m = 0; m < numDudes; m++)
  23. {
  24. monsters.Add(new Monster());
  25. }
  26.  
  27. // Round robin the monsters
  28. List<int> wins = new List<int>();
  29. for (int i = 0; i < numDudes; i++)
  30. {
  31. wins.Add(0);
  32. for (int j = 0; j < numDudes; j++)
  33. {
  34. // Don't fight ourselves
  35. if (i == j)
  36. continue;
  37.  
  38. wins[i] += monsters[i].Fight(monsters[j]) ? 1 : 0;
  39. }
  40. }
  41.  
  42. List<KeyValuePair<int, int>> kvp = new List<KeyValuePair<int, int>>();
  43. for (int i = 0; i < wins.Count; i++)
  44. kvp.Add(new KeyValuePair<int, int>(i, wins[i]));
  45.  
  46. // Sort
  47. kvp.Sort(delegate(KeyValuePair<int, int> x, KeyValuePair<int, int> y) { return x.Value.CompareTo(y.Value); });
  48.  
  49. for (int w = wins.Count - 1; w > wins.Count - 6; w--)
  50. AppendMonster(resStream, monsters[kvp[w].Key]);
  51. }
  52.  
  53. Console.WriteLine ("Hello World!");
  54. }
  55.  
  56. private static void AppendValue(FileStream fs, string value)
  57. {
  58. byte[] info = new UTF8Encoding(true).GetBytes(value);
  59. fs.Write(info, 0, info.Length);
  60. }
  61.  
  62. private static void AppendMonster(FileStream fs, Monster value)
  63. {
  64. string monsterString =
  65. value.Strength.ToString() + ", " +
  66. value.Mojo.ToString() + ", " +
  67. value.Soak.ToString() + ", " +
  68. value.Willpower.ToString() + ", " +
  69. value.Reflex.ToString() + ", " +
  70. value.Intelligence.ToString() + "\r\n";
  71. AppendValue(fs, monsterString);
  72. }
  73. }
  74. }
Add Comment
Please, Sign In to add comment