SHARE
TWEET

sorter.lua

HertzDevil Aug 17th, 2015 (edited) 235 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ----------------------------------------
  2. -- beginning of touhou character data
  3. -- data taken from http://tohosort.comoj.com/src/fnc_data_v2.js
  4. -- sets converted to arrays
  5. ----------------------------------------
  6.  
  7. local CHAR = {
  8.   -- main gals
  9.   {"Reimu Hakurei",           {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20}, {4}},
  10.   {"Marisa Kirisame",         {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, {4, 7}},
  11.  
  12.   -- eosd
  13.   {"Rumia",                   {1, 6, 15, 20}, {1}},
  14.   {"Daiyousei",               {1, 20}, {2, 7}},
  15.   {"Cirno",                   {1, 2, 5, 6, 10, 13, 15, 16, 17, 20}, {2}},
  16.   {"Hong Meiling",            {1, 3, 6, 10, 20}, {3}},
  17.   {"Koakuma",                 {1, 20}, {4}},
  18.   {"Patchouli Knowledge",     {1, 3, 6, 8, 10, 15, 20}, {4, 7}},
  19.   {"Sakuya Izayoi",           {1, 2, 3, 4, 5, 6, 8, 10, 15, 16, 17, 20}, {5, 6}},
  20.   {"Remilia Scarlet",         {1, 3, 4, 6, 8, 10, 15, 17, 20}, {6}},
  21.   {"Flandre Scarlet",         {1, 6, 20}, {7}},
  22.  
  23.   -- pcb
  24.   {"Letty Whiterock",         {2, 6, 15, 20}, {1}},
  25.   {"Chen",                    {2, 3, 6, 8, 10, 15, 20}, {2, 7}},
  26.   {"Alice Margatroid",        {2, 3, 4, 6, 8, 10, 15, 20}, {3}},
  27.   {"Lily White",              {2, 5, 15, 20}, {4, 7}},
  28.   {"Lunasa Prismriver",       {2, 5, 15, 20}, {4}},
  29.   {"Merlin Prismriver",       {2, 5, 15, 20}, {4}},
  30.   {"Lyrica Prismriver",       {2, 5, 15, 20}, {4}},
  31.   {"Youmu Konpaku",           {2, 3, 4, 5, 6, 8, 10, 14, 15, 17, 20}, {5, 6}},
  32.   {"Yuyuko Saigyouji",        {2, 3, 4, 6, 8, 10, 14, 15, 17, 20}, {1, 6}},
  33.   {"Ran Yakumo",              {2, 3, 4, 6, 8, 10, 15, 20}, {7}},
  34.   {"Yukari Yakumo",           {2, 3, 4, 6, 8, 10, 15, 17, 20}, {7}},
  35.  
  36.   -- iamp
  37.   {"Suika Ibuki",             {3, 6, 8, 10, 12, 15, 17, 20}, {6}},
  38.  
  39.   -- in
  40.   {"Wriggle Nightbug",        {4, 6, 15, 20}, {1}},
  41.   {"Mystia Lorelei",          {4, 5, 6, 15, 20}, {2}},
  42.   {"Keine Kamishirasawa",     {4, 6, 15, 17, 20}, {3, 7}},
  43.   {"Tewi Inaba",              {4, 5, 6, 15, 20}, {5}},
  44.   {"Reisen Udongein Inaba",   {4, 5, 6, 10, 15, 19, 20}, {5}},
  45.   {"Eirin Yagokoro",          {4, 6, 15, 20}, {6}},
  46.   {"Kaguya Houraisan",        {4, 6, 15, 20}, {6}},
  47.   {"Fujiwara no Mokou",       {4, 6, 15, 17, 18, 20}, {7}},
  48.  
  49.   -- pofv
  50.   {"Aya Shameimaru",          {5, 6, 7, 8, 10, 15, 17, 20}, {4}},
  51.   {"Medicine Melancholy",     {5, 6, 15, 20}, {4}},
  52.   {"Yuuka Kazami",            {5, 6, 15, 20}, {5}},
  53.   {"Komachi Onozuka",         {5, 6, 8, 10, 15, 20}, {5}},
  54.   {"Eiki Shiki, Yamaxanadu",  {5, 6, 15, 20}, {6}},
  55.  
  56.   -- mof
  57.   {"Shizuha Aki",             {7, 12, 15}, {1}},
  58.   {"Minoriko Aki",            {7, 12, 15}, {1}},
  59.   {"Hina Kagiyama",           {7, 12, 15}, {2}},
  60.   {"Nitori Kawashiro",        {7, 12, 15, 17, 18}, {3}},
  61.   {"Momiji Inubashiri",       {7, 12, 17}, {4}},
  62.   {"Sanae Kochiya",           {7, 9, 10, 11, 12, 14, 15, 17, 19}, {5, 7}},
  63.   {"Kanako Yasaka",           {7, 10, 12, 15, 17}, {6, 7}},
  64.   {"Suwako Moriya",           {7, 9, 10, 12, 15, 17}, {7}},
  65.  
  66.   -- swr
  67.   {"Iku Nagae",               {8, 10, 12, 15}, {5}},
  68.   {"Tenshi Hinanawi",         {8, 10, 12, 15, 17}, {6}},
  69.  
  70.   -- sa
  71.   {"Kisume",                  {9, 12}, {1}},
  72.   {"Yamame Kurodani",         {9, 12, 15}, {1}},
  73.   {"Parsee Mizuhashi",        {9, 12, 15}, {2}},
  74.   {"Yuugi Hoshiguma",         {9, 12, 15}, {3}},
  75.   {"Satori Komeiji",          {9, 12, 15}, {4}},
  76.   {"Rin Kaenbyou (Orin)",     {9, 12, 15}, {4, 5, 6}},
  77.   {"Utsuho Reiuji (Okuu)",    {9, 10, 12, 15}, {6}},
  78.   {"Koishi Komeiji",          {9, 12, 15, 18}, {7}},
  79.  
  80.   -- soku
  81.   {"Great Catfish",           {10}, {6}},
  82.  
  83.   -- ufo
  84.   {"Nazrin",                  {11, 12, 15}, {1, 5}},
  85.   {"Kogasa Tatara",           {11, 12, 15}, {2, 7}},
  86.   {"Ichirin Kumoi",           {11, 12, 15, 18}, {3}},
  87.   {"Unzan",                   {11, 12, 15, 18}, {3}},
  88.   {"Minamitsu Murasa",        {11, 12, 15}, {4}},
  89.   {"Shou Toramaru",           {11, 12, 15}, {5}},
  90.   {"Byakuren Hijiri",         {11, 12, 15, 17, 18}, {6}},
  91.   {"Nue Houjuu",              {11, 12, 14, 15}, {4, 6, 7}},
  92.  
  93.   -- ds
  94.   {"Hatate Himekaidou",       {12, 15, 17}, {7}},
  95.  
  96.   -- gfw
  97.   {"Sunny Milk",              {13, 15, 20}, {1, 2, 3}},
  98.   {"Luna Child",              {13, 15, 20}, {1, 2, 3}},
  99.   {"Star Sapphire",           {13, 15, 20}, {1, 2, 3}},
  100.  
  101.   -- td
  102.   {"Kyouko Kasodani",         {14, 15, 17}, {2}},
  103.   {"Yoshika Miyako",          {14, 15, 17}, {3, 4}},
  104.   {"Seiga Kaku",              {14, 15, 17}, {4}},
  105.   {"Soga no Tojiko",          {14, 15}, {5}},
  106.   {"Mononobe no Futo",        {14, 15, 17, 18}, {5}},
  107.   {"Toyosatomimi no Miko",    {14, 15, 17, 18}, {6}},
  108.   {"Mamizou Futatsuiwa",      {14, 15, 17, 18}, {7}},
  109.  
  110.   -- hm
  111.   {"Hata no Kokoro",          {15, 18}, {6}},
  112.  
  113.   -- ddc
  114.   {"Wakasagihime",            {16, 17}, {1}},
  115.   {"Sekibanki",               {16, 17}, {2}},
  116.   {"Kagerou Imaizumi",        {16, 17}, {3}},
  117.   {"Benben Tsukumo",          {16, 17}, {4, 7}},
  118.   {"Yatsuhashi Tsukumo",      {16, 17}, {4, 7}},
  119.   {"Seija Kijin",             {16, 17}, {5, 6}},
  120.   {"Shinmyoumaru Sukuna",     {16, 17, 18}, {6}},
  121.   {"Raiko Horikawa",          {16, 17}, {7}},
  122.  
  123.   -- ulil
  124.   {"Sumireko Usami",          {18}, {6}},
  125.  
  126.   -- lolk
  127.   {"Seiran",                  {19}, {1}},
  128.   {"Ringo",                   {19}, {2}},
  129.   {"Doremy Sweet",            {19}, {3, 7}},
  130.   {"Sagume Kishin",           {19}, {4}},
  131.   {"Clownpiece",              {19}, {5}},
  132.   {"Junko",                   {19}, {6, 7}},
  133.   {"Hecatia Lapislazuli",     {19}, {7}},
  134.  
  135.   -- peeps
  136.   {"Rinnosuke Morichika",     {15, 20}, {}},
  137.   {"Hieda no Akyuu",          {20}, {}},
  138.   {"Tokiko",                  {20}, {}},
  139.   {"Reisen (Manga)",          {20}, {}},
  140.   {"Watatsuki no Toyohime",   {20}, {}},
  141.   {"Watatsuki no Yorihime",   {20}, {}},
  142.   {"Maribel Hearn",           {20}, {}},
  143.   {"Renko Usami",             {20}, {}},
  144.   {"Kasen Ibaraki",           {18, 20}, {5}},
  145.   {"Kosuzu Motoori",          {15, 20}, {}},
  146.  
  147.   -- hrtp
  148.   {"Reimu Hakurei (PC-98)",   {21, 22, 23, 24, 25}, {4}},
  149.   {"Genji",                   {21, 22, 23, 24, 25}, {}},
  150.   {"Shingyoku (Male)",        {21}, {1}},
  151.   {"Shingyoku (Female)",      {21}, {1}},
  152.   {"YuugenMagan",             {21}, {3}},
  153.   {"Mima",                    {21, 22, 23, 25}, {3, 5, 6}},
  154.   {"Elis",                    {21}, {5}},
  155.   {"Kikuri",                  {21}, {5}},
  156.   {"Sariel",                  {21}, {6}},
  157.   {"Konngara",                {21}, {6}},
  158.  
  159.   -- soew
  160.   {"Rika",                    {22}, {1, 7}},
  161.   {"Evil Eye Sigma",          {22}, {7}},
  162.   {"Meira",                   {22}, {2}},
  163.   {"Marisa Kirisame (PC-98)", {22, 23, 24, 25}, {4}},
  164.  
  165.   -- podd
  166.   {"Ellen",                   {23}, {}},
  167.   {"Kotohime",                {23}, {}},
  168.   {"Kana Anaberal",           {23}, {}},
  169.   {"Rikako Asakura",          {23}, {}},
  170.   {"Chiyuri Kitashirakawa",   {23}, {5}},
  171.   {"Yumemi Okazaki",          {23}, {6}},
  172.   {"Ruukoto",                 {23}, {}},
  173.  
  174.   -- lls
  175.   {"Orange",                  {24}, {1}},
  176.   {"Kurumi",                  {24}, {2}},
  177.   {"Elly",                    {24}, {3}},
  178.   {"Yuuka (PC-98)",           {24, 25}, {5, 6}},
  179.   {"Mugetsu",                 {24}, {7}},
  180.   {"Gengetsu",                {24}, {7}},
  181.  
  182.   -- ms
  183.   {"Sara",                    {25}, {1}},
  184.   {"Louise",                  {25}, {2, 4}},
  185.   {"Alice (PC-98)",           {25}, {3, 7}},
  186.   {"Yuki",                    {25}, {4}},
  187.   {"Mai",                     {25}, {4}},
  188.   {"Yumeko",                  {25}, {5}},
  189.   {"Shinki",                  {25}, {6}},
  190.  
  191.   -- more peeps
  192.   {"Layla Prismriver",        {26}, {}},
  193.   {"Youki Konpaku",           {26}, {}},
  194.   {"Myouren Hijiri",          {26}, {}},
  195. }
  196.  
  197. local SERIES = {
  198.   "Embodiment of Scarlet Devil",
  199.   "Perfect Cherry Blossom",
  200.   "Immaterial and Missing Power",
  201.   "Imperishable Night",
  202.   "Phantasmagoria of Flower View",
  203.   "Shoot the Bullet",
  204.   "Mountain of Faith",
  205.   "Scarlet Weather Rhapsody",
  206.   "Subterranean Animism",
  207.   "Touhou Hisoutensoku",
  208.   "Undefined Fantastic Object",
  209.   "Double Spoiler",
  210.   "Great Fairy Wars",
  211.   "Ten Desires",
  212.   "Hopeless Masquerade",
  213.   "Double Dealing Character",
  214.   "Impossible Spell Card",
  215.   "Urban Legend in Limbo",
  216.   "Legacy of Lunatic Kingdom",
  217.   "Books and CDs",
  218.   "The Highly Responsive to Prayers",
  219.   "The Story of Eastern Wonderland",
  220.   "Phantasmagoria of Dim.Dream",
  221.   "Lotus Land Story",
  222.   "Mystic Square",
  223.   "Others",
  224. }
  225.  
  226. local STAGE = {"Stage 1", "Stage 2", "Stage 3", "Stage 4", "Stage 5", "Final Stage", "EX/Phantasm"}
  227.  
  228. local function makeTable ()
  229.   local sel = {}
  230.   for i = 1, 20 --[[#SERIES]] do sel[i] = true end
  231.   while true do
  232.     for i, v in ipairs(SERIES) do
  233.       print(string.format(" %s %2d - %s", sel[i] and "X" or " ", i, v))
  234.     end
  235.     local n = tonumber(io.read())
  236.     if not n or not SERIES[n] then break end
  237.     sel[n] = not sel[n]
  238.   end
  239.  
  240.   local stg = {}
  241.   for i = 1, #STAGE do stg[i] = true end
  242.   local filter = false
  243.   while true do
  244.     print(" " .. (filter and "X" or " ") .. "  0 - Filter by stage")
  245.     for i, v in ipairs(STAGE) do
  246.       print(string.format(" %s %2d - %s", not filter and "-" or stg[i] and "X" or " ", i, v))
  247.     end
  248.     local n = tonumber(io.read())
  249.     if n == 0 then
  250.       filter = not filter
  251.     elseif n and STAGE[n] then
  252.       if filter then stg[n] = not stg[n] end
  253.     else break end
  254.   end
  255.  
  256.   local t = {}
  257.   for _, v in ipairs(CHAR) do
  258.     local use = not filter
  259.     if filter then for _, s in ipairs(v[3]) do
  260.       if stg[s] then use = true end
  261.     end end
  262.     if use then for _, game in ipairs(v[2]) do if sel[game] then
  263.       t[#t + 1] = v[1]
  264.       break
  265.     end end end
  266.   end
  267.   if #t >= 2 then return t end
  268.  
  269.   print("Not enough entries!")
  270.   os.execute("pause")
  271.   return makeTable()
  272. end
  273.  
  274. ----------------------------------------
  275. -- end of touhou character data
  276. ----------------------------------------
  277.  
  278. local HELP = [[
  279. Y - Left wins
  280. N - Right wins
  281. T - Tie]]
  282.  
  283. local GREATER = 3
  284. local EQUAL = 2
  285. local LESS = 1
  286.  
  287. local rank = function (entry)
  288.   local rel = {}
  289.   local d = 0
  290.   local count = 0
  291.   local battle = {}
  292.   local pool = {}
  293.   for i = 1, #entry do
  294.     rel[i] = {[i] = EQUAL}
  295.     battle[i] = 1
  296.     pool[i] = i
  297.   end
  298.   local showHelp = true
  299.  
  300.   local disp = function ()
  301.     local ch = {[GREATER] = ">", [LESS] = "<", [EQUAL] = "="}
  302.     print("  " .. table.concat(entry, " "))
  303.     for i, v in ipairs(entry) do
  304.       io.write(v)
  305.       for j = 1, #entry do io.write(" ", ch[rel[i][j]] or " ") end
  306.       io.write(" ", tostring(battle[i]))
  307.       io.write("\n")
  308.     end
  309.   end
  310.  
  311.   local OPTION = {Y = GREATER, N = LESS, T = EQUAL}
  312.   math.randomseed(os.time())
  313.   while #pool > 0 do
  314.     local left, right, result
  315.     repeat
  316.       left = math.random(#pool)
  317.       right = math.random(#pool - 1)
  318.       if right == left then right = right + 1 end
  319.       left, right = pool[left], pool[right]
  320.     until not rel[left][right]
  321.  
  322.     d = d + 1
  323.     repeat
  324.       print("Battle No. " .. d .. " (" .. math.floor(count * 100 / #entry / (#entry - 1)) .. "% complete)")
  325.       print(entry[left] .. " > " .. entry[right])
  326.       if showHelp then print(HELP) end
  327.       local str = io.read()
  328.       result = OPTION[str:upper()]
  329.       showHelp = not result
  330.     until result ~= nil
  331.     showHelp = false
  332.  
  333.     local closure = {}
  334.     local set = {{}, {}, {}}
  335.  
  336.     local function step (x, res)
  337.       closure[x] = res
  338.       set[res][x] = true
  339.       for i = 1, #entry do if rel[i][x] and not closure[i] then
  340.         if res == GREATER then
  341.           if rel[i][x] == GREATER or rel[i][x] == EQUAL then step(i, GREATER) end
  342.         elseif res == LESS then
  343.           if rel[i][x] == LESS or rel[i][x] == EQUAL then step(i, LESS) end
  344.         elseif res == EQUAL then
  345.           step(i, rel[i][x])
  346.         end
  347.       end end
  348.     end
  349.     step(left, result)
  350.     step(right, 4 - result)
  351.  
  352.     for _, a in ipairs {GREATER, EQUAL} do for _, b in ipairs {EQUAL, LESS} do
  353.       for i in pairs(set[a]) do for j in pairs(set[b]) do if not rel[i][j] then
  354.         count = count + 2
  355.         rel[i][j] = a == b and EQUAL or GREATER
  356.         rel[j][i] = a == b and EQUAL or LESS
  357.         battle[i] = battle[i] + 1
  358.         battle[j] = battle[j] + 1
  359.         print(string.format("%s %s %s", entry[i], a == b and "ties with" or "defeats", entry[j]))
  360.       end end end
  361.     end end
  362.  
  363.     for i in pairs(closure) do if battle[i] == #entry then
  364.       for p, v in ipairs(pool) do if v == i then
  365.         table.remove(pool, p)
  366.         break
  367.       end end
  368.     end end
  369.  
  370.     -- disp()
  371.   end
  372.  
  373.   local t = {}
  374.   for i = 1, #entry do t[i] = {} end
  375.   for i = 1, #entry do
  376.     local c = 0
  377.     for j = 1, #entry do
  378.       if rel[i][j] == LESS then c = c + 1 end
  379.     end
  380.     t[c + 1][#t[c + 1] + 1] = entry[i]
  381.   end
  382.  
  383.   return t
  384. end
  385.  
  386. local main = function ()
  387.   local t = rank(makeTable())
  388.   local str = {}
  389.   for i, v in ipairs(t) do for _, s in ipairs(v) do str[#str + 1] = i .. "\t" .. s .. "\n" end end
  390.   str = table.concat(str)
  391.  
  392.   print("Save to:")
  393.   local fname = io.read()
  394.   if fname == "" then
  395.     print(str)
  396.   else
  397.     local f = io.open(fname, "w")
  398.     f:write(str)
  399.     f:close()
  400.   end
  401.   os.execute("pause")
  402. end
  403.  
  404. main(arg)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top