-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Shogi] Add and fix buggy test samples #358
Merged
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6196478
syuusei sfen2state hand
youyou-ku e22e64b
add test
youyou-ku c703d5f
rfm test
youyou-ku ac8a89e
Merge remote-tracking branch 'origin/main' into dif_from_cshogi
sotetsuk cd7be49
.
sotetsuk 13d66ee
.
sotetsuk 7dd9b53
.
sotetsuk 7172099
fix
sotetsuk ca188be
fmt
sotetsuk b07124e
add tests
sotetsuk 5ac2b0c
add tests
sotetsuk dd89ace
.
sotetsuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import jax.numpy as jnp | ||
|
||
from pgx.shogi import * | ||
from pgx.shogi import _init, _step, _step_move, _step_drop, _flip, _apply_effects, _legal_actions, _rotate, _to_direction | ||
from pgx.shogi import _init, _step, _step_move, _step_drop, _flip, _apply_effects, _legal_actions, _rotate, _to_direction, _sfen_to_state | ||
|
||
|
||
# check visualization results by image preview plugins | ||
|
@@ -373,3 +373,29 @@ def test_step(): | |
s = step(s, 3 * 81 + xy2i(3, 8)) | ||
visualize(s, "tests/assets/shogi/step_003.svg") | ||
assert not s.legal_action_mask[3 * 81 + xy2i(3, 8)] | ||
|
||
|
||
# 今やると落ちる | ||
def test_legal_action_mask(): | ||
# 歩以外の持ち駒に対しての二歩判定回避 | ||
sfen = "9/9/9/9/9/9/PPPPPPPPP/9/9 b NLP 1" | ||
legal_action = _to_direction(_legal_actions(_sfen_to_state(sfen))) | ||
# 歩は二歩になるので打てない | ||
assert (legal_action[81*20:81*21] == False).all() | ||
# 香車は1列目と6列目(歩がいる)二は打てない | ||
# 二列目には打てる | ||
assert (legal_action[81*21+1:81*22:9] == True).all() | ||
assert (legal_action[81*21:81*22:9] == False).all() | ||
assert (legal_action[81*21+5:81*22:9] == False).all() | ||
# 桂馬は1.2列目に打てない | ||
# 三列目には打てる | ||
assert (legal_action[81*22+1:81*23:9] == False).all() | ||
assert (legal_action[81*22:81*23:9] == False).all() | ||
assert (legal_action[81*21+5:81*22:9] == False).all() | ||
|
||
# 成駒のpromotion判定 | ||
sfen = "9/2+B1G1+P2/9/9/9/9/9/9/9 b - 1" | ||
legal_action = _to_direction(_legal_actions(_sfen_to_state(sfen))) | ||
legal_action = jnp.where(legal_action, 1, 0) | ||
# promotionは生成されてたらダメ | ||
assert jnp.all(legal_action[810:] == 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. このテスト意味がわからないんですけどどういう意味ですか? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. とりあえずコメントを参考に修正済 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
== False
みたいなコードを書くのはやめましょう(~legal_action[81*21+5:81*22:9]).all()