Skip to content

[Shogi] Randomly initialize the current_player variable.#1298

Merged
sotetsuk merged 1 commit intosotetsuk:mainfrom
KazukiOhta:patch-3
Feb 16, 2025
Merged

[Shogi] Randomly initialize the current_player variable.#1298
sotetsuk merged 1 commit intosotetsuk:mainfrom
KazukiOhta:patch-3

Conversation

@KazukiOhta
Copy link
Copy Markdown
Contributor

@KazukiOhta KazukiOhta commented Feb 6, 2025

Thank you for developing your nice library. I am really enjoying using it.

Issue

In Shogi environment, current_player is not randomly initialized.
This can cause issues when the users use the information of current_player in their code.

The following code can reproduce this issue.

import pgx
import jax

env = pgx.make("chess")
chess_states = jax.vmap(env.init)(jax.random.split(jax.random.key(0), 16))
print(chess_states.current_player) # -> [0 0 1 1 1 0 1 1 1 0 1 0 0 0 1 0]

env = pgx.make("shogi")
shogi_states = jax.vmap(env.init)(jax.random.split(jax.random.key(0), 16))
print(shogi_states.current_player) # -> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

Reason

In the _init function of pgx/pgx/shogi.py, the variable player_order is randomly initialized, but it is not reflected to the variable current_player.

Therefore, current_player stays to be jnp.int32(0), as initialized in class definition.

Proposal

I propose to initialize the current_player variable in the _init function.

Specifically, I propose to copy and paste the _init function in chess.py into shogi.py.

@KazukiOhta
Copy link
Copy Markdown
Contributor Author

KazukiOhta commented Feb 6, 2025

Hmm, the test on 3.13 has failed.
However, when I look into the test log, many tests are failing such as tests/test_sparrow_mahjong.py, tests/test_play2048.py, tests/test_go.py, ....

Maybe these failures are not caused by the modification in this pull request...?

@sotetsuk
Copy link
Copy Markdown
Owner

sotetsuk commented Feb 7, 2025

Thank you again for reporting bugs! Recent changes may have introduced this bug ... 😢
I'll check it this weekend!

@KazukiOhta
Copy link
Copy Markdown
Contributor Author

Thank you for your kind and quick reply!

This was referenced Feb 9, 2025
@sotetsuk sotetsuk merged commit 079b2d7 into sotetsuk:main Feb 16, 2025
@KazukiOhta
Copy link
Copy Markdown
Contributor Author

Thank you for releasing v2.6.0!

@KazukiOhta KazukiOhta deleted the patch-3 branch March 6, 2025 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants