-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai.py
41 lines (29 loc) · 852 Bytes
/
ai.py
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
import enum
import random
from abc import ABC, abstractmethod
from collections import Counter
class AI(ABC):
@staticmethod
@abstractmethod
def make_choice(*args, **kwargs) -> int or None:
...
class AIMostCommon(AI):
@staticmethod
def make_choice(data: list[int]):
most_common = Counter(data).most_common(1)
result = None if len(most_common) == 0 else most_common[0][0]
return result
class AIRandom(AI):
@staticmethod
def make_choice(data: list[int], exclude: int or None = None):
if exclude:
result = exclude
while result == exclude:
result = random.choice(data)
else:
result = random.choice(data)
return result
@enum.unique
class AIList(enum.Enum):
RND = AIRandom()
MOST_COMMON = AIMostCommon()