-
Notifications
You must be signed in to change notification settings - Fork 11
/
ai_lou.js
3210 lines (2973 loc) · 129 KB
/
ai_lou.js
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
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ailou16.js
TM AI Ver 16 2022 October Corrections to RiverWalker locations and Orange factions
Copyright (C) 2013-2016 by Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
//Lou's AI controller.
var AILou = function(level) {
this.scoreActionValues = {};
this.restrictions = clone(defaultRestrictions);
AILou.ail = level; //processing level (TODO: danger: global variable instead of class field. making TMAI support players with different AIs would not be supported because of this! use this.ail here and make functions prototype to fix this)
};
inherit(AILou, Actor);
//LOU include specific advice on preferred bonus and favor tiles
AILou.xfaction = 0;
AILou.ybonus = 0;
AILou.yfavor = 0;
AILou.info = false; //information please, print extra processing data in output file
var townSelected = []; //avoid previous action town tile
var upgradeSA = -1; //avoid both FAV6tw and upgradeSA during same action
var letters = ['A','B','C','D','E','F','G','H','I'];
var numbers = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20'];
function getRoundTileP1() {
if(state.round < 6) {
var roundP1 = state.round + 1;
return game.roundtiles[roundP1];
}
else return 0;
}
function getRoundTileP2() {
if(state.round < 5) {
var roundP2 = state.round + 2;
return game.roundtiles[roundP2];
}
else return 0;
}
AILou.powerToCoin = function(actions,coin) {
var action1C = new Action(A_CONVERT_1PW_1C);
for(var i = 0; i < coin; i++) {
actions.push(action1C);
}
};
//LOU function to convert power (usually to coins) to avoid power overflow
//LOU Check for power income and compare against bowls
AILou.convertPower = function(playerIndex, coin, actions, bonPower) {
//var restrictions = clone(defaultRestrictions);
//var restrictions = {w_cost: 0.33, p_cost: 1, pw_cost: 0.16, burn_cost: 1, max_burn: 6 };
//var actions = getPossibleActions(player, restrictions);
var player = game.players[playerIndex];
var bowl2 = player.pw2;
var powerUse = bowl2;
var takePower = 0;
// Check for no ability to get power
if (player.pw0 + player.pw1 == 0) {
switch(bowl2) {
case 0: break;
case 1: AILou.powerToCoin(actions, powerUse);
coin += powerUse;
break;
case 2: AILou.powerToCoin(actions, powerUse);
coin += powerUse;
break;
case 3: if (player.getFaction().canTakeAction(player, A_POWER_1P, game)) {
var action2 = new Action(A_POWER_1P);
takePower++;
actions.push(action2);
break;
} else {
AILou.powerToCoin(actions, powerUse);
coin += powerUse;
break;
}
case 4: if (player.getFaction().canTakeAction(player, A_POWER_7C, game)) {
var action2 = new Action(A_POWER_7C);
takePower++;
actions.push(action2);
break;
} else if (player.getFaction().canTakeAction(player, A_POWER_2W, game)) {
var action2 = new Action(A_POWER_2W);
takePower++;
actions.push(action2);
break;
} else {
AILou.powerToCoin(actions, powerUse);
coin += powerUse;
break;
}
case 5: AILou.powerToCoin(actions, 1);
coin += 1;
break;
case 6: break;
case 7:
default: AILou.powerToCoin(actions, 1);
coin += 1;
}
}
//Check powerIncome greater than can be used
//INCOME = { c: player.c, w: player.w, p: player.p, pw: [player.pw(0,1,2)], vp: player.vp
//LOU use all power action up even if one left over
if (state.round < 6) {
var income = getIncome(player, false, state.round); //from rules.js, false = no bonus tile
income[3] += bonPower; //include power from new bonus tile
var powerSurplus = income[3] - (coin*2 + player.pw0*2 + player.pw1);
var powerLeft = bowl2 - coin;
if (powerSurplus > 0 && powerLeft > 0) {
var powerOver = Math.min(Math.ceil(powerSurplus/2), powerLeft);
AILou.powerToCoin(actions, powerOver);
coin += powerOver;
}
if(AILou.info) addLog('CONVERT: convertPower for EXECUTE/PASS action = '
+ income + ' power in bowl2 ' + powerLeft + ' extraPower ' + powerSurplus);
}
var result = [takePower, coin, actions];
return result;
};
//given an array of items and an array of corresponding scores, returns the index of the item with best score.
//if the best score is shared between multiple items, a random one of those is chosen so that the AI is not predictable
//used for choosing actions, bonus tiles, favor tiles, town tiles, choosing extra dig locations, etc.....
//distributerandom:
//-if false, picks only the one with best score (randomizing if there are ties).
//-if true, every single item has a chance, the scores are the probability distribution function.
AILou.pickWithBestScore = function(items, scores, distributerandom) {
if(distributerandom) {
var sum = 0;
for(var i = 0; i < scores.length; i++) sum += scores[i];
// Make it work if all scores are 0
if(sum <= 0) {
sum = scores.length;
if (sum <= 0) sum = 1;
scores = [];
for(var j = 0; j < sum; j++) scores[j] = 1;
}
var r = Math.random() * sum;
var count = 0;
for(var i = 0; i < scores.length; i++) {
count += scores[i];
if(r < count) return i;
}
return items.length - 1;
} else {
var besti = 0;
var bestscore = -999999;
for(var i = 0; i < items.length; i++) {
if(scores[i] > bestscore) {
bestscore = scores[i];
besti = i;
}
}
var same = [];
for(var i = 0; i < items.length; i++) {
if(scores[i] == bestscore) {
same.push(i);
}
}
var s = randomIndex(same);
return same[s];
}
};
/*
Debuggen AI scoring in de chrome console:
var actions = getPossibleActions(game.players[1], defaultRestrictions);
var scores = [];
for(var j = 0; j < actions.length; j++) {
scores.push(game.players[1].actor.scoreActionAI_(game.players[1], actions[j], 0));
}
for(var i = 0; i < actions.length; i++) console.log(actionsToString(actions[i]) + ' ' + scores[i]);
*/
AILou.prototype.doAction = function(playerIndex, callback) {
var player = game.players[playerIndex];
this.updateScoreActionValues_(player, state.round);
var actions = getPossibleActions(player, this.restrictions);
//LOU change possible actions here to avoid changing scores in strategy.js
//TODO: support chaos magicians double action
var chosen = 0;
var scores = [];
for(var j = 0; j < actions.length; j++) {
scores.push(this.scoreActionAI_(player, actions[j], 0));
}
//handy for chrome console debugging:
//if(state.round < 3) {
// console.log(' round= ' + state.round + ': ' + (player.faction+1) + ': ' + actions.length);
// for(var i = 0; i < actions.length; i++) console.log(actionsToString(actions[i]) + ':' + scores[i]);
//}
var besti = AILou.pickWithBestScore(actions, scores, false);
if(scores[besti] > 0) {
chosen = actions[besti];
}
AILou.xfaction = player.faction + 1;
var favtown6 = -1;
townSelected = []
upgradeSA = -1; // used to avoid selection of FAV6TW
var cantPass = 0;
if(!chosen) {
//LOU this is where pass option selected, convert power before pass
twoTown = 0;
var actionPass = new Action(A_PASS);
if(state.round != 6) actionPass.bontile = this.getPreferredBonusTile_(player);
var actionCoin = [];
var coin = 0;
var bonPower = 0;
if(actionPass.bontile == T_BON_3PW_SHIP ||
actionPass.bontile == T_BON_3PW_1W ||
actionPass.bontile == T_BON_PASSSHIPVP_3PW) bonPower = 3;
var result = AILou.convertPower(playerIndex, coin, actionCoin, bonPower);
cantPass = result[0];
coin = result[1];
actionCoin = result[2];
if (cantPass > 0) {
chosen = actionCoin;
}
else if (coin == 0) {
chosen = [actionPass];
}
else if (coin > 0) {
actionCoin.push(actionPass);
chosen = actionCoin;
}
}
// some chosen action taken, find selected Favor or Town
else {
for(var i = 0; i < chosen.length; i++) {
for(var j = 0; j < chosen[i].favtiles.length; j++) {
if (chosen[i].twtiles.length > 0) upgradeSA = 1;
var tiles = getPossibleFavorTiles(player, chosen[i].favtiles);
chosen[i].favtiles[j] = this.getPreferredFavorTile_(player, tiles);
if (chosen[i].favtiles[j] == T_FAV_2F_6TW) favtown6 = i;
}
//LOU10 when FAV6TW selected by TE, examine for possible towns, avoid selected by SA
if (favtown6 >= 0) {
//from rules.js -- var numtw = actionCreatesTown(player, chosen, null);
//calculateTownClusters();
var town6 = getPlayerTownSize(player.woodcolor, townclusters, 6);
chosen[i].twtiles.length += town6.length;
}
for(var j = 0; j < chosen[i].twtiles.length; j++) {
var tiles = getPossibleTownTiles(player, chosen[i].twtiles);
chosen[i].twtiles[j] = this.getPreferredTownTile_(player, tiles);
townSelected.push(chosen[i].twtiles[j]);
updateWToPConversionAfterDarklingsSHTownTile(player, chosen);
}
}
}
//LOU this is where the chosen action 'place bridge' and 'get favor6tw' previously fails.
//LOU this is where favor6tw fails when making a town. Error: too few town tiles chosen (fixed)
//LOU10 Error: this town tile is no longer available (fixed, two same town tiles no longer chosen by action)
//LOU10 Error: no town tile chosen , Error: town tile chosen injustly (these are not errors)
var error = callback(playerIndex, chosen);
if(error != '') {
addLog('=============================================================');
addLog('ERROR: AI tried invalid EXECUTE/PASS action. Error: ' + error);
//instead, pass.
var action = new Action(A_PASS);
if(state.round != 6) action.bontile = this.getPreferredBonusTile_(player);
callback(playerIndex, [action]);
}
};
AILou.prototype.updateScoreActionValues_ = function(player, roundnum) {
//TODO: different score for consume and produce resource? e.g. I want to make darklings priests worth a lot for getting, but not worth a lot for spending so that they'll actually use them
this.scoreActionValues = {
vp: 1,
c: 0.33,
w: 1,
p: 1.5,
pw: 0.166,
shipping: 1.5,
digging: 1,
b_d: 6,
b_tp: 5,
b_te: 5.5,
b_sh: 6,
b_sa: 6,
b_prefer: 0, //this is not used in ai
t_fav: 1,
t_tw: 10, //TODO: if bridge forms town, but both parts were already 6 power or so, give PENALTY for that, because that ruins two towns for just one!
burn: -0.166,
maxburn: 6,
bridge: 0,
conbridge: 0, //ENGINEER bridge
forbridge: 0, //ENGINEER bridge
dig: 0.1, //it must have a positive value but less than the resource cost, so that for e.g. sandstorm it appreciates further dig distances more
cultspade: 1,
cult: [[1,1,1,1],[2,2,2,2],[3,3,3,3]],
p_gone: player.pp < 3 ? -5 : 0,
existingtown: -2,
towardstown: 5,
interacts: 1,
networkcon: state.fireice ? 4 : 2, //network connectivity value in VP per build
outpostcon: 2,
shtosacon: 4,
distancon: 3,
settlecon: 4,
shift: 0, //SHAPESHIFTERS power3 or 5
shift2: 0, //SHAPESHIFTERS token3 or 5
specific: {},
};
var s = this.scoreActionValues;
//CULT track evaluation
if (roundnum <= 4) {
for(var i = 1; i <= 3; i++) {
for(var j = C_F; j <= C_A; j++) {
s.cult[i - 1][j] = this.scoreCultTrackVP_(player, j, i, false) / (5 - i);
//divided because overall a single cult track move is not worth the whole VP
}
}
//entirely number of VP gain (ignores round 5 bonus)
} else if (roundnum > 4) {
for(var numk = 1; numk <= 3; numk++) {
for(var j = C_F; j <= C_A; j++) {
var pcult = [];
for(var i = 0; i < game.players.length; i++) pcult[i] = game.players[i].cult[j];
var fromcultvp = getDistributedPoints(player.index, pcult, [8,4,2], 1);
pcult[player.index] += numk;
var tocultvp = getDistributedPoints(player.index, pcult, [8,4,2], 1);
var vpgain = (tocultvp - fromcultvp);
s.cult[numk - 1][j] = vpgain;
}
}
}
//make the AI's go for the power actions more aggressively
s.specific[A_POWER_1P] = roundnum < 6 ? 2 : 3;
s.specific[A_POWER_2W] = player.w < 4 ? 5 : 0;
s.specific[A_POWER_7C] = roundnum > 1 ? 5 : 0;
s.specific[A_POWER_SPADE] = 5;
s.specific[A_POWER_2SPADE] = 6;
s.t_fav = player.favortiles.length > 3 ? 0 : 1;
//get TOWN count and favor6TW available
var towncount = 0;
var favor6TW = 0;
for(var i = 0; i < 4; i++) if(player.towntiles[i] != undefined) towncount++;
var tiles = getPossibleFavorTiles(player, {});
for(var i = 0; i < tiles.length; i++) {
if (tiles[i] == T_FAV_2F_6TW) favor6TW = 1;
}
// Round specific
var FINALRESVAL = player.faction == F_ALCHEMISTS ? 0.5 : 0.33;
if(roundnum < 3) {
s.vp = 0.5;
s.c = 0.5;
s.w = 1;
s.p = 1.5;
s.pw = 0.5;
} else if(roundnum != 6) {
s.vp = 1;
s.c = FINALRESVAL;
s.w = 0.5;
s.p = 1;
s.pw = 0.5;
s.b_d = 4;
s.b_tp = 4;
s.b_te = 4.5;
s.b_sh = 4;
s.b_sa = 4;
} else /*final round*/{
s.vp = 1;
s.c = FINALRESVAL;
s.w = FINALRESVAL;
s.p = FINALRESVAL;
s.pw = 0.166;
s.b_d = 2;
s.b_tp = 0;
s.b_te = 0;
s.b_sh = 0;
s.b_sa = 0;
s.shipping = 3;
}
//reduce coin value so not too many (avoid for NOMADS, DARK and BLUE)
if(roundnum > 3 && player.c > 8 && (player.c > (2.5 * player.w))) s.c /= 2;
if(roundnum > 2 && player.c > 12 && (player.c > (3 * player.w))) {
s.c /= 4;
s.specific[A_POWER_7C] = -5;
s.specific[A_POWER_2W] += 2;
s.specific[A_POWER_1P] += 1;
}
var sanctuarytwiddle = 2;
//The AIs are not building sanctuaries.... let's add some score
//LOU SA seem to be built prematurely, only add score in round 4 or greater.
if(roundnum > 3) s.b_sa += sanctuarytwiddle;
if(AILou.ail < 2 && game.finalscoring == 2 && roundnum < 5) s.b_sa = 0;
if(AILou.ail >= 2 && game.finalscoring == 2 && roundnum < 6) s.b_sa = 0;
//LOU for settlements, shipping is better for expansion
if(game.finalscoring == 4) s.shipping += 1;
// make SH essential, except for the given power actions
var makeSHEssential = function(pow_7c, pow_2w, pow_dig1, pow_dig2) {
if(built_sh(player) == 0) {
if(built_tp(player) == 0) s.b_tp += 50;
s.b_sh += 50;
// But it should still do these first
if(pow_7c > 0) s.specific[A_POWER_7C] = 20 + pow_7c;
if(pow_2w > 0) s.specific[A_POWER_2W] = 20 + pow_2w;
if(pow_dig1 > 0) s.specific[A_POWER_SPADE] = 20 + pow_dig1;
if(pow_dig2 > 0) s.specific[A_POWER_2SPADE] = 20 + pow_dig2;
}
};
// make the num_temple (can be 0,1,2,3), except for the given power actions
var makeTemple = function(num_temple, pow_7c, pow_2w, pow_dig1, pow_dig2) {
if(built_te(player) == num_temple-1) {
if(built_tp(player) == 0) s.b_tp += 10;
s.b_te += 10;
// But it should still do these first
if(pow_7c > 0) s.specific[A_POWER_7C] = player.c > 10 ? 4 : 12 + pow_7c;
if(pow_2w > 0) s.specific[A_POWER_2W] = 10 + pow_2w;
if(pow_dig1 > 0) s.specific[A_POWER_SPADE] = 10 + pow_dig1;
if(pow_dig2 > 0) s.specific[A_POWER_2SPADE] = 10 + pow_dig2;
}
};
// make the num_ship (can be 1,2,3), except for the given power actions
var makeShipping = function(num_ship, pow_7c, pow_2w, pow_dig1, pow_dig2) {
if(player.shipping == num_ship-1) {
s.shipping += 10;
// But it should still do these first
if(pow_7c > 0) s.specific[A_POWER_7C] = player.c > 10 ? 4 : 12 + pow_7c;
if(pow_2w > 0) s.specific[A_POWER_2W] = 12 + pow_2w;
if(pow_dig1 > 0) s.specific[A_POWER_SPADE] = 14 + pow_dig1;
if(pow_dig2 > 0) s.specific[A_POWER_2SPADE] = 14 + pow_dig2;
}
};
//no resources given after this round
if (roundnum == 6) {
//modify favor selection so build temple for last round gets cult+3 favor
//LOU12 sometimes no temple is built unless value is greater than residual of 2.33
s.b_te += 4;
if(built_tp(player) == 0) s.b_tp += 3;
//add value for dwelling as an outpost
if(game.finalscoring == 1) s.b_d += 2;
//select SH and SA to give SH_SA distance bonus in selection
if(game.finalscoring == 2 && built_sa(player) > 0) s.b_sh += 6;
if(game.finalscoring == 2 && built_sh(player) > 0) s.b_sa += 5;
}
//Faction specific
AILou.xfaction = player.faction + 1;
if(player.faction == F_CHAOS) {
s.b_tp += 4;
s.b_sh -= 3;
s.b_te += 2;
makeTemple(1,0,0,0,0);
if (roundnum <= 2) {
s.b_tp += 50;
s.specific[A_POWER_7C] = -50;
s.specific[A_POWER_2W] = -50;
}
s.specific[A_POWER_1P] = 0;
if(roundnum > 2) makeTemple(2,0,0,4,3);
if(player.shipping == 0) s.shipping += 5;
}
if(player.faction == F_GIANTS) {
makeSHEssential(5, 10, 0, player.w > 6 ? 15:0);
if(roundnum > 3) makeTemple (1,10,5,0,5);
if(roundnum > 4) makeShipping(1,0,0,0,0);
}
// build TE (70%)
if(player.faction == F_FAKIRS) {
// Get temple early for priest income
makeTemple (1,10,10,15,20);
if(built_sh(player)) s.digging = 0; //they should go to non-dig places instead
// There is nothing for stronghold here because quite frankly it is expensive and not that good
s.b_sh = 0;
}
// either SH first (68%) or TE first
if(player.faction == F_NOMADS) {
if(player.bonustile == T_BON_PASSSHSAVP_2W || player.bonustile == T_BON_PASSDVP_2C
|| player.bonustile == T_BON_SPADE_2C || player.bonustile == T_BON_6C) {
makeSHEssential(0,0,0,0);
if(roundnum > 2) makeTemple(1,10,player.w > 6 ? 0:5,player.w > 6 ? 10:0, player.w > 6 ? 10:0);
}
else {
makeTemple(1,10,player.w > 6 ? 0:5,player.w > 6 ? 5:0, player.w > 6 ? 5:0);
if(roundnum > 2) makeSHEssential(10, player.w > 6 ? 0:5, player.w > 7 ? 5:0, player.w > 7 ? 5:0);
}
if(roundnum > 4) makeShipping(1,0,0,0,0)
if(player.pw2 >= 4) s.specific[A_POWER_7C] = player.c < 9 ? 12 : 6;
if(roundnum > 4 && (player.pw0 + player.pw1) <= 1) {
s.specific[A_POWER_1P] = 8;
if(player.c > 2*player.w) {
s.specific[A_POWER_2W] = 10;
} else {
if (player.w < 7) s.specific[A_POWER_2W] = 10;
s.specific[A_POWER_7C] = 14;
}
}
}
//look for spade>>2 in round 4
if(player.faction == F_HALFLINGS) {
s.digging = 20;
s.b_sh = built_te(player) > 0 ? 6 : 0;
if(roundnum < 6) s.b_d += 2;
// Do get some dwellings first
if(built_d(player) > 2) makeTemple (1,0,0,0,0);
if(roundnum < 3 && player.p == 0) s.specific[A_POWER_1P] += 10;
if(roundnum > 4) makeShipping(1,0,0,0,0);
}
//build TE (72%)
if(player.faction == F_CULTISTS) {
if(roundnum < 5) s.b_sh = 0; //don't waste resources on the SH
else s.b_sh = 7;
s.interacts += 2;
if(roundnum > 1) makeTemple (1,0,0,0,0);
if(roundnum > 4) makeShipping(1,0,0,0,0);
}
if(player.faction == F_ALCHEMISTS) {
if(roundnum < 2) {
makeSHEssential(0, 0, 0, 0);
s.specific[A_POWER_SPADE] = 10;
s.specific[A_POWER_2SPADE] = 20;
}
makeSHEssential(5, 10, 0, player.w > 4 ? 15 : 0);
if(roundnum < 6) s.b_d += 2; //because alchemists will be low on workers
if(roundnum > 4) makeShipping(1,0,0,0,0);
s.specific[A_POWER_7C] = 0; //alchemists can get coin from VP
}
if(player.faction == F_DARKLINGS) {
s.p += 2;
s.dig += 2; //otherwise they'll refuse to use the priests for the digging...
s.b_sh = (player.w >= 7 && player.c >= 6) ? 10 : -5;
//only build SH if can convert 3w to 3p and must not burn too much manna (coin from 4 to 6)
if(roundnum < 6) s.b_te += 5; //get more priests for digging
//SA here produces two priests, so is good before round 6
if(AILou.ail > 1 && (roundnum == 4 || roundnum == 5)) {
s.b_sa += 3;
if(built_te(player) > 0) s.b_te -= 2;
}
if(roundnum > 4) makeShipping(1,0,0,0,0);
}
//build TE (63%); defer town?
if(player.faction == F_MERMAIDS) {
if (roundnum >= 2) makeTemple (1,0,0,3,9);
if(roundnum < 6) s.b_te += 5;
if(roundnum < 6) s.b_d += 10;
if (player.pw2 >= 4) s.specific[A_POWER_7C] = player.c < 9 ? 12:6;
s.bridge = -50; // rarely build bridges
s.forbridge = -50;
if(game.finalscoring == 2) s.b_sh += 4;
//increase shipping for shipVP bonus
s.shipping += player.shipping;
if (player.bonustile[T_BON_PASSSHIPVP_3PW] || game.bonustiles[T_BON_PASSSHIPVP_3PW]) {
if(player.shipping < 3) s.shipping += 3;
if(player.shipping >= 3 && roundnum > 4) s.shipping += 6;
}
if (player.shipping == 5) s.shipping = 0;
}
//SH gives free TP per round
if(player.faction == F_SWARMLINGS) {
if(roundnum > 1) makeSHEssential(10, 10, 0, player.w > 6 ? 15:0);
//only in round 2 because I think early SH for swarmlings results in too few dwellings ==> no worker income
//all their buildings must have increased score, or they'll refuse to spend resources on them
if(roundnum < 6) {
s.b_d++;
s.b_tp++;
s.b_te++;
s.b_sh++;
s.b_sa++;
}
if(roundnum > 2) makeTemple(1,0,0,0,0);
//SA here produces two priests, so is good before round 6
if(AILou.ail > 1 && (roundnum == 4 || roundnum == 5)) {
s.b_sa += 3;
if(built_te(player) > 0) s.b_te -= 2;
}
if(roundnum > 4) makeShipping(1,0,0,0,0);
}
// most SH start (72%) with 3D, but TE does better
if(player.faction == F_AUREN) {
if(roundnum >= 4) s.b_sh += 5;
if(roundnum > 4) makeShipping(1,0,0,0,0);
s.specific[A_POWER_7C] -= 3;
}
//build SH (50%) soon LOU15 change priority to temple and cult track
if(player.faction == F_WITCHES) {
if(roundnum >= 1) makeTemple(1,0,0,0,0);
else if(roundnum >= 3) {
if(game.finalscoring == 2 && built_sh(player) == 0) {
if(built_d(player) >= 2 && built_tp(player) == 0) s.b_tp += 5;
s.b_sh += 5;
}
else if(game.finalscoring == 3) {
s.b_sh += 2;
if(built_d(player) >= 2 && built_tp(player) == 0) s.b_tp += 2;
}
}
//LOU13 probability of anolther TE too small
if(built_sh(player) == 1 && built_te(player) == 0) s.b_te += roundnum+0.5;
s.t_tw += 5; //get extra 5VP for making town
s.bridge -= 2; //avoid unneeded bridge from E9-D11 in F&I World
if(roundnum >= 3 && player.bonustile == T_BON_3PW_SHIP) makeShipping(1,0,0,0,0);
if(roundnum >= 4 && game.finalcoring != 2) makeTemple(2,0,0,0,0);
}
//repairs needed; build TE (75%) two TE to get the 5PW; ENG_BRIDGE fix, not ship
if(player.faction == F_ENGINEERS) {
s.w += 0.5; //do NOT make this number any higher. Setting it to += 1 makes engineers build nothing anymore...
if(roundnum >= 5) s.conbridge = 6;
s.forbridge = 0;
s.shipping -= 2;
s.b_sa -= 3;
if(roundnum == 1 && built_d(player) > 1) s.b_tp += 3;
if(roundnum == 1 && built_te(player) == 0) s.b_te += 5;
if(roundnum <= 4 && built_te(player) == 1) s.b_te += 3;
if(built_te(player) >= 2) s.b_te -= 9;
if(built_tp(player) >= 2) s.b_tp -= 9;
if(roundnum >= 4 && game.finalscoring == 2) s.b_sh += 6;
if(built_bridges(player) && built_sh(player) == 0) {
s.b_sh += 10;
if(built_tp(player) == 0) {
s.b_tp += 10;
s.b_te = -10;
}
}
if(roundnum < 6) s.digging = -5;
if(built_d(player) < 3) s.b_d += 5;
if(built_d(player) >= 3) s.b_d += 2;
s.specific[A_POWER_7C] -= 2;
s.specific[A_POWER_2W] += 2;
if (roundnum >= 5 && built_sh(player) == 1) {
s.conbridge += 6;
s.shipping -= 5;
}
//once shipping, then SH or SA are less useful
if(player.shipping > 0 && game.finalscoring != 2) {
s.b_sh -= 4;
s.b_sa -= 4;
s.conbridge = 0;
}
//if not SH-SA, not need SA as much
if(game.finalscoring != 2) s.b_sa -= 2;
//prefer D to TP since more W needed for faction
if(built_tp(player) == 1) s.b_tp -=3;
}
//Dwarves - should TE be earlier?
if(player.faction == F_DWARVES) {
s.digging = 0; //they should go to non-dig places instead
s.b_tp -= 1;
if(built_d(player) > 7) s.b_tp += 2;
s.c -= 0.05; //coin surplus in most games
s.specific[A_POWER_1P] += 2;
s.specific[A_POWER_7C] -= 4;
if(roundnum >= 3 && built_te(player) == 0) s.b_te += 1.5;
}
//add tuning for fireice factions:
//IceMaidens have free FavorTile, get 3 VP per TE on Pass when SH
if(player.faction == F_ICEMAIDENS) {
s.b_te += 2.0;
s.specific[A_POWER_1P] = 0;
if(roundnum >= 1) makeTemple(1,0,0,4,2);
if(roundnum > 2) makeTemple(2,0,0,5,3);
if(roundnum > 4) makeShipping(1,0,0,6,4);
//LOU12 digging is beneficial to ice factions
s.digging += 2;
if(built_te(player) >= 2) s.b_sh += 11;
if(built_sh(player) && game.finalscoring != 2) s.b_sa -= 5;
s.specific[A_POWER_7C] -= 2;
}
//TE first (55%), or SH(23%); has higher value for PW, better with SH
if(player.faction == F_YETIS) {
// yeti get a discount on power actions and can overlay with SH
s.specific[A_POWER_1P] = player.p < 2 ? 6 : 3;
s.specific[A_POWER_2W] = player.w < 4 ? 4 : 2;
s.specific[A_POWER_7C] = player.c < 6 ? 6 : 3;
s.specific[A_POWER_SPADE] = 6;
s.specific[A_POWER_2SPADE] = 8;
if(getRoundTile() == T_ROUND_SHSA5VP_2F1W || getRoundTile() == T_ROUND_SHSA5VP_2A1W) {
makeSHEssential(0,0,0,0);
}
else if(built_d(player) > 2) makeTemple(1,0,0,0,0);
//LOU12 digging is beneficial to ice factions
s.digging += 2;
//need to keep more tokens for later use
if(roundnum < 6) {
s.burn = -.3;
s.b_te += 3;
s.b_sh += 4;
s.maxburn = 8;
}
if(roundnum > 4) makeShipping(1,player.c > 8 ? 0:4,0,1,2);
}
if(player.faction == F_ACOLYTES) {
if(roundnum > 2) makeTemple(1,0,0,0,0);
if(roundnum > 4) makeShipping(1,0,0,0,0);
s.b_tp -= 1;
}
//Add special tuning for Dragonlords to make SH after Round 1 and keep 4 Power
if(player.faction == F_DRAGONLORDS) {
if(roundnum > 1) {
makeSHEssential(10, 5, -50, -50);
}
if(roundnum > 4) makeShipping(1,player.c > 8 ? 0:10,0,0,0);
//see strategy.js for dig implementation
if((player.pw0 + player.pw1 + player.pw2) <= 5) s.digging = 0;
}
if(player.faction == F_SHAPESHIFTERS) {
if(player.bonustile == T_BON_3PW_SHIP || player.bonustile == T_BON_PASSDVP_2C) {
makeTemple(1,0,0,0,0);
} else if(player.bonustile == T_BON_PASSSHSAVP_2W) {
makeSHEssential(0, 0, 0, 0);
} else {
if(roundnum > 1 && !state.fireiceerrata) makeSHEssential(0, 0, 0, 0);
if(roundnum > 2) makeTemple(1,0,0,0,0);
}
if(roundnum > 4) makeShipping(1,0,0,0,0);
if(roundnum < 6) s.b_sa = 1;
s.specific[A_POWER_7C] -= 2;
s.specific[A_POWER_2W] -= 1;
//allow AI action when SH is built to spend 3/5 tokens or 3/5 power to change free color
if(player.b_sh == 0) {
var oldColor = player.auxcolor;
newColor = oldColor; //from strategy.js
useToken = 0; //from strategy.js
var result = AILou.getNewAuxColor(player, oldColor); //get shift color and value
var shiftcost = state.fireiceerrata ? 5 : 3;
if(result >= 2 && player.pw2 >= shiftcost) s.shift = result + 8;
else if(result >= 2 && player.pw2 == shiftcost-1) s.shift = result + 4;
if(roundnum == 6 && player.pw0+player.pw1 >= shiftcost) {
s.shift2 = 6; // will get 2VP at end even if not used
useToken = shiftcost;
}
}
}
if(player.faction == F_RIVERWALKERS) {
s.shipping = 0;
// generally need more coin and priest, not workers
s.specific[A_POWER_1P] = roundnum < 3 ? 4 : 3;
s.specific[A_POWER_2W] -= 3;
s.specific[A_POWER_SPADE] = -50;
s.specific[A_POWER_2SPADE] = -50;
//build temple early for priest
makeTemple(1,10,0,0,0);
//gain from two temples later, avoid sanctuary
if(roundnum < 4) {
s.b_tp -= 1;
s.b_te -= 2;
} else {
makeTemple(2,5,0,0,0);
}
s.b_sa = 0;
s.b_d += 4;
if(roundnum > 5) {
s.b_d += 2;
s.b_sh += 4;
}
//LOU12 improve odds of SH in rounds 4 and 5, avoid building bridges pending 2 bridge build
if(roundnum == 4) {
if(getRoundTile() == T_ROUND_SHSA5VP_2F1W || getRoundTile() == T_ROUND_SHSA5VP_2A1W) {
s.b_sh += 5;
if(built_sh(player) == 0) s.bridge -=10;
}
if(getRoundTileP1() == T_ROUND_SHSA5VP_2F1W || getRoundTileP1() == T_ROUND_SHSA5VP_2A1W) {
s.b_sh -= 5;
s.t_tw -= 5;
if(built_sh(player) == 0) s.bridge -= 10;
}
}
else if(roundnum == 5) {
if(getRoundTile() == T_ROUND_SHSA5VP_2F1W || getRoundTile() == T_ROUND_SHSA5VP_2A1W) {
s.b_sh += 5;
if(built_sh(player) == 0) s.bridge -=10;
}
if(game.finalscoring == 2) {
s.b_sh += 10;
if(built_sh(player) == 0) s.bridge -=10;
}
}
else if(roundnum == 6 && game.finalscoring == 2 && built_sh(player) > 0) s.b_sa += 15;
//must use power if full or less than replacement (SPADE not allowed)
if(roundnum > 4 && (player.pw0 + player.pw1) <= 1) {
s.specific[A_POWER_1P] = 10;
if(player.c > 2*player.w) {
s.specific[A_POWER_2W] = 12;
} else {
if (player.w < 7) s.specific[A_POWER_2W] = 12;
s.specific[A_POWER_7C] = 16;
}
}
s.existingtown = -4;
}
/* general strength from terra.snellman.net + BGG suggestions
Rating Name Games
1141 shapeshifters 612 color brown,gray,yellow
1086 riverwalkers 618 color red,yellow,brown = get to correct spaces
1074 darklings 5862 build 3-4D, P bonus, build TE soon
1044 chaosmagicians 5671 build TE/SA, four tiles 1E, 1F, 2A, 2E
1040 nomads 4988 build TE/2TP/SH, tile 1E, bonus 2W, SH start
1031 mermaids 4335 build 3D+TP, TE soon, tile 1E, ship ship track/nonus
1029 cultists 2859 build TE, tile 1E
1027 witches 4506 build 4D/ SH, bonus 2W, SH start
1021 swarmlings 4290 build 3D+TE/ SH+TE, tile 1E, 1A
995 giants 2342 build SH, 2W bonus, SH start
991 halflings 4754 build 4D or TE, tile 1E, P bonus, up build track
966 dragonlords 643 build 4D, SH second turn
961 icemaidens 578 build TE
959 engineers 3192 build 4D/2TE(common), tile 2E
955 fakirs 1528 avoid in standard game
953 dwarves 3187 build TE or SA, tile 1E
948 yetis 718 build TE
943 auren 2170 4D is good, otherwise build SH
930 alchemists 3027 build SH, use 10 VP for $
894 acolytes 427 avoid in expansion
*/
//LOU check to see how much shipping will benefit network
//LOU compute score, add 1 to shipping, determine benefit
//LOU give score to shipping based on benefit, return shipping value to original
//LOU if benefit is high, reserve resources for shipping for later use.
//scoreProjection returns array of projected end game scores per player.
//Per player it's an array of: total, cult, network, final, resource, passing
//if(state.round == 6) scoreProjection = projectEndGameScores();
//var p = scoreProjection[player.index];
if(player.faction == F_FAKIRS || player.faction == F_DWARVES
|| player.faction == F_RIVERWALKERS || roundnum < 6 ) {
} else {
var reserveOneShip = 0;
var reserveTwoShip = 0;
var reserveThreeShip = 0;
var reserveTotal = 0;
var scoreNow = [];
var scoreShip1 = [];
var scoreShip2 = [];
var scoreShip3 = [];
var scoreProjection = [];
var xplayerp = player.p;
var xplayerc = player.c;
var xplayers = player.shipping;
var adjustCoin = 0;
var shipVP = 0;
//get more coin if needed
if((player.c < 4) && (player.getFaction().canTakeAction(player, A_POWER_7C, game))) {
s.specific[A_POWER_7C] += 20;
} else {
if(player.c == 7 && player.p > 1 && (player.pw2 > 0 || player.w > 0)) adjustCoin = 1;
if(player.c == 3 && player.p > 0 && (player.pw2 > 0 || player.w > 0)) adjustCoin = 1;
if(player.c == 2 && player.p > 0 && (player.pw2 > 1 || player.w > 1)) adjustCoin = 2;
if(player.c == 1 && player.p > 0 && (player.pw2 > 2 || player.w > 2)) adjustCoin = 3;
if(player.c == 0 && player.p > 0 && player.w > 3) adjustCoin = 4;
//determine value of more shipping
if(player.p > 0 && player.c > (3-adjustCoin) && player.shipping < 3) {
//if(AILou.info) addLog('SHIP: AI endship for: ' + logPlayerNameFun(player) );
scoreProjection = projectEndGameScores();
scoreNow = scoreProjection[player.index];
if(AILou.info) addLog('SHIP: AI endship scoreNow: ' + scoreNow);
player.p--;
player.c -= 4;
player.shipping++;
shipVP = player.shipping+1;
scoreProjection = projectEndGameScores();
scoreShip1 = scoreProjection[player.index];
scoreShip1[0] += shipVP;
if(AILou.info) addLog('SHIP: AI scoreShip1 num_'+ player.shipping +': ' + scoreShip1);
if (scoreShip1[0] > (scoreNow[0] + 6)) {
reserveOneShip = scoreShip1[0] - scoreNow[0];
}
if (player.p > 0 && player.c > (3-adjustCoin) && player.shipping < 3) {
player.p--;
player.c -= 4;
player.shipping++;
shipVP = player.shipping+1;
scoreProjection = projectEndGameScores();
scoreShip2 = scoreProjection[player.index];
scoreShip2[0] += shipVP;
if(AILou.info) addLog('SHIP: AI scoreShip2 num_'+ player.shipping +': ' + scoreShip2);
if (scoreShip2[0] > (scoreShip1[0] + 8)
&& scoreShip2[0] > (scoreNow[0] + 10) ) {
reserveTwoShip = scoreShip2[0] - scoreShip1[0];
}
}
if (player.p > 0 && player.c > 3 && player.shipping < 3) {
player.p--;
player.c -= 4;
player.shipping++;
shipVP = player.shipping+1;
scoreProjection = projectEndGameScores();
scoreShip3 = scoreProjection[player.index];
scoreShip3[0] += shipVP;
if(AILou.info) addLog('SHIP: AI scoreShip3 num_'+ player.shipping +': ' + scoreShip3);
if (scoreShip3[0] > (scoreShip2[0] + 10)
&& scoreShip3[0] > (scoreShip1[0] + 12)
&& scoreShip3[0] > (scoreNow[0] + 14) ) {
reserveThreeShip = scoreShip3[0] - scoreShip2[0];
}
}
reserveTotal = reserveOneShip + reserveTwoShip + reserveThreeShip;
//temporary to see if reserve is needed
if (reserveTotal > 0) s.shipping += reserveTotal + 4;
else s.shipping = 0;
player.p = xplayerp;
player.c = xplayerc;
player.shipping = xplayers;
}
}
}
//NEXT- There are many VP for the following: (Use scoreProjection, then undo)
// 1. Dwelling placement to extend network
// 2. Stronghold for bonus VP and sh_sa
// 3. Sanctuary for town and sh_sa
// 4. TODO Project several turns ahead
// Final finetuning
if(built_te(player) + built_sa(player) == 0) s.b_te += 2;
if(built_d(player) == 8) s.b_tp += s.b_d; //make room for more dwellings
if(built_tp(player) == 4) s.b_te += s.b_tp; //make room for more tps
if(built_d(player) < 2) s.b_tp = 0; //ensure to have some worker income
s.specific[A_CONVERT_5PW_1P] = -10; //no matter how good that action for some races, don't burn 5 pw for it...
// Update restrictions based on that too
this.restrictions = {
w_cost: s.w,
p_cost: s.p,
pw_cost: s.pw,
burn_cost: -s.burn,
max_burn: (roundnum < 6 ? s.maxburn : 4),