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
|
# frozen_string_literal: true
require './lib/colonial_twilight/actions/fln/rally'
require './lib/colonial_twilight/actions/fln/agitate'
require './lib/colonial_twilight/actions/fln/attack'
require './lib/colonial_twilight/actions/fln/march'
require './lib/colonial_twilight/actions/fln/terror'
require './lib/colonial_twilight/actions/fln/extort'
require './lib/colonial_twilight/actions/fln/subvert'
require './lib/colonial_twilight/actions/fln/ambush'
require './lib/colonial_twilight/actions/fln/oas'
require './lib/colonial_twilight/board'
require './spec/mock_board'
describe ColonialTwilight::Actions::FLN do
before do
@board = ColonialTwilight::Board.new
end
describe 'Rally' do
let(:action_class) { ColonialTwilight::Actions::FLN::Rally }
it 'collects spaces where operation can be conducted' do
# all but countries
expect(action_class.possible_spaces(@board).size).to eq(28)
end
it 'collects spaces where operation can be conducted' do
@board.load :short
# 25 sectors + 2 countries
expect(action_class.possible_spaces(@board).size).to eq(27)
end
it 'applicable? France track' do
t = Track.new(5, 'France track')
expect(action_class.applicable?(t)).to be true
t = Track.new(5, 'France ')
expect(action_class.applicable?(t)).to be false
end
it 'applicable? sector' do
a = Sector.new
expect(action_class.applicable?(a)).to be true
end
it 'applicable? in city not at support' do
a = Sector.new({ name: 'city', support: false })
expect(action_class.applicable?(a)).to be true
end
it 'not applicable? in city at support' do
a = Sector.new({ name: 'city', support: true })
expect(action_class.applicable?(a)).to be false
end
it 'applicable? in independent country' do
a = Sector.new({ name: 'country', independent: true })
expect(action_class.applicable?(a)).to be true
end
it 'not applicable? not in not independent country' do
a = Sector.new({ name: 'country', independent: false })
expect(action_class.applicable?(a)).to be false
end
it 'may place 1 guerrillas' do
a = Sector.new({ pop: 3 })
modes = action_class.available_modes(a)
expect(modes.keys.size).to eq(1)
expect(modes[:place_guerilla]).to eq(1)
end
it 'may place pop + base guerrillas' do
a = Sector.new({ pop: 3, fln_bases: 2 })
modes = action_class.available_modes(a)
expect(modes.keys.size).to eq(1)
expect(modes[:place_guerilla]).to eq(5)
end
it 'may flip underground guerillas' do
a = Sector.new({ fln_active: 3, fln_underground: 2, fln_bases: 1 })
modes = action_class.available_modes(a)
expect(modes.keys.size).to eq(3)
expect(modes[:place_base]).to eq(1)
expect(modes[:place_guerilla]).to eq(1)
expect(modes[:underground]).to eq(3)
end
it 'may create action within available modes' do
a = Sector.new({ fln_active: 3, fln_underground: 2, fln_bases: 1 })
expect { action_class.new(a, { underground: 3 }) }.not_to raise_error
expect(action_class.new(a, { underground: 3 }).cost).to eq(1)
end
it 'may not create action within a not applicable space' do
a = Sector.new({ name: 'city', support: true })
expect { action_class.new(a, {}) }.to raise_error(/not applicable/)
end
it 'may not create action within higher value' do
a = Sector.new({ fln_active: 3, fln_underground: 2, fln_bases: 1 })
expect { action_class.new(a, { underground: 4 }) }.to raise_error(/value:/)
end
it 'may create action within available modes' do
a = Sector.new({ fln_active: 3, fln_underground: 2, fln_bases: 1 })
expect { action_class.new(a, { wrong: 3 }) }.to raise_error(/mode:/)
end
it 'may agitate and compute cost' do
a = Sector.new({ fln_active: 3, fln_underground: 2, fln_bases: 1, terror: 2 })
expect { action_class.new(a, { underground: 3 }).agitate!({ remove_terror: 1 }) }.not_to raise_error
expect(action_class.new(a, { underground: 3 }).agitate!({ remove_terror: 1 }).cost).to eq(2)
expect(action_class.new(a, { underground: 3 }).agitate!({ remove_terror: 2 }).cost).to eq(3)
end
it 'may not agitate if not applicable' do
a = Sector.new({ fln_active: 3, fln_underground: 2, fln_bases: 1, oppose: true })
expect { action_class.new(a, { underground: 3 }).agitate!({ remove_terror: 1 }) }.to raise_error(/not applicable/)
end
it 'may not agitate twice' do
a = Sector.new({ fln_active: 3, fln_underground: 2, fln_bases: 1, terror: 1 })
expect { action_class.new(a, { underground: 3 }).agitate!({ remove_terror: 1 }).agitate!({ remove_terror: 1 }) }.to raise_error(/agitate! called/)
end
end
describe 'Attack' do
let(:action_class) { ColonialTwilight::Actions::FLN::Attack }
it 'is applicable where FLN and GOV are present' do
a = Sector.new(fln_active: 1, gov_cubes: 1)
expect(action_class.applicable?(a)).to be true
end
it 'is not applicable without FLN' do
a = Sector.new(fln_active: 0, gov_cubes: 1)
expect(action_class.applicable?(a)).to be false
end
it 'is not applicable without GOV' do
a = Sector.new(fln_active: 1, gov_cubes: 0)
expect(action_class.applicable?(a)).to be false
end
it 'has no modes' do
a = Sector.new(fln_active: 1, gov_cubes: 1)
expect(action_class.available_modes(a).empty?).to be true
end
it 'can have an ambush' do
a = Sector.new(fln_active: 1, fln_underground: 1, gov_cubes: 1)
action = action_class.new(a)
expect { action.ambush! }.not_to raise_error
end
end
describe 'March' do
let(:action_class) { ColonialTwilight::Actions::FLN::March }
it 'is applicable where FLN guerrillas are present' do
a = Sector.new(fln_active: 1)
expect(action_class.applicable?(a)).to be true
end
it 'is not applicable without FLN guerrillas' do
a = Sector.new(fln_active: 0)
expect(action_class.applicable?(a)).to be false
end
it 'calculates cost based on destinations' do
a = Sector.new(fln_active: 5)
allow(a).to receive(:adjacents).and_return([1, 2, 3])
action = action_class.new(a, { 1 => 2, 2 => 3 })
expect(action.cost).to eq(2)
end
end
describe 'Terror' do
let(:action_class) { ColonialTwilight::Actions::FLN::Terror }
it 'is applicable in populated space with underground FLN' do
a = Sector.new(pop: 1, fln_underground: 1)
expect(action_class.applicable?(a)).to be true
end
it 'is not applicable in unpopulated space' do
a = Sector.new(pop: 0, fln_underground: 1)
expect(action_class.applicable?(a)).to be false
end
it 'is not applicable without underground FLN' do
a = Sector.new(pop: 1, fln_underground: 0)
expect(action_class.applicable?(a)).to be false
end
it 'is not applicable in countries' do
a = Sector.new(name: 'country', pop: 1, fln_underground: 1)
expect(action_class.applicable?(a)).to be false
end
it 'has no mode' do
a = Sector.new(pop: 1, fln_underground: 1)
expect(action_class.available_modes(a).empty?).to be true
end
end
describe 'Extort' do
let(:action_class) { ColonialTwilight::Actions::FLN::Extort }
it 'is applicable in populated space with underground FLN and FLN control' do
a = Sector.new(pop: 1, fln_underground: 1, fln_active: 2, gov_cubes: 0)
expect(action_class.applicable?(a)).to be true
end
it 'is applicable in independent countries with underground FLN' do
a = Sector.new(name: 'country', independent: true, fln_underground: 1)
expect(action_class.applicable?(a)).to be true
end
it 'is not applicable without FLN control in sector' do
a = Sector.new(pop: 1, fln_underground: 1, fln_active: 0, gov_cubes: 2)
expect(action_class.applicable?(a)).to be false
end
end
describe 'Subvert' do
let(:action_class) { ColonialTwilight::Actions::FLN::Subvert }
it 'is applicable with underground FLN and Algerian cubes' do
a = Sector.new(fln_underground: 1, algerian_police: 1)
expect(action_class.applicable?(a)).to be true
end
it 'provides replace_police and remove_police modes' do
a = Sector.new(fln_underground: 1, algerian_police: 2)
modes = action_class.available_modes(a)
expect(modes[:replace_police]).to eq(1)
expect(modes[:remove_police]).to eq(2)
expect(modes[:remove_troops]).to be_nil
end
it 'provides replace_police and remove_troops modes' do
a = Sector.new(fln_underground: 1, algerian_troops: 2)
modes = action_class.available_modes(a)
expect(modes[:replace_police]).to be_nil
expect(modes[:remove_police]).to be_nil
expect(modes[:remove_troops]).to eq(2)
end
it 'may chain subvert in 2 spaces' do
a = Sector.new(fln_underground: 1, algerian_police: 2)
b = Sector.new(fln_underground: 1, algerian_troops: 1)
act = action_class.new(a, { remove_police: 1 })
expect { act.subvert!(b, { remove_troops: 1 }) }.to_not raise_error
expect { act.subvert!(b, { remove_troops: 2 }) }.to raise_error(/subvert! called/)
act = action_class.new(a, { remove_police: 1 })
b = Sector.new(fln_underground: 1, algerian_police: 2)
expect { act.subvert!(b, { remove_police: 2 }) }.to raise_error(/remove 3 police/)
b = Sector.new(fln_underground: 1, algerian_troops: 2)
act = action_class.new(a, { remove_police: 1 })
expect { act.subvert!(b, { remove_troops: 2 }) }.to raise_error(/remove 1 police/)
end
it 'cannot chain after replace_police' do
a = Sector.new(fln_underground: 1, algerian_police: 2)
b = Sector.new(fln_underground: 1, algerian_troops: 1)
act = action_class.new(a, { replace_police: 1 })
expect { act.subvert!(b, {}) }.to raise_error(/cannot subvert! after/)
act = action_class.new(a, { remove_police: 1 })
expect { act.subvert!(b, { replace_police: 1 }) }.to raise_error(/cannot subvert! with/)
end
end
describe 'Ambush' do
let(:action_class) { ColonialTwilight::Actions::FLN::Ambush }
it 'is applicable with underground FLN and GOV present' do
a = Sector.new(fln_underground: 1, gov_cubes: 1)
expect(action_class.applicable?(a)).to be true
end
end
describe 'OAS' do
let(:action_class) { ColonialTwilight::Actions::FLN::Oas }
it 'is applicable in populated space with no terror and not a country' do
a = Sector.new(pop: 1, terror: 0)
expect(action_class.applicable?(a)).to be true
end
it 'is not applicable if terror present' do
a = Sector.new(pop: 1, terror: 1)
expect(action_class.applicable?(a)).to be false
end
end
end
|