游戏王残局简化版

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

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

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

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)
dbb3ab98a4 2024-02-03   10:   local k1_0
fb63b2804e 2024-02-03   11:   --~ 集排
dbb3ab98a4 2024-02-03   12:   k1_0 = {}
5b69db85ea 2024-02-13   13:   for o5 = 1, #u1_0 do
1265aac793 2024-02-13   14:     k1_0[#k1_0 + 1] = u1(u1_0[o5], u2, u3, u4)
fb63b2804e 2024-02-03   15:     end
dbb3ab98a4 2024-02-03   16:   return k1_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)
4af7b78130 2024-02-03   23:   local k1_0
0b316b136c 2024-02-03   24:   --~ 集排
4af7b78130 2024-02-03   25:   k1_0 = {}
1265aac793 2024-02-13   26:   for o5 in u2(u1, u3, u4) do
02fb4461e1 2024-02-05   27:     k1_0[#k1_0 + 1] = o5
f4c48d2eb7 2024-02-05   28:     end
f4c48d2eb7 2024-02-05   29:   return k1_0
f4c48d2eb7 2024-02-05   30:   end
c4461ce231 2024-02-05   31: --~ 排
c4461ce231 2024-02-05   32: --~ 能
a4c0b3bd26 2024-02-13   33: function s.历排取一(u1_0, u1)
c4461ce231 2024-02-05   34:   local k1
a4c0b3bd26 2024-02-13   35:   for u2 = 1, #u1_0 do
c4461ce231 2024-02-05   36:     --~ 值
a4c0b3bd26 2024-02-13   37:     k1 = s.历排取一的模(k1, u1_0[u2], u1)
c4461ce231 2024-02-05   38:     end
c4461ce231 2024-02-05   39:   return k1
c4461ce231 2024-02-05   40:   end
abd9f389ae 2024-02-05   41: --~ 值
abd9f389ae 2024-02-05   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
abd9f389ae 2024-02-05   48:   else
a4c0b3bd26 2024-02-13   49:     return u1
abd9f389ae 2024-02-05   50:     end
abd9f389ae 2024-02-05   51:   end
c4461ce231 2024-02-05   52: --~ 对
c4461ce231 2024-02-05   53: --~ 能
a4c0b3bd26 2024-02-13   54: function s.历对取一(u1_0, u1)
c4461ce231 2024-02-05   55:   local k1, k2
a4c0b3bd26 2024-02-13   56:   for u2, u2_0 in pairs(u1_0) do
c4461ce231 2024-02-05   57:     --~ 键
c4461ce231 2024-02-05   58:     --~ 值
a4c0b3bd26 2024-02-13   59:     k1, k2 = s.历对取一的模(k1, k2, u2, u2_0, u1)
c4461ce231 2024-02-05   60:     end
c4461ce231 2024-02-05   61:   return k1, k2
c4461ce231 2024-02-05   62:   end
1265aac793 2024-02-13   63: function s.历对取一的模(u1, u2, u3, u4, o5)
a4c0b3bd26 2024-02-13   64:   if u1 == nil then
1265aac793 2024-02-13   65:     return u3, u4
1265aac793 2024-02-13   66:   elseif o5(u1, u2, u3, u4) then
1265aac793 2024-02-13   67:     return u3, u4
abd9f389ae 2024-02-05   68:   else
a4c0b3bd26 2024-02-13   69:     return u1, u2
abd9f389ae 2024-02-05   70:     end
abd9f389ae 2024-02-05   71:   end
a4c0b3bd26 2024-02-13   72: function s.历对(u1_0, u1, u2)
91958121fe 2024-02-05   73:   local k1
91958121fe 2024-02-05   74:   local k1_0, k2_0
f4c48d2eb7 2024-02-05   75:   --~ 对
f4c48d2eb7 2024-02-05   76:   k1_0 = {}
4c19907139 2024-02-13   77:   for u3, u2_0 in pairs(u1_0) do
f4c48d2eb7 2024-02-05   78:     --~ 键
f4c48d2eb7 2024-02-05   79:     --~ 值
4c19907139 2024-02-13   80:     k1, k2_0 = u1(u3, u2_0, u2)
91958121fe 2024-02-05   81:     if k1 then
91958121fe 2024-02-05   82:       k1_0[k1] = k2_0
f4c48d2eb7 2024-02-05   83:     else
f4c48d2eb7 2024-02-05   84:       end
2fe4cafc95 2024-02-03   85:     end
4af7b78130 2024-02-03   86:   return k1_0
2fe4cafc95 2024-02-03   87:   end
c4461ce231 2024-02-05   88: --~ 排中值
2fe4cafc95 2024-02-03   89: --~ 值类
2fe4cafc95 2024-02-03   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)
1fd4d78c98 2024-02-03   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)
5b69db85ea 2024-02-13  154:   local k1
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")
4e48ffd0e5 2024-02-03  158:   --~ 文
4e48ffd0e5 2024-02-03  159:   k1 = k1_3:read("a")
4e48ffd0e5 2024-02-03  160:   k1_3:flush()
4e48ffd0e5 2024-02-03  161:   k1_3:close()
4e48ffd0e5 2024-02-03  162:   return k1
4e48ffd0e5 2024-02-03  163:   end
4e48ffd0e5 2024-02-03  164: --~ 常量排
5b69db85ea 2024-02-13  165: function s.加对限(u1_0)
5b69db85ea 2024-02-13  166:   table.insert(u1_0, 1, "local k1_0 = {}")
5b69db85ea 2024-02-13  167:   table.insert(u1_0, "return k1_0")
5b69db85ea 2024-02-13  168:   return table.concat(u1_0, "\n")
4e48ffd0e5 2024-02-03  169:   end
4e48ffd0e5 2024-02-03  170: --~ 文
4e48ffd0e5 2024-02-03  171: --~ 文件路
4e48ffd0e5 2024-02-03  172: --~ 式
4c19907139 2024-02-13  173: function s.写文件(u1, u2, u3)
4e48ffd0e5 2024-02-03  174:   local k1_3
4e48ffd0e5 2024-02-03  175:   --~ 文件
4c19907139 2024-02-13  176:   k1_3 = io.open(u2, u3 or "w")
a4c0b3bd26 2024-02-13  177:   k1_3:write(u1)
4e48ffd0e5 2024-02-03  178:   k1_3:flush()
4e48ffd0e5 2024-02-03  179:   k1_3:close()
4e48ffd0e5 2024-02-03  180:   end
1b64e61bc7 2024-02-04  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+$", "")
f4c48d2eb7 2024-02-05  185:   end
f4c48d2eb7 2024-02-05  186: --~ 对
f4c48d2eb7 2024-02-05  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
f4c48d2eb7 2024-02-05  191:     end
5b69db85ea 2024-02-13  192:   return u1_0
f4c48d2eb7 2024-02-05  193:   end
f4c48d2eb7 2024-02-05  194: --~ 键
f4c48d2eb7 2024-02-05  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
f4c48d2eb7 2024-02-05  199:   else
7d4a9f036c 2024-02-13  200:     return u1_0, u2_0
f4c48d2eb7 2024-02-05  201:     end
f4c48d2eb7 2024-02-05  202:   end
f4c48d2eb7 2024-02-05  203: do
f4c48d2eb7 2024-02-05  204:   --~ 加数
f4c48d2eb7 2024-02-05  205:   local k1 = 0
5b9fb5e09f 2024-02-13  206:   function s.递增()
f4c48d2eb7 2024-02-05  207:     k1 = k1 + 1
f4c48d2eb7 2024-02-05  208:     return k1
f4c48d2eb7 2024-02-05  209:     end
f4c48d2eb7 2024-02-05  210:   end
f4c48d2eb7 2024-02-05  211: --~ 左加数
f4c48d2eb7 2024-02-05  212: --~ 右加数
a4c0b3bd26 2024-02-13  213: function s.加法(u1, u2)
a4c0b3bd26 2024-02-13  214:   return u1 + u2
f4c48d2eb7 2024-02-05  215:   end
f4c48d2eb7 2024-02-05  216: --~ 左减数
f4c48d2eb7 2024-02-05  217: --~ 右减数
a4c0b3bd26 2024-02-13  218: function s.减法(u1, u2)
a4c0b3bd26 2024-02-13  219:   return u1 - u2
f4c48d2eb7 2024-02-05  220:   end
f4c48d2eb7 2024-02-05  221: --~ 左乘数
f4c48d2eb7 2024-02-05  222: --~ 右乘数
a4c0b3bd26 2024-02-13  223: function s.乘法(u1, u2)
a4c0b3bd26 2024-02-13  224:   return u1 * u2
f4c48d2eb7 2024-02-05  225:   end
f4c48d2eb7 2024-02-05  226: --~ 左除数
f4c48d2eb7 2024-02-05  227: --~ 右除数
a4c0b3bd26 2024-02-13  228: function s.除法(u1, u2)
a4c0b3bd26 2024-02-13  229:   return u1 / u2
7a7894a746 2024-02-05  230:   end
7a7894a746 2024-02-05  231: --~ 左数
7a7894a746 2024-02-05  232: --~ 右数
a4c0b3bd26 2024-02-13  233: function s.位和(u1, u2)
a4c0b3bd26 2024-02-13  234:   return bit.band(u1, u2)
91958121fe 2024-02-05  235:   end
91958121fe 2024-02-05  236: --~ 数
91958121fe 2024-02-05  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
91958121fe 2024-02-05  265:   end
91958121fe 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)
91958121fe 2024-02-05  269:   return uint64_pointer[0]
6bd570d52a 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