-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontrolers.py
More file actions
953 lines (819 loc) · 33 KB
/
Copy pathcontrolers.py
File metadata and controls
953 lines (819 loc) · 33 KB
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
from constants import option
from constants import ai_hint
import time
import random
import globe
from constants2 import CardType
from frames import actions
import enum
view = None
def set_view(vi):
global view
view = vi
# import view
class controler:
# boss = None
player = None
def __init__(self, player, invisible=None):
# self.boss = boss
self.player = player
def choose_persona(self, persona_list):
return persona_list[0]
# Choose to end turn or play any cards
def turn(self):
# This is where turn logic goes
return True
def may_defend(self, options, attacking_card, attacking_player=None):
return (option.OK, 0)
def choose_one_of(self, instruction_text, player, cards, hint, source=None):
# base on hint
return [0]
def may_choose_one_of(self, instruction_text, player, cards, hint, source=None):
# base on hint
return [option.NO]
# def may_put_on_top(self,instruction_text):
# return [option.OK]
def ok_or_no(self, instruction_text, player, card, hint):
return [option.NO]
# No responce needed
def reveal(self, instruction_text, player, cards):
return
def choose_even_or_odd(self, instruction_text, player):
return [option.EVEN]
def choose_a_player(self, instruction_text, player, options, hint, source=None):
return 0
# min(self.player.pid, len(options) - 1)
# NO,HAND,DISCARD
# def may_destroy_card_in_hand_or_discard(self):
# return (option.NO,-1)
# only OK or CANNOT are accepted
# def discard_a_card(self):
# return (option.OK,0)
# NO,OK
# def may_play_one_of_these_cards(self,cards):
# return (option.NO,-1)
# NO,OK
# def may_destroy_card_in_discard(self):
# return (option.NO,-1)
def choose_however_many(self, instruction_text, player, cards, hint=None, source=None):
return [option.NO]
class human_view(controler):
def await_turn(self, process):
print("Waiting for player input...", flush=True)
while True:
if globe.bus is None:
raise globe.GameAborted()
if len(globe.bus.on_bus) > 0:
result = process()
if result is not None:
return result
time.sleep(0.1)
# except Exception as e:
# print("ERRROROROROR:", e)
def turn(self):
globe.bus.clear()
def process():
current = globe.bus.read()
if current.header == "card":
# hand to play
if current.content in self.player.hand.contents:
self.player.play_c(current.content)
globe.bus.clear()
return
# lineup to buy
if current.content in globe.boss.lineup.contents:
self.player.buy_c(current.content)
globe.bus.clear()
return
# kick to buy
if current.content in globe.boss.kick_stack.contents:
self.player.buy_kick()
globe.bus.clear()
return
# sv to buy
if current.content in globe.boss.supervillain_stack.contents:
self.player.buy_supervillain()
globe.bus.clear()
return
card_option = None
for special_option in self.player.played.special_options:
if special_option.card is not None and special_option.card == current.content:
if card_option is None:
card_option = special_option
else:
# Multiple options exist for the same card... not sure how to proceed
globe.bus.clear()
return None
if card_option:
self.player.click_action(card_option)
globe.bus.clear()
return
if current.header == "button":
# hand to play
if current.content == actions.ENDTURN:
globe.bus.clear()
return True
if type(current.content) == actions.special_action:
self.player.click_action(current.content)
# .click_action(self.player)
globe.bus.clear()
return
print(f"Current power: {self.player.played.power}", flush=True)
self.await_turn(process)
def choose_persona(self, persona_list):
globe.bus.clear()
text = f"Who would you like to play as?"
options = []
for i in persona_list:
options.append(i)
# try:
globe.bus.query(text, None, options)
# except Exception as e:
# print("ERROR", e)
def process():
current = globe.bus.read()
if current.header == "card":
# hand to play
if current.content in persona_list:
globe.bus.clear()
return current.content
choosen = self.await_turn(process)
return choosen
def may_defend(self, options, attacking_card, attacking_player=None):
globe.bus.clear()
text = f"You are getting attacked by {attacking_card.name}\n{attacking_card.attack_text}.\nWould you like to defend?"
# try:
options.insert(0, option.NO)
globe.bus.query(text, attacking_card, options)
# except Exception as e:
# print("ERROR", e)
def process():
current = globe.bus.read()
if current.header == "card":
# hand to play
if current.content in options:
globe.bus.clear()
return (option.OK, options.index(current.content))
if current.header == "button":
# hand to play
if current.content == option.NO:
globe.bus.clear()
return (option.NO, -1)
return self.await_turn(process)
def choose_one_of(self, instruction_text, player, cards, hint, source=None):
# options = []
# # for c in cards:
# # if isinstance(c,enum.Enum):
# # options.append(c.name)
# # else:
# # options.append(c)
options = cards
globe.bus.clear()
text = instruction_text
# try:
globe.bus.query(text, source, cards)
# except Exception as e:
# print("ERRORR", e)
def process():
current = globe.bus.read()
if current.header == "card":
# hand to play
if current.content in options:
globe.bus.clear()
return [options.index(current.content)]
if current.header == "button":
if current.content in options:
globe.bus.clear()
return [current.content]
return self.await_turn(process)
# base on hint
# return [0]
def may_choose_one_of(self, instruction_text, player, cards, hint, source=None):
options = [option.NO]
options.extend(cards)
print(f"options: {options}", flush=True)
globe.bus.clear()
text = instruction_text
# try:
globe.bus.query(text, source, options)
# except Exception as e:
# print("ERROR", e)
def process():
current = globe.bus.read()
if current.header == "card":
# hand to play
if current.content in options:
globe.bus.clear()
return [option.OK, cards.index(current.content)]
if current.header == "button":
# hand to play
if current.content == option.NO:
globe.bus.clear()
return [option.NO]
if current.content in options:
globe.bus.clear()
return [current.content]
return self.await_turn(process)
def ok_or_no(self, instruction_text, player, card, hint):
options = [option.NO, option.OK]
globe.bus.clear()
text = instruction_text
# try:
globe.bus.query(text, card, options)
# except Exception as e:
# print("ERROR", e)
def process():
current = globe.bus.read()
if current.header == "button":
if current.content == option.NO or current.content == option.OK:
globe.bus.clear()
return [current.content]
return self.await_turn(process)
# No responce needed
def reveal(self, instruction_text, player, cards):
options = [option.DONE]
try:
options.extend(cards)
except:
options.append(cards)
globe.bus.clear()
text = instruction_text
# try:
globe.bus.query(text, None, options)
# except Exception as e:
# print("ERROR", e)
def process():
current = globe.bus.read()
if current.header == "button":
if current.content == option.DONE:
globe.bus.clear()
return [current.content]
return self.await_turn(process)
def choose_even_or_odd(self, instruction_text, player, source=None):
options = [option.ODD, option.EVEN]
globe.bus.clear()
text = instruction_text
# try:
globe.bus.query(text, source, options)
# except Exception as e:
# print("ERROR", e)
def process():
current = globe.bus.read()
if current.header == "button":
if current.content == option.EVEN or current.content == option.ODD:
globe.bus.clear()
return [current.content]
return self.await_turn(process)
def choose_a_player(self, instruction_text, player, options, hint=None, source=None):
globe.bus.clear()
text = instruction_text
globe.bus.query(text, source, options)
def process():
current = globe.bus.read()
if current.header == "card":
# hand to play
if current.content in options:
globe.bus.clear()
return options.index(current.content)
return self.await_turn(process)
def choose_however_many(self, instruction_text, player, cards, hint=None, source=None):
assemble = [option.OK]
assemble_started = False
while True:
options = [option.DONE]
for c in cards:
if c not in assemble:
options.append(c)
globe.bus.clear()
text = instruction_text
# try:
globe.bus.query(text, source, options)
# except Exception as e:
# print("ERROR", e)
def process():
current = globe.bus.read()
if current.header == "card":
# hand to play
if current.content in options:
globe.bus.clear()
return current.content
if current.header == "button":
# hand to play
if current.content == option.DONE:
globe.bus.clear()
return option.DONE
result = self.await_turn(process)
if result == option.DONE and not assemble_started:
return [option.NO]
elif result == option.DONE:
for i in range(1, len(assemble)):
assemble[i] = cards.index(assemble[i])
return assemble
else:
assemble_started = True
assemble.append(result)
# return [option.NO]
def get_input():
global view
x = input().split(" ")
# try:
if x[0] == "back":
view.print_board()
elif x[0] == "destroyed":
view.print_destroyed()
elif x[0] == "discard":
if len(x) == 1:
view.print_discard()
else:
try:
intx = int(x[1])
view.print_discard(intx)
except:
print("?")
elif x[0] == "help":
print("back, discard, others discard, help, ok, no, or a #")
elif x[0] == "deck":
if len(x) == 1:
view.print_deck()
else:
try:
intx = int(x[1])
view.print_deck(intx)
except:
print("?")
elif x[0] == "hand":
if len(x) == 1:
print("?")
else:
try:
intx = int(x[1])
view.print_hand(intx)
except:
print("?")
elif x[0] == "play":
if len(x) == 1:
print("?")
else:
try:
intx = int(x[1])
view.print_played(intx)
except:
print("?")
elif x[0] == "under":
if len(x) == 1:
print("?")
else:
try:
intx = int(x[1])
view.print_under(intx)
except:
print("?")
elif x[0] == "actions":
view.print_actions()
else:
return x
return get_input()
class human(controler):
global view
def state_name(self):
print(f" - {self.player.pid} - {self.player.persona.name} - ")
def turn(self):
view.print_board()
print(f"{self.player.pid}'s Turn!")
while True:
x = get_input()
if x[0] == "end":
return
# print(int(x))
# try:
if x[0] == "buy":
result = False
if x[1] == "sv":
result = self.player.buy_supervillain()
view.print_power()
elif x[1] == "kick":
result = self.player.buy_kick()
view.print_power()
else:
safe = True
intx = -1
try:
intx = int(x[1])
except:
print("?")
safe = False
if safe:
result = self.player.buy(int(x[1]))
view.print_board()
if not result:
print("COULD NOT BUY")
elif x[0] == "action":
safe = True
intx = -1
try:
intx = int(x[1])
except:
safe = False
print("?")
if safe:
self.player.played.special_options[intx].click_action(self.player)
print("clicked")
elif x[0] == "sh":
result = self.player.persona.any_time()
else:
safe = True
intx = -1
try:
intx = int(x[0])
except:
print("?")
safe = False
if safe:
if intx < 0 or intx >= self.player.hand.size():
print("Err: Not a valid card")
else:
self.player.play(intx)
view.print_board()
else:
print("?")
# except Exception as e:
# print("?", e)
# except:
# print("?")
def choose_persona(self, persona_list):
print("Who would you like to be?")
for i, p in enumerate(persona_list):
print(f"{i} {p.name}: {p.text}")
x = get_input()
try:
intx = int(x[0])
except:
print("?")
return self.choose_persona(persona_list)
return persona_list[intx]
def may_defend(self, options, attacking_card, attacking_player=None):
global view
self.state_name()
print(f"!{self.player.pid}! may_defend")
print(f"{attacking_card.name}'s attack: {attacking_card.attack_text}.")
view.print_custom(options)
x = get_input()
if x[0] == "no":
return (option.NO, -1)
elif x[0] == "ok":
intx = -1
try:
intx = int(x[1])
except:
return self.may_defend(options, attacking_card, attacking_player)
return (option.OK, intx)
else:
return self.may_defend(options, attacking_card, attacking_player)
def choose_one_of(self, instruction_text, player, cards, hint, source=None):
self.state_name()
global view
print(f"{instruction_text} ( '0' / '2' )")
view.print_custom(cards)
print(instruction_text)
x = get_input()
intx = -1
try:
intx = int(x[0])
except:
print("?")
return self.choose_one_of(instruction_text, player, cards, hint, source=source)
return [intx]
def may_choose_one_of(self, instruction_text, player, cards, hint, source=None):
self.state_name()
global view
print(f"{instruction_text} ('no' / 'ok 2')")
view.print_custom(cards)
print(instruction_text)
x = get_input()
if x[0] == "no":
return [option.NO]
elif x[0] == "ok":
intx = -1
safe = True
try:
intx = int(x[1])
except:
print("?")
safe = False
if safe:
return [option.OK, intx]
print("??")
return self.may_choose_one_of(instruction_text, player, cards, hint, source=None)
def ok_or_no(self, instruction_text, player, card, hint):
self.state_name()
global view
print(f"{instruction_text} ('ok / 'no')")
if card != None:
view.print_card(card)
print(instruction_text)
x = get_input()
if x[0] == "ok":
return [option.OK]
elif x[0] == "no":
return [option.NO]
else:
print("?")
return self.ok_or_no(instruction_text, player, card, hint)
def reveal(self, instruction_text, player, cards):
self.state_name()
global view
print(instruction_text, flush=True)
view.print_custom(cards)
time.sleep(3)
return
def choose_even_or_odd(self, instruction_text, player):
self.state_name()
print(f"{instruction_text} ('even'/'odd')")
x = get_input()
if x[0] == "even":
return [option.EVEN]
elif x[0] == "odd":
return [option.ODD]
else:
return self.choose_even_or_odd(instruction_text, player)
def choose_a_player(self, instruction_text, player, options, hint, source=None):
self.state_name()
print(instruction_text)
for i, p in enumerate(options):
print(f"{i} - {p.persona.name}")
x = get_input()
intx = -1
try:
intx = int(x[0])
except:
print("?")
return self.choose_a_player(instruction_text, player, options, hint, source=source)
return [intx]
def choose_however_many(self, instruction_text, player, cards, hint=None, source=None):
print(f"{instruction_text} (Example: 'no', or 'ok 0 2 3')")
x = get_input()
if x[0] == "no":
return [option.NO]
elif x[0] == "ok":
assemble = [option.OK]
for r in x[1:]:
safe = True
intx = -1
try:
intx = int(r)
except:
print("?")
safe = False
if not safe:
print(f"Unknown # {r}")
return self.choose_however_many(instruction_text, player, cards, hint=hint, source=source)
assemble.append(intx)
return assemble
print("?")
return self.choose_however_many(instruction_text, player, cards, hint=hint, source=source)
class cpu(controler):
# sleep length between actions
slti = 0
invisible = False
def __init__(self, player, invisible=False):
# self.boss = boss
self.player = player
self.invisible = invisible
self.slti = globe.TIME_BETWEEN_CPU_MOVES
def display_thought(self, text, long=False, quick=True):
if not self.invisible:
print(text, flush=True)
if not quick and not globe.PAUSED_STATE == 2:
time.sleep(self.slti)
if long:
time.sleep(self.slti)
while globe.PAUSED_STATE == 0:
time.sleep(1)
def sort_by_cost(self, card):
if card.name == "Weakness":
return -2
if card.name == "Vunerability":
return -1
# if card.name == "Punch":
return card.cost + self.player.persona.ai_overvalue(card)
def sort_by_play_order(self, card):
if card.name == "Weakness":
return 500
if card.name == "Vunerability":
return 750
if card.name == "Punch":
return 250
if card.ctype_eq(CardType.LOCATION):
return -1
return card.cost
def choose_persona(self, persona_list):
return random.choice(persona_list)
# Choose to end turn or play any cards
def turn(self):
global view
if not self.invisible:
view.print_board()
self.display_thought(f"Begining of AI {self.player.pid}'s turn", quick=False)
self.player.hand.contents.sort(key=self.sort_by_play_order)
self.player.persona.ai_is_now_a_good_time()
while self.player.hand.size() > 0:
size_check = self.player.hand.size()
self.display_thought(
f"AI {self.player.pid}-{self.player.persona.name} is going to play a {self.player.hand.contents[0].name} (total power = {self.player.played.power})",
quick=False)
self.player.play(0)
if size_check - 1 != self.player.hand.size():
self.display_thought("(Differtent cards than expected)", quick=False)
self.player.hand.contents.sort(key=self.sort_by_play_order)
self.player.persona.ai_is_now_a_good_time()
for sa in self.player.played.special_options:
sa.click_action(self.player)
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} has {self.player.played.power} power!",
quick=False)
if globe.boss.supervillain_stack.size() > 0 and self.player.buy_supervillain():
self.display_thought(
f"AI {self.player.pid}-{self.player.persona.name} is buying the supervillain! ({self.player.played.power} power left)",
True, quick=False)
assemble = []
for c in globe.boss.lineup.contents:
assemble.append(c)
assemble.sort(key=self.sort_by_cost)
# Tries to buy everything from most to least expensive
while len(assemble) > 0:
test = assemble.pop()
if self.player.buy_c(test):
self.display_thought(
f"AI {self.player.pid}-{self.player.persona.name} bought {test.name} ({self.player.played.power} power left)",
True, quick=False)
while self.player.played.power >= 3 and globe.boss.kick_stack.size() > 0:
self.player.buy_kick()
self.display_thought(
f"AI {self.player.pid}-{self.player.persona.name} bought a kick ({self.player.played.power} power left)",
True, quick=False)
# Emit state snapshot before turn_end() clears played_this_turn, so the
# frontend can see what the AI played and bought this turn.
if globe.bus and getattr(globe.bus, 'on_state_change', None):
try:
globe.bus.on_state_change()
except Exception:
pass
return
def may_defend(self, options, attacking_card, attacking_player=None):
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} choose to defend with {options[0]}")
return (option.OK, 0)
def choose_one_of(self, instruction_text, player, cards, hint, source=None):
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} got:{instruction_text}")
if hint == ai_hint.RANDOM:
return [random.randint(0, len(cards) - 1)]
cards.sort(key=self.sort_by_cost)
if hint == ai_hint.BEST:
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} choose {cards[-1].name}")
return [len(cards) - 1]
elif hint == ai_hint.WORST:
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} choose {cards[0].name}")
return [0]
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} choose {cards[0].name}")
return [0]
def may_choose_one_of(self, instruction_text, player, cards, hint, source=None):
cards.sort(key=self.sort_by_cost)
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} got:{instruction_text}")
if len(cards) == 0:
return [option.NO]
if hint == ai_hint.ALWAYS:
return [option.OK, len(cards) - 1]
if hint == ai_hint.BEST and cards[-1].cost >= 3:
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} choose {cards[-1].name}")
return [option.OK, len(cards) - 1]
elif hint == ai_hint.WORST and cards[0].cost <= 2:
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} choose {cards[0].name}")
return [option.OK, 0]
elif hint == ai_hint.IFBAD and cards[0].cost <= 2:
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} choose {cards[0].name}")
return [option.OK, 0]
elif hint == ai_hint.RANDOM:
return [option.OK, random.randint(0, len(cards) - 1)]
else:
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} choose not to so")
return [option.NO]
def ok_or_no(self, instruction_text, player, card, hint):
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} got:{instruction_text}")
if hint == ai_hint.ALWAYS:
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} choose to do so")
return [option.OK]
elif hint == ai_hint.IFBAD and card.cost > 1:
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} choose NOT to do so")
return [option.NO]
elif hint == ai_hint.NEVER:
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} choose NOT to do so")
return [option.NO]
elif card != None and hint == ai_hint.IFGOOD:
if card.cost >= 4:
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} choose to do so")
return [option.OK]
else:
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} choose NOT to do so")
return [option.NO]
else:
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} choose to do so (by default)")
return [option.OK]
def choose_a_player(self, instruction_text, player, options, hint, source=None):
if hint == ai_hint.BEST:
if self.player in options:
return options.index(self.player)
else:
return random.randint(0, len(options) - 1)
elif hint == ai_hint.WORST:
if self.player in options:
choose = random.randint(0, len(options) - 1)
if choose >= options.index(self.player):
choose += 1
return choose
else:
return random.randint(0, len(options) - 1)
else:
return random.randint(0, len(options) - 1)
def choose_however_many(self, instruction_text, player, cards, hint=None, source=None):
if hint == ai_hint.IFBAD:
choose = [option.OK]
for i, c in enumerate(cards):
if c.cost <= 4:
choose.append(i)
if len(choose) > 1:
return choose
return [option.NO]
class human_web(human_view):
"""Controller for web-based human player.
Identical to human_view - reads from globe.bus event queue.
The web server feeds events into globe.bus via HTTP/WebSocket actions.
"""
pass
class cpu_greedy(cpu):
# Choose to end turn or play any cards
def turn(self):
global view
if not self.invisible:
view.print_board()
self.display_thought(f"Begining of AI {self.player.pid}'s turn", quick=False)
self.player.hand.contents.sort(key=self.sort_by_play_order)
while self.player.hand.size() > 0:
size_check = self.player.hand.size()
self.display_thought(
f"AI {self.player.pid}-{self.player.persona.name} is going to play a {self.player.hand.contents[0].name} (total power = {self.player.played.power})",
quick=False)
self.player.play(0)
if size_check - 1 != self.player.hand.size():
self.display_thought("(Differtent cards than expected)", quick=False)
self.player.hand.contents.sort(key=self.sort_by_play_order)
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} has {self.player.played.power} power!",
quick=False)
if globe.boss.supervillain_stack.size() > 0 and self.player.played.power >= \
globe.boss.supervillain_stack.contents[-1].cost:
self.player.buy_supervillain()
self.display_thought(
f"AI {self.player.pid}-{self.player.persona.name} is buying the supervillain! ({self.player.played.power} power left)",
quick=False)
assemble = []
for c in globe.boss.lineup.contents:
assemble.append(c)
assemble.sort(reverse=True, key=self.sort_by_cost)
# Tries to buy everything from most to least expensive
while len(assemble) > 0:
test = assemble.pop()
if self.player.buy_c(test):
self.display_thought(
f"AI {self.player.pid}-{self.player.persona.name} bought {test.name} ({self.player.played.power} power left)",
quick=False)
while self.player.played.power >= 3 and globe.boss.kick_stack.size() > 0:
self.player.buy_kick()
self.display_thought(
f"AI {self.player.pid}-{self.player.persona.name} bought a kick ({self.player.played.power} power left)",
quick=False)
return
class cpu_chatgpt_minimal(cpu):
#gptrim
def turn(self):
global view
self.display_thought(f"Begining of AI {self.player.pid}'s turn", quick=False)
# self.player.hand.contents.sort(key=self.sort_by_play_order),
if self.player.hand.size() > 0:
prompt = "You are playing a deck building game where the objective is to have the most victory points (vp) at the end of the game (when the last super villain is bought/defeated). You can buy cards from the lineup using power, which you get by playing cards. The order of cards you play matters. You control cards that you have played that turn, or ongoing from a previous turn."
prompt += "Here are the cards in your hand. Respond with only the names of the cards in the order that you choose to play them, seperated by commas. Do not respond with anything else.\n"
for c in self.player.hand.contents:
prompt += f"- name: {c.name} type: {c.ctype} text: {c.text}\n"
self.display_thought(f"{prompt}", quick=False)
while self.player.hand.size() > 0:
self.player.play(0)
self.display_thought(f"AI {self.player.pid}-{self.player.persona.name} has {self.player.played.power} power!",
quick=False)
if globe.boss.supervillain_stack.size() > 0 and self.player.played.power >= \
globe.boss.supervillain_stack.contents[-1].cost:
self.player.buy_supervillain()
self.display_thought(
f"AI {self.player.pid}-{self.player.persona.name} is buying the supervillain! ({self.player.played.power} power left)",
quick=False)
while self.player.played.power >= 3 and globe.boss.kick_stack.size() > 0:
self.player.buy_kick()
self.display_thought(
f"AI {self.player.pid}-{self.player.persona.name} bought a kick ({self.player.played.power} power left)",
quick=False)
return