Advertisement
Guest User

Untitled

a guest
Nov 10th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.54 KB | None | 0 0
  1. /// This file has been generated, if you wish to
  2. /// modify it in a permanent way, please refer
  3. /// to the script file : gen/generator_cxx.rb
  4.  
  5. #ifndef PROLOGIN_HH_
  6. # define PROLOGIN_HH_
  7.  
  8. # include <functional>
  9.  
  10. # include <string>
  11.  
  12. # include <vector>
  13.  
  14. /// All possible error types that can be returned by action functions
  15. typedef enum error {
  16.   OK, /* <- no error occurred */
  17.   OUT_OF_BOUNDS, /* <- provided position is out of bounds */
  18.   ALREADY_OCCUPIED, /* <- someone already played at the provided position */
  19.   ALREADY_PLAYED, /* <- you already played this turn, you cheater! */
  20. } error;
  21. // This is needed for old compilers
  22. namespace std
  23. {
  24.   template <> struct hash<error> {
  25.     size_t operator()(const error& v) const {
  26.       return hash<int>()(static_cast<int>(v));
  27.     }
  28.   };
  29. }
  30.  
  31. /// Position on the TicTacToe board
  32. typedef struct position {
  33.   int x;  /* <- X coordinate */
  34.   int y;  /* <- Y coordinate */
  35. } position;
  36.  
  37.  
  38. /// Play at the given position
  39. extern "C" error api_play(position pos);
  40. static inline error play(position pos)
  41. {
  42.   return api_play(pos);
  43. }
  44.  
  45.  
  46. /// Returns your team number
  47. extern "C" int api_my_team();
  48. static inline int my_team()
  49. {
  50.   return api_my_team();
  51. }
  52.  
  53.  
  54. /// Returns the TicTacToe board
  55. extern "C" std::vector<int> api_board();
  56. static inline std::vector<int> board()
  57. {
  58.   return api_board();
  59. }
  60.  
  61.  
  62. /// Cancels the last played action
  63. extern "C" bool api_cancel();
  64. static inline bool cancel()
  65. {
  66.   return api_cancel();
  67. }
  68.  
  69.  
  70. /// Affiche le contenu d'une valeur de type error
  71. extern "C" void api_afficher_error(error v);
  72. static inline void afficher_error(error v)
  73. {
  74.   api_afficher_error(v);
  75. }
  76.  
  77.  
  78. /// Affiche le contenu d'une valeur de type position
  79. extern "C" void api_afficher_position(position v);
  80. static inline void afficher_position(position v)
  81. {
  82.   api_afficher_position(v);
  83. }
  84.  
  85.  
  86. // Les fonctions suivantes définissent les opérations de comparaison, d'égalité
  87. // et de hachage sur les structures du sujet.
  88.  
  89. namespace std {
  90.   template <typename T>
  91.   struct hash<std::vector<T>>
  92.   {
  93.     std::size_t operator()(const std::vector<T>& v) const
  94.     {
  95.       std::size_t res = v.size();
  96.       for (const auto& e : v)
  97.         res ^= std::hash<T>()(e) + 0x9e3779b9 + (res << 6) + (res >> 2);
  98.       return res;
  99.     }
  100.   };
  101. }
  102.  
  103. inline bool operator==(const position& a, const position& b) {
  104.   if (a.x != b.x) return false;
  105.   if (a.y != b.y) return false;
  106.   return true;
  107. }
  108.  
  109. inline bool operator!=(const position& a, const position& b) {
  110.   if (a.x != b.x) return true;
  111.   if (a.y != b.y) return true;
  112.   return false;
  113. }
  114.  
  115. inline bool operator<(const position& a, const position& b) {
  116.   if (a.x < b.x) return true;
  117.   if (a.x > b.x) return false;
  118.   if (a.y < b.y) return true;
  119.   if (a.y > b.y) return false;
  120.   return false;
  121. }
  122.  
  123. inline bool operator>(const position& a, const position& b) {
  124.   if (a.x > b.x) return true;
  125.   if (a.x < b.x) return false;
  126.   if (a.y > b.y) return true;
  127.   if (a.y < b.y) return false;
  128.   return false;
  129. }
  130.  
  131. namespace std {
  132.   template <>
  133.   struct hash<position>
  134.   {
  135.     std::size_t operator()(const position& s) const
  136.     {
  137.       std::size_t res = 0;
  138.       res ^= 0x9e3779b9 + (res << 6) + (res >> 2) + std::hash<int>()(s.x);
  139.       res ^= 0x9e3779b9 + (res << 6) + (res >> 2) + std::hash<int>()(s.y);
  140.       return res;
  141.     }
  142.   };
  143. }
  144.  
  145.  
  146. extern "C" {
  147.  
  148. /// Function called at the start of the game
  149. void init_game();
  150.  
  151. /// Called when this is your turn to play
  152. void play_turn();
  153.  
  154. /// Function called at the end of the game
  155. void end_game();
  156.  
  157. }
  158. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement