fork download
  1. using System;
  2.  
  3. public class DiceOnYacht
  4. {
  5. public enum Category
  6. {
  7. Ones, Twos, Threes, Fours, Fives, Sixes, Sevens, Eights,
  8. SmallStraight,
  9. AllDifferent,
  10. AllSame
  11. }
  12.  
  13. private static byte numdie = 5; // number of die in game
  14. // must be in the range [2, 16] in order for
  15. // all methods to be valid
  16.  
  17.  
  18. private bool isInSequence ( byte [] arr, byte a, byte b )
  19. {
  20. // Returns true if the values in the array arr
  21. // in the range of indexes [a, b] are in sequence.
  22. // Returns false otherwise
  23. while (a <= b)
  24. {
  25. if ((arr[a] + 1) == arr[a+1])
  26. ++a;
  27. else
  28. return false;
  29. }
  30. return true;
  31. }
  32.  
  33. private bool isSmallStraight ( byte [numdie] die )
  34. {
  35. // Returns true if die can be arranged to form a sequence
  36. // of length numdie-1
  37. Array.Sort(die);
  38. return isInSequence(die,0,numdie-2) || isInSequence(die,1,numdie-1);
  39. }
  40.  
  41. private byte getSinglesScores ( Category cat, byte [numdie] die )
  42. {
  43. // cat: one of Ones, Twos, Threes, Fours, Fives, Sixes, Sevens, Eights
  44. // die: array numbers rolled on the die, e.g. [1, 2, 1, 3, 8]
  45. byte score = 0;
  46. byte catAsByte = (byte)cat;
  47. foreach ( byte dice in arr ) if (dice == catAsByte) score += catAsByte;
  48. return score;
  49. }
  50.  
  51. public byte getAnyScore ( Category cat, byte [numdie] die )
  52. {
  53. byte score;
  54. switch (cat)
  55. {
  56. case Category.Ones:
  57. case Category.Twos:
  58. case Category.Threes:
  59. case Category.Fours:
  60. case Category.Fives:
  61. case Category.Sixes:
  62. case Category.Sevens:
  63. case Category.Eights:
  64. score = getSinglesScores(cat,die);
  65. break;
  66. case Category.SmallStraight:
  67. score = isSmallStraight(die) ? 30 : 0;
  68. break;
  69. case Category.AllDifferent:
  70. score = die.Distinct().Count() == 5 ? 40 : 0;
  71. break;
  72. case Category.AllSame:
  73. score = die.Distinct.Count() == 1 ? 50 : 0;
  74. break;
  75. }
  76. return score;
  77. }
  78.  
  79. public Category getSuggestion ( byte [numdie] die )
  80. {
  81. Category topcat; byte topscore = 0;
  82. // ...
  83. return topcat;
  84. }
  85.  
  86. public static void Main()
  87. {
  88. Console.WriteLine("hehe");
  89. }
  90. }
Compilation error #stdin compilation error #stdout 0.04s 23912KB
stdin
Standard input is empty
compilation info
prog.cs(33,38): error CS1525: Unexpected symbol `numdie', expecting `,' or `]'
prog.cs(41,53): error CS1525: Unexpected symbol `numdie', expecting `,' or `]'
prog.cs(51,47): error CS1525: Unexpected symbol `numdie', expecting `,' or `]'
prog.cs(79,39): error CS1525: Unexpected symbol `numdie', expecting `,' or `]'
Compilation failed: 4 error(s), 0 warnings
stdout
Standard output is empty