Skip to content

Commit 14fdfc1

Browse files
authored
Merge pull request #13 from findmyway/bump_version
bump version
2 parents 44ff781 + 236b9b2 commit 14fdfc1

File tree

3 files changed

+153
-109
lines changed

3 files changed

+153
-109
lines changed

.github/workflows/CI.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- master
6+
tags: '*'
7+
pull_request:
8+
concurrency:
9+
# Skip intermediate builds: always.
10+
# Cancel intermediate builds: only if it is a pull request build.
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
13+
jobs:
14+
test:
15+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
version:
21+
- '1'
22+
- '1.6'
23+
os:
24+
- ubuntu-latest
25+
arch:
26+
- x64
27+
steps:
28+
- uses: actions/checkout@v2
29+
- uses: julia-actions/setup-julia@v1
30+
with:
31+
version: ${{ matrix.version }}
32+
arch: ${{ matrix.arch }}
33+
- uses: julia-actions/cache@v1
34+
- uses: julia-actions/julia-buildpkg@v1
35+
- uses: julia-actions/julia-runtest@v1
36+
- uses: julia-actions/julia-processcoverage@v1
37+
- uses: codecov/codecov-action@v2
38+
with:
39+
files: lcov.info

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
name = "OpenSpiel"
22
uuid = "ceb70bd2-fe3f-44f0-b81f-41608acaf2f2"
33
authors = ["Jun Tian <[email protected]>"]
4-
version = "0.1.3"
4+
version = "0.1.4"
55

66
[deps]
77
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"
88
OpenSpiel_jll = "bd10a763-4654-5023-a028-c4918c6cd33e"
99

1010
[compat]
11-
CxxWrap = "0.10"
12-
OpenSpiel_jll = "0.1"
13-
julia = "1.3"
11+
CxxWrap = "0.12"
12+
OpenSpiel_jll = "1"
13+
julia = "1.6"
1414

1515
[extras]
1616
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

test/games_simulation.jl

Lines changed: 110 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,141 @@
11
@testset "games simulation" begin
22

3-
MAX_ACTIONS_PER_GAME = 1000
3+
MAX_ACTIONS_PER_GAME = 1000
44

5-
SPIEL_GAMES_LIST = registered_games()
5+
SPIEL_GAMES_LIST = registered_games()
66

7-
SPIEL_LOADABLE_GAMES_LIST = [
8-
g for g in SPIEL_GAMES_LIST if default_loadable(g)
9-
]
7+
SPIEL_LOADABLE_GAMES_LIST = [
8+
g for g in SPIEL_GAMES_LIST if default_loadable(g)
9+
]
1010

11-
@test length(SPIEL_LOADABLE_GAMES_LIST) >= 38
11+
@test length(SPIEL_LOADABLE_GAMES_LIST) >= 38
1212

13-
SPIEL_SIMULTANEOUS_GAMES_LIST = [
14-
g for g in SPIEL_LOADABLE_GAMES_LIST
15-
if dynamics(g) == SIMULTANEOUS
16-
]
13+
SPIEL_SIMULTANEOUS_GAMES_LIST = [
14+
g for g in SPIEL_LOADABLE_GAMES_LIST
15+
if dynamics(g) == SIMULTANEOUS
16+
]
1717

18-
@test length(SPIEL_SIMULTANEOUS_GAMES_LIST) >= 14
18+
@test length(SPIEL_SIMULTANEOUS_GAMES_LIST) >= 14
1919

20-
SPIEL_MULTIPLAYER_GAMES_LIST = [
21-
(g, p)
22-
for g in SPIEL_LOADABLE_GAMES_LIST
23-
for p in max(min_num_players(g), 2) : min(max_num_players(g), 6)
24-
if (max_num_players(g) > 2) &&
20+
SPIEL_MULTIPLAYER_GAMES_LIST = [
21+
(g, p)
22+
for g in SPIEL_LOADABLE_GAMES_LIST
23+
for p in max(min_num_players(g), 2):min(max_num_players(g), 6)
24+
if (max_num_players(g) > 2) &&
2525
(max_num_players(g) > min_num_players(g)) &&
2626
(short_name(g) != "tiny_hanabi") && # default payoff only works for 2p
2727
(short_name(g) != "universal_poker")
28-
]
28+
]
2929

