Example #1
0
 def __init__(self,
              wp=5,
              wb1=-10,
              wb2=-40,
              wb3=-20,
              we1=10,
              we2=80,
              ww=10000):
     self.p = PossibilityScorer(wp)
     self.b = BlankScorer(wb1, wb2, wb3)
     self.ec = EdgeCornerScorer(we1, we2)
     self.w = WinLoseScorer(ww)
Example #2
0
class Evaluator_PBWEc(AbstractEvaluator):
    """Specific Evaluator Possibility + Blank + WinLose + EdgeCorner

           盤面の評価値を着手可能数+空きマスと辺と隅のパターン+勝敗で算出
    """
    def __init__(self,
                 wp=5,
                 wb1=-10,
                 wb2=-40,
                 wb3=-20,
                 we1=10,
                 we2=80,
                 ww=10000):
        self.p = PossibilityScorer(wp)
        self.b = BlankScorer(wb1, wb2, wb3)
        self.ec = EdgeCornerScorer(we1, we2)
        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_p = self.p.get_score(color, board, possibility_b, possibility_w)
        score_b = self.b.get_score(color, board, possibility_b, possibility_w)
        score_ec = self.ec.get_score(color, board, possibility_b,
                                     possibility_w)

        return score_p + score_b + score_ec
Example #3
0
 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):
     self.t = TableScorer(size, corner, c, a1, a2, b1, b2, b3, x, o1, o2)
     self.p = PossibilityScorer(wp)
     self.w = WinLoseScorer(ww)
Example #4
0
class Evaluator_W(AbstractEvaluator):
    """Specific Evaluator WinLose

           盤面の評価値を勝敗で算出
    """
    def __init__(self, ww=10000):
        self.scorer = WinLoseScorer(ww)  # 勝敗による評価値算出

    def evaluate(self, color, board, possibility_b, possibility_w):
        """evaluate
        """
        return self.scorer.get_score(color, board, possibility_b,
                                     possibility_w)
Example #5
0
 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]
Example #6
0
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
Example #7
0
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
Example #8
0
class Evaluator_PW(AbstractEvaluator):
    """Specific Evaluator Possibility + WinLose

           盤面の評価値を配置可能数+勝敗で算出
    """
    def __init__(self, wp=5, ww=10000):
        self.p = PossibilityScorer(wp)
        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_p = self.p.get_score(color, board, possibility_b, possibility_w)

        return score_p
Example #9
0
class Evaluator_BW(AbstractEvaluator):
    """Specific Evaluator Blank + WinLose

           盤面の評価値を空きマス+勝敗で算出
    """
    def __init__(self, wb1=-1, wb2=-4, wb3=-2, ww=10000):
        self.b = BlankScorer(wb1, wb2, wb3)
        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_b = self.b.get_score(color, board, possibility_b, possibility_w)

        return score_b
Example #10
0
class Evaluator_NW(AbstractEvaluator):
    """Specific Evaluator Number + WinLose

           盤面の評価値を石数+勝敗で算出
    """
    def __init__(self, ww=10000):
        self.n = NumberScorer()
        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_n = self.n.get_score(color, board, possibility_b, possibility_w)

        return score_n
Example #11
0
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
Example #12
0
class Evaluator_EcW(AbstractEvaluator):
    """Specific Evaluator EdgeCorner + WinLose

           盤面の評価値を辺と隅のパターン+勝敗で算出
    """
    def __init__(self, wec1=1, wec2=8, ww=10000):
        self.ec = EdgeCornerScorer(wec1, wec2)
        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_ec = self.ec.get_score(color, board, possibility_b,
                                     possibility_w)

        return score_ec
Example #13
0
class Evaluator_PWE(AbstractEvaluator):
    """Specific Evaluator Possibility + WinLose + Edge

           盤面の評価値を配置可能数+勝敗+辺のパターンで算出
    """
    def __init__(self, size=8, wp=10, ww=10000, we=75):
        self.p = PossibilityScorer(wp)
        self.w = WinLoseScorer(ww)
        self.e = EdgeScorer(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_p = self.p.get_score(color, board, possibility_b, possibility_w)
        score_e = self.e.get_score(color, board, possibility_b, possibility_w)

        return score_p + score_e
Example #14
0
 def __init__(self, wp=5, ww=10000):
     self.p = PossibilityScorer(wp)
     self.w = WinLoseScorer(ww)
Example #15
0
 def __init__(self, size=8, wp=10, ww=10000, we=75):
     self.p = PossibilityScorer(wp)
     self.w = WinLoseScorer(ww)
     self.e = EdgeScorer(we)
Example #16
0
 def __init__(self, wb1=-1, wb2=-4, wb3=-2, we1=1, we2=8, ww=10000):
     self.b = BlankScorer(wb1, wb2, wb3)
     self.ec = EdgeCornerScorer(we1, we2)
     self.w = WinLoseScorer(ww)
Example #17
0
 def __init__(self, wec1=1, wec2=8, ww=10000):
     self.ec = EdgeCornerScorer(wec1, wec2)
     self.w = WinLoseScorer(ww)
Example #18
0
 def __init__(self, ww=10000):
     self.n = NumberScorer()
     self.w = WinLoseScorer(ww)
Example #19
0
 def __init__(self, ww=10000):
     self.scorer = WinLoseScorer(ww)  # 勝敗による評価値算出
Example #20
0
        Arg:
            w : winlose weight
"""

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, ),
Example #21
0
 def __init__(self, wb1=-1, wb2=-4, wb3=-2, ww=10000):
     self.b = BlankScorer(wb1, wb2, wb3)
     self.w = WinLoseScorer(ww)