This commit is contained in:
512song committed 2024-05-18 22:23:06 +08:00
1 parent 7a85886cf8
commit bf25c548e6
1 file changed
+176
+176
View File
@@ -0,0 +1,176 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "0f939dd1-de12-4b54-bd08-16ebbbfdbfdd",
"metadata": {},
"source": [
"## 选择白子黑子图片"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0569e182-b008-4173-ab0d-7f4a2904f72e",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import glob\n",
"import os,shutil\n",
"from pathlib import Path\n",
"\n",
"filepath = 'img/白/'\n",
"\n",
"files = glob.glob(f'{filepath}*.jpg')\n",
"for fn in files:\n",
" fi_name =Path(fn).stem\n",
" if int(fi_name) % 2 !=0:\n",
" shutil.copy(fn, './img')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "44683ca5-166c-4d3a-9447-6fe46ab7c12d",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import glob\n",
"import os,shutil\n",
"from pathlib import Path\n",
"\n",
"filepath = 'img/黑/'\n",
"\n",
"files = glob.glob(f'{filepath}*.jpg')\n",
"for fn in files:\n",
" fi_name =Path(fn).stem\n",
" if int(fi_name) % 2 ==0:\n",
" shutil.copy(fn, './img')"
]
},
{
"cell_type": "markdown",
"id": "230c5cb3-ee5b-4490-b0a2-6eb62461204b",
"metadata": {},
"source": [
"## 棋子替代"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "3ecfe0a8-3af1-4f48-a2b0-6c3eb25df07d",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-18T12:47:00.736753Z",
"iopub.status.busy": "2024-05-18T12:47:00.736098Z",
"iopub.status.idle": "2024-05-18T12:47:00.742633Z",
"shell.execute_reply": "2024-05-18T12:47:00.741589Z",
"shell.execute_reply.started": "2024-05-18T12:47:00.736738Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{{ img_11 }}当{{ img_12 }}位碰为正。{{ img_12 }}至{{ img_18 }}争先亦是。{{ img_20 }}拆三当时。{{ img_21 }}可缓,当{{ img_122 }}位大飞,黑拆三尚须关补。{{ img_27 }}压、{{ img_29 }}扳活动。{{ img_32 }}不于{{ img_106 }}位打,防白{{ img_113 }}位打,黑{{ img_107 }}位提,白{{ img_187 }}位打,黑粘,白{{ img_33 }}位虎,黑{{ img_34 }}位长,白{{ img_124 }}位立,黑转,局促。{{ img_34 }}不打亦是。{{ img_35 }}等着分角尚早,有{{ img_38 }}敲,外面便生出劫。{{ img_41 }}扳,将官子着尽,是当时习气。{{ img_51 }}若{{ img_55 }}位长,嫌机缓,姑扳以图变。{{ img_52 }}至{{ img_62 }}乘间攻角,不可缓。{{ img_64 }}必长,{{ img_66 }}、{{ img_68 }}有次序。{{ img_72 }}至{{ img_78 }}机法相生,纯乎自然。{{ img_80 }}接老当,胜{{ img_142 }}位长。{{ img_81 }}长,劲。{{ img_93 }}虎应,是。{{ img_99 }}接,连三子,收{{ img_101 }}位先手断觑便宜。{{ img_103 }}因中间残损,紧逼黑边,补角顾腹,最为扼要。{{ img_104 }}扳、{{ img_108 }}反打,妙,有成算。{{ img_115 }}因三子受逼,难于转身,用借引法兼可攻角。{{ img_116 }}顾角,任白扳接,合活得先,外势自固;若呆取三子,便无余味。{{ img_117 }}至{{ img_145 }}彼此稳惬。{{ img_148 }}收法紧。{{ img_157 }}大。{{ img_170 }}落得先手分腹。{{ img_177 }}、{{ img_179 }}尖断黑子要紧。{{ img_186 }}、{{ img_188 }}收,得便宜。{{ img_190 }}必扳。{{ img_195 }}嵌法巧。{{ img_200 }}大。{{ img_274 }}官子粗,若于十▪二路补,便胜一子。 国初时,名手如林,龙士年最幼,诸家遇之辄望风而靡,唯东侯刻意追新,喜出偏锋,率战不屈。此局如春秋晋楚主盟,不相上下,可称劲敌。 (吴评) ['101', '103', '104', '106', '107', '108', '11', '113', '115', '116', '117', '12', '122', '124', '142', '145', '148', '157', '170', '177', '179', '18', '186', '187', '188', '190', '195', '20', '200', '21', '27', '274', '29', '32', '33', '34', '35', '38', '41', '51', '52', '55', '62', '64', '66', '68', '72', '78', '80', '81', '93', '99']\n"
]
}
],
"source": [
"import glob\n",
"import os,shutil\n",
"from pathlib import Path\n",
"import re\n",
"\n",
"def find_all_numbers(text):\n",
" return re.findall(r'\\d+', text)\n",
"\n",
"def replace_numbers(text):\n",
" pattern = r'\\d+'\n",
" replacement = lambda x:'{{ '+ f'img_{x.group()}'+' }}'\n",
" modified_text = re.sub(pattern, replacement, text)\n",
" return modified_text\n",
"\n",
"list1 = []\n",
"filepath = '文本文件/'\n",
"files = glob.glob(f'{filepath}*.txt')\n",
"for fn in files:\n",
" with open(fn, \"r\") as f:\n",
" data = f.readlines()\n",
" for s in data:\n",
" ss = replace_numbers(s)\n",
" list1 = find_all_numbers(ss)\n",
" list1 = list(set(list1))\n",
" list1.sort()\n",
" print(ss,list1)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "8d3f1a7a-1322-48b5-9b14-c7ba8f38bacb",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-18T12:56:39.329276Z",
"iopub.status.busy": "2024-05-18T12:56:39.328470Z",
"iopub.status.idle": "2024-05-18T12:56:39.464527Z",
"shell.execute_reply": "2024-05-18T12:56:39.464059Z",
"shell.execute_reply.started": "2024-05-18T12:56:39.329242Z"
},
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"from docxtpl import DocxTemplate,InlineImage\n",
"from docx.shared import Mm\n",
"\n",
"dict1 = {}\n",
"\n",
"tpl = DocxTemplate(\"test1.docx\")\n",
"for item in list1: \n",
" dict1['img_'+str(item)] = InlineImage(tpl, image_descriptor=f'./img/{str(item)}.jpg',width=Mm(4))\n",
"#dict1['img_radar'] = InlineImage(tpl, image_descriptor=dict1['radar'])\n",
"\n",
"tpl.render(dict1)\n",
"tpl.save('test2.docx')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "14696c7a-d44e-4c99-9d28-a810d991ed20",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}