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