30-
@test length(SPIEL_MULTIPLAYER_GAMES_LIST) >= 35
30+
@test length(SPIEL_MULTIPLAYER_GAMES_LIST) >= 35
3131

32-
function apply_action_test_clone(state, action)
33-
state_copy = copy(state)
34-
@test string(state) == string(state_copy)
35-
@test history(state) == history(state_copy)
32+
function apply_action_test_clone(state, action)
33+
state_copy = copy(state)
34+
@test string(state) == string(state_copy)
35+
@test history(state) == history(state_copy)
3636

37-
apply_action(state, action)
38-
apply_action(state_copy, action)
37+
apply_action(state, action)
38+
apply_action(state_copy, action)
3939

40-
@test string(state) == string(state_copy)
41-
@test history(state) == history(state_copy)
42-
end
40+
@test string(state) == string(state_copy)
41+
@test history(state) == history(state_copy)
42+
end
4343

44-
function serialize_deserialize(game, state)
45-
ser_str = serialize_game_and_state(game, state)
46-
new_game, new_state = deserialize_game_and_state(ser_str)
47-
@test string(game) == string(new_game)
48-
@test string(state) == string(new_state)
49-
end
44+
function serialize_deserialize(game, state)
45+
ser_str = serialize_game_and_state(game, state)
46+
new_game, new_state = deserialize_game_and_state(ser_str)
47+
@test string(game) == string(new_game)
48+
@test string(state) == string(new_state)
49+
end
5050

51-
function simulate_game(game)
52-
@info "simulating game $(short_name(get_type(game)))"
53-
min_u, max_u = min_utility(game), max_utility(game)
54-
@test min_u < max_u
51+
function simulate_game(game)
52+
@info "simulating game $(short_name(get_type(game)))"
53+
min_u, max_u = min_utility(game), max_utility(game)
54+
@test min_u < max_u
55+
56+
state = new_initial_state(game)
57+
total_actions = 0
58+
59+
next_serialize_check = 1
60+
61+
while !is_terminal(state) && (total_actions <= MAX_ACTIONS_PER_GAME)
62+
total_actions += 1
63+
64+
# Serialize/Deserialize is costly. Only do it every power of 2 actions.
65+
if total_actions >= next_serialize_check
66+
serialize_deserialize(game, state)
67+
next_serialize_check *= 2
68+
end
69+
70+
# The state can be of four different types: chance node,
71+
# simultaneous node, decision node or mean field node.
72+
if is_chance_node(state)
73+
# Chance node: sample an outcome
74+
outcomes = chance_outcomes(state)
75+
@test length(outcomes) > 0
76+
action_list, prob_list = zip(outcomes...)
77+
action = action_list[sample(weights(collect(prob_list)))]
78+
apply_action(state, action)
79+
elseif is_simultaneous_node(state)
80+
chosen_actions = [
81+
rand(legal_actions(state, pid - 1))
82+
for pid in 1:num_players(game)
83+
] # in julia, index starts with 1
84+
# Apply the joint action and test cloning states.
85+
apply_action_test_clone(state, chosen_actions)
86+
elseif is_mean_field_node(state)
87+
num_states = length(distribution_support(state))
88+
update_distribution(
89+
state, StdVector([1.0 / num_states for _ in 1:num_states]))
90+
else
91+
@test is_player_node(state)
92+
# Decision node: sample action for the single current player
93+
action = rand(legal_actions(state, current_player(state)))
94+
# Apply action and test state cloning.
95+
apply_action_test_clone(state, action)
96+
end
97+
end
5598

56-
state = new_initial_state(game)
57-
total_actions = 0
99+
@test total_actions > 0
58100

59-
next_serialize_check = 1
101+
if is_terminal(state)
102+
# Check there are no legal actions.
103+
@test length(legal_actions(state)) == 0
104+
for player in 0:(num_players(game)-1)
105+
@test length(legal_actions(state, player)) == 0
106+
end
60107

