简单算命脚本

2024-03-15 20:36
文章标签 简单 脚本 算命

本文主要是介绍简单算命脚本,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

效果展示

在这里插入图片描述

文件内容

main.py文件

import json
import random
import time# 别挂配置数据
gua_data_path = "data.json"# 别卦数据
gua_data_map = {}
fake_delay = 10# 读取别卦数据
def init_gua_data(json_path):with open(gua_data_path, 'r', encoding='utf8') as fp:global gua_data_mapgua_data_map = json.load(fp)# 爻图标映射
yao_icon_map = {0: "- -",1: "---"
}# 经卦名
base_gua_name_map = {0: "坤", 1: "震", 2: "坎", 3: "兑", 4: "艮", 5: "离", 6: "巽", 7: "乾"
}# 数字转化为二进制数组
def base_gua_to_yao(gua, yao_length=3):result = []while gua >= 1:level = 0 if gua % 2 == 0 else 1gua //= 2result.append(level)while len(result) < yao_length:result.append(0)return result# 二进制数组转化为数字
def base_yao_to_gua(array):array = array[:]while len(array) > 0 and array[-1] == 0:array.pop()result = 0for i in range(len(array)):if array[i] == 0:continueresult += pow(2, i)return result# 打印一个挂
def print_gua(gua):yao_list = base_gua_to_yao(gua, 6)up_yao_list = yao_list[0:3]up = base_yao_to_gua(up_yao_list)print(yao_icon_map[up_yao_list[2]])print(yao_icon_map[up_yao_list[1]] + " " + base_gua_name_map[up])print(yao_icon_map[up_yao_list[0]])print("")down_yao_list = yao_list[3:6]down = base_yao_to_gua(down_yao_list)print(yao_icon_map[down_yao_list[2]])print(yao_icon_map[down_yao_list[1]] + " " + base_gua_name_map[down])print(yao_icon_map[down_yao_list[0]])# 使用梅花易数
def calculate_with_plum_flower():# 起上卦print("使用梅花易数♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️")print_a_wait_animation("卜上卦:", fake_delay)up_base_gua = int(round(time.time() * 1000)) % 8up_yao_array = base_gua_to_yao(up_base_gua)print("上卦获取成功,上卦为:", base_gua_name_map[up_base_gua])# 起下卦print_a_wait_animation("正在获取下卦:", fake_delay)down_base_gua = random.randint(0, 999999999999) % 8down_yao_array = base_gua_to_yao(down_base_gua)print("上卦获取成功,下卦为:", base_gua_name_map[down_base_gua])# 组成卦象print_a_wait_animation("正在组成本卦:", fake_delay)print("------------------------------------------------本卦------------------------------------------------")yao_list = up_yao_array + down_yao_arraygua = base_yao_to_gua(yao_list)print_gua(gua)# 读取本卦象信息gua_code = str(base_gua_name_map[up_base_gua]) + str(base_gua_name_map[down_base_gua])gua_data = gua_data_map[gua_code]print("本卦为:", gua_data['name'])print("辞:", gua_data['words'], "译:", gua_data['white_words'])print("象:", gua_data['picture'], "译:", gua_data['white_picture'])print_a_wait_animation("正在组成互卦:", fake_delay)print("------------------------------------------------互卦------------------------------------------------")# 读取互卦象信息up_hu_yao_list = [yao_list[4], yao_list[5], yao_list[0]]up_hu_gua = base_yao_to_gua(up_hu_yao_list)down_hu_yao_list = [yao_list[5], yao_list[0], yao_list[1]]down_hu_gua = base_yao_to_gua(down_hu_yao_list)hu_yao_list = up_hu_yao_list + down_hu_yao_listhu_gua = base_yao_to_gua(hu_yao_list)hu_gua_code = str(base_gua_name_map[up_hu_gua]) + str(base_gua_name_map[down_hu_gua])hu_gua_data = gua_data_map[hu_gua_code]print_gua(hu_gua)print("互卦为:", hu_gua_data['name'])print("辞:", hu_gua_data['words'], "译:", hu_gua_data['white_words'])print("象:", hu_gua_data['picture'], "译:", hu_gua_data['white_picture'])print_a_wait_animation("正在组成变卦:", fake_delay)print("------------------------------------------------变卦------------------------------------------------")change_index = int(round(time.time() * 1000)) % 6change_yao_list = yao_list[:]change_yao_list[change_index] = 0 if change_yao_list[change_index] == 1 else 1up_change_yao_list = change_yao_list[0:3]up_change_gua = base_yao_to_gua(up_change_yao_list)down_change_yao_list = change_yao_list[3:5]down_change_gua = base_yao_to_gua(down_change_yao_list)change_gua = base_yao_to_gua(change_yao_list)print_gua(change_gua)change_gua_code = str(base_gua_name_map[up_change_gua]) + str(base_gua_name_map[down_change_gua])change_gua_data = gua_data_map[change_gua_code]print("变卦为:", change_gua_data['name'])print("辞:", change_gua_data['words'], "译:", change_gua_data['white_words'])print("象:", change_gua_data['picture'], "译:", change_gua_data['white_picture'])def print_a_wait_animation(tips, times):animation = "|/-\\"idx = 0for i in range(times):print(tips + animation[idx % len(animation)], animation[idx % len(animation)], animation[idx % len(animation)],animation[idx % len(animation)], animation[idx % len(animation)], end="\r"),idx += 1time.sleep(0.1)init_gua_data(gua_data_path)
calculate_with_plum_flower()

