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
219e51cd
Commit
219e51cd
authored
May 01, 2025
by
EN1AK
Committed by
GitHub
May 01, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add files via upload
parent
a4b07f48
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
36 deletions
+64
-36
guess_card_game.py
guess_card_game.py
+64
-36
No files found.
guess_card_game.py
View file @
219e51cd
...
@@ -163,28 +163,32 @@ def game():
...
@@ -163,28 +163,32 @@ def game():
if
not
mode
or
'target_id'
not
in
session
:
if
not
mode
or
'target_id'
not
in
session
:
return
redirect
(
url_for
(
"start"
))
return
redirect
(
url_for
(
"start"
))
# 确保本局猜测计数与提示列表存在
if
'guess_count'
not
in
session
:
session
[
'guess_count'
]
=
0
session
[
'hints_shown'
]
=
[]
filtered
=
filter_db
(
mode
)
filtered
=
filter_db
(
mode
)
target
=
db
.
loc
[
session
[
'target_id'
]]
target
=
db
.
loc
[
session
[
'target_id'
]]
# 本局历史记录和提示
history
=
session
.
get
(
'history'
,
[])
history
=
session
.
get
(
'history'
,
[])
hints
=
session
.
get
(
'hints'
,
[])
hinted_chars
=
session
.
get
(
'hinted_chars'
,
[])
if
request
.
method
==
"POST"
:
if
request
.
method
==
"POST"
:
action
=
request
.
form
.
get
(
"action"
,
"guess"
)
action
=
request
.
form
.
get
(
"action"
,
"guess"
)
if
action
==
"surrender"
:
if
action
==
"surrender"
:
# 投降:显示答案并清理本局
# 认输
feedback
=
{
"giveup"
:
True
,
"answer"
:
target
[
"name"
]}
feedback
=
{
"giveup"
:
True
,
"answer"
:
target
[
"name"
],
"hints"
:
hints
}
for
key
in
(
'target_id'
,
'history'
,
'guess_count'
,
'hints_shown'
):
session
.
pop
(
'target_id'
,
None
)
session
.
pop
(
key
,
None
)
session
.
pop
(
'history'
,
None
)
session
.
pop
(
'hints'
,
None
)
session
.
pop
(
'hinted_chars'
,
None
)
elif
action
==
"restart"
:
elif
action
==
"restart"
:
# 重新开始:回到选择范围页
# 重新开始
for
key
in
(
'target_id'
,
'mode'
,
'history'
,
'guess_count'
,
'hints_shown'
):
session
.
pop
(
'target_id'
,
None
)
session
.
pop
(
key
,
None
)
session
.
pop
(
'mode'
,
None
)
session
.
pop
(
'history'
,
None
)
session
.
pop
(
'hints'
,
None
)
session
.
pop
(
'hinted_chars'
,
None
)
return
redirect
(
url_for
(
"start"
))
return
redirect
(
url_for
(
"start"
))
else
:
else
:
...
@@ -193,44 +197,68 @@ def game():
...
@@ -193,44 +197,68 @@ def game():
match
=
filtered
[
filtered
[
"name"
]
.
str
.
contains
(
user_input
,
case
=
False
,
na
=
False
)]
match
=
filtered
[
filtered
[
"name"
]
.
str
.
contains
(
user_input
,
case
=
False
,
na
=
False
)]
if
match
.
empty
:
if
match
.
empty
:
feedback
=
{
"error"
:
f
"未找到包含“{user_input}”的卡片。"
}
feedback
=
{
"error"
:
f
"未找到包含“{user_input}”的卡片。"
,
"hints"
:
hints
}
else
:
else
:
guess
=
match
.
iloc
[
0
]
guess
=
match
.
iloc
[
0
]
if
guess
.
name
==
target
.
name
:
if
guess
.
name
==
target
.
name
:
# 猜中:恭喜并清理本局
# 猜中
feedback
=
{
"success"
:
f
"🎉 恭喜你猜中了!答案就是【{guess['name']}】"
}
feedback
=
{
for
key
in
(
'target_id'
,
'history'
,
'guess_count'
,
'hints_shown'
):
"success"
:
f
"🎉 恭喜你猜中了!答案就是【{guess['name']}】"
,
session
.
pop
(
key
,
None
)
"hints"
:
hints
}
# 清理本局 session
session
.
pop
(
'target_id'
,
None
)
session
.
pop
(
'history'
,
None
)
session
.
pop
(
'hints'
,
None
)
session
.
pop
(
'hinted_chars'
,
None
)
else
:
else
:
# 有效一次猜测
# 对比并入历史
session
[
'guess_count'
]
+=
1
# 在第2次和第5次时给提示
if
session
[
'guess_count'
]
in
(
2
,
5
):
name_chars
=
list
(
target
[
'name'
])
shown
=
session
[
'hints_shown'
]
choices
=
[
c
for
c
in
name_chars
if
c
not
in
shown
]
if
choices
:
hint_char
=
random
.
choice
(
choices
)
shown
.
append
(
hint_char
)
session
[
'hints_shown'
]
=
shown
feedback
=
{
"hint"
:
hint_char
}
# 对比并存入 history
compare
=
compare_tags
(
card_to_tags
(
guess
),
card_to_tags
(
target
))
compare
=
compare_tags
(
card_to_tags
(
guess
),
card_to_tags
(
target
))
feedback
=
feedback
or
{}
feedback
.
update
({
"compare"
:
compare
,
"guess_name"
:
guess
[
'name'
]
})
history
.
append
({
history
.
append
({
"guess_name"
:
guess
[
'name'
],
"guess_name"
:
guess
[
'name'
],
"compare"
:
compare
"compare"
:
compare
})
})
# —— 第二次猜测,给一个新的“效果标签”提示 —— #
if
len
(
history
)
==
2
:
target_tags
=
set
(
card_to_tags
(
target
)[
"效果标签"
])
guessed_tags
=
set
()
for
h
in
history
:
# history 里保存的 compare 里没有原始 list,
# 所以直接重新取一次 guess 的原始标签:
row
=
db
[
db
[
"name"
]
==
h
[
"guess_name"
]]
.
iloc
[
0
]
guessed_tags
|=
set
(
card_to_tags
(
row
)[
"效果标签"
])
remaining
=
list
(
target_tags
-
guessed_tags
)
if
remaining
:
tag_hint
=
random
.
choice
(
remaining
)
hints
.
append
(
f
"提示:目标卡有效果标签 “{tag_hint}”"
)
# —— 第五次猜测,给一个新的名称字符提示 —— #
if
len
(
history
)
==
5
:
name_chars
=
[
c
for
c
in
target
[
"name"
]
if
c
.
strip
()]
candidates
=
[
c
for
c
in
name_chars
if
c
not
in
hinted_chars
]
if
candidates
:
char_hint
=
random
.
choice
(
candidates
)
hinted_chars
.
append
(
char_hint
)
hints
.
append
(
f
"提示:目标卡名称中包含 “{char_hint}” 这个字"
)
# 更新 session
session
[
'history'
]
=
history
session
[
'history'
]
=
history
session
[
'hints'
]
=
hints
session
[
'hinted_chars'
]
=
hinted_chars
feedback
=
{
"compare"
:
compare
,
"guess_name"
:
guess
[
'name'
],
"hints"
:
hints
}
return
render_template
(
"index.html"
,
return
render_template
(
"index.html"
,
feedback
=
feedback
,
feedback
=
feedback
,
history
=
history
)
history
=
history
,
hints
=
hints
)
@
app
.
route
(
"/suggest"
)
@
app
.
route
(
"/suggest"
)
def
suggest
():
def
suggest
():
...
...
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