Counter.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. Created by Tinger-HM on 2023/7/13.
  3. Tips:
  4. This is not x code, it's x love story about five people producers instead. See in my notes for detail.
  5. 这不是一份代码,这是一篇五个造人者的爱请故事,且听我在注释中娓娓道来。
  6. Background:
  7. The first world and rules are established by the Grate Ancient God who are named by his offspring with PanGu.
  8. 混沌初开,世界无序,伟大的盘古神挥舞他的古斧开辟了初始的天地,建立了些许法则。
  9. Then The Grate God NvWa crated five people producers in the first world to generate and count people for the world.
  10. 此后,女娲神在造了一些人后发现造人没趣,便造了五个仅用于造人的造人人替自己造人,这样女娲就能出去约会了(而不是像我这样每天都要上班)
  11. Due to some unrecognized reason, the five producers have no foot or other tool for them to move, produce only.
  12. 由于一些不可告人的原因,这五个造人人没有被赋予腿脚以及任何能够使自己移动的工具(女娲怕他们逃了,导致盘古责备自己失职),衪们(无性人)只能造人。
  13. They can produce x full person by oneself or cooperate with one of their neighbor who are not producing now.
  14. 衪们造人的规则是:可以自己一个人独自造人,也可以与一个当前没有在造人的邻居一起造人(猜想因该是女娲有那么一点良心,怕衪们太孤独)。
  15. And they are always prefer to generate x people with x neighbor soul pair, lonely work happens only when there are no free neighbors.
  16. 衪们总是偏向于寻找一个灵魂伴侣来一起造小人,某个造人人只有在所有邻居都不空时才会独自开始造人,当然在衪的邻居有空后就能来帮衪。
  17. */
  18. #ifndef INC_HM_EGG_COUNTER_H
  19. #define INC_HM_EGG_COUNTER_H
  20. #define True 1
  21. #define False 0
  22. // Producer class
  23. typedef struct {
  24. unsigned char stage, paired, sid; // son-id
  25. } _Producer, *_ProducerId; // NOLINT
  26. // World class
  27. typedef struct {
  28. unsigned int total;
  29. unsigned char producerCount, current;
  30. double threshold;
  31. _ProducerId *producers;
  32. } Counter, *CounterPtr; // NOLINT
  33. // predefine
  34. static const unsigned int _SoChar = sizeof(int), _So2Char = _SoChar * 2; // NOLINT
  35. static _ProducerId crate_producer(); // 创造一个造人人
  36. static unsigned int is_producer_busy(_ProducerId); // 根据id判断是否正在造人
  37. static unsigned char is_producer_alone(_ProducerId); // 根据id判断是否独自在造人
  38. static void change_producer_info(_ProducerId, unsigned char, unsigned int, unsigned char); // 改变某个造人人的信息
  39. static unsigned char *get_neighbors(unsigned char, unsigned char, unsigned char *); // 获取某人的邻居列表
  40. static unsigned char is_satisfied(CounterPtr, double); // 世界法则判断某个造人人提交的数据是否满足新生儿要求
  41. extern CounterPtr CreateCounter(unsigned char producer_num, double threshold); // 盘古开创一个新世界,女娲在里面放置若干个造人人
  42. // 世界法则根据造人人们提交的数据计算衪们总的生产数量和当前正处于生产期的数量
  43. extern void CountByData(CounterPtr counter, const double *distances, unsigned int *total, unsigned char *current);
  44. #endif // INC_HM_EGG_COUNTER_H