-
Notifications
You must be signed in to change notification settings - Fork 87
/
Mulligan.cs
514 lines (445 loc) · 19.3 KB
/
Mulligan.cs
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
using System;
using System.Collections.Generic;
namespace HREngine.Bots
{
public class Mulligan
{
public class CardIDEntity
{
public string id = "";
public int entitiy = 0;
public CardIDEntity(string id, int entt)
{
this.id = id;
this.entitiy = entt;
}
}
class mulliitem
{
public string cardid = "";
public string enemyclass = "";
public string ownclass = "";
public int howmuch = 2;
public string[] requiresCard = null;
public int manarule = -1;
public string rulestring = "";
public int coinrule = 0; //0 = for both, 1 = if you are first, 2 if you are second
/*public mulliitem(string id, string own, string enemy, int number, string[] req = null, int coinr = 0, int mrule = -1)
{
this.cardid = id;
this.ownclass = own;
this.enemyclass = enemy;
this.howmuch = number;
this.requiresCard = req;
this.manarule = mrule;
this.coinrule = coinr;
}*/
public mulliitem(string all, string id, string own, string enemy, int number, string[] req = null, int coinr = 0, int mrule = -1)
{
this.cardid = id;
this.ownclass = own;
this.enemyclass = enemy;
this.howmuch = number;
this.requiresCard = req;
this.manarule = mrule;
this.rulestring = all;
this.coinrule = coinr;
}
}
class concedeItem
{
public HeroEnum urhero = HeroEnum.None;
public List<HeroEnum> enemhero = new List<HeroEnum>();
}
List<mulliitem> holdlist = new List<mulliitem>();
List<mulliitem> deletelist = new List<mulliitem>();
List<concedeItem> concedelist = new List<concedeItem>();
public bool loserLoserLoser = false;
private static Mulligan instance;
public static Mulligan Instance
{
get
{
if (instance == null)
{
instance = new Mulligan();
}
return instance;
}
}
private Mulligan()
{
readCombos();
}
private void readCombos()
{
string[] lines = new string[0] { };
this.holdlist.Clear();
this.deletelist.Clear();
try
{
string path = Settings.Instance.path;
lines = System.IO.File.ReadAllLines(path + "_mulligan.txt");
}
catch
{
Helpfunctions.Instance.logg("cant find _mulligan.txt");
Helpfunctions.Instance.ErrorLog("cant find _mulligan.txt (if you dont created your own mulliganfile, ignore this message)");
return;
}
Helpfunctions.Instance.logg("read _mulligan.txt...");
Helpfunctions.Instance.ErrorLog("read _mulligan.txt...");
foreach (string line in lines)
{
string shortline = line.Replace(" ", "");
if (shortline.StartsWith("//")) continue;
if (line.StartsWith("loser"))
{
this.loserLoserLoser = true;
continue;
}
if (line.StartsWith("concede:"))
{
try
{
string ownh = line.Split(':')[1];
concedeItem ci = new concedeItem();
ci.urhero = Hrtprozis.Instance.heroNametoEnum(ownh);
string enemlist = line.Split(':')[2];
foreach (string s in enemlist.Split(','))
{
ci.enemhero.Add(Hrtprozis.Instance.heroNametoEnum(s));
}
concedelist.Add(ci);
}
catch
{
Helpfunctions.Instance.logg("mullimaker cant read: " + line);
Helpfunctions.Instance.ErrorLog("mullimaker cant read: " + line);
}
continue;
}
if (line.StartsWith("hold;"))
{
try
{
string ownclass = line.Split(';')[1];
string enemyclass = line.Split(';')[2];
string cardlist = line.Split(';')[3];
int coinrule = 0;
if (line.Split(';').Length >= 5)
{
string coin = line.Split(';')[4];
if (coin == "nocoin") coinrule = 1;
if (coin == "coin") coinrule = 2;
}
foreach (string crd in cardlist.Split(','))
{
if (crd.Contains(":"))
{
if ((crd.Split(':')).Length == 3)
{
this.holdlist.Add(new mulliitem(line, crd.Split(':')[0], ownclass, enemyclass, Convert.ToInt32(crd.Split(':')[1]), crd.Split(':')[2].Split('/'),coinrule,-1));
}
else
{
this.holdlist.Add(new mulliitem(line, crd.Split(':')[0], ownclass, enemyclass, Convert.ToInt32(crd.Split(':')[1]),null, coinrule,-1));
}
}
else
{
this.holdlist.Add(new mulliitem(line, crd, ownclass, enemyclass, 2,null,coinrule,-1));
}
}
if (line.Split(';').Length >= 6)
{
string mr = (line.Split(';')[5]).Replace(" ", "");
if (mr == "") continue;
int manarule = Convert.ToInt32(mr);
if (manarule <= 0) continue;
Console.WriteLine("manarule "+mr);
this.holdlist.Add(new mulliitem(line, "#MANARULE", ownclass, enemyclass, 2, null, coinrule, manarule));
}
}
catch
{
Helpfunctions.Instance.logg("mullimaker cant read: " + line);
Helpfunctions.Instance.ErrorLog("mullimaker cant read: " + line);
}
}
else
{
if (line.StartsWith("discard;"))
{
try
{
string ownclass = line.Split(';')[1];
string enemyclass = line.Split(';')[2];
string cardlist = line.Split(';')[3];
int coinrule = 0;
if (line.Split(';').Length >= 5)
{
string coin = line.Split(';')[4];
if (coin == "nocoin") coinrule = 1;
if (coin == "coin") coinrule = 2;
}
foreach (string crd in cardlist.Split(','))
{
if (crd == null || crd == "") continue;
this.deletelist.Add(new mulliitem(line, crd, ownclass, enemyclass, 2,null, coinrule, -1));
}
if (line.Split(';').Length >= 6)
{
string mr = (line.Split(';')[5]).Replace(" ","");
if (mr == "") continue;
int manarule = Convert.ToInt32(mr);
if (manarule <= 0) continue;
this.deletelist.Add(new mulliitem(line, "#MANARULE", ownclass, enemyclass, 2, null, coinrule, manarule));
}
}
catch
{
Helpfunctions.Instance.logg("mullimaker cant read: " + line);
Helpfunctions.Instance.ErrorLog("mullimaker cant read: " + line);
}
}
else
{
}
}
}
}
public bool hasmulliganrules(string ownclass, string enemclass)
{
if (this.holdlist.Count == 0 && this.deletelist.Count == 0) return false;
bool hasARule = false;
foreach (mulliitem mi in this.holdlist)
{
if ((mi.enemyclass == "all" || mi.enemyclass == enemclass) && (mi.ownclass == "all" || mi.ownclass == ownclass)) hasARule = true;
}
foreach (mulliitem mi in this.deletelist)
{
if ((mi.enemyclass == "all" || mi.enemyclass == enemclass) && (mi.ownclass == "all" || mi.ownclass == ownclass)) hasARule = true;
}
return hasARule;
}
public bool hasHoldListRule(string ownclass, string enemclass)
{
bool hasARule = false;
foreach (mulliitem mi in this.holdlist)
{
if ((mi.enemyclass == "all" || mi.enemyclass == enemclass) && (mi.ownclass == "all" || mi.ownclass == ownclass)) hasARule = true;
}
return hasARule;
}
public List<int> whatShouldIMulligan(List<CardIDEntity> cards, string ownclass, string enemclass, bool hascoin)
{
Helpfunctions.Instance.ErrorLog("do mulligan...");
if (hascoin)
{
Helpfunctions.Instance.ErrorLog("we hold the coin");
}
else
{
Helpfunctions.Instance.ErrorLog("we dont hold the coin");
}
List<int> discarditems = new List<int>();
bool usedManarule = false;
foreach (mulliitem mi in this.deletelist)
{
if (hascoin && mi.coinrule == 1) continue;
if (!hascoin && mi.coinrule == 2) continue;
foreach (CardIDEntity c in cards)
{
if (mi.cardid == "#MANARULE" && (mi.enemyclass == "all" || mi.enemyclass == enemclass) && (mi.ownclass == "all" || mi.ownclass == ownclass))
{
usedManarule = true;
if (CardDB.Instance.getCardDataFromID(CardDB.Instance.cardIdstringToEnum(c.id)).cost >= mi.manarule)
{
if (discarditems.Contains(c.entitiy)) continue;
Helpfunctions.Instance.ErrorLog("discard " + c.id + " because of this rule " + mi.rulestring);
discarditems.Add(c.entitiy);
}
continue;
}
if (c.id == mi.cardid && (mi.enemyclass == "all" || mi.enemyclass == enemclass) && (mi.ownclass == "all" || mi.ownclass == ownclass))
{
if (discarditems.Contains(c.entitiy)) continue;
Helpfunctions.Instance.ErrorLog("discard " + c.id + " because of this rule " + mi.rulestring);
discarditems.Add(c.entitiy);
}
}
}
if (holdlist.Count == 0 || !hasHoldListRule(ownclass, enemclass)) return discarditems;
Dictionary<string, int> holddic = new Dictionary<string, int>();
List<string> combosToHold = new List<string>();
foreach (CardIDEntity c in cards)
{
bool delete = true;
foreach (mulliitem mi in this.holdlist)
{
if (hascoin && mi.coinrule == 1) continue;
if (!hascoin && mi.coinrule == 2) continue;
if (mi.cardid == "#MANARULE" && (mi.enemyclass == "all" || mi.enemyclass == enemclass) && (mi.ownclass == "all" || mi.ownclass == ownclass))
{
if (CardDB.Instance.getCardDataFromID(CardDB.Instance.cardIdstringToEnum(c.id)).cost <= mi.manarule)
{
delete = false;
}
continue;
}
if (c.id == mi.cardid && (mi.enemyclass == "all" || mi.enemyclass == enemclass) && (mi.ownclass == "all" || mi.ownclass == ownclass))
{
if (mi.requiresCard == null)
{
if (holddic.ContainsKey(c.id)) // we are holding one of the cards
{
if (mi.howmuch == 2)
{
delete = false;
}
}
else
{
delete = false;
}
}
else
{
bool hasRequirements = false;
foreach (string s in mi.requiresCard)
{
if (s.Contains("+"))
{
int shouldadd = 1;
foreach (string ss in s.Split('+'))
{
if(ss=="") continue;
bool hascard = false;
foreach (CardIDEntity reqs2 in cards)
{
if (reqs2.id == ss) hascard = true;
}
if (hascard)
{
shouldadd++;
}
else
{
shouldadd -= 1000;
}
}
if (shouldadd >= 1)
{
hasRequirements = true;
foreach (string ss in s.Split('+'))
{
if (ss == "") continue;
combosToHold.Add(ss);
}
}
}
else
{
//Helpfunctions.Instance.ErrorLog("search cards for: " + s);
foreach (CardIDEntity reqs in cards)
{
//Helpfunctions.Instance.ErrorLog("in hand " + reqs.id);
if (s == reqs.id)
{
hasRequirements = true;
combosToHold.Add(s);
//break;
}
}
//Helpfunctions.Instance.ErrorLog("hasreqiresments " + hasRequirements);
}
}
if (hasRequirements)
{
if (holddic.ContainsKey(c.id)) // we are holding one of the cards
{
if (mi.howmuch == 2)
{
delete = false;
}
}
else
{
delete = false;
}
}
}
}
}
if (!usedManarule)
{
if (delete)
{
if (discarditems.Contains(c.entitiy)) continue;
discarditems.Add(c.entitiy);
}
else
{
discarditems.RemoveAll(x => x == c.entitiy);
if (holddic.ContainsKey(c.id))
{
holddic[c.id]++;
}
else
{
holddic.Add(c.id, 1);
}
}
}
else
{//used manarules in discard line
if (!delete)
{
discarditems.RemoveAll(x => x == c.entitiy);
if (holddic.ContainsKey(c.id))
{
holddic[c.id]++;
}
else
{
holddic.Add(c.id, 1);
}
}
}
}
//remove combo items from discard list
foreach (CardIDEntity cie in cards)
{
int amountInDiscard = 0;
int amountInHand =0 ;
foreach (CardIDEntity cie2 in cards)
{
if(cie.id == cie2.id)
{
amountInHand++;
if(discarditems.Contains(cie2.entitiy)) amountInDiscard++;
}
}
if (amountInDiscard == amountInHand && combosToHold.Contains(cie.id))
{
//remove item
discarditems.Remove(cie.entitiy);
}
}
return discarditems;
}
public void setAutoConcede(bool mode)
{
this.loserLoserLoser = mode;
}
public bool shouldConcede(HeroEnum ownhero, HeroEnum enemHero)
{
foreach (concedeItem ci in concedelist)
{
if (ci.urhero == ownhero && ci.enemhero.Contains(enemHero)) return true;
}
return false;
}
}
}