-
-
Notifications
You must be signed in to change notification settings - Fork 990
/
break_replay_with_lua_random.cfg
87 lines (84 loc) · 2.19 KB
/
break_replay_with_lua_random.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 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 30 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 should be roughly less than one in a billion.
#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 30
{RETURN ([true][/true])}
[/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 =<<
wesnoth.set_variable("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)
wesnoth.set_variable("rnd_num", result.value)
>>
[/lua]
)}