Ejemplo n.º 1
0
    def put(self, mass_list):
        max_balance_value = -100
        x = 0
        y = 0

        opp_mass_type = Util.get_opp_type(self.mass_type)

        max_piece_num = 0
        FORECAST_TURN = 3

        for i in range(Common.MASS_NUM):
            for j in range(Common.MASS_NUM):
                if Util.can_put(mass_list, i, j, self.mass_type):
                    mass_list_process = Util.copy_mass_list(mass_list)

                    # まず今回の探索位置におく
                    mass_list_process = Util.reverse(mass_list_process, i, j,
                                                     self.mass_type)

                    # 指定ターン数先まで繰り返す
                    for count in range(FORECAST_TURN):

                        # 敵→自分→敵→自分の順番
                        if count % 2 == 0:
                            turn_mass_type = opp_mass_type
                        else:
                            turn_mass_type = self.mass_type

                        # 一番多くひっくり返せるところに置く
                        this_x, this_y = self.put_most_piece(
                            mass_list_process, turn_mass_type)
                        if this_x != 0 and this_y != 0:
                            mass_list_process = Util.reverse(
                                mass_list_process, this_x, this_y,
                                turn_mass_type)

                        # どちらも置けなくなったら強制終了
                        if Util.can_put_somewhere(
                                mass_list_process,
                                self.mass_type) or Util.can_put_somewhere(
                                    mass_list_process, opp_mass_type):
                            break

                    # 数ターン後の自分の枚数
                    final_piece_num = Util.get_piece_num(
                        mass_list_process, self.mass_type)

                    # 現時点の最大値より大きければ更新
                    if max_piece_num < final_piece_num:
                        max_piece_num = final_piece_num
                        x = i
                        y = j

        return x, y
Ejemplo n.º 2
0
 def can_put_somewhere(self, mass_type):
     return Util.can_put_somewhere(self.mass_list, mass_type)