61-
while !is_terminal(state) && (total_actions <= MAX_ACTIONS_PER_GAME)
62-
total_actions += 1
108+
utilities = returns(state)
63109

64-
# Serialize/Deserialize is costly. Only do it every power of 2 actions.
65-
if total_actions >= next_serialize_check
66-
serialize_deserialize(game, state)
67-
next_serialize_check *= 2
68-
end
110+
for u in utilities
111+
@test u >= min_utility(game)
112+
@test u <= max_utility(game)
113+
end
69114

70-
# The state can be three different types: chance node,
71-
# simultaneous node, or decision node
72-
if is_chance_node(state)
73-
# Chance node: sample an outcome
74-
outcomes = chance_outcomes(state)
75-
@test length(outcomes) > 0
76-
action_list, prob_list = zip(outcomes...)
77-
action = action_list[sample(weights(collect(prob_list)))]
78-
apply_action(state, action)
79-
elseif is_simultaneous_node(state)
80-
chosen_actions = [
81-
rand(legal_actions(state, pid-1))
82-
for pid in 1:num_players(game)
83-
] # in julia, index starts with 1
84-
# Apply the joint action and test cloning states.
85-
apply_action_test_clone(state, chosen_actions)
115+
@info "Simulation of game $game" total_actions utilities
86116
else
87-
# Decision node: sample action for the single current player
88-
action = rand(legal_actions(state, current_player(state)))
89-
# Apply action and test state cloning.
90-
apply_action_test_clone(state, action)
117+
@info "Simulation of game $game terminated after maximum number of actions $MAX_ACTIONS_PER_GAME"
91118
end
92119
end
93120

94-
@test total_actions > 0
95-
96-
if is_terminal(state)
97-
# Check there are no legal actions.
98-
@test length(legal_actions(state)) == 0
99-
for player in 0:(num_players(game)-1)
100-
@test length(legal_actions(state, player)) == 0
101-
end
102-
103-
utilities = returns(state)
104-
105-
for u in utilities
106-
@test u >= min_utility(game)
107-
@test u <= max_utility(game)
108-
end
109-
110-
@info "Simulation of game $game" total_actions utilities
111-
else
112-
@info "Simulation of game $game terminated after maximum number of actions $MAX_ACTIONS_PER_GAME"
121+
for game_info in SPIEL_LOADABLE_GAMES_LIST
122+
game = load_game(short_name(game_info))
123+
@test num_players(game) >= min_num_players(game_info)
124+
@test num_players(game) <= max_num_players(game_info)
125+
simulate_game(game)
113126
end
114-
end
115127

116-
for game_info in SPIEL_LOADABLE_GAMES_LIST
117-
game = load_game(short_name(game_info))
118-
@test num_players(game) >= min_num_players(game_info)
119-
@test num_players(game) <= max_num_players(game_info)
120-
simulate_game(game)
121-
end
122-
123-
for game_info in SPIEL_SIMULTANEOUS_GAMES_LIST
124-
converted_game = load_game_as_turn_based(short_name(game_info))
125-
simulate_game(converted_game)
126-
end
128+
for game_info in SPIEL_SIMULTANEOUS_GAMES_LIST
129+
converted_game = load_game_as_turn_based(short_name(game_info))
130+
simulate_game(converted_game)
131+
end
127132

128-
for (game_info, n) in SPIEL_MULTIPLAYER_GAMES_LIST
129-
game = load_game(short_name(game_info); players=GameParameter(n))
130-
simulate_game(game)
131-
end
133+
for (game_info, n) in SPIEL_MULTIPLAYER_GAMES_LIST
134+
game = load_game(short_name(game_info); players=GameParameter(n))
135+
simulate_game(game)
136+
end
132137

133-
simulate_game(load_game("breakthrough(rows=6,columns=6)"))
134-
simulate_game(load_game("pig(players=2,winscore=15)"))
138+
simulate_game(load_game("breakthrough(rows=6,columns=6)"))
139+
simulate_game(load_game("pig(players=2,winscore=15)"))
135140

136-
end
141+
end

0 commit comments

Comments
 (0)