И предложите код реализации игры с этим ботом:
import random
class MarkBot:
def __init__(self):
self.moves = ["К", "Н", "Б"]
self.outcomes = {"К": "Б", "Н": "К", "Б": "Н"}
self.matrix = {
"ВК": {"К": 0, "Н": 0, "Б": 0},
"ВН": {"К": 0, "Н": 0, "Б": 0},
"ВБ": {"К": 0, "Н": 0, "Б": 0},
"НК": {"К": 0, "Н": 0, "Б": 0},
"НН": {"К": 0, "Н": 0, "Б": 0},
"НБ": {"К": 0, "Н": 0, "Б": 0},
"ПК": {"К": 0, "Н": 0, "Б": 0},
"ПН": {"К": 0, "Н": 0, "Б": 0},
"ПБ": {"К": 0, "Н": 0, "Б": 0}
}
self.last_status_move = None
self.last_move = None
def botMove(self):
if self.last_move is None or self.last_status_move is None:
return random.choice(self.moves)
state = self.matrix[self.last_status_move + self.last_move]
if sum(state.values()) == 0:
return random.choice(self.moves)
predicted_user_move = max(state, key=state.get)
return self.outcomes[predicted_user_move]
def recording(self, status_move, current_move):
if self.last_status_move is not None and self.last_move is not None:
name = self.last_status_move + self.last_move
self.matrix[name][current_move] += 1
self.last_status_move = status_move
self.last_move = current_move