summaryrefslogtreecommitdiffstats
path: root/spec/fln_bot_rules_spec.rb
blob: 2d46f0bf5240e9c52230ebf5defcddce52db5c63 (plain)
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
# frozen_string_literal: true

require './lib/colonial_twilight/fln_rules'
require './lib/colonial_twilight/fln_bot_rules'
require './spec/mock_board'

class FLNRulesImpl
  include ColonialTwilight::FLNRules
  include ColonialTwilight::FLNBotRules
  attr_reader :board
  attr_writer :debug, :limited_op_only, :first_eligible, :will_be_next_first_eligible

  def initialize
    @debug = 0
    @board = Board.new
    @limited_op_only = true
    @first_eligible = true
    @will_be_next_first_eligible = true
  end

  def set(hash = {})
    board.sector.data = hash
    board.sector
  end

  def limited_op_only?
    @limited_op_only
  end

  def d6
    3
  end

  def first_eligible?
    @first_eligible
  end

  def will_be_next_first_eligible?
    @will_be_next_first_eligible
  end
end

describe ColonialTwilight::FLNBotRules do
  before do
    @rules = FLNRulesImpl.new
    @board = @rules.board
  end

  describe 'Debug' do
    it 'level 1' do
      @rules.debug = 1
      expect { @rules.dbg('msg', true) }.to output("  msg\n").to_stdout
    end

    it 'level 2' do
      @rules.debug = 2
      expect { @rules.dbg('msg', false) }.to output("  msg : NO\n").to_stdout
    end
  end

  describe 'Pass' do
    it 'pass? no resources' do
      expect(@rules.pass?).to be true
    end

    it 'pass? no resources but not op only' do
      @rules.limited_op_only = false
      expect(@rules.pass?).to be false
    end

    it 'pass? has resources' do
      @rules.board.fln_resources = 15
      expect(@rules.pass?).to be false
    end
  end

  describe 'Terror' do
    it 'terror1? 1 pop 2 underground' do
      @rules.set(pop: 1, fln_bases: 1, fln_underground: 2)
      expect(@rules.terror1?).to be true
    end

    it 'terror1? 1 pop 1 underground' do
      @rules.set(pop: 1, fln_bases: 1, fln_underground: 1)
      expect(@rules.terror1?).to be false
    end

    it 'terror1? 0 pop 1 underground' do
      @rules.set(pop: 0, fln_bases: 1, fln_underground: 1)
      expect(@rules.terror1?).to be true
    end

    it 'terror1? 0 pop 0 underground' do
      @rules.set(pop: 0, fln_bases: 1, fln_underground: 0)
      expect(@rules.terror1?).to be false
    end

    it 'terror2?' do
      expect(@rules.terror2?).to be false
    end

    it 'terror2? true' do
      @rules.first_eligible = false
      expect(@rules.terror2?).to be true
    end

    it 'terror2? true' do
      @rules.first_eligible = false
      @rules.will_be_next_first_eligible = false
      expect(@rules.terror2?).to be false
    end
  end

  describe 'Rally' do
    it 'rally1? false' do
      expect(@rules.rally1?).to be false
    end

    it 'rally1? may rally_1' do
      @rules.set(fln_active: 1, fln_underground: 2)
      expect(@rules.rally1?).to be true
    end

    it 'rally1? may rally_2' do
      @rules.set(fln_active: 2, fln_underground: 2)
      expect(@rules.rally1?).to be true
    end

    it 'rally1? may rally_1 but no bases' do
      @rules.set(fln_active: 1, fln_underground: 2)
      @board.available_fln_bases = 0
      expect(@rules.rally1?).to be false
    end

    it 'rally1? may rally_2 but no bases' do
      @rules.set(fln_active: 2, fln_underground: 2)
      @board.available_fln_bases = 0
      expect(@rules.rally1?).to be false
    end

    it 'rally2? enough fln at bases' do
      @rules.set(fln_bases: 2, fln_underground: 3)
      expect(@rules.rally2?).to be false
    end

    it 'rally2? false' do
      @rules.set(fln_bases: 2, fln_underground: 2)
      expect(@rules.rally2?).to be true
    end
  end

  describe 'Rally Specific' do
    it 'may_rally_1_in? not enough fln guerrillas' do
      a = Sector.new(fln_active: 1, fln_underground: 1)
      expect(@rules.may_rally_1_in?(a)).to be false
    end

    it 'may_rally_1_in? 3+ guerrillas' do
      a = Sector.new(fln_active: 1, fln_underground: 2)
      expect(@rules.may_rally_1_in?(a)).to be true
    end

    it 'may_rally_1_in? 3+ guerrillas no limited op' do
      a = Sector.new(fln_active: 1, fln_underground: 2)
      @rules.limited_op_only = false
      expect(@rules.may_rally_1_in?(a)).to be true
    end

    it 'may_rally_1_in? 3+ guerrillas but gov cubes' do
      a = Sector.new(fln_active: 1, fln_underground: 2, gov_cubes: 1)
      @rules.limited_op_only = false
      expect(@rules.may_rally_1_in?(a)).to be false
    end

    it 'may_rally_2_in? not enough fln guerrillas' do
      a = Sector.new(fln_active: 2, fln_underground: 1)
      expect(@rules.may_rally_2_in?(a)).to be false
    end

    it 'may_rally_2_in? 4+ guerrillas' do
      a = Sector.new(fln_active: 2, fln_underground: 2)
      expect(@rules.may_rally_2_in?(a)).to be true
    end

    it 'may_rally_3_in? no base' do
      a = Sector.new
      expect(@rules.may_rally_3_in?(a)).to be false
    end

    it 'may_rally_3_in? base and pop 0' do
      a = Sector.new(fln_bases: 1)
      expect(@rules.may_rally_3_in?(a)).to be true
    end

    it 'may_rally_3_in? base and pop 0 but has fln underground' do
      a = Sector.new(fln_bases: 1, fln_underground: 1)
      expect(@rules.may_rally_3_in?(a)).to be false
    end

    it 'may_rally_3_in? base and country but not independent' do
      a = Sector.new(fln_bases: 1, pop: 1, name: 'country', independent: false)
      expect(@rules.may_rally_3_in?(a)).to be false
    end

    it 'may_rally_3_in? base and country' do
      a = Sector.new(fln_bases: 1, pop: 1, name: 'country', independent: true)
      expect(@rules.may_rally_3_in?(a)).to be true
    end

    it 'may_rally_3_in? base and country but has fln underground' do
      a = Sector.new(fln_bases: 1, pop: 1, name: 'country', independent: true, fln_underground: 1)
      expect(@rules.may_rally_3_in?(a)).to be false
    end

    it 'may_rally_3_in? base and pop' do
      a = Sector.new(fln_bases: 1, pop: 1, fln_underground: 1)
      expect(@rules.may_rally_3_in?(a)).to be true
    end

    it 'may_rally_3_in? base and pop but too many fln underground ' do
      a = Sector.new(fln_bases: 1, pop: 1, fln_underground: 2)
      expect(@rules.may_rally_3_in?(a)).to be false
    end

    it 'rally_3_priority Algeria' do
      a = Sector.new(name: 'country')
      b = Sector.new
      expect(@rules.rally_3_priority([a, b])[0]).to be b
    end

    it 'rally_3_priority with GOV cubes' do
      a = Sector.new
      b = Sector.new(gov_cubes: 1)
      expect(@rules.rally_3_priority([a, b])[0]).to be b
    end

    it 'rally_3_priority pop 1+' do
      a = Sector.new(pop: 1)
      b = Sector.new(gov_cubes: 1)
      c = Sector.new(gov_cubes: 1, pop: 1)
      expect(@rules.rally_3_priority([a, b, c])[0]).to be c
    end

    it 'rally_3_priority least fln_underground' do
      a = Sector.new(pop: 1)
      b = Sector.new(gov_cubes: 1, pop: 1, fln_underground: 1)
      c = Sector.new(gov_cubes: 1, pop: 1)
      expect(@rules.rally_3_priority([a, b, c])[0]).to be c
    end

    it 'may_rally_5_in? city' do
      a = Sector.new(name: 'city', support: true)
      expect(@rules.may_rally_5_in?(a)).to be false
    end

    it 'may_rally_5_in? fln underground' do
      a = Sector.new(support: true, fln_underground: 1)
      expect(@rules.may_rally_5_in?(a)).to be false
    end

    it 'may_rally_5_in? no support' do
      a = Sector.new(support: false)
      expect(@rules.may_rally_5_in?(a)).to be false
    end

    it 'may_rally_5_in? good' do
      a = Sector.new(support: true)
      expect(@rules.may_rally_5_in?(a)).to be true
    end

    it 'rally_5_priority most pop' do
      a = Sector.new(pop: 1)
      b = Sector.new(pop: 2)
      expect(@rules.rally_5_priority([a, b])[0]).to be b
    end

    it 'may_rally_6_in? pop 1' do
      a = Sector.new(pop: 1)
      expect(@rules.may_rally_6_in?(a, false)).to be false
    end

    it 'may_rally_6_in? pop 2+ but no base, no control after' do
      a = Sector.new(pop: 2, gov_cubes: 1)
      @board.available_fln_underground = 1
      expect(@rules.may_rally_6_in?(a, false)).to be false
    end

    it 'may_rally_6_in? pop 2+ and base' do
      a = Sector.new(pop: 2, gov_cubes: 6, fln_bases: 1)
      expect(@rules.may_rally_6_in?(a, false)).to be true
    end

    it 'may_rally_6_in? pop 2+ and control' do
      a = Sector.new(pop: 2, gov_cubes: 1, fln_active: 1)
      @board.available_fln_underground = 1
      expect(@rules.may_rally_6_in?(a, false)).to be true
    end

    it 'may_rally_6_in? pop 2+ and control but oppose' do
      a = Sector.new(pop: 2, gov_cubes: 1, fln_active: 1, oppose: true)
      @board.available_fln_underground = 1
      expect(@rules.may_rally_6_in?(a, false)).to be false
    end

    it 'may_rally_6_in? pop 2+ and control but oppose but terror' do
      a = Sector.new(pop: 2, gov_cubes: 1, fln_active: 1, oppose: true, terror: 1)
      @board.available_fln_underground = 1
      expect(@rules.may_rally_6_in?(a, false)).to be true
    end

    it 'rally_6_priority population' do
      a = Sector.new(pop: 1)
      b = Sector.new(pop: 2)
      expect(@rules.rally_6_priority([a, b])[0]).to be b
    end

    it 'rally_6_priority min terror' do
      a = Sector.new(pop: 1, terror: 2)
      b = Sector.new(pop: 2, terror: 2)
      c = Sector.new(pop: 2, terror: 1)
      expect(@rules.rally_6_priority([a, b, c])[0]).to be c
    end

    it 'rally_6_priority support' do
      a = Sector.new(pop: 2, terror: 1, support: false)
      b = Sector.new(pop: 2, terror: 2, support: true)
      c = Sector.new(pop: 2, terror: 1, support: true)
      expect(@rules.rally_6_priority([a, b, c])[0]).to be c
    end

    it 'may_rally_7_in?' do
      a = Sector.new
      expect(@rules.may_rally_7_in?(a)).to be true
    end

    it 'may_rally_7_in? not in city at support' do
      a = Sector.new(name: 'city', support: true)
      expect(@rules.may_rally_7_in?(a)).to be false
    end

    it 'may_rally_7_in? not in not independent country' do
      a = Sector.new(name: 'country', independent: false)
      expect(@rules.may_rally_7_in?(a)).to be false
    end

    it 'rally_7_priority population' do
      a = Sector.new(pop: 1)
      b = Sector.new(pop: 1)
      c = Sector.new(pop: 2)
      expect(@rules.rally_7_priority([a, b, c])[0]).to be c
    end

    it 'rally_7_priority gain FLN control' do
      a = Sector.new(gov_cubes: 2)
      b = Sector.new(gov_cubes: 1, fln_active: 3)
      c = Sector.new(gov_cubes: 1, fln_active: 1)
      @board.available_fln_underground = 1
      expect(@rules.rally_7_priority([a, b, c])[0]).to be c
    end

    it 'rally_7_priority remove GOV control' do
      a = Sector.new(gov_cubes: 3)
      b = Sector.new(gov_cubes: 2)
      c = Sector.new(gov_cubes: 1)
      @board.available_fln_underground = 1
      expect(@rules.rally_7_priority([a, b, c])[0]).to be c
    end

    it 'rally_7_priority city?' do
      a = Sector.new
      b = Sector.new
      c = Sector.new(name: 'city')
      expect(@rules.rally_7_priority([a, b, c])[0]).to be c
    end

    it 'rally_7_priority least terror' do
      a = Sector.new
      b = Sector.new(name: 'city', terror: 2)
      c = Sector.new(name: 'city', terror: 1)
      expect(@rules.rally_7_priority([a, b, c])[0]).to be c
    end

    it 'may_rally_8_in? no fln guerrillas' do
      a = Sector.new
      expect(@rules.may_rally_8_in?(a)).to be false
    end

    it 'may_rally_8_in? fln guerrillas but base' do
      a = Sector.new(fln_active: 1, fln_bases: 1)
      expect(@rules.may_rally_8_in?(a)).to be false
    end

    it 'may_rally_8_in? fln guerrillas and 0 base' do
      a = Sector.new(fln_underground: 1)
      expect(@rules.may_rally_8_in?(a)).to be true
    end

    it 'rally_8_priority Algeria' do
      a = Sector.new(name: 'country')
      b = Sector.new
      expect(@rules.rally_8_priority([a, b])[0]).to be b
    end

    it 'rally_8_priority most guerrillas' do
      a = Sector.new
      b = Sector.new(fln_active: 1, fln_underground: 1)
      c = Sector.new(fln_active: 2, fln_underground: 1)
      expect(@rules.rally_8_priority([a, b, c])[0]).to be c
    end

    it 'rally_8_priority no cubes' do
      a = Sector.new
      b = Sector.new(fln_active: 1, fln_underground: 1, gov_cubes: 1)
      c = Sector.new(fln_active: 1, fln_underground: 1)
      expect(@rules.rally_8_priority([a, b, c])[0]).to be c
    end

    it 'may_rally_9_in? no control and no base' do
      a = Sector.new(terror: 2)
      expect(@rules.may_rally_9_in?(a)).to be false
    end

    it 'may_rally_9_in? has control but no terror and oppose' do
      a = Sector.new(fln_active: 1, oppose: true)
      expect(@rules.may_rally_9_in?(a)).to be false
    end

    it 'may_rally_9_in? has base but no terror and oppose' do
      a = Sector.new(fln_bases: 1, gov_cubes: 1, oppose: true)
      expect(@rules.may_rally_9_in?(a)).to be false
    end

    it 'may_rally_9_in? has control and terror' do
      a = Sector.new(fln_active: 1, terror: 1)
      expect(@rules.may_rally_9_in?(a)).to be true
    end

    it 'may_rally_9_in? has base and terror' do
      a = Sector.new(fln_bases: 1, gov_cubes: 1, terror: 1)
      expect(@rules.may_rally_9_in?(a)).to be true
    end

    it 'may_rally_9_in? has control and not oppose' do
      a = Sector.new(fln_active: 1, terror: 1)
      expect(@rules.may_rally_9_in?(a)).to be true
    end

    it 'may_rally_9_in? has base and not oppose' do
      a = Sector.new(fln_bases: 1, gov_cubes: 1, terror: 1)
      expect(@rules.may_rally_9_in?(a)).to be true
    end

    it 'rally_9_priority support' do
      a = Sector.new(terror: 1, oppose: true)
      b = Sector.new(terror: 3, support: true)
      c = Sector.new(terror: 2, support: true)
      expect(@rules.rally_9_priority([a, b, c], 3)[0]).to be c
    end

    it 'rally_9_priority neutral' do
      a = Sector.new(terror: 1, oppose: true)
      b = Sector.new(terror: 3, neutral: true)
      c = Sector.new(terror: 2, neutral: true)
      expect(@rules.rally_9_priority([a, b, c], 3)[0]).to be c
    end

    it 'rally_9_priority infinite resources' do
      a = Sector.new(terror: 1, oppose: true)
      b = Sector.new(terror: 3, support: true)
      c = Sector.new(terror: 2, support: true)
      expect(@rules.rally_9_priority([a, b, c], 0).size).to be 2
    end
  end

  describe 'Extort' do
    it 'may_extort_0_in?' do
      a = Sector.new
      expect(@rules.may_extort_0_in?(a)).to be false
    end

    it 'may_extort_0_in? pop' do
      a = Sector.new(pop: 1)
      expect(@rules.may_extort_0_in?(a)).to be false
    end

    it 'may_extort_0_in? pop and underground' do
      a = Sector.new(pop: 1, fln_underground: 1)
      expect(@rules.may_extort_0_in?(a)).to be true
    end

    it 'may_extort_0_in? pop and guerrillas but active' do
      a = Sector.new(pop: 1, fln_active: 1)
      expect(@rules.may_extort_0_in?(a)).to be false
    end

    it 'may_extort_0_in? pop and underground but no control' do
      a = Sector.new(pop: 1, fln_underground: 1, gov_cubes: 2)
      expect(@rules.may_extort_0_in?(a)).to be false
    end

    it 'may_extort_0_in? pop and underground but base' do
      a = Sector.new(pop: 1, fln_underground: 1, fln_bases: 1)
      expect(@rules.may_extort_0_in?(a)).to be false
    end

    it 'may_extort_0_in? pop, base and enough underground' do
      a = Sector.new(pop: 1, fln_underground: 2, fln_bases: 1, gov_cubes: 2)
      expect(@rules.may_extort_0_in?(a)).to be true
    end

    it 'extort_priority 2+' do
      a = Sector.new()
      b = Sector.new(fln_underground: 1)
      c = Sector.new(fln_underground: 2)
      expect(@rules.extort_priority([a, b, c])[0]).to be c
    end

    it 'extort_priority 3+ if fln bases and gov cubes' do
      a = Sector.new(fln_underground: 2, fln_bases: 1, gov_cubes: 1)
      b = Sector.new(fln_underground: 1, fln_bases: 1, gov_cubes: 1)
      c = Sector.new(fln_underground: 3, fln_bases: 1, gov_cubes: 1)
      expect(@rules.extort_priority([a, b, c])[0]).to be c
    end

    it 'extort_priority country' do
      a = Sector.new(fln_underground: 2, fln_bases: 1, gov_cubes: 1)
      b = Sector.new(fln_underground: 3, fln_bases: 1, gov_cubes: 1)
      c = Sector.new(name: 'country', fln_underground: 3, fln_bases: 1, gov_cubes: 1)
      expect(@rules.extort_priority([a, b, c])[0]).to be c
    end
  end

  describe 'Subvert' do
    it 'may_subvert_1_in?' do
      a = Sector.new
      expect(@rules.may_subvert_1_in?(a, 2)).to be false
    end

    it 'may_subvert_1_in?' do
      a = Sector.new(fln_underground: 1, algerian_police: 1)
      expect(@rules.may_subvert_1_in?(a, 2)).to be true
    end

    it 'may_subvert_1_in?' do
      a = Sector.new(fln_underground: 1, algerian_police: 3)
      expect(@rules.may_subvert_1_in?(a, 2)).to be false
    end

    it 'subvert_1_priority algerian police' do
      a = Sector.new(fln_underground: 1, algerian_police: 1)
      b = Sector.new(fln_underground: 1, algerian_police: 2)
      c = Sector.new(fln_underground: 1, algerian_police: 3)
      expect(@rules.subvert_1_priority([a, b, c])[0]).to be c
    end

    it 'may_subvert_2_in?' do
      a = Sector.new(fln_underground: 1)
      expect(@rules.may_subvert_2_in?(a)).to be false
    end

    it 'may_subvert_2_in?' do
      a = Sector.new(fln_underground: 1, algerian_police: 1)
      expect(@rules.may_subvert_2_in?(a)).to be true
    end
  end

  describe 'Terror' do
    it 'may_terror_1_in?' do
      a = Sector.new(pop: 1, fln_underground: 1, support: true)
      expect(@rules.may_terror_1_in?(a)).to be true
    end

    it 'may_terror_1_in? no pop' do
      a = Sector.new(fln_underground: 1, support: true)
      expect(@rules.may_terror_1_in?(a)).to be false
    end

    it 'may_terror_1_in? no support' do
      a = Sector.new(pop: 1, fln_underground: 1)
      expect(@rules.may_terror_1_in?(a)).to be false
    end

    it 'may_terror_1_in? no underground' do
      a = Sector.new(pop: 1, support: true)
      expect(@rules.may_terror_1_in?(a)).to be false
    end

    it 'may_terror_1_in? base and not enough underground' do
      a = Sector.new(pop: 1, fln_bases: 1, fln_underground: 1, support: true)
      expect(@rules.may_terror_1_in?(a)).to be false
    end

    it 'may_terror_1_in? base and enough underground' do
      a = Sector.new(pop: 1, fln_bases: 1, fln_underground: 2, support: true)
      expect(@rules.may_terror_1_in?(a)).to be true
    end

    it 'terror_1_priority most pop' do
      a = Sector.new(pop: 1)
      b = Sector.new(pop: 2)
      expect(@rules.terror_1_priority([a, b])[0]).to be b
    end

    it 'may_terro_2_in?' do
      a = Sector.new(pop: 1, fln_underground: 1, neutral: true, gov_bases: 1)
      expect(@rules.may_terror_2_in?(a)).to be true
    end

    it 'may_terro_2_in? default' do
      a = Sector.new(pop: 1, fln_underground: 1)
      expect(@rules.may_terror_2_in?(a)).to be false
    end

    it 'may_terro_2_in? is neutral' do
      a = Sector.new(pop: 1, fln_underground: 1, neutral: true)
      expect(@rules.may_terror_2_in?(a)).to be false
    end

    it 'may_terro_2_in? gov base' do
      a = Sector.new(pop: 1, fln_underground: 1, gov_bases: 1)
      expect(@rules.may_terror_2_in?(a)).to be false
    end

    it 'may_terro_2_in? neutral and gov base but terror' do
      a = Sector.new(pop: 1, fln_underground: 1, neutral: true, gov_bases: 1, terror: 1)
      expect(@rules.may_terror_2_in?(a)).to be false
    end

    it '_pacifiable no gov base' do
      a = Sector.new
      expect(@rules._pacifiable(a, false)).to be false
    end

    it '_pacifiable not country' do
      a = Sector.new(name: 'country', gov_bases: 1)
      expect(@rules._pacifiable(a, false)).to be false
    end

    it '_pacifiable not country and gov base' do
      a = Sector.new(gov_bases: 1)
      expect(@rules._pacifiable(a, false)).to be true
    end

    it '_pacifiable de Gaule country' do
      a = Sector.new(name: 'country', troops: 1, police: 1)
      expect(@rules._pacifiable(a, true)).to be false
    end

    it '_pacifiable de Gaule sector and troops and police and gov control' do
      a = Sector.new(troops: 1, french_police: 1)
      expect(@rules._pacifiable(a, true)).to be true
    end

    it '_pacifiable de Gaule no troops' do
      a = Sector.new(french_police: 1)
      expect(@rules._pacifiable(a, true)).to be false
    end

    it '_pacifiable de Gaule no police' do
      a = Sector.new(troops: 1)
      expect(@rules._pacifiable(a, true)).to be false
    end

    it '_pacifiable de Gaule no control' do
      a = Sector.new(troops: 1, french_police: 1, fln_underground: 2)
      expect(@rules._pacifiable(a, true)).to be false
    end
  end

  describe 'Attack' do
    it 'may attack 1' do
      a = Sector.new(gov_cubes: 1, fln_underground: 2, fln_active: 4)
      expect(@rules.may_attack_1_in?(a)).to be true
    end

    it 'may attack 1 but no gov' do
      a = Sector.new(fln_underground: 2, fln_active: 4)
      expect(@rules.may_attack_1_in?(a)).to be false
    end

    it 'may attack 1 but not enough fln' do
      a = Sector.new(gov_cubes: 1, fln_underground: 2, fln_active: 3)
      expect(@rules.may_attack_1_in?(a)).to be false
    end

    it 'may attack 1 but fln base' do
      a = Sector.new(gov_cubes: 1, fln_underground: 2, fln_active: 4, fln_bases: 1)
      expect(@rules.may_attack_1_in?(a)).to be false
    end

    it 'may attack 2' do
      a = Sector.new(gov_cubes: 1, fln_underground: 2, fln_active: 2)
      expect(@rules.may_attack_2_in?(a)).to be true
    end

    it 'may attack 2 but no gov' do
      a = Sector.new(fln_underground: 2, fln_active: 2)
      expect(@rules.may_attack_2_in?(a)).to be false
    end

    it 'may attack 2 but not enough fln' do
      a = Sector.new(gov_cubes: 1, fln_underground: 2, fln_active: 1)
      expect(@rules.may_attack_2_in?(a)).to be false
    end

    it 'may attack 2 but fln base' do
      a = Sector.new(gov_cubes: 1, fln_underground: 2, fln_active: 2, fln_bases: 1)
      expect(@rules.may_attack_2_in?(a)).to be false
    end

    it 'may ambush 1 in' do
      a = Sector.new(gov_cubes: 1, fln_underground: 1)
      expect(@rules.may_ambush_1_in?(a)).to be true
    end

    it 'may ambush 1 in but no underground' do
      a = Sector.new(gov_cubes: 1, fln_active: 1)
      expect(@rules.may_ambush_1_in?(a)).to be false
    end

    it 'may ambush 1 in but bases' do
      a = Sector.new(gov_cubes: 1, fln_underground: 1, fln_bases: 1)
      expect(@rules.may_ambush_1_in?(a)).to be false
    end

    it 'may ambush 1 in bases and enough guerillas' do
      a = Sector.new(gov_cubes: 1, fln_underground: 1, fln_active: 1, fln_bases: 1)
      expect(@rules.may_ambush_1_in?(a)).to be true
    end

    it 'attack priority at bases' do
      a = Sector.new(gov_bases: 0)
      b = Sector.new(gov_bases: 1)
      c = Sector.new(gov_bases: 2)
      expect(@rules.attack_priority([a, b, c])[0]).to be c
    end

    it 'attack priority french troops' do
      a = Sector.new(gov_bases: 2, algerian_troops: 6)
      b = Sector.new(gov_bases: 3, french_troops: 1)
      c = Sector.new(gov_bases: 3, french_troops: 2)
      expect(@rules.attack_priority([a, b, c])[0]).to be c
    end

    it 'attack priority french police' do
      a = Sector.new(gov_bases: 1, french_troops: 3, algerian_police: 6)
      b = Sector.new(gov_bases: 3, french_troops: 1, french_police: 1)
      c = Sector.new(gov_bases: 2, french_troops: 2, french_police: 2)
      expect(@rules.attack_priority([a, b, c])[0]).to be c
    end

    it 'attack priority gov most pieces, gov base' do
      a = Sector.new(gov_bases: 2, french_troops: 2, french_police: 2)
      b = Sector.new(gov_bases: 2, french_troops: 2, french_police: 2)
      c = Sector.new(gov_bases: 3, french_troops: 2, french_police: 2)
      expect(@rules.attack_priority([a, b, c])[0]).to be c
    end

    it 'attack priority gov most pieces, french troops' do
      a = Sector.new(gov_bases: 2, french_troops: 2, french_police: 2)
      b = Sector.new(gov_bases: 2, french_troops: 2, french_police: 2)
      c = Sector.new(gov_bases: 2, french_troops: 3, french_police: 2)
      expect(@rules.attack_priority([a, b, c])[0]).to be c
    end

    it 'attack priority gov most pieces, french police' do
      a = Sector.new(gov_bases: 2, french_troops: 2, french_police: 2)
      b = Sector.new(gov_bases: 2, french_troops: 2, french_police: 2)
      c = Sector.new(gov_bases: 2, french_troops: 2, french_police: 3)
      expect(@rules.attack_priority([a, b, c])[0]).to be c
    end
  end

  describe '8.1.2 Procedure Guidelines' do
    it 'placeable_guerrillas?' do
      expect(@rules.placeable_guerrillas?).to be false
    end

    it 'placeable_guerrillas? available' do
      @board.available_fln_underground = 1
      expect(@rules.placeable_guerrillas?).to be true
    end

    it 'placeable_guerrillas? active on map' do
      @board.spaces << Sector.new(name: 'a', fln_active: 1)
      expect(@rules.placeable_guerrillas?).to be true
    end

    it 'placeable_guerrillas' do
      expect(@rules.placeable_guerrillas).to eq 0
    end

    it 'placeable_guerrillas available' do
      @board.available_fln_underground = 1
      expect(@rules.placeable_guerrillas).to eq 1
    end

    it 'placeable_guerrillas active on map' do
      @board.spaces << Sector.new(name: 'a', fln_active: 1)
      expect(@rules.placeable_guerrillas).to eq 1
    end

    it 'available_fln_bases?' do
      @board.available_fln_bases = 0
      expect(@rules.available_fln_bases?).to be false
    end

    it 'available_fln_bases?' do
      @board.available_fln_bases = 1
      expect(@rules.available_fln_bases?).to be true
    end

    it 'may_add_base_in?' do
      a = Sector.new(fln_active: 3)
      expect(@rules.may_add_base_in?(a)).to be true
    end

    it 'may_add_base_in? not enough fln' do
      a = Sector.new(fln_active: 2)
      expect(@rules.may_add_base_in?(a)).to be false
    end

    it 'may_add_base_in? but has base' do
      a = Sector.new(fln_bases: 1, fln_active: 3)
      expect(@rules.may_add_base_in?(a)).to be false
    end

    it 'may_add_base_in? country ' do
      a = Sector.new(name: 'country', fln_bases: 2, fln_active: 3)
      expect(@rules.may_add_base_in?(a)).to be true
    end

    it 'may_add_base_in? country but limit' do
      a = Sector.new(name: 'country', fln_bases: 3, fln_active: 3)
      expect(@rules.may_add_base_in?(a)).to be false
    end

    it 'max_placable_guerrillas_in? 1' do
      a = Sector.new(pop: 2)
      expect(@rules.max_placable_guerrillas_in?(a)).to eq(1)
    end

    it 'max_placable_guerrillas_in? pop + base' do
      a = Sector.new(pop: 2, fln_bases: 1)
      expect(@rules.max_placable_guerrillas_in?(a)).to eq(3)
    end

    it 'max_placable_guerrillas_in? max pop + 1' do
      a = Sector.new(pop: 2, fln_bases: 1, fln_active: 1, fln_underground: 1)
      expect(@rules.max_placable_guerrillas_in?(a)).to eq(1)
    end

    it 'place_guerrillas_in' do
      a = Sector.new(pop: 2, fln_bases: 1)
      @board.available_fln_underground = 1
      @board.spaces << Sector.new(name: 'a', fln_bases: 1, fln_active: 2, fln_underground: 1)
      h = @rules.place_guerrillas_in(a)
      expect(@rules.max_placable_guerrillas_in?(a)).to eq(3)
      expect(h[:available]).to eq(1)
      expect(h[@board.spaces[0]]).to eq(1)
    end

    it 'place_guerrillas_in' do
      a = Sector.new(pop: 2, fln_bases: 1)
      @board.available_fln_underground = 0
      h = @rules.place_guerrillas_in(a)
      expect(@rules.max_placable_guerrillas_in?(a)).to eq(3)
      expect(h[:available]).to be nil
      expect(h.empty?).to be true
    end

    it '_removable_guerrillas active' do
      a = Sector.new(fln_active: 2, fln_underground: 3)
      expect(@rules._removable_guerrillas(a)).to eq(2)
    end

    it '_removable_guerrillas leave 2 at support' do
      a = Sector.new(support: true, fln_active: 3)
      expect(@rules._removable_guerrillas(a)).to eq(1)
    end

    it '_removable guerrillas leave 2 at bases' do
      a = Sector.new(fln_bases: 1, fln_active: 3, fln_underground: 1)
      expect(@rules._removable_guerrillas(a)).to eq(2)
    end

    it 'place_guerrillas_priority support' do
      a = Sector.new(support: false)
      b = Sector.new(support: false)
      c = Sector.new(support: true)
      expect(@rules.place_guerrillas_priority([a, b, c])[0]).to be c
    end

    it 'place_guerrillas_priority support and fln_active' do
      a = Sector.new(support: false)
      b = Sector.new(support: true)
      c = Sector.new(support: true, fln_active: 1)
      expect(@rules.place_guerrillas_priority([a, b, c])[0]).to be c
    end

    it '_remove_guerrillas_priority none' do
      a = Sector.new
      b = Sector.new
      expect(@rules._remove_guerrillas_priority([a, b], {}).empty?).to be true
    end

    it '_remove_guerrillas_priority most guerrillas' do
      a = Sector.new(fln_active: 2, fln_underground: 1)
      b = Sector.new(fln_active: 1, fln_underground: 2)
      c = Sector.new(fln_active: 2, fln_underground: 2)
      d = Sector.new(fln_active: 3, fln_underground: 2)
      expect(@rules._remove_guerrillas_priority([a, b, c, d], { d => true })[0]).to be c
    end

    it 'pick guerrillas from most guerrillas' do
      @rules.board.spaces << Sector.new(fln_active: 2, fln_underground: 1)
      @rules.board.spaces << (b = Sector.new(fln_active: 2, fln_underground: 2))
      @rules.board.spaces << Sector.new(fln_active: 1, fln_underground: 2)
      expect(@rules.pick_guerrillas_from(@rules.board)).to be b
    end

    it 'remove_from all' do
      a = Sector.new(fln_active: 2, fln_underground: 1, fln_bases: 1)
      h = @rules.remove_from(a, 6)
      expect(h[:fln_underground]).to be 1
      expect(h[:fln_active]).to be 2
      expect(h[:fln_bases]).to be 1
    end

    it 'remove_from a few' do
      a = Sector.new(fln_active: 1, fln_underground: 1)
      h = @rules.remove_from(a, 2)
      expect(h[:fln_underground]).to be 1
      expect(h[:fln_active]).to be 1
      expect(h[:fln_bases]).to be 0
    end
  end
end