data.json文件内容

import json
import random
import time# 别挂配置数据
gua_data_path = "data.json"# 别卦数据
gua_data_map = {}
fake_delay = 10# 读取别卦数据
def init_gua_data(json_path):with open(gua_data_path, 'r', encoding='utf8') as fp:global gua_data_mapgua_data_map = json.load(fp)# 爻图标映射
yao_icon_map = {0: "- -",1: "---"
}# 经卦名
base_gua_name_map = {0: "坤", 1: "震", 2: "坎", 3: "兑", 4: "艮", 5: "离", 6: "巽", 7: "乾"
}# 数字转化为二进制数组
def base_gua_to_yao(gua, yao_length=3):result = []while gua >= 1:level = 0 if gua % 2 == 0 else 1gua //= 2result.append(level)while len(result) < yao_length:result.append(0)return result# 二进制数组转化为数字
def base_yao_to_gua(array):array = array[:]while len(array) > 0 and array[-1] == 0:array.pop()result = 0for i in range(len(array)):if array[i] == 0:continueresult += pow(2, i)return result# 打印一个挂
def print_gua(gua):yao_list = base_gua_to_yao(gua, 6)up_yao_list = yao_list[0:3]up = base_yao_to_gua(up_yao_list)print(yao_icon_map[up_yao_list[2]])print(yao_icon_map[up_yao_list[1]] + " " + base_gua_name_map[up])print(yao_icon_map[up_yao_list[0]])print("")down_yao_list = yao_list[3:6]down = base_yao_to_gua(down_yao_list)print(yao_icon_map[down_yao_list[2]])print(yao_icon_map[down_yao_list[1]] + " " + base_gua_name_map[down])print(yao_icon_map[down_yao_list[0]])# 使用梅花易数
def calculate_with_plum_flower():# 起上卦print("使用梅花易数♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️♣️")print_a_wait_animation("卜上卦:", fake_delay)up_base_gua = int(round(time.time() * 1000)) % 8up_yao_array = base_gua_to_yao(up_base_gua)print("上卦获取成功,上卦为:", base_gua_name_map[up_base_gua])# 起下卦print_a_wait_animation("正在获取下卦:", fake_delay)down_base_gua = random.randint(0, 999999999999) % 8down_yao_array = base_gua_to_yao(down_base_gua)print("上卦获取成功,下卦为:", base_gua_name_map[down_base_gua])# 组成卦象print_a_wait_animation("正在组成本卦:", fake_delay)print("------------------------------------------------本卦------------------------------------------------")yao_list = up_yao_array + down_yao_arraygua = base_yao_to_gua(yao_list)print_gua(gua)# 读取本卦象信息gua_code = str(base_gua_name_map[up_base_gua]) + str(base_gua_name_map[down_base_gua])gua_data = gua_data_map[gua_code]print("本卦为:", gua_data['name'])print("辞:", gua_data['words'], "译:", gua_data['white_words'])print("象:", gua_data['picture'], "译:", gua_data['white_picture'])print_a_wait_animation("正在组成互卦:", fake_delay)print("------------------------------------------------互卦------------------------------------------------")# 读取互卦象信息up_hu_yao_list = [yao_list[4], yao_list[5], yao_list[0]]up_hu_gua = base_yao_to_gua(up_hu_yao_list)down_hu_yao_list = [yao_list[5], yao_list[0], yao_list[1]]down_hu_gua = base_yao_to_gua(down_hu_yao_list)hu_yao_list = up_hu_yao_list + down_hu_yao_listhu_gua = base_yao_to_gua(hu_yao_list)hu_gua_code = str(base_gua_name_map[up_hu_gua]) + str(base_gua_name_map[down_hu_gua])hu_gua_data = gua_data_map[hu_gua_code]print_gua(hu_gua)print("互卦为:", hu_gua_data['name'])print("辞:", hu_gua_data['words'], "译:", hu_gua_data['white_words'])print("象:", hu_gua_data['picture'], "译:", hu_gua_data['white_picture'])print_a_wait_animation("正在组成变卦:", fake_delay)print("------------------------------------------------变卦------------------------------------------------")change_index = int(round(time.time() * 1000)) % 6change_yao_list = yao_list[:]change_yao_list[change_index] = 0 if change_yao_list[change_index] == 1 else 1up_change_yao_list = change_yao_list[0:3]up_change_gua = base_yao_to_gua(up_change_yao_list)down_change_yao_list = change_yao_list[3:5]down_change_gua = base_yao_to_gua(down_change_yao_list)change_gua = base_yao_to_gua(change_yao_list)print_gua(change_gua)change_gua_code = str(base_gua_name_map[up_change_gua]) + str(base_gua_name_map[down_change_gua])change_gua_data = gua_data_map[change_gua_code]print("变卦为:", change_gua_data['name'])print("辞:", change_gua_data['words'], "译:", change_gua_data['white_words'])print("象:", change_gua_data['picture'], "译:", change_gua_data['white_picture'])def print_a_wait_animation(tips, times):animation = "|/-\\"idx = 0for i in range(times):print(tips + animation[idx % len(animation)], animation[idx % len(animation)], animation[idx % len(animation)],animation[idx % len(animation)], animation[idx % len(animation)], end="\r"),idx += 1time.sleep(0.1)init_gua_data(gua_data_path)
calculate_with_plum_flower()

