游戏王残局简化版

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

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

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

9942dfa51d 2024-02-04    1: local d = {}
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
02fb4461e1 2024-02-05    9: function d.历排(o1_0, o1, o2, o3, o4)
dbb3ab98a4 2024-02-03   10:   local k1_0
fb63b2804e 2024-02-03   11:   --~ 集排
dbb3ab98a4 2024-02-03   12:   k1_0 = {}
02fb4461e1 2024-02-05   13:   for o5 = 1, #o1_0 do
02fb4461e1 2024-02-05   14:     k1_0[#k1_0 + 1] = o1(o1_0[o5], o2, o3, o4)
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
02fb4461e1 2024-02-05   22: function d.历文(o1, o2, o3, o4)
4af7b78130 2024-02-03   23:   local k1_0
0b316b136c 2024-02-03   24:   --~ 集排
4af7b78130 2024-02-03   25:   k1_0 = {}
02fb4461e1 2024-02-05   26:   for o5 in o2(o1, o3, o4) 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: --~ 能
c4461ce231 2024-02-05   33: function d.历排取一(o1_0, o1)
c4461ce231 2024-02-05   34:   local k1
c4461ce231 2024-02-05   35:   for o2 = 1, #o1_0 do
c4461ce231 2024-02-05   36:     --~ 值
abd9f389ae 2024-02-05   37:     k1 = d.历排取一的模(k1, o1_0[o2], o1)
c4461ce231 2024-02-05   38:     end
c4461ce231 2024-02-05   39:   return k1
abd9f389ae 2024-02-05   40:   end
abd9f389ae 2024-02-05   41: --~ 值
abd9f389ae 2024-02-05   42: --~ 排中值
abd9f389ae 2024-02-05   43: function d.历排取一的模(o1, o2, o3)
abd9f389ae 2024-02-05   44:   if o1 == nil then
abd9f389ae 2024-02-05   45:     return o2
abd9f389ae 2024-02-05   46:   elseif o3(o1, o2) then
abd9f389ae 2024-02-05   47:     return o2
abd9f389ae 2024-02-05   48:   else
abd9f389ae 2024-02-05   49:     return o1
abd9f389ae 2024-02-05   50:     end
c4461ce231 2024-02-05   51:   end
c4461ce231 2024-02-05   52: --~ 对
c4461ce231 2024-02-05   53: --~ 能
c4461ce231 2024-02-05   54: function d.历对取一(o1_0, o1)
c4461ce231 2024-02-05   55:   local k1, k2
c4461ce231 2024-02-05   56:   for o2, o2_0 in pairs(o1_0) do
c4461ce231 2024-02-05   57:     --~ 键
c4461ce231 2024-02-05   58:     --~ 值
abd9f389ae 2024-02-05   59:     k1, k2 = d.历对取一的模(k1, k2, o2, o2_0, o1)
c4461ce231 2024-02-05   60:     end
c4461ce231 2024-02-05   61:   return k1, k2
abd9f389ae 2024-02-05   62:   end
abd9f389ae 2024-02-05   63: function d.历对取一的模(o1, o2, o3, o4, o5)
abd9f389ae 2024-02-05   64:   if o1 == nil then
abd9f389ae 2024-02-05   65:     return o3, o4
abd9f389ae 2024-02-05   66:   elseif o5(o1, o2, o3, o4) then
abd9f389ae 2024-02-05   67:     return o3, o4
abd9f389ae 2024-02-05   68:   else
abd9f389ae 2024-02-05   69:     return o1, o2
abd9f389ae 2024-02-05   70:     end
c4461ce231 2024-02-05   71:   end
c4461ce231 2024-02-05   72: function d.历对(o1_0, o1, o2)
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 = {}
c4461ce231 2024-02-05   77:   for o3, o2_0 in pairs(o1_0) do
f4c48d2eb7 2024-02-05   78:     --~ 键
f4c48d2eb7 2024-02-05   79:     --~ 值
c4461ce231 2024-02-05   80:     k1, k2_0 = o1(o3, o2_0, o2)
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
4af7b78130 2024-02-03   85:     end
4af7b78130 2024-02-03   86:   return k1_0
4af7b78130 2024-02-03   87:   end
c4461ce231 2024-02-05   88: --~ 排中值
4af7b78130 2024-02-03   89: --~ 值类
4af7b78130 2024-02-03   90: --~ 办值的能
9942dfa51d 2024-02-04   91: function d.操类(o1_0, o1, o2)
733d68b305 2024-02-04   92:   if type(o1_0) == o1 then
733d68b305 2024-02-04   93:     return o2(o1_0)
4af7b78130 2024-02-03   94:   else
733d68b305 2024-02-04   95:     return o1_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
9942dfa51d 2024-02-04  102: function d.全筛文(o1, o2, o3, o4)
d1b9d0d34f 2024-02-03  103:   if string.find(o1, o2, o3, o4) then
e94f91e6b3 2024-02-03  104:     return o1
e94f91e6b3 2024-02-03  105:     end
e94f91e6b3 2024-02-03  106:   end
e94f91e6b3 2024-02-03  107: --~ 文
e94f91e6b3 2024-02-03  108: --~ 前缀
9942dfa51d 2024-02-04  109: function d.加前缀(o1, o2)
4d150d683b 2024-02-03  110:   return (o2 or "") .. o1
4d150d683b 2024-02-03  111:   end
4d150d683b 2024-02-03  112: --~ 文
4d150d683b 2024-02-03  113: --~ 后缀
9942dfa51d 2024-02-04  114: function d.加后缀(o1, o2)
4d150d683b 2024-02-03  115:   return o1 .. (o2 or "")
4d150d683b 2024-02-03  116:   end
4d150d683b 2024-02-03  117: --~ 令
9942dfa51d 2024-02-04  118: function d.办令(o1)
4d150d683b 2024-02-03  119:   print(o1)
4d150d683b 2024-02-03  120:   os.execute(o1)
4d150d683b 2024-02-03  121:   end
4d150d683b 2024-02-03  122: --~ 文
4d150d683b 2024-02-03  123: --~ 前缀
9942dfa51d 2024-02-04  124: function d.全筛前缀(o1, o2)
4d150d683b 2024-02-03  125:   if string.sub(o1, 1, #o2) == o2 then
4d150d683b 2024-02-03  126:     return o1
4d150d683b 2024-02-03  127:     end
4d150d683b 2024-02-03  128:   end
4d150d683b 2024-02-03  129: --~ 文
4d150d683b 2024-02-03  130: --~ 后缀
9942dfa51d 2024-02-04  131: function d.全筛后缀(o1, o2)
168300f866 2024-02-03  132:   if string.sub(o1, -#o2) == o2 then
168300f866 2024-02-03  133:     return o1
168300f866 2024-02-03  134:     end
168300f866 2024-02-03  135:   end
0ebfa0e128 2024-02-04  136: --~ 目对
9942dfa51d 2024-02-04  137: function d.用令行工具操文件(o1_0)
4e48ffd0e5 2024-02-03  138:   local k1_9
4e48ffd0e5 2024-02-03  139:   --~ 令行排
9942dfa51d 2024-02-04  140:   k1_9 = d.历文(o1_0.文件目, 简文件库.dir)
9942dfa51d 2024-02-04  141:   k1_9 = d.历排(k1_9, d.全筛后缀, o1_0.文件类)
0ebfa0e128 2024-02-04  142:   for o1 = 1, #k1_9 do
9942dfa51d 2024-02-04  143:     k1_9[o1] = d.加前缀(k1_9[o1], o1_0.文件目)
9942dfa51d 2024-02-04  144:     k1_9[o1] = d.加前缀(k1_9[o1], [["]])
9942dfa51d 2024-02-04  145:     k1_9[o1] = d.加后缀(k1_9[o1], [["]])
9942dfa51d 2024-02-04  146:     k1_9[o1] = d.加前缀(k1_9[o1], o1_0.令行前缀)
9942dfa51d 2024-02-04  147:     d.办令(k1_9[o1])
4e48ffd0e5 2024-02-03  148:     end
4e48ffd0e5 2024-02-03  149:   end
4e48ffd0e5 2024-02-03  150: --~ 文件路
4e48ffd0e5 2024-02-03  151: --~ 式
9942dfa51d 2024-02-04  152: function d.读文件(o1, o2)
4e48ffd0e5 2024-02-03  153:   local k1
4e48ffd0e5 2024-02-03  154:   local k1_3
4e48ffd0e5 2024-02-03  155:   --~ 文件
4e48ffd0e5 2024-02-03  156:   k1_3 = io.open(o1, o2 or "r")
4e48ffd0e5 2024-02-03  157:   --~ 文
4e48ffd0e5 2024-02-03  158:   k1 = k1_3:read("a")
4e48ffd0e5 2024-02-03  159:   k1_3:flush()
4e48ffd0e5 2024-02-03  160:   k1_3:close()
4e48ffd0e5 2024-02-03  161:   return k1
4e48ffd0e5 2024-02-03  162:   end
4e48ffd0e5 2024-02-03  163: --~ 常量排
9942dfa51d 2024-02-04  164: function d.加对限(o1_0)
b92c73c8f3 2024-02-04  165:   table.insert(o1_0, 1, "local k1_0 = {}")
b92c73c8f3 2024-02-04  166:   table.insert(o1_0, "return k1_0")
b92c73c8f3 2024-02-04  167:   return table.concat(o1_0, "\n")
4e48ffd0e5 2024-02-03  168:   end
4e48ffd0e5 2024-02-03  169: --~ 文
4e48ffd0e5 2024-02-03  170: --~ 文件路
4e48ffd0e5 2024-02-03  171: --~ 式
9942dfa51d 2024-02-04  172: function d.写文件(o1, o2, o3)
168300f866 2024-02-03  173:   local k1_3
168300f866 2024-02-03  174:   --~ 文件
168300f866 2024-02-03  175:   k1_3 = io.open(o2, o3 or "w")
168300f866 2024-02-03  176:   k1_3:write(o1)
168300f866 2024-02-03  177:   k1_3:flush()
168300f866 2024-02-03  178:   k1_3:close()
168300f866 2024-02-03  179:   end
1b64e61bc7 2024-02-04  180: --~ 文
9942dfa51d 2024-02-04  181: function d.删左右空白(o1)
168300f866 2024-02-03  182:   o1 = string.gsub(o1, "^%s+", "")
168300f866 2024-02-03  183:   return string.gsub(o1, "%s+$", "")
f4c48d2eb7 2024-02-05  184:   end
f4c48d2eb7 2024-02-05  185: --~ 对
f4c48d2eb7 2024-02-05  186: --~ 对
f4c48d2eb7 2024-02-05  187: function d.连两对(o1_0, o2_0)
f4c48d2eb7 2024-02-05  188:   for o3_0, o4_0 in pairs(o2_0) do
f4c48d2eb7 2024-02-05  189:     o1_0[o3_0] = o4_0
f4c48d2eb7 2024-02-05  190:     end
f4c48d2eb7 2024-02-05  191:   return o1_0
f4c48d2eb7 2024-02-05  192:   end
f4c48d2eb7 2024-02-05  193: --~ 键
f4c48d2eb7 2024-02-05  194: --~ 值
f4c48d2eb7 2024-02-05  195: function d.修对类(o1_0, o2_0)
f4c48d2eb7 2024-02-05  196:   if tonumber(o1_0) then
f4c48d2eb7 2024-02-05  197:     return tonumber(o1_0), o2_0
f4c48d2eb7 2024-02-05  198:   else
f4c48d2eb7 2024-02-05  199:     return o1_0, o2_0
f4c48d2eb7 2024-02-05  200:     end
f4c48d2eb7 2024-02-05  201:   end
f4c48d2eb7 2024-02-05  202: do
f4c48d2eb7 2024-02-05  203:   --~ 加数
f4c48d2eb7 2024-02-05  204:   local k1 = 0
f4c48d2eb7 2024-02-05  205:   function d.递增()
f4c48d2eb7 2024-02-05  206:     k1 = k1 + 1
f4c48d2eb7 2024-02-05  207:     return k1
f4c48d2eb7 2024-02-05  208:     end
f4c48d2eb7 2024-02-05  209:   end
f4c48d2eb7 2024-02-05  210: --~ 左加数
f4c48d2eb7 2024-02-05  211: --~ 右加数
f4c48d2eb7 2024-02-05  212: function d.加法(o1, o2)
f4c48d2eb7 2024-02-05  213:   return o1 + o2
f4c48d2eb7 2024-02-05  214:   end
f4c48d2eb7 2024-02-05  215: --~ 左减数
f4c48d2eb7 2024-02-05  216: --~ 右减数
f4c48d2eb7 2024-02-05  217: function d.减法(o1, o2)
f4c48d2eb7 2024-02-05  218:   return o1 - o2
f4c48d2eb7 2024-02-05  219:   end
f4c48d2eb7 2024-02-05  220: --~ 左乘数
f4c48d2eb7 2024-02-05  221: --~ 右乘数
f4c48d2eb7 2024-02-05  222: function d.乘法(o1, o2)
f4c48d2eb7 2024-02-05  223:   return o1 * o2
f4c48d2eb7 2024-02-05  224:   end
f4c48d2eb7 2024-02-05  225: --~ 左除数
f4c48d2eb7 2024-02-05  226: --~ 右除数
f4c48d2eb7 2024-02-05  227: function d.除法(o1, o2)
f4c48d2eb7 2024-02-05  228:   return o1 / o2
7a7894a746 2024-02-05  229:   end
7a7894a746 2024-02-05  230: --~ 左数
7a7894a746 2024-02-05  231: --~ 右数
7a7894a746 2024-02-05  232: function d.位和(o1, o2)
7a7894a746 2024-02-05  233:   return bit.band(o1, o2)
6bd570d52a 2024-02-05  234:   end
91958121fe 2024-02-05  235: --~ 数
91958121fe 2024-02-05  236: --~ 右移几位
91958121fe 2024-02-05  237: function d.位右移(o1, o2)
91958121fe 2024-02-05  238:   return bit.rshift(o1, o2)
91958121fe 2024-02-05  239:   end
c4461ce231 2024-02-05  240: --~ 键
c4461ce231 2024-02-05  241: --~ 最大值
c4461ce231 2024-02-05  242: --~ 键
c4461ce231 2024-02-05  243: --~ 值
c4461ce231 2024-02-05  244: function d.筛对中最大值(o1, o2, o3, o4)
abd9f389ae 2024-02-05  245:   if o2 < o4 then
abd9f389ae 2024-02-05  246:     return true
c4461ce231 2024-02-05  247:     end
c4461ce231 2024-02-05  248:   end
c4461ce231 2024-02-05  249: --~ 最短键
abd9f389ae 2024-02-05  250: --~ 值
c4461ce231 2024-02-05  251: --~ 键
c4461ce231 2024-02-05  252: --~ 值
c4461ce231 2024-02-05  253: function d.筛对中最短键(o1, o2, o3, o4)
abd9f389ae 2024-02-05  254:   if #o1 > #o3 then
abd9f389ae 2024-02-05  255:     return true
c4461ce231 2024-02-05  256:     end
c4461ce231 2024-02-05  257:   end
c4461ce231 2024-02-05  258: --~ 最短文
c4461ce231 2024-02-05  259: --~ 值
c4461ce231 2024-02-05  260: function d.筛排中最短文(o1, o2)
abd9f389ae 2024-02-05  261:   if #o1 > #o2 then
abd9f389ae 2024-02-05  262:     return true
c4461ce231 2024-02-05  263:     end
91958121fe 2024-02-05  264:   end
91958121fe 2024-02-05  265: --~ 内数
91958121fe 2024-02-05  266: function d.to_uint64(o1)
91958121fe 2024-02-05  267:   local uint64_pointer = ffi.new("uint64_t[1]", o1)
91958121fe 2024-02-05  268:   return uint64_pointer[0]
c4461ce231 2024-02-05  269:   end
c4461ce231 2024-02-05  270: --~ 键
c4461ce231 2024-02-05  271: --~ 值
c4461ce231 2024-02-05  272: --~ 要找的值
c4461ce231 2024-02-05  273: function d.全等筛对中值(o1, o2, o3)
c4461ce231 2024-02-05  274:   if o2 == o3 then
c4461ce231 2024-02-05  275:     return o1, o2
c4461ce231 2024-02-05  276:   else
c4461ce231 2024-02-05  277:     end
9942dfa51d 2024-02-04  278:   end
9942dfa51d 2024-02-04  279: return d