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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
# frozen_string_literal: true
require './lib/colonial_twilight/fln_bot'
require './spec/mock_board'
class ColonialTwilight::FLNBot
attr_writer :debug
def setup(op_limited: true)
@possible_actions = %i[pass op op_limited] unless op_limited
@possible_actions = %i[pass op_limited] if op_limited
end
end
describe ColonialTwilight::FLNBot do
before do
@game = Game.new
@game.board.fln_resources = 1
@game.board.available_fln_underground = 1
@bot = ColonialTwilight::FLNBot.new(@game, :FLN)
@bot.setup
end
describe 'Pass' do
it 'cost' do
expect(@bot.pass).to be true
expect(@game.action.cost).to eq(-1)
end
it 'steps' do
expect(@bot.pass).to be true
expect(@game.action.steps.size).to eq(1)
end
it 'kind' do
expect(@bot.pass).to be true
expect(@game.action.steps[0][:kind]).to eq(:pass)
end
end
describe 'Extort' do
it 'nowhere' do
expect(@bot.extort).to be false
end
it 'success' do
@game.set(pop: 1, fln_underground: 1)
expect(@bot.extort).to be true
end
it 'not if special activity already done' do
@bot.turn.special_activity_in(:subvert, @game.board.spaces[0], 1)
@game.set(pop: 1, fln_underground: 1)
expect(@bot.extort).to be false
end
end
describe 'Terror' do
it 'nowhere' do
expect(@bot.terror).to be false
end
it 'terror 1' do
@game.set(pop: 1, fln_underground: 1, support: true)
expect(@bot.terror).to be true
end
it 'terror 2' do
@game.set(pop: 1, fln_underground: 1, neutral: true, gov_bases: 1)
expect(@bot.terror).to be true
end
it 'terror 1 + extort' do
@game.board.fln_resources = 0
@game.set(pop: 1, fln_underground: 2, support: true)
expect(@bot.terror).to be true
end
it 'terror 1 + extort not possible' do
@game.board.fln_resources = 0
@game.set(pop: 1, fln_underground: 1, support: true)
expect(@bot.terror).to be false
end
end
describe 'Attack' do
def check_transfer(step, what, dst, num)
expect(step[:kind]).to be :transfer
expect(step[:what]).to be what
expect(step[:dst]).to be dst
expect(step[:num]).to eq num
end
def check_activate(step, num)
expect(step[:kind]).to be :activate
expect(step[:num]).to eq num
end
it 'algerian_police ambush' do
@game.set(algerian_police: 1, fln_active: 5, fln_underground: 1)
expect(@bot.attack).to be true
expect(@game.action.type).to be :ambush
check_activate(@game.action.steps[0], 1)
check_transfer(@game.action.steps[1], :algerian_police, :casualties, 1)
check_transfer(@game.action.steps[2], :fln_active, :available, 1)
end
it 'ambush twice then attack' do
@game.board.fln_resources = 3
@game.set(french_troops: 1, french_police: 1, algerian_police: 1, fln_active: 3, fln_underground: 3)
@game.set(gov_bases: 1, algerian_police: 1, fln_active: 4, fln_underground: 2)
@game.set(algerian_police: 1, fln_active: 1, fln_underground: 5)
expect(@bot.attack).to be true
act = @game.actions[0]
expect(act.type).to be :ambush
check_activate(act.steps[0], 1)
check_transfer(act.steps[1], :french_police, :casualties, 1)
check_transfer(act.steps[2], :fln_active, :available, 1)
act = @game.actions[1]
expect(act.type).to be :ambush
check_activate(act.steps[0], 1)
check_transfer(act.steps[1], :algerian_police, :casualties, 1)
check_transfer(act.steps[2], :fln_active, :available, 1)
act = @game.actions[2]
expect(act.type).to be :attack
check_activate(act.steps[0], 5)
check_transfer(act.steps[1], :algerian_police, :casualties, 1)
check_transfer(act.steps[2], :fln_active, :available, 1)
end
it 'roll to attack' do
@game.board.fln_resources = 3
@game.set(algerian_police: 3, fln_active: 2, fln_underground: 1)
@game.set(algerian_police: 3, fln_active: 2, fln_underground: 1)
@game.set(algerian_police: 1, fln_active: 2, fln_underground: 2)
expect(@bot.attack).to be true
act = @game.actions[2]
expect(act.type).to be :attack
check_activate(@game.action.steps[0], 2)
check_activate(act.steps[0], 2)
check_transfer(act.steps[1], :algerian_police, :casualties, 1)
check_transfer(act.steps[2], :fln_active, :available, 1)
end
it 'attrition' do
@game.board.fln_resources = 3
@game.set(algerian_police: 30, fln_active: 2, fln_underground: 1)
@game.set(algerian_police: 30, fln_active: 2, fln_underground: 1)
@game.set(algerian_police: 3, fln_active: 2, fln_underground: 2)
expect(@bot.attack).to be true
act = @game.actions[2]
expect(act.type).to be :attack
check_activate(@game.action.steps[0], 2)
check_activate(act.steps[0], 2)
check_transfer(act.steps[1], :algerian_police, :casualties, 2)
check_transfer(act.steps[2], :fln_active, :available, 1)
check_transfer(act.steps[3], :fln_active, :casualties, 1)
end
it 'attack + extort' do
@game.board.fln_resources = 0
@game.set(algerian_police: 3, fln_active: 2, fln_underground: 1)
@game.set(name: 'country', pop: 1, fln_underground: 1, independent: true)
expect(@bot.attack).to be true
end
end
describe 'Subvert' do
it 'nowhere' do
expect(@bot.subvert).to be false
end
it 'subvert 1' do
@game.set(fln_underground: 1, algerian_police: 1)
expect(@bot.subvert).to be true
expect(@game.actions.size).to be 1
expect(@game.action.steps.size).to be 1
end
it 'subvert 2' do
@game.set(fln_underground: 1, algerian_police: 1, french_troops: 1)
expect(@bot.subvert).to be true
expect(@game.actions.size).to be 1
expect(@game.action.steps.size).to be 2
end
it 'subvert 1 + remove anywhere' do
@game.set(fln_underground: 1, algerian_police: 1)
@game.set(fln_underground: 1, algerian_troops: 1, french_troops: 1)
expect(@bot.subvert).to be true
expect(@game.actions.size).to be 2
end
it 'OP + 2 x remove anywhere' do
expect(@bot.pass).to be true
@game.set(name: 'a', fln_underground: 1, algerian_troops: 1, french_troops: 1)
@game.set(name: 'b', fln_underground: 1, algerian_troops: 1, french_troops: 1)
expect(@bot.subvert).to be true
expect(@game.actions.size).to be 3
end
end
describe 'Rally' do
it 'nowhere' do
expect(@bot.rally).to be false
end
it 'rally 1' do
@game.set(fln_active: 1, fln_underground: 2)
expect(@bot.rally).to be true
expect(@game.action.steps.size).to be 3
end
it 'rally 2' do
@bot.setup(op_limited: false)
@game.set(fln_active: 2, fln_underground: 2, french_troops: 1)
expect(@bot.rally).to be true
expect(@game.action.steps.size).to be 2
end
it 'rally 3' do
@game.set(fln_bases: 1)
@game.set(fln_bases: 2)
expect(@bot.rally).to be true
expect(@game.action.steps.size).to be 1
end
it 'rally 4' do
@game.board.france_track = 2
expect(@bot.rally).to be true
end
it 'rally 5' do
@game.set(support: true)
@game.set(support: true)
expect(@bot.rally).to be true
expect(@game.action.steps.size).to be 1
end
it 'rally 6 + agitate' do
@game.board.fln_resources = 20
@game.set(pop: 2, terror: 2)
@game.set(pop: 2, terror: 3)
expect(@bot.rally).to be true
expect(@game.action.cost).to be 3
expect(@game.actions.size).to be 2
end
it 'rally 6 + only reduce terror' do
@game.board.fln_resources = 9
@game.set(pop: 2, terror: 8)
expect(@bot.rally).to be true
expect(@bot.turn.cost).to be 6
expect(@game.action.cost).to be 5
expect(@game.actions.size).to be 2
end
it 'rally 6 + extort + agitate' do
@game.board.fln_resources = 1
@game.set(pop: 2, terror: 1)
@game.set(name: 'country', pop: 1, fln_underground: 1, independent: true)
@game.set(name: 'country', pop: 1, fln_underground: 1, independent: true)
expect(@bot.rally).to be true
expect(@game.actions.size).to be 4
end
it 'rally 6 + cannot extort => rally 7' do
@game.board.fln_resources = 1
@game.set(pop: 2, terror: 1)
expect(@bot.rally).to be true
expect(@game.actions.size).to be 1
end
it 'rally 7 + limited agitate' do
@game.keep = true
@game.board.fln_resources = 9
@game.set(fln_active: 1, terror: 10)
expect(@bot.rally).to be true
expect(@game.actions.size).to be 2
expect(@game.actions[1].cost).to be 5
end
it 'rally 7 + extort + agitate' do
@game.keep = true
@game.board.fln_resources = 1
@game.set(pop: 1, french_police: 3, fln_active: 1, fln_bases: 1, terror: 10)
@game.set(name: 'country', pop: 1, fln_underground: 1, independent: true)
@game.set(name: 'country', pop: 1, fln_underground: 1, independent: true)
@game.set(name: 'country', pop: 1, fln_underground: 1, independent: true)
expect(@bot.rally).to be true
expect(@game.actions.size).to be 5
expect(@game.actions[4].type).to eq :agitate
expect(@game.actions[4].cost).to be 3
end
it 'agitate unselected' do
@game.keep = true
@game.board.fln_resources = 3
@game.set(fln_active: 0, fln_bases: 1, terror: 1)
expect(@bot.rally).to be true
expect(@game.actions.size).to be 2
expect(@game.actions[1].type).to eq :agitate
expect(@game.actions[1].cost).to be 2
end
it '2 rally 7 + rally 8' do
@bot.setup(op_limited: false)
@game.board.fln_resources = 3
@game.set(fln_active: 1, oppose: 1)
@game.set(fln_active: 1, oppose: 1)
@game.set(fln_active: 1, oppose: 1)
@game.set(fln_active: 1, oppose: 1)
expect(@bot.rally).to be true
expect(@game.actions.size).to be 3
end
end
end
|