执行方式

启动main.py文件

这篇关于简单算命脚本的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/813194

相关文章

csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)

这是一道扩展欧几里得算法的简单应用题,这题是在湖南多校训练赛中队友ac的一道题,在比赛之后请教了队友,然后自己把它a掉 这也是自己独自做扩展欧几里得算法的题目 题意:把题意转变下就变成了:求d1*x - d2*y = f2 - f1的解,很明显用exgcd来解 下面介绍一下exgcd的一些知识点:求ax + by = c的解 一、首先求ax + by = gcd(a,b)的解 这个

hdu2289(简单二分)

虽说是简单二分,但是我还是wa死了  题意:已知圆台的体积,求高度 首先要知道圆台体积怎么求:设上下底的半径分别为r1,r2,高为h,V = PI*(r1*r1+r1*r2+r2*r2)*h/3 然后以h进行二分 代码如下: #include<iostream>#include<algorithm>#include<cstring>#include<stack>#includ

usaco 1.3 Prime Cryptarithm(简单哈希表暴搜剪枝)

思路: 1. 用一个 hash[ ] 数组存放输入的数字,令 hash[ tmp ]=1 。 2. 一个自定义函数 check( ) ,检查各位是否为输入的数字。 3. 暴搜。第一行数从 100到999,第二行数从 10到99。 4. 剪枝。 代码: /*ID: who jayLANG: C++TASK: crypt1*/#include<stdio.h>bool h

uva 10387 Billiard(简单几何)

题意是一个球从矩形的中点出发,告诉你小球与矩形两条边的碰撞次数与小球回到原点的时间,求小球出发时的角度和小球的速度。 简单的几何问题,小球每与竖边碰撞一次,向右扩展一个相同的矩形;每与横边碰撞一次,向上扩展一个相同的矩形。 可以发现,扩展矩形的路径和在当前矩形中的每一段路径相同,当小球回到出发点时,一条直线的路径刚好经过最后一个扩展矩形的中心点。 最后扩展的路径和横边竖边恰好组成一个直

poj 1113 凸包+简单几何计算

题意: 给N个平面上的点,现在要在离点外L米处建城墙,使得城墙把所有点都包含进去且城墙的长度最短。 解析: 韬哥出的某次训练赛上A出的第一道计算几何,算是大水题吧。 用convexhull算法把凸包求出来,然后加加减减就A了。 计算见下图: 好久没玩画图了啊好开心。 代码: #include <iostream>#include <cstdio>#inclu

uva 10130 简单背包

题意: 背包和 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <stack>#include <vector>#include <queue>#include <map>

Linux服务器Java启动脚本

Linux服务器Java启动脚本 1、初版2、优化版本3、常用脚本仓库 本文章介绍了如何在Linux服务器上执行Java并启动jar包, 通常我们会使用nohup直接启动,但是还是需要手动停止然后再次启动, 那如何更优雅的在服务器上启动jar包呢,让我们一起探讨一下吧。 1、初版 第一个版本是常用的做法,直接使用nohup后台启动jar包, 并将日志输出到当前文件夹n

centos6一键安装vsftpd脚本

centos6一键安装vsftpd脚本 手动安装vsftpd参考教程:Centos下安装Vsftpd的图文教程 vsftpd脚本功能: 1.安装 (命令执行:sh xxx.sh)2.添加ftp用户 (命令执行:sh xxx.sh add)3.卸载vsftpd (命令执行:sh xxx.sh uninstall) 测试环境:centos6 x64 centos6 x86(测试centos7以

JAVA用最简单的方法来构建一个高可用的服务端,提升系统可用性

一、什么是提升系统的高可用性 JAVA服务端,顾名思义就是23体验网为用户提供服务的。停工时间,就是不能向用户提供服务的时间。高可用,就是系统具有高度可用性,尽量减少停工时间。如何用最简单的方法来搭建一个高效率可用的服务端JAVA呢? 停工的原因一般有: 服务器故障。例如服务器宕机,服务器网络出现问题,机房或者机架出现问题等;访问量急剧上升,导致服务器压力过大导致访问量急剧上升的原因;时间和

简单的角色响应鼠标而移动

actor类 //处理移动距离,核心是找到角色坐标在世界坐标的向量的投影(x,y,z),然后在世界坐标中合成,此CC是在地面行走,所以Y轴投影始终置为0; using UnityEngine; using System.Collections; public class actor : MonoBehaviour { public float speed=0.1f; CharacterCo