游戏王残局简化版

Annotation For 残局文料/lua_lib/常用库.lua
Login

Annotation For 残局文料/lua_lib/常用库.lua

Origin for each line in 残局文料/lua_lib/常用库.lua from check-in 89f423ff38:

5b9fb5e09f 2024-02-13    1: local s = {}
1fd4d78c98 2024-02-03    2: local 简文件库 = require("lfs")
91958121fe 2024-02-05    3: local ffi = require("ffi")
2c6261c44d 2024-02-03    4: --~ 排
2c6261c44d 2024-02-03    5: --~ 办排中值的能
fb63b2804e 2024-02-03    6: --~ 入参2
fb63b2804e 2024-02-03    7: --~ 入参3
fb63b2804e 2024-02-03    8: --~ 入参4
1265aac793 2024-02-13    9: function s.历排(u1_0, u1, u2, u3, u4)
0a84ce44ba 2024-02-13   10:   local h1_0
fb63b2804e 2024-02-03   11:   --~ 集排
0a84ce44ba 2024-02-13   12:   h1_0 = {}
f1bea6a75e 2024-02-13   13:   for u5 = 1, #u1_0 do
f1bea6a75e 2024-02-13   14:     h1_0[#h1_0 + 1] = u1(u1_0[u5], u2, u3, u4)
fb63b2804e 2024-02-03   15:     end
0a84ce44ba 2024-02-13   16:   return h1_0
fb63b2804e 2024-02-03   17:   end
fb63b2804e 2024-02-03   18: --~ 文
fb63b2804e 2024-02-03   19: --~ 历文的能
fb63b2804e 2024-02-03   20: --~ 入参2
fb63b2804e 2024-02-03   21: --~ 入参3
1265aac793 2024-02-13   22: function s.历文(u1, u2, u3, u4)
0a84ce44ba 2024-02-13   23:   local h1_0
a4c0b3bd26 2024-02-13   24:   --~ 集排
0a84ce44ba 2024-02-13   25:   h1_0 = {}
f1bea6a75e 2024-02-13   26:   for u5 in u2(u1, u3, u4) do
f1bea6a75e 2024-02-13   27:     h1_0[#h1_0 + 1] = u5
a4c0b3bd26 2024-02-13   28:     end
0a84ce44ba 2024-02-13   29:   return h1_0
a4c0b3bd26 2024-02-13   30:   end
a4c0b3bd26 2024-02-13   31: --~ 排
a4c0b3bd26 2024-02-13   32: --~ 能
a4c0b3bd26 2024-02-13   33: function s.历排取一(u1_0, u1)
89f423ff38 2024-02-13   34:   local h1
a4c0b3bd26 2024-02-13   35:   for u2 = 1, #u1_0 do
a4c0b3bd26 2024-02-13   36:     --~ 值
89f423ff38 2024-02-13   37:     h1 = s.历排取一的模(h1, u1_0[u2], u1)
a4c0b3bd26 2024-02-13   38:     end
89f423ff38 2024-02-13   39:   return h1
a4c0b3bd26 2024-02-13   40:   end
a4c0b3bd26 2024-02-13   41: --~ 值
a4c0b3bd26 2024-02-13   42: --~ 排中值
4c19907139 2024-02-13   43: function s.历排取一的模(u1, u2, u3)
a4c0b3bd26 2024-02-13   44:   if u1 == nil then
a4c0b3bd26 2024-02-13   45:     return u2
4c19907139 2024-02-13   46:   elseif u3(u1, u2) then
a4c0b3bd26 2024-02-13   47:     return u2
a4c0b3bd26 2024-02-13   48:   else
a4c0b3bd26 2024-02-13   49:     return u1
a4c0b3bd26 2024-02-13   50:     end
a4c0b3bd26 2024-02-13   51:   end
a4c0b3bd26 2024-02-13   52: --~ 对
a4c0b3bd26 2024-02-13   53: --~ 能
a4c0b3bd26 2024-02-13   54: function s.历对取一(u1_0, u1)
89f423ff38 2024-02-13   55:   local h1, h2
a4c0b3bd26 2024-02-13   56:   for u2, u2_0 in pairs(u1_0) do
a4c0b3bd26 2024-02-13   57:     --~ 键
a4c0b3bd26 2024-02-13   58:     --~ 值
89f423ff38 2024-02-13   59:     h1, h2 = s.历对取一的模(h1, h2, u2, u2_0, u1)
a4c0b3bd26 2024-02-13   60:     end
89f423ff38 2024-02-13   61:   return h1, h2
a4c0b3bd26 2024-02-13   62:   end
f1bea6a75e 2024-02-13   63: function s.历对取一的模(u1, u2, u3, u4, u5)
a4c0b3bd26 2024-02-13   64:   if u1 == nil then
1265aac793 2024-02-13   65:     return u3, u4
f1bea6a75e 2024-02-13   66:   elseif u5(u1, u2, u3, u4) then
1265aac793 2024-02-13   67:     return u3, u4
a4c0b3bd26 2024-02-13   68:   else
a4c0b3bd26 2024-02-13   69:     return u1, u2
a4c0b3bd26 2024-02-13   70:     end
a4c0b3bd26 2024-02-13   71:   end
a4c0b3bd26 2024-02-13   72: function s.历对(u1_0, u1, u2)
89f423ff38 2024-02-13   73:   local h1
caceb3cbb9 2024-02-13   74:   local h1_0, h2_0
a4c0b3bd26 2024-02-13   75:   --~ 对
0a84ce44ba 2024-02-13   76:   h1_0 = {}
4c19907139 2024-02-13   77:   for u3, u2_0 in pairs(u1_0) do
a4c0b3bd26 2024-02-13   78:     --~ 键
a4c0b3bd26 2024-02-13   79:     --~ 值
89f423ff38 2024-02-13   80:     h1, h2_0 = u1(u3, u2_0, u2)
89f423ff38 2024-02-13   81:     if h1 then
89f423ff38 2024-02-13   82:       h1_0[h1] = h2_0
a4c0b3bd26 2024-02-13   83:     else
a4c0b3bd26 2024-02-13   84:       end
a4c0b3bd26 2024-02-13   85:     end
0a84ce44ba 2024-02-13   86:   return h1_0
a4c0b3bd26 2024-02-13   87:   end
a4c0b3bd26 2024-02-13   88: --~ 排中值
a4c0b3bd26 2024-02-13   89: --~ 值类
a4c0b3bd26 2024-02-13   90: --~ 办值的能
a4c0b3bd26 2024-02-13   91: function s.操类(u1_0, u1, u2)
a4c0b3bd26 2024-02-13   92:   if type(u1_0) == u1 then
a4c0b3bd26 2024-02-13   93:     return u2(u1_0)
5b69db85ea 2024-02-13   94:   else
5b69db85ea 2024-02-13   95:     return u1_0
1fd4d78c98 2024-02-03   96:     end
1fd4d78c98 2024-02-03   97:   end
1fd4d78c98 2024-02-03   98: --~ 排中文
1fd4d78c98 2024-02-03   99: --~ 入参2
1fd4d78c98 2024-02-03  100: --~ 入参3
1fd4d78c98 2024-02-03  101: --~ 入参4
1265aac793 2024-02-13  102: function s.全筛文(u1, u2, u3, u4)
a4c0b3bd26 2024-02-13  103:   print(4)
1265aac793 2024-02-13  104:   if string.find(u1, u2, u3, u4) then
a4c0b3bd26 2024-02-13  105:     return u1
a4c0b3bd26 2024-02-13  106:     end
a4c0b3bd26 2024-02-13  107:   end
a4c0b3bd26 2024-02-13  108: --~ 文
a4c0b3bd26 2024-02-13  109: --~ 前缀
a4c0b3bd26 2024-02-13  110: function s.加前缀(u1, u2)
a4c0b3bd26 2024-02-13  111:   return (u2 or "") .. u1
a4c0b3bd26 2024-02-13  112:   end
a4c0b3bd26 2024-02-13  113: --~ 文
a4c0b3bd26 2024-02-13  114: --~ 后缀
a4c0b3bd26 2024-02-13  115: function s.加后缀(u1, u2)
a4c0b3bd26 2024-02-13  116:   return u1 .. (u2 or "")
a4c0b3bd26 2024-02-13  117:   end
a4c0b3bd26 2024-02-13  118: --~ 令
a4c0b3bd26 2024-02-13  119: function s.办令(u1)
a4c0b3bd26 2024-02-13  120:   print(u1)
a4c0b3bd26 2024-02-13  121:   os.execute(u1)
a4c0b3bd26 2024-02-13  122:   end
a4c0b3bd26 2024-02-13  123: --~ 文
a4c0b3bd26 2024-02-13  124: --~ 前缀
a4c0b3bd26 2024-02-13  125: function s.全筛前缀(u1, u2)
a4c0b3bd26 2024-02-13  126:   if string.sub(u1, 1, #u2) == u2 then
a4c0b3bd26 2024-02-13  127:     return u1
a4c0b3bd26 2024-02-13  128:     end
a4c0b3bd26 2024-02-13  129:   end
a4c0b3bd26 2024-02-13  130: --~ 文
a4c0b3bd26 2024-02-13  131: --~ 后缀
a4c0b3bd26 2024-02-13  132: function s.全筛后缀(u1, u2)
a4c0b3bd26 2024-02-13  133:   if string.sub(u1, -#u2) == u2 then
a4c0b3bd26 2024-02-13  134:     return u1
5b69db85ea 2024-02-13  135:     end
5b69db85ea 2024-02-13  136:   end
5b69db85ea 2024-02-13  137: --~ 目对
5b69db85ea 2024-02-13  138: function s.用令行工具操文件(u1_0)
5b69db85ea 2024-02-13  139:   local k1_9
5b69db85ea 2024-02-13  140:   --~ 令行排
5b69db85ea 2024-02-13  141:   k1_9 = s.历文(u1_0.文件目, 简文件库.dir)
5b69db85ea 2024-02-13  142:   k1_9 = s.历排(k1_9, s.全筛后缀, u1_0.文件类)
a4c0b3bd26 2024-02-13  143:   for u1 = 1, #k1_9 do
a4c0b3bd26 2024-02-13  144:     k1_9[u1] = s.加前缀(k1_9[u1], u1_0.文件目)
a4c0b3bd26 2024-02-13  145:     k1_9[u1] = s.加前缀(k1_9[u1], [["]])
a4c0b3bd26 2024-02-13  146:     k1_9[u1] = s.加后缀(k1_9[u1], [["]])
a4c0b3bd26 2024-02-13  147:     k1_9[u1] = s.加前缀(k1_9[u1], u1_0.令行前缀)
a4c0b3bd26 2024-02-13  148:     s.办令(k1_9[u1])
5b69db85ea 2024-02-13  149:     end
5b69db85ea 2024-02-13  150:   end
5b69db85ea 2024-02-13  151: --~ 文件路
5b69db85ea 2024-02-13  152: --~ 式
a4c0b3bd26 2024-02-13  153: function s.读文件(u1, u2)
89f423ff38 2024-02-13  154:   local h1
5b69db85ea 2024-02-13  155:   local k1_3
5b69db85ea 2024-02-13  156:   --~ 文件
a4c0b3bd26 2024-02-13  157:   k1_3 = io.open(u1, u2 or "r")
5b69db85ea 2024-02-13  158:   --~ 文
89f423ff38 2024-02-13  159:   h1 = k1_3:read("a")
5b69db85ea 2024-02-13  160:   k1_3:flush()
5b69db85ea 2024-02-13  161:   k1_3:close()
89f423ff38 2024-02-13  162:   return h1
5b69db85ea 2024-02-13  163:   end
5b69db85ea 2024-02-13  164: --~ 常量排
5b69db85ea 2024-02-13  165: function s.加对限(u1_0)
0a84ce44ba 2024-02-13  166:   table.insert(u1_0, 1, "local h1_0 = {}")
0a84ce44ba 2024-02-13  167:   table.insert(u1_0, "return h1_0")
5b69db85ea 2024-02-13  168:   return table.concat(u1_0, "\n")
5b69db85ea 2024-02-13  169:   end
5b69db85ea 2024-02-13  170: --~ 文
5b69db85ea 2024-02-13  171: --~ 文件路
5b69db85ea 2024-02-13  172: --~ 式
4c19907139 2024-02-13  173: function s.写文件(u1, u2, u3)
5b69db85ea 2024-02-13  174:   local k1_3
5b69db85ea 2024-02-13  175:   --~ 文件
4c19907139 2024-02-13  176:   k1_3 = io.open(u2, u3 or "w")
a4c0b3bd26 2024-02-13  177:   k1_3:write(u1)
5b69db85ea 2024-02-13  178:   k1_3:flush()
5b69db85ea 2024-02-13  179:   k1_3:close()
5b69db85ea 2024-02-13  180:   end
5b69db85ea 2024-02-13  181: --~ 文
a4c0b3bd26 2024-02-13  182: function s.删左右空白(u1)
a4c0b3bd26 2024-02-13  183:   u1 = string.gsub(u1, "^%s+", "")
a4c0b3bd26 2024-02-13  184:   return string.gsub(u1, "%s+$", "")
5b69db85ea 2024-02-13  185:   end
5b69db85ea 2024-02-13  186: --~ 对
5b69db85ea 2024-02-13  187: --~ 对
7d4a9f036c 2024-02-13  188: function s.连两对(u1_0, u2_0)
dfc13a8abd 2024-02-13  189:   for u3_0, u4_0 in pairs(u2_0) do
dfc13a8abd 2024-02-13  190:     u1_0[u3_0] = u4_0
5b69db85ea 2024-02-13  191:     end
5b69db85ea 2024-02-13  192:   return u1_0
5b69db85ea 2024-02-13  193:   end
5b69db85ea 2024-02-13  194: --~ 键
5b69db85ea 2024-02-13  195: --~ 值
7d4a9f036c 2024-02-13  196: function s.修对类(u1_0, u2_0)
5b69db85ea 2024-02-13  197:   if tonumber(u1_0) then
7d4a9f036c 2024-02-13  198:     return tonumber(u1_0), u2_0
5b69db85ea 2024-02-13  199:   else
7d4a9f036c 2024-02-13  200:     return u1_0, u2_0
5b69db85ea 2024-02-13  201:     end
5b69db85ea 2024-02-13  202:   end
5b69db85ea 2024-02-13  203: do
5b69db85ea 2024-02-13  204:   --~ 加数
89f423ff38 2024-02-13  205:   local h1 = 0
5b69db85ea 2024-02-13  206:   function s.递增()
89f423ff38 2024-02-13  207:     h1 = h1 + 1
89f423ff38 2024-02-13  208:     return h1
5b69db85ea 2024-02-13  209:     end
5b69db85ea 2024-02-13  210:   end
5b69db85ea 2024-02-13  211: --~ 左加数
5b69db85ea 2024-02-13  212: --~ 右加数
a4c0b3bd26 2024-02-13  213: function s.加法(u1, u2)
a4c0b3bd26 2024-02-13  214:   return u1 + u2
5b69db85ea 2024-02-13  215:   end
5b69db85ea 2024-02-13  216: --~ 左减数
5b69db85ea 2024-02-13  217: --~ 右减数
a4c0b3bd26 2024-02-13  218: function s.减法(u1, u2)
a4c0b3bd26 2024-02-13  219:   return u1 - u2
5b69db85ea 2024-02-13  220:   end
5b69db85ea 2024-02-13  221: --~ 左乘数
5b69db85ea 2024-02-13  222: --~ 右乘数
a4c0b3bd26 2024-02-13  223: function s.乘法(u1, u2)
a4c0b3bd26 2024-02-13  224:   return u1 * u2
5b69db85ea 2024-02-13  225:   end
5b69db85ea 2024-02-13  226: --~ 左除数
5b69db85ea 2024-02-13  227: --~ 右除数
a4c0b3bd26 2024-02-13  228: function s.除法(u1, u2)
a4c0b3bd26 2024-02-13  229:   return u1 / u2
5b69db85ea 2024-02-13  230:   end
5b69db85ea 2024-02-13  231: --~ 左数
5b69db85ea 2024-02-13  232: --~ 右数
a4c0b3bd26 2024-02-13  233: function s.位和(u1, u2)
a4c0b3bd26 2024-02-13  234:   return bit.band(u1, u2)
5b69db85ea 2024-02-13  235:   end
5b69db85ea 2024-02-13  236: --~ 数
5b69db85ea 2024-02-13  237: --~ 右移几位
a4c0b3bd26 2024-02-13  238: function s.位右移(u1, u2)
a4c0b3bd26 2024-02-13  239:   return bit.rshift(u1, u2)
c4461ce231 2024-02-05  240:   end
c4461ce231 2024-02-05  241: --~ 键
c4461ce231 2024-02-05  242: --~ 最大值
c4461ce231 2024-02-05  243: --~ 键
c4461ce231 2024-02-05  244: --~ 值
1265aac793 2024-02-13  245: function s.筛对中最大值(u1, u2, u3, u4)
1265aac793 2024-02-13  246:   if u2 < u4 then
abd9f389ae 2024-02-05  247:     return true
c4461ce231 2024-02-05  248:     end
c4461ce231 2024-02-05  249:   end
c4461ce231 2024-02-05  250: --~ 最短键
abd9f389ae 2024-02-05  251: --~ 值
c4461ce231 2024-02-05  252: --~ 键
c4461ce231 2024-02-05  253: --~ 值
1265aac793 2024-02-13  254: function s.筛对中最短键(u1, u2, u3, u4)
4c19907139 2024-02-13  255:   if #u1 > #u3 then
abd9f389ae 2024-02-05  256:     return true
c4461ce231 2024-02-05  257:     end
c4461ce231 2024-02-05  258:   end
c4461ce231 2024-02-05  259: --~ 最短文
c4461ce231 2024-02-05  260: --~ 值
a4c0b3bd26 2024-02-13  261: function s.筛排中最短文(u1, u2)
a4c0b3bd26 2024-02-13  262:   if #u1 > #u2 then
abd9f389ae 2024-02-05  263:     return true
c4461ce231 2024-02-05  264:     end
c4461ce231 2024-02-05  265:   end
c4461ce231 2024-02-05  266: --~ 内数
a4c0b3bd26 2024-02-13  267: function s.to_uint64(u1)
a4c0b3bd26 2024-02-13  268:   local uint64_pointer = ffi.new("uint64_t[1]", u1)
c4461ce231 2024-02-05  269:   return uint64_pointer[0]
c4461ce231 2024-02-05  270:   end
c4461ce231 2024-02-05  271: --~ 键
c4461ce231 2024-02-05  272: --~ 值
c4461ce231 2024-02-05  273: --~ 要找的值
4c19907139 2024-02-13  274: function s.全等筛对中值(u1, u2, u3)
4c19907139 2024-02-13  275:   if u2 == u3 then
a4c0b3bd26 2024-02-13  276:     return u1, u2
c4461ce231 2024-02-05  277:   else
c4461ce231 2024-02-05  278:     end
c4461ce231 2024-02-05  279:   end
5b9fb5e09f 2024-02-13  280: return s