最近为了解决skynet的跑得快ai的核心算法性能问题,那么我们自然就用C来写核心算法,之前从来没做过二维数组交互,也是折腾了一番才能正常理解与运行。先看示例代码
//数组计算加一返回数组
int GetCardCal(lua_State* L)
{
int arrayNum[20][20] = { 0 };
lua_pushnil(L);
int index = lua_gettop(L)-1;
luaL_checktype(L, index, LUA_TTABLE); //检测传递过来的是否为table
int indexA = 0;
while (lua_next(L, index)) {
int tempindex = lua_gettop(L);
lua_pushnil(L);
int count = 0;
while (lua_next(L, tempindex)) {
int card = luaL_checkinteger(L, -1);
arrayNum[indexA][count++] = card;
lua_pop(L, 1); // pop value
}
indexA++;
lua_pop(L, 1); // pop value
}
for (int i = 0; i < 20;i++)
{
for (int j = 0; j < 20; j++)
{
if (arrayNum[i][j]>0)
{
arrayNum[i][j]++;
}
}
}
lua_newtable(L);
lua_newtable(L);
int arrayIndex1 = 1;
for (int i = 0; i < 20; i++)
{
if (arrayNum[i][0]==0)
{