Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
yugioh-ccb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
yugioh-ccb
Commits
6b846d24
Commit
6b846d24
authored
May 02, 2025
by
EN1AK
Committed by
GitHub
May 02, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add files via upload
parent
2aeeb548
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
20 deletions
+34
-20
data_utils.py
data_utils.py
+15
-11
guess_card_game.py
guess_card_game.py
+14
-4
map.py
map.py
+1
-1
templates/index.html
templates/index.html
+4
-4
No files found.
data_utils.py
View file @
6b846d24
import
sqlite3
import
sqlite3
import
pandas
as
pd
import
pandas
as
pd
import
numbers
import
numbers
from
pathlib
import
Path
from
pathlib
import
Path
import
sys
import
sys
from
map
import
RACE_MAP
,
TYPE_MAP
,
CATEGORY_TAGS
,
TYPE_LINK
,
LINK_MARKERS
,
SETNAME_MAP
,
ATTR_MAP
from
map
import
RACE_MAP
,
TYPE_MAP
,
CATEGORY_TAGS
,
TYPE_LINK
,
LINK_MARKERS
,
SETNAME_MAP
,
ATTR_MAP
,
TYPE_PENDULUM
def
parse_flags
(
value
,
mapping
):
def
parse_flags
(
value
,
mapping
):
return
[
name
for
bit
,
name
in
mapping
.
items
()
if
value
&
bit
]
return
[
name
for
bit
,
name
in
mapping
.
items
()
if
value
&
bit
]
def
parse_category
(
cat
):
def
parse_category
(
cat
):
return
[
CATEGORY_TAGS
[
1100
+
i
]
for
i
in
range
(
64
)
if
(
cat
>>
i
)
&
1
and
(
1100
+
i
)
in
CATEGORY_TAGS
]
return
[
CATEGORY_TAGS
[
1100
+
i
]
for
i
in
range
(
64
)
if
(
cat
>>
i
)
&
1
and
(
1100
+
i
)
in
CATEGORY_TAGS
]
...
@@ -24,7 +24,7 @@ def parse_setcode(setcode, name_map):
...
@@ -24,7 +24,7 @@ def parse_setcode(setcode, name_map):
# 3. 每 4 位一组
# 3. 每 4 位一组
names
=
[]
names
=
[]
for
i
in
range
(
0
,
len
(
hex_str
),
4
):
for
i
in
range
(
0
,
len
(
hex_str
),
4
):
segment
=
hex_str
[
i
:
i
+
4
]
segment
=
hex_str
[
i
:
i
+
4
]
# 全 0 的段跳过
# 全 0 的段跳过
if
segment
==
"0000"
:
if
segment
==
"0000"
:
continue
continue
...
@@ -33,6 +33,7 @@ def parse_setcode(setcode, name_map):
...
@@ -33,6 +33,7 @@ def parse_setcode(setcode, name_map):
names
.
append
(
name_map
[
code
])
names
.
append
(
name_map
[
code
])
return
names
return
names
def
extract_arrows
(
def_value
):
def
extract_arrows
(
def_value
):
"""
"""
从 link_marker 的整数值中提取出 所有 生效的箭头符号,返回一个列表。
从 link_marker 的整数值中提取出 所有 生效的箭头符号,返回一个列表。
...
@@ -88,19 +89,22 @@ def load_card_database(path: str = None) -> pd.DataFrame:
...
@@ -88,19 +89,22 @@ def load_card_database(path: str = None) -> pd.DataFrame:
)
)
return
df
return
df
def
card_to_tags
(
row
):
def
card_to_tags
(
row
):
is_link
=
bool
(
row
[
"type"
]
&
TYPE_LINK
)
is_link
=
bool
(
row
[
"type"
]
&
TYPE_LINK
)
is_pendulum
=
bool
(
row
[
"type"
]
&
TYPE_PENDULUM
)
# 链接怪兽的“守备”清空
# 链接怪兽的“守备”清空
defense
=
""
if
is_link
else
row
[
"def"
]
defense
=
""
if
is_link
else
row
[
"def"
]
# 如果是链接怪兽,从 link_marker 提取箭头
arrows
=
extract_arrows
(
row
[
"def"
])
if
is_link
else
[]
arrows
=
extract_arrows
(
row
[
"def"
])
if
is_link
else
[]
scale
=
(
row
[
"level"
]
>>
24
)
&
0xFF
if
is_pendulum
else
""
return
{
return
{
"卡名"
:
row
[
"name"
],
"卡名"
:
row
[
"name"
],
"攻击"
:
row
[
"atk"
],
"攻击"
:
row
[
"atk"
],
"守备"
:
defense
,
"守备"
:
defense
,
"等级"
:
row
[
"level"
]
&
0xFF
,
"等级
/阶级
"
:
row
[
"level"
]
&
0xFF
,
"箭头"
:
arrows
,
"箭头"
:
arrows
,
"刻度"
:
(
row
[
"level"
]
>>
24
)
&
0xFF
,
"刻度"
:
scale
,
"类型"
:
parse_flags
(
row
[
"type"
],
TYPE_MAP
),
"类型"
:
parse_flags
(
row
[
"type"
],
TYPE_MAP
),
"属性"
:
ATTR_MAP
.
get
(
row
[
"attribute"
],
f
"0x{row['attribute']:X}"
),
"属性"
:
ATTR_MAP
.
get
(
row
[
"attribute"
],
f
"0x{row['attribute']:X}"
),
"种族"
:
RACE_MAP
.
get
(
row
[
"race"
],
f
"0x{row['race']:X}"
),
"种族"
:
RACE_MAP
.
get
(
row
[
"race"
],
f
"0x{row['race']:X}"
),
...
@@ -111,8 +115,10 @@ def card_to_tags(row):
...
@@ -111,8 +115,10 @@ def card_to_tags(row):
def
compare_tags
(
guess_tags
,
answer_tags
):
def
compare_tags
(
guess_tags
,
answer_tags
):
def
cmp
(
key
,
val1
,
val2
):
def
cmp
(
key
,
val1
,
val2
):
if
val1
is
None
or
val1
==
""
or
val2
is
None
or
val2
==
""
:
if
(
val1
==
""
or
val1
is
None
)
and
(
val2
==
""
or
val2
is
None
):
# 要么是用户没猜,要么目标也无该字段,都算“未猜”
return
'<span class="tag tag-gray">—</span>'
# 如果其中一个没——黄色“部分”
if
val1
==
""
or
val1
is
None
or
val2
==
""
or
val2
is
None
:
return
'<span class="partial">—</span>'
return
'<span class="partial">—</span>'
if
key
==
"箭头"
:
if
key
==
"箭头"
:
...
@@ -139,7 +145,7 @@ def compare_tags(guess_tags, answer_tags):
...
@@ -139,7 +145,7 @@ def compare_tags(guess_tags, answer_tags):
cls
=
"tag-yellow"
cls
=
"tag-yellow"
else
:
else
:
cls
=
"tag-gray"
cls
=
"tag-gray"
elif
key
in
(
"等级"
,
"刻度"
):
elif
key
in
(
"等级
/阶级
"
,
"刻度"
):
if
diff
<=
2
:
if
diff
<=
2
:
cls
=
"tag-yellow"
cls
=
"tag-yellow"
else
:
else
:
...
@@ -168,5 +174,3 @@ def compare_tags(guess_tags, answer_tags):
...
@@ -168,5 +174,3 @@ def compare_tags(guess_tags, answer_tags):
key
:
cmp
(
key
,
guess_tags
[
key
],
answer_tags
[
key
])
key
:
cmp
(
key
,
guess_tags
[
key
],
answer_tags
[
key
])
for
key
in
guess_tags
for
key
in
guess_tags
}
}
guess_card_game.py
View file @
6b846d24
...
@@ -14,6 +14,8 @@ db = None
...
@@ -14,6 +14,8 @@ db = None
target_row
=
None
target_row
=
None
app
.
secret_key
=
"你自己的随机 Secret Key"
app
.
secret_key
=
"你自己的随机 Secret Key"
db
=
load_card_database
()
def
filter_db
(
mode
):
def
filter_db
(
mode
):
"""
"""
...
@@ -33,7 +35,7 @@ def filter_db(mode):
...
@@ -33,7 +35,7 @@ def filter_db(mode):
# all
# all
return
db
return
db
db
=
load_card_database
()
@
app
.
route
(
"/"
,
methods
=
[
"GET"
,
"POST"
])
@
app
.
route
(
"/"
,
methods
=
[
"GET"
,
"POST"
])
def
start
():
def
start
():
"""游戏开始前,选择卡牌范围和猜测次数"""
"""游戏开始前,选择卡牌范围和猜测次数"""
...
@@ -130,13 +132,22 @@ def game():
...
@@ -130,13 +132,22 @@ def game():
if
guess_count
>
max_attempts
:
if
guess_count
>
max_attempts
:
feedback
=
{
feedback
=
{
"error"
:
"😢 猜测次数已用尽!
"
,
"error"
:
f
"😢 猜测次数已用尽!答案是【{target['name']}】
"
,
"giveup"
:
True
,
"giveup"
:
True
,
"answer"
:
target
[
"name"
],
"answer"
:
target
[
"name"
],
"hints"
:
hints
"hints"
:
hints
}
}
for
key
in
(
'target_id'
,
'history'
,
'hints'
,
'hinted_chars'
,
'guess_count'
):
for
key
in
(
'target_id'
,
'history'
,
'hints'
,
'hinted_chars'
,
'guess_count'
):
session
.
pop
(
key
,
None
)
session
.
pop
(
key
,
None
)
return
render_template
(
"index.html"
,
feedback
=
feedback
,
history
=
history
,
hints
=
hints
,
mode
=
mode
,
guess_count
=
guess_count
,
max_attempts
=
max_attempts
)
user_input
=
request
.
form
.
get
(
"guess"
,
""
)
.
strip
()
user_input
=
request
.
form
.
get
(
"guess"
,
""
)
.
strip
()
match
=
filtered
[
filtered
[
"name"
]
.
str
.
contains
(
user_input
,
case
=
False
,
na
=
False
)]
match
=
filtered
[
filtered
[
"name"
]
.
str
.
contains
(
user_input
,
case
=
False
,
na
=
False
)]
...
@@ -225,7 +236,7 @@ def suggest():
...
@@ -225,7 +236,7 @@ def suggest():
if
not
q
:
if
not
q
:
return
jsonify
([])
return
jsonify
([])
mode
=
session
.
get
(
'mode'
,
'all'
)
mode
=
session
.
get
(
'mode'
,
'all'
)
pool
=
filter_db
(
mode
)
# ← 改这里
pool
=
filter_db
(
mode
)
matches
=
pool
[
matches
=
pool
[
pool
[
"name"
]
.
str
.
contains
(
q
,
case
=
False
,
na
=
False
)
pool
[
"name"
]
.
str
.
contains
(
q
,
case
=
False
,
na
=
False
)
][
"name"
]
.
tolist
()
][
"name"
]
.
tolist
()
...
@@ -233,7 +244,6 @@ def suggest():
...
@@ -233,7 +244,6 @@ def suggest():
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
host
=
"0.0.0.0"
host
=
"0.0.0.0"
port
=
int
(
os
.
environ
.
get
(
"PORT"
,
5000
))
port
=
int
(
os
.
environ
.
get
(
"PORT"
,
5000
))
...
...
map.py
View file @
6b846d24
...
@@ -25,7 +25,7 @@ CATEGORY_TAGS = {
...
@@ -25,7 +25,7 @@ CATEGORY_TAGS = {
1130
:
'超量相关'
,
1131
:
'效果无效'
1130
:
'超量相关'
,
1131
:
'效果无效'
}
}
TYPE_LINK
=
0x4000000
TYPE_LINK
=
0x4000000
TYPE_PENDULUM
=
0x1000000
LINK_MARKERS
=
{
LINK_MARKERS
=
{
0x040
:
"↖"
,
# TOP_LEFT
0x040
:
"↖"
,
# TOP_LEFT
0x080
:
"↑"
,
# TOP
0x080
:
"↑"
,
# TOP
...
...
templates/index.html
View file @
6b846d24
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
height
:
36px
;
height
:
36px
;
border-radius
:
50%
;
border-radius
:
50%
;
box-shadow
:
0
0
4px
rgba
(
0
,
0
,
0
,
0.3
);
box-shadow
:
0
0
4px
rgba
(
0
,
0
,
0
,
0.3
);
}
.tag
{
.tag
{
display
:
inline-block
;
display
:
inline-block
;
padding
:
2px
8px
;
padding
:
2px
8px
;
...
@@ -91,12 +91,12 @@
...
@@ -91,12 +91,12 @@
</style>
</style>
</head>
</head>
<body>
<body>
<h1>
🎴 游戏王CCB
</h1>
<div
class=
"github-link"
>
<div
class=
"github-link"
>
<a
href=
"https://github.com/EN1AK/yugioh-ccb"
target=
"_blank"
rel=
"noopener"
>
<a
href=
"https://github.com/EN1AK/yugioh-ccb"
target=
"_blank"
rel=
"noopener"
>
<img
src=
"https://avatars.githubusercontent.com/EN1AK"
alt=
"GitHub"
>
<img
src=
"https://avatars.githubusercontent.com/EN1AK"
alt=
"GitHub"
>
</a>
</a>
</div>
</div>
<h1>
🎴 游戏王CCB
</h1>
<form
method=
"POST"
style=
"margin-bottom:1em;"
>
<form
method=
"POST"
style=
"margin-bottom:1em;"
>
<label>
题库:
<label>
题库:
<select
name=
"mode"
>
<select
name=
"mode"
>
...
@@ -127,7 +127,7 @@
...
@@ -127,7 +127,7 @@
<table>
<table>
<thead>
<thead>
<tr>
<tr>
<th>
卡名
</th><th>
攻击
</th><th>
守备
</th><th>
等级
</th><th>
刻度
</th><th>
箭头
</th>
<th>
卡名
</th><th>
攻击
</th><th>
守备
</th><th>
等级
/阶级
</th><th>
刻度
</th><th>
箭头
</th>
<th>
类型
</th><th>
属性
</th><th>
种族
</th><th>
效果标签
</th><th>
系列
</th>
<th>
类型
</th><th>
属性
</th><th>
种族
</th><th>
效果标签
</th><th>
系列
</th>
</tr>
</tr>
</thead>
</thead>
...
@@ -137,7 +137,7 @@
...
@@ -137,7 +137,7 @@
<td>
{{ entry.guess_name }}
</td>
<td>
{{ entry.guess_name }}
</td>
<td>
{{ entry.compare['攻击']|safe }}
</td>
<td>
{{ entry.compare['攻击']|safe }}
</td>
<td>
{{ entry.compare['守备']|safe }}
</td>
<td>
{{ entry.compare['守备']|safe }}
</td>
<td>
{{ entry.compare['等级']|safe }}
</td>
<td>
{{ entry.compare['等级
/阶级
']|safe }}
</td>
<td>
{{ entry.compare['刻度']|safe }}
</td>
<td>
{{ entry.compare['刻度']|safe }}
</td>
<td>
{{ entry.compare['箭头']|safe }}
</td>
<td>
{{ entry.compare['箭头']|safe }}
</td>
<td
style=
"white-space: nowrap;"
>
{{ entry.compare['类型']|safe }}
</td>
<td
style=
"white-space: nowrap;"
>
{{ entry.compare['类型']|safe }}
</td>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment