mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-06 23:44:19 +00:00
89 lines
2.7 KiB
INI
89 lines
2.7 KiB
INI
# The purpose of this test is to make a scenario that plays but goes out of sync with the replay.
|
|
# This is done as a sanity check of the unit testing mechanism.
|
|
# We use the unsynced rng, lua.random, to achieve this.
|
|
# Basically we keep giving side 1 a random amount of gold and recruiting as
|
|
# many woses as possible, killing them immediately to make space. We do this
|
|
# for 60 turns. In the replay we will actually have a random amount of gold
|
|
# each time, so if we have bad luck one turn we won't have enough to afford
|
|
# that many woses.
|
|
# For each turn its about 50-50 not to go out of sync, so the chance not to
|
|
# go out of sync (for true randomness) would be ~ 2^{-60}.
|
|
# (However none of our generators use more than 32 bits per seed.)
|
|
|
|
#define TEST_BREAK_REPLAY ID GET_RND_NUM
|
|
{GENERIC_UNIT_TEST {ID} (
|
|
[event]
|
|
name = start
|
|
[allow_recruit]
|
|
side=1
|
|
type=Wose
|
|
[/allow_recruit]
|
|
[/event]
|
|
[event]
|
|
name = recruit
|
|
first_time_only = no
|
|
[kill]
|
|
x = $x1
|
|
y = $y1
|
|
animate=yes
|
|
[/kill]
|
|
[/event]
|
|
[event]
|
|
name = side 1 turn refresh
|
|
first_time_only=no
|
|
{GET_RND_NUM}
|
|
[modify_side]
|
|
side = 1
|
|
gold = $rnd_num
|
|
[/modify_side]
|
|
[while]
|
|
{VARIABLE_CONDITIONAL rnd_num greater_than_equal_to 20}
|
|
[do]
|
|
[do_command]
|
|
[recruit]
|
|
type="Wose"
|
|
x,y=7,4
|
|
[from]
|
|
x,y=7,3
|
|
[/from]
|
|
[/recruit]
|
|
[/do_command]
|
|
{VARIABLE_OP rnd_num sub 20}
|
|
[/do]
|
|
[/while]
|
|
[end_turn]
|
|
[/end_turn]
|
|
[/event]
|
|
[event]
|
|
name = side 2 turn 60
|
|
{SUCCEED}
|
|
[/event]
|
|
[event]
|
|
name = side 2 turn refresh
|
|
first_time_only=no
|
|
[end_turn]
|
|
[/end_turn]
|
|
[/event]
|
|
)}
|
|
#enddef
|
|
|
|
{TEST_BREAK_REPLAY "break_replay_with_lua_random" (
|
|
[lua]
|
|
code =<<
|
|
wml.variables["rnd_num"] = math.random(200)
|
|
>>
|
|
[/lua]
|
|
)}
|
|
|
|
{TEST_BREAK_REPLAY "fixed_lua_random_replay_with_sync_choice" (
|
|
[lua]
|
|
code =<<
|
|
local result = wesnoth.synchronize_choice(
|
|
function()
|
|
return { value = math.random(200) }
|
|
end)
|
|
wml.variables["rnd_num"] = result.value
|
|
>>
|
|
[/lua]
|
|
)}
|