2019-11-26 00:07:07 UNSELECTED

Unknown type code

Copy Copied! Full
--簡略化 local STATE = vci.state local ASSET = vci.assets local WHITE_COL = Color.__new(1, 1, 1, 1) local BLACK_COL = Color.__new(0.3, 0.3, 0.3, 1) local REVERSE_GAME = { stone_scale = 0.8, max_player = 2, str = {"駒集合", "駒集合1", "盤", "初期化", "戻る", "CPU", "白黒", "自動許可"}, str_material = {"", "", "", "", "", "UPU", "白黒", "自動許可"}, ban_num = 3, first_num = 4, return_num = 5, cpu_num = 6, bl_wh_num = 7, auto_permission_num = 8, str_subitem = {}, str_stone = "駒", str_stone_subitem = {}, stone_max = 64, stone_hozyo = {65, 66}, stone_PL = {67, 68}, --白、クロ bl_wh_PL = {0, 1}, PL_stone_pos = 0.12, ban_stone_pos = 0.12, put_flg = {}, max_dist = 0.3 } for i = 1, #REVERSE_GAME.str do REVERSE_GAME.str_subitem[i] = ASSET.GetSubItem(REVERSE_GAME.str[i]) if ASSET.IsMine and i < REVERSE_GAME.ban_num then REVERSE_GAME.str_subitem[i].SetLocalScale( Vector3.__new(REVERSE_GAME.stone_scale, REVERSE_GAME.stone_scale, REVERSE_GAME.stone_scale) ) end end for i = 1, REVERSE_GAME.stone_PL[REVERSE_GAME.max_player] do REVERSE_GAME.str_stone_subitem[i] = ASSET.GetSubItem(REVERSE_GAME.str_stone .. tostring(i)) if ASSET.IsMine then REVERSE_GAME.str_stone_subitem[i].SetLocalScale( Vector3.__new(REVERSE_GAME.stone_scale, REVERSE_GAME.stone_scale, REVERSE_GAME.stone_scale) ) end end local return_data = nil local grab_flg = 0 local cpu_flg = false --false local cpu_bl_flg = 0 --0:OFF(NormalFuncする前)、1:OFF(した後)、2:ON local auto_permission_flg = 0 --0 local min_num1 = 0 local min_num2 = 0 local first_flg = false local koma_first = 2 --2 if ASSET.IsMine then first_flg = true end local time1 = 0 local time1_count = 0.05 local time2 = 0 local time2_count = 0.3 local time3 = 0 local time3_count = 1.6 --= 1.6 local time3_flg = true function update() if first_flg then FirstDataInput() first_flg = false end if (os.clock() - time2) >= time2_count then if cpu_flg then ASSET._ALL_SetMaterialColorFromName(REVERSE_GAME.str_material[REVERSE_GAME.cpu_num], BLACK_COL) else ASSET._ALL_SetMaterialColorFromName(REVERSE_GAME.str_material[REVERSE_GAME.cpu_num], WHITE_COL) end if cpu_bl_flg == 1 then ASSET._ALL_SetMaterialColorFromName(REVERSE_GAME.str_material[REVERSE_GAME.bl_wh_num], BLACK_COL) else ASSET._ALL_SetMaterialColorFromName(REVERSE_GAME.str_material[REVERSE_GAME.bl_wh_num], WHITE_COL) end if auto_permission_flg == 2 then ASSET._ALL_SetMaterialColorFromName(REVERSE_GAME.str_material[REVERSE_GAME.auto_permission_num], BLACK_COL) else ASSET._ALL_SetMaterialColorFromName(REVERSE_GAME.str_material[REVERSE_GAME.auto_permission_num], WHITE_COL) end time2 = os.clock() end local all_stone = true local wh_stone = 0 for i = 1, REVERSE_GAME.stone_max do if REVERSE_GAME.put_flg[i] == 2 then all_stone = false break elseif REVERSE_GAME.put_flg[i] == 0 then wh_stone = wh_stone + 1 end end if all_stone then if (os.clock() - time1) >= time1_count then for i = 1, REVERSE_GAME.stone_max do if i <= wh_stone then REVERSE_GAME.put_flg[i] = 0 else REVERSE_GAME.put_flg[i] = 1 end end local ban = REVERSE_GAME.str_subitem[REVERSE_GAME.ban_num] local ban_pos = ban.GetLocalPosition() local ban_ang = ban.GetLocalRotation().eulerAngles local stone for i = 1, REVERSE_GAME.stone_max do local put_x = -1 / 8 * (((i - 1) % 8) - 4) - 1 / 16 local put_z = 1 / 8 * math.floor(((i - 1) / 8) - 4) + 1 / 16 if REVERSE_GAME.put_flg[i] ~= 2 then stone = REVERSE_GAME.str_stone_subitem[i] BanPut(i, put_x, REVERSE_GAME.ban_stone_pos, put_z) Rot_LocalQuat_Euler( stone, ban_ang.x + REVERSE_GAME.put_flg[i] * 180, ban_ang.y, (1 - REVERSE_GAME.put_flg[i] * 2) * ban_ang.z ) end end time1 = os.clock() end else if cpu_flg then if auto_permission_flg ~= 0 then if cpu_bl_flg ~= koma_first then if time3_flg then local ban = REVERSE_GAME.str_subitem[REVERSE_GAME.ban_num] local ban_pos = ban.GetLocalPosition() local ban_ang = ban.GetLocalRotation().eulerAngles local stone for i = 1, REVERSE_GAME.stone_max do local put_x = -1 / 8 * (((i - 1) % 8) - 4) - 1 / 16 local put_z = 1 / 8 * math.floor(((i - 1) / 8) - 4) + 1 / 16 if REVERSE_GAME.put_flg[i] ~= 2 then stone = REVERSE_GAME.str_stone_subitem[i] BanPut(i, put_x, REVERSE_GAME.ban_stone_pos, put_z) Rot_LocalQuat_Euler( stone, ban_ang.x + REVERSE_GAME.put_flg[i] * 180, ban_ang.y, (1 - REVERSE_GAME.put_flg[i] * 2) * ban_ang.z ) end end time3_flg = false time3 = os.clock() end if (os.clock() - time3) >= time3_count then CPUFunc() time3_flg = true end else NormalFunc() time3_flg = true end else NormalFunc() time3_flg = true end else NormalFunc() time3_flg = true end end end function NormalFunc() if (os.clock() - time1) >= time1_count then local ban = REVERSE_GAME.str_subitem[REVERSE_GAME.ban_num] -- Rot_LocalQuat_Euler(ban, 30, 0, 0) local ban_pos = ban.GetLocalPosition() local ban_ang = ban.GetLocalRotation().eulerAngles local hozyo_stone1 = REVERSE_GAME.str_stone_subitem[REVERSE_GAME.stone_hozyo[1]] local hozyo_stone2 = REVERSE_GAME.str_stone_subitem[REVERSE_GAME.stone_hozyo[2]] local pos_stone1 = REVERSE_GAME.str_stone_subitem[REVERSE_GAME.stone_PL[1]] local pos1 = pos_stone1.GetLocalPosition() pos1 = pos1 - ban_pos local pos_stone2 = REVERSE_GAME.str_stone_subitem[REVERSE_GAME.stone_PL[2]] local pos2 = pos_stone2.GetLocalPosition() pos2 = pos2 - ban_pos local min_dist1 = REVERSE_GAME.max_dist local min_x1 = 0 local min_z1 = 0 local min_dist2 = REVERSE_GAME.max_dist local min_x2 = 0 local min_z2 = 0 min_num1 = 0 min_num2 = 0 local stone_pos local permission_num = 0 for i = 1, REVERSE_GAME.stone_max do local put_x = -1 / 8 * (((i - 1) % 8) - 4) - 1 / 16 local put_z = 1 / 8 * math.floor(((i - 1) / 8) - 4) + 1 / 16 if REVERSE_GAME.put_flg[i] ~= 2 then local stone = REVERSE_GAME.str_stone_subitem[i] stone_pos = BanPut(i, put_x, REVERSE_GAME.ban_stone_pos, put_z) Rot_LocalQuat_Euler( stone, ban_ang.x + REVERSE_GAME.put_flg[i] * 180, ban_ang.y, (1 - REVERSE_GAME.put_flg[i] * 2) * ban_ang.z ) else stone_pos = BanPut(0, put_x, REVERSE_GAME.ban_stone_pos, put_z) end local dist = 100 local permission_flg if koma_first == 2 or koma_first == 1 then dist = math.sqrt( (stone_pos.x - pos1.x) * (stone_pos.x - pos1.x) + (stone_pos.y - pos1.y) * (stone_pos.y - pos1.y) + (stone_pos.z - pos1.z) * (stone_pos.z - pos1.z) ) --print(stone_pos) --print(pos1) permission_flg = KomaPermission(REVERSE_GAME.put_flg, 0, i) if min_dist1 > dist and REVERSE_GAME.put_flg[i] == 2 and permission_flg then min_dist1 = dist min_num1 = i min_x1 = put_x min_z1 = put_z end end if koma_first == 2 or koma_first == 0 then dist = math.sqrt( (stone_pos.x - pos2.x) * (stone_pos.x - pos2.x) + (stone_pos.y - pos2.y) * (stone_pos.y - pos2.y) + (stone_pos.z - pos2.z) * (stone_pos.z - pos2.z) ) permission_flg = KomaPermission(REVERSE_GAME.put_flg, 1, i) if min_dist2 > dist and REVERSE_GAME.put_flg[i] == 2 and permission_flg then min_dist2 = dist min_num2 = i min_x2 = put_x min_z2 = put_z end end if min_num1 ~= 0 and min_dist1 < REVERSE_GAME.max_dist then BanPut(REVERSE_GAME.stone_hozyo[1], min_x1, REVERSE_GAME.ban_stone_pos, min_z1) Rot_LocalQuat_Euler( hozyo_stone1, ban_ang.x + REVERSE_GAME.bl_wh_PL[1] * 180, ban_ang.y, (1 - REVERSE_GAME.bl_wh_PL[1] * 2) * ban_ang.z ) else hozyo_stone1.SetPosition(Vector3.__new(0, -10000000, 0)) end if min_num2 ~= 0 and min_dist2 < REVERSE_GAME.max_dist then BanPut(REVERSE_GAME.stone_hozyo[2], min_x2, REVERSE_GAME.ban_stone_pos, min_z2) Rot_LocalQuat_Euler( hozyo_stone2, ban_ang.x + REVERSE_GAME.bl_wh_PL[2] * 180, ban_ang.y, (1 - REVERSE_GAME.bl_wh_PL[2] * 2) * ban_ang.z ) else hozyo_stone2.SetPosition(Vector3.__new(0, -10000000, 0)) end end for i = 1, REVERSE_GAME.stone_max do if REVERSE_GAME.put_flg[i] == 2 then local permission_flg if koma_first == 2 or koma_first == 1 then permission_flg = KomaPermission(REVERSE_GAME.put_flg, 0, i) if permission_flg then permission_num = permission_num + 1 end end if koma_first == 2 or koma_first == 0 then permission_flg = KomaPermission(REVERSE_GAME.put_flg, 1, i) if permission_flg then permission_num = permission_num + 1 end end end end if permission_num == 0 then vci.message.Emit(REVERSE_GAME.str_stone .. "Scale", koma_first + 1) koma_first = (koma_first + 1) % 2 if auto_permission_flg == 0 then auto_permission_flg = 1 end min_num1 = 0 min_num2 = 0 grab_flg = 1 print("次") end time1 = os.clock() end end local max_max = 100000 local deep_count = 17 local max_deep_count = 7 local search_count = 1 local estimate_count = 0 local search_time = 0 local search_time_count = 0.5 function CPUFunc() local stone_count = 0 for i = 1, REVERSE_GAME.stone_max do if REVERSE_GAME.put_flg[i] ~= 2 then stone_count = stone_count + 1 end end estimate_count = 0 local max = -max_max local max_num = 0 local min = max_max local data = {} local bl_wh_data = cpu_bl_flg local permission_data = {} local num = 1 data = TableCreate(REVERSE_GAME.put_flg) if stone_count >= REVERSE_GAME.stone_max - deep_count then print("deepルート") --end for i = 1, REVERSE_GAME.stone_max do if REVERSE_GAME.put_flg[i] == 2 then if KomaPermission(data, bl_wh_data, i) then permission_data[num] = i num = num + 1 end end end search_time = os.clock() --for i2 = search_count, REVERSE_GAME.stone_max - stone_count do for i = 1, #permission_data do data = TableCreate(REVERSE_GAME.put_flg) data = KomaReverse(data, bl_wh_data, permission_data[i]) data[permission_data[i]] = bl_wh_data local count = max_deep_count if count > REVERSE_GAME.stone_max - stone_count - (1 - (REVERSE_GAME.stone_max - stone_count) % 2) then count = REVERSE_GAME.stone_max - stone_count - (1 - (REVERSE_GAME.stone_max - stone_count) % 2) end print(count) local ret_data = DeepFunc(data, max - min, -max, min, ((cpu_bl_flg + 1) % 2), count) if max < ret_data then max = ret_data max_num = permission_data[i] end end else for i = 1, REVERSE_GAME.stone_max do if REVERSE_GAME.put_flg[i] == 2 then if KomaPermission(data, bl_wh_data, i) then permission_data[num] = i num = num + 1 end end end search_time = os.clock() for i2 = search_count, REVERSE_GAME.stone_max, 2 do --REVERSE_GAME.stone_max do if (os.clock() - search_time) < search_time_count then for i = 1, #permission_data do data = TableCreate(REVERSE_GAME.put_flg) data = KomaReverse(data, bl_wh_data, permission_data[i]) data[permission_data[i]] = bl_wh_data --print((bl_wh_data + 1) % 2) local ret_data = CommonFunc(data, -min, -max, ((cpu_bl_flg + 1) % 2), i2) if max < ret_data and (ret_data ~= max) then max = ret_data max_num = permission_data[i] end end else print("ルート" .. i2) break end end end print("得点:" .. max) print("計算回数:" .. estimate_count) print("---------------------") if max_num ~= 0 then REVERSE_GAME.put_flg = KomaReverse(REVERSE_GAME.put_flg, cpu_bl_flg, max_num) REVERSE_GAME.put_flg[max_num] = cpu_bl_flg end return_data = nil koma_first = cpu_bl_flg vci.message.Emit(REVERSE_GAME.str_stone .. "Scale", cpu_bl_flg + 1) min_num1 = 0 min_num2 = 0 grab_flg = 1 --print(max_num) end function DeepFunc(fn_flg, fn_max, fn_min, fn_bl_wh, fn_search_count) estimate_count = estimate_count + 1 if fn_search_count <= 1 then return DeepEstimate(fn_flg, (fn_bl_wh + 1) % 2) end local ret_data = -DeepEstimate(fn_flg, fn_bl_wh) if ret_data > fn_max then fn_max = ret_data end --print(fn_max) local data = {} data = TableCreate(fn_flg) local permission_data = {} local num = 1 for i = 1, REVERSE_GAME.stone_max do if fn_flg[i] == 2 then if KomaPermission(data, fn_bl_wh, i) then permission_data[num] = i num = num + 1 end end end local sss = fn_max for i = 1, #permission_data do data = TableCreate(fn_flg) data = KomaReverse(data, fn_bl_wh, permission_data[i]) data[permission_data[i]] = fn_bl_wh fn_max = -DeepFunc(data, -fn_min, -fn_max, (fn_bl_wh + 1) % 2, fn_search_count - 1) if fn_max > fn_min then --print(fn_max, fn_min) -- if (fn_min ~= max_max) or (fn_min ~= -max_max) or (fn_max ~= max_max) or (fn_max ~= -max_max) then return fn_max --end end end return fn_max end function CommonFunc(fn_flg, fn_max, fn_min, fn_bl_wh, fn_search_count) estimate_count = estimate_count + 1 if fn_search_count <= 1 then return Estimate(fn_flg, (fn_bl_wh + 1) % 2) end local ret_data = -Estimate(fn_flg, fn_bl_wh) if ret_data > fn_max then fn_max = ret_data end local data = {} data = TableCreate(fn_flg) local permission_data = {} local num = 1 for i = 1, REVERSE_GAME.stone_max do if fn_flg[i] == 2 then if KomaPermission(data, fn_bl_wh, i) then permission_data[num] = i num = num + 1 end end end local sss = fn_max for i = 1, #permission_data do data = TableCreate(fn_flg) data = KomaReverse(data, fn_bl_wh, permission_data[i]) data[permission_data[i]] = fn_bl_wh fn_max = -CommonFunc(data, -fn_min, -fn_max, (fn_bl_wh + 1) % 2, fn_search_count - 1) if fn_max > fn_min then --print(fn_max, fn_min) -- if (fn_min ~= max_max) or (fn_min ~= -max_max) or (fn_max ~= max_max) or (fn_max ~= -max_max) then return fn_max --end end end return fn_max end
RECOMMEND