Skip to content
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

Add missing bindings in Julia wrapper #1230

Merged
merged 4 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions open_spiel/julia/src/OpenSpiel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ using CxxWrap
import CxxWrap:argument_overloads
import Base: step, first, last

struct PlayerAction
player::Int32
action::Int64
end

@wrapmodule(LIB_OPEN_SPIEL)

include("patch.jl")
Expand Down
6 changes: 6 additions & 0 deletions open_spiel/julia/test/games_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,28 @@ end
game = load_game("kuhn_poker")
state = new_initial_state(game)
@test is_chance_node(state) == true
@test is_initial_state(state) == true
@test chance_outcomes(state) == [0 => 1/3, 1 => 1/3, 2 => 1/3]

apply_action(state, 1)
@test is_chance_node(state) == true
@test is_initial_state(state) == false
@test chance_outcomes(state) == [0 => 1/2, 2 => 1/2]

apply_action(state, 2)
@test is_chance_node(state) == false
@test is_initial_state(state) == false
@test legal_actions(state) == [0, 1]

@test length(full_history(state)) == 2
end

@testset "tic_tac_toe" begin
game = load_game("tic_tac_toe")
state = new_initial_state(game)
@test is_chance_node(state) == false
@test is_terminal(state) == false
@test is_initial_state(state) == true
@test legal_actions(state) == 0:8
end

Expand Down
5 changes: 5 additions & 0 deletions open_spiel/julia/wrapper/spieljl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& mod) {
jlcxx::stl::apply_stl<std::vector<int>>(mod);
jlcxx::stl::apply_stl<std::vector<std::vector<int>>>(mod);
jlcxx::stl::apply_stl<std::vector<open_spiel::Action>>(mod);

mod.map_type<open_spiel::State::PlayerAction>("PlayerAction");
jlcxx::stl::apply_stl<std::vector<open_spiel::State::PlayerAction>>(mod);

mod.add_bits<open_spiel::GameParameter::Type>("GameParameterStateType",
jlcxx::julia_type("CppEnum"));
Expand Down Expand Up @@ -306,6 +309,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& mod) {
})
.method("to_string", &open_spiel::State::ToString)
.method("is_terminal", &open_spiel::State::IsTerminal)
.method("is_initial_state", &open_spiel::State::IsInitialState)
.method("rewards", &open_spiel::State::Rewards)
.method("returns", &open_spiel::State::Returns)
.method("player_reward", &open_spiel::State::PlayerReward)
Expand All @@ -316,6 +320,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& mod) {
.method("is_player_node", &open_spiel::State::IsPlayerNode)
.method("history", &open_spiel::State::History)
.method("history_str", &open_spiel::State::HistoryString)
.method("full_history", &open_spiel::State::FullHistory)
.method("information_state_string",
[](open_spiel::State& s, open_spiel::Player p) {
return s.InformationStateString(p);
Expand Down
Loading