Ejemplo n.º 1
0
    def put(self, mass_list):
        max_balance_value = -100
        x = 0
        y = 0
        mass_list_origin = Util.copy_mass_list(mass_list)
        opp_mass_type = Util.get_opp_type(self.mass_type)

        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):
                    new_mass_list = Util.copy_mass_list(mass_list)
                    max_value_this_time = 0

                    # 配置してひっくり返す
                    new_mass_list[i][j] = self.mass_type
                    new_mass_list = Util.reverse(new_mass_list, i, j,
                                                 self.mass_type)

                    for s in range(Common.MASS_NUM):
                        for t in range(Common.MASS_NUM):
                            if Util.can_put(new_mass_list, s, t,
                                            opp_mass_type):
                                if max_value_this_time < self.evaluation[s][t]:
                                    max_value_this_time = self.evaluation[s][t]

                    # 自分が置くときの評価値と、次相手が置くときの評価値を差し引き
                    balance_value = self.evaluation[i][j] - max_value_this_time

                    if max_balance_value < balance_value:
                        max_balance_value = balance_value
                        x = i
                        y = j

        print(str(self.type) + ": " + str(x) + " " + str(y))
        return x, y
Ejemplo n.º 2
0
    def put(self, mass_list):
        min_max_value = 5
        x = 0
        y = 0
        mass_list_origin = Util.copy_mass_list(mass_list)
        opp_mass_type = Util.get_opp_type(self.mass_type)

        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):
                    new_mass_list = Util.copy_mass_list(mass_list)
                    max_value_this_time = 0

                    # 配置してひっくり返す
                    new_mass_list[i][j] = self.mass_type
                    new_mass_list = Util.reverse(new_mass_list, i, j,
                                                 self.mass_type)

                    for s in range(Common.MASS_NUM):
                        for t in range(Common.MASS_NUM):
                            if Util.can_put(new_mass_list, s, t,
                                            opp_mass_type):
                                if max_value_this_time < self.evaluation[s][t]:
                                    max_value_this_time = self.evaluation[s][t]

                    if max_value_this_time <= min_max_value:
                        min_max_value = max_value_this_time
                        x = i
                        y = j

        print(str(self.type) + ": " + str(x) + " " + str(y))
        return x, y
Ejemplo n.º 3
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.º 4
0
 def cpu_put(self):
     mass_list_temp = Util.copy_mass_list(self.board.mass_list)
     x, y = self.players[self.turn].put(mass_list_temp)
     self.update(x, y)