def __init__(self, size=8, corner=50, c=-20, a1=0, a2=-1, b1=-1, b2=-1, b3=-1, x=-25, o1=-5, o2=-5): self.scorer = TableScorer(size, corner, c, a1, a2, b1, b2, b3, x, o1, o2) # Tableによる評価値算出
def __init__(self, size=8, corner=50, c=-20, a1=0, a2=-1, b1=-1, b2=-1, b3=-1, x=-25, o1=-5, o2=-5, wp=5): self.t = TableScorer(size, corner, c, a1, a2, b1, b2, b3, x, o1, o2) self.p = PossibilityScorer(wp)
class Evaluator_T(AbstractEvaluator): """Specific Evaluator Table 盤面の評価値をTableで算出 """ def __init__(self, size=8, corner=50, c=-20, a1=0, a2=-1, b1=-1, b2=-1, b3=-1, x=-25, o1=-5, o2=-5): self.scorer = TableScorer(size, corner, c, a1, a2, b1, b2, b3, x, o1, o2) # Tableによる評価値算出 def evaluate(self, color, board, possibility_b, possibility_w): """evaluate """ return self.scorer.get_score(color, board, possibility_b, possibility_w)
class Evaluator_TPO(AbstractEvaluator): """Specific Evaluator Table + Possibility + Opening 盤面の評価値をTable+配置可能数+開放度で算出 """ def __init__(self, size=8, corner=50, c=-20, a1=0, a2=-1, b1=-1, b2=-1, b3=-1, x=-25, o1=-5, o2=-5, wp=5, wo=-0.75): self.t = TableScorer(size, corner, c, a1, a2, b1, b2, b3, x, o1, o2) self.p = PossibilityScorer(wp) self.o = OpeningScorer(wo) def evaluate(self, color, board, possibility_b, possibility_w): """evaluate """ score_t = self.t.get_score(color, board, possibility_b, possibility_w) score_p = self.p.get_score(color, board, possibility_b, possibility_w) score_o = self.o.get_score(color, board, possibility_b, possibility_w) return score_t + score_p + score_o
def __init__(self, size=8, corner=50, c=-20, a1=0, a2=-1, b1=-1, b2=-1, b3=-1, x=-25, o1=-5, o2=-5, wp=5, ww=10000, we=100): self.t = TableScorer(size, corner, c, a1, a2, b1, b2, b3, x, o1, o2) self.p = PossibilityScorer(wp) self.w = WinLoseScorer(ww) self.e = EdgeScorer(we)
class Evaluator_TPWEB(AbstractEvaluator): """Specific Evaluator Table + Possibility + WinLose + Edge + Blank 盤面の評価値をTable+配置可能数+勝敗+辺+空きマスのパターンで算出 """ def __init__(self, size=8, corner=50, c=-20, a1=0, a2=-1, b1=-1, b2=-1, b3=-1, x=-25, o1=-5, o2=-5, wp=5, ww=10000, we=100, wb1=-5, wb2=-20, wb3=-10): self.t = TableScorer(size, corner, c, a1, a2, b1, b2, b3, x, o1, o2) self.p = PossibilityScorer(wp) self.w = WinLoseScorer(ww) self.e = EdgeScorer(we) self.b = BlankScorer(wb1, wb2, wb3) self.params = [wp, ww, we] def evaluate(self, color, board, possibility_b, possibility_w): """evaluate """ score_w = self.w.get_score(color, board, possibility_b, possibility_w) # 勝敗が決まっている場合 if score_w is not None: return score_w score_t = self.t.get_score(color, board, possibility_b, possibility_w) score_p = self.p.get_score(color, board, possibility_b, possibility_w) score_e = self.e.get_score(color, board, possibility_b, possibility_w) score_b = self.b.get_score(color, board, possibility_b, possibility_w) return score_t + score_p + score_e + score_b
class Evaluator_TPWEC(AbstractEvaluator): """Specific Eavluator Table + Possibility + WinLose + Edge + Corner 盤面の評価値をTable+配置可能数+勝敗+辺のパターン+隅のパターンで算出 """ def __init__(self, size=8, corner=50, c=-20, a1=0, a2=-1, b1=-1, b2=-1, b3=-1, x=-25, o1=-5, o2=-5, wp=5, ww=10000, we=100, wc=120): self.t = TableScorer(size, corner, c, a1, a2, b1, b2, b3, x, o1, o2) self.p = PossibilityScorer(wp) self.w = WinLoseScorer(ww) self.e = EdgeScorer(we) self.c = CornerScorer(wc) def evaluate(self, color, board, possibility_b, possibility_w): """evaluate """ score_w = self.w.get_score(color, board, possibility_b, possibility_w) # 勝敗が決まっている場合 if score_w is not None: return score_w score_t = self.t.get_score(color, board, possibility_b, possibility_w) score_p = self.p.get_score(color, board, possibility_b, possibility_w) score_e = self.e.get_score(color, board, possibility_b, possibility_w) score_c = self.c.get_score(color, board, possibility_b, possibility_w) return score_t + score_p + score_e + score_c
class Evaluator_TPOW(AbstractEvaluator): """Specific Evaluator Table + Possibility + Opening + WinLose 盤面の評価値をTable+配置可能数+開放度+勝敗で算出 """ def __init__(self, size=8, corner=50, c=-20, a1=0, a2=-1, b1=-1, b2=-1, b3=-1, x=-25, o1=-5, o2=-5, wp=5, wo=-0.75, ww=10000): self.t = TableScorer(size, corner, c, a1, a2, b1, b2, b3, x, o1, o2) self.p = PossibilityScorer(wp) self.o = OpeningScorer(wo) self.w = WinLoseScorer(ww) def evaluate(self, color, board, possibility_b, possibility_w): """evaluate """ score_w = self.w.get_score(color, board, possibility_b, possibility_w) # 勝敗が決まっている場合 if score_w is not None: return score_w score_t = self.t.get_score(color, board, possibility_b, possibility_w) score_p = self.p.get_score(color, board, possibility_b, possibility_w) score_o = self.o.get_score(color, board, possibility_b, possibility_w) return score_t + score_p + score_o
from reversi import Reversi from reversi.strategies import AlphaBeta from reversi.strategies.coordinator import Evaluator, TableScorer, PossibilityScorer, WinLoseScorer Reversi({ 'AlphaBeta': AlphaBeta( depth=4, evaluator=Evaluator( separated=[ WinLoseScorer(w=10000, ), ], combined=[ TableScorer( corner=50, c=-20, a1=0, a2=-1, b1=-1, b2=-1, b3=-1, x=-25, o1=-5, o2=-5, ), PossibilityScorer(w=5, ), ], ), ), }).start()