周易算卦流程c++实现

代码

cpp 复制代码
#include<iostream>
using namespace std;
#include<vector>
#include<cstdlib>
#include<ctime>
#include<Windows.h>

int huaYiXiangLiang(int all, int& left)
{
	Sleep(3000);
	srand(time(0));
	left = rand() % all + 1;
	while (true) {
		if (left >= all-1 || left <= 1)
		{
			left = rand() % all + 1;
		}
		else break;
	}
	return all - left;
}

int main()
{
	vector<int> liuYao;

	for (int yao = 1; yao <= 6; ++yao) {
		vector<int> gua;
		int daYanZhiShu = 55;
		int qiYong = 55 - 6;

		for (int step = 1; step <= 3; ++step) {
			#if 1 分而为二以象两
			int left = 0;
			int right = huaYiXiangLiang(qiYong, left);
			cout << "left: " << left << ", right: " << right << endl;
			#endif

			int tmpRight = right;
#if 1 挂一以象三
			tmpRight -= 1;
			gua.push_back(1);
			cout << "tmpRight: " << tmpRight << endl;
#endif

#if 1 揲之以四以象四时
			while (tmpRight > 4)
			{
				tmpRight -= 4;
			}
			cout << "tmpRight: " << tmpRight << endl;
#endif

#if 1 归奇于扐以象闰
			if (tmpRight == 4) {
				left -= 4;
				tmpRight -= 4;
				gua.push_back(8);
			}
			else if (tmpRight < 4)
			{
				left -= (4 - tmpRight);
				tmpRight = 0;
				gua.push_back(4);
			}
			cout << "left: " << left << endl;
#endif

			for (int i = 0; i < gua.size(); ++i)
			{
				qiYong -= gua[i];
			}
			gua.clear();

			std::cout << "new qiYong: " << qiYong << endl;

			if (step != 3) {
				// 放回1
				qiYong += 1;
			}

		}
		liuYao.push_back( qiYong / 4 );
		cout << yao << " complete.\r\n";
	}
	for (int yao : liuYao) {
		cout << yao << " ";
	}
	cout << endl;

	return 0;
}

六爻分别为:少阴、少阴、少阳、老阳、老阳、少阴

相关推荐
浩浩乎@4 小时前
【openGLES】纹理
c++·opengles
叫我龙翔4 小时前
【设计模式】从游戏角度开始了解设计模式 --- 抽象工厂模式
c++·游戏·设计模式
青草地溪水旁4 小时前
设计模式(C++)详解—单例模式(1)
c++·单例模式
北城以北88884 小时前
Java高级编程--XML
xml·java·开发语言·intellij-idea
冬天vs不冷5 小时前
Java基础(十一):关键字final详解
java·开发语言
HMBBLOVEPDX5 小时前
C++(深拷贝和浅拷贝)
开发语言·c++·浅拷贝和深拷贝
l1t5 小时前
DeepSeek辅助编写的利用quick_xml把xml转为csv的rust程序
xml·开发语言·人工智能·rust·解析器·quick-xml
逐雨~5 小时前
9.11QT作业
开发语言
烟锁池塘柳05 小时前
【已解决,亲测有效】解决使用Python Matplotlib库绘制图表中出现中文乱码(中文显示为框)的问题的方法
开发语言·python·matplotlib
周小码5 小时前
llama-stack实战:Python构建Llama应用的可组合开发框架(8k星)
开发语言·python·llama