static PyObject *Py_table_join(PyObject *self, PyObject *args) { PyObject *ret = NULL; PyObject *id1 = NULL, *id2 = NULL, *m1 = NULL, *m2 = NULL; const char *join_type = NULL; try { PyObject *id1_, *id2_, *m1_, *m2_; if (! PyArg_ParseTuple(args, "OOOOs", &id1_, &id2_, &m1_, &m2_, &join_type)) throw E(PyExc_Exception, "Wrong number or type of args"); if ((id1 = PyArray_ContiguousFromAny(id1_, PyArray_UINT64, 1, 1)) == NULL) throw E(PyExc_Exception, "id1 is not a 1D uint64 NumPy array"); if ((id2 = PyArray_ContiguousFromAny(id2_, PyArray_UINT64, 1, 1)) == NULL) throw E(PyExc_Exception, "Could not cast the value of id2 to 1D NumPy array"); if ((m1 = PyArray_ContiguousFromAny(m1_, PyArray_UINT64, 1, 1)) == NULL) throw E(PyExc_Exception, "Could not cast the value of m1 to 1D NumPy array"); if ((m2 = PyArray_ContiguousFromAny(m2_, PyArray_UINT64, 1, 1)) == NULL) throw E(PyExc_Exception, "Could not cast the value of m2 to 1D NumPy array"); if (PyArray_DIM(m1, 0) != PyArray_DIM(m2, 0)) throw E(PyExc_Exception, "The sizes of len(m1) and len(m2) must be the same"); #define DATAPTR(type, obj) ((type*)PyArray_DATA(obj)) PyOutput o; table_join( o, DATAPTR(uint64_t, id1), PyArray_Size(id1), DATAPTR(uint64_t, id2), PyArray_Size(id2), DATAPTR(uint64_t, m1), DATAPTR(uint64_t, m2), PyArray_Size(m2), join_type ); #undef DATAPTR o.resize(o.size); ret = PyTuple_New(4); // because PyTuple will take ownership (and PyOutput will do a DECREF on destruction). Py_INCREF(o.o_idx1); Py_INCREF(o.o_idx2); Py_INCREF(o.o_idxLink); Py_INCREF(o.o_isnull); PyTuple_SetItem(ret, 0, (PyObject *)o.o_idx1); PyTuple_SetItem(ret, 1, (PyObject *)o.o_idx2); PyTuple_SetItem(ret, 2, (PyObject *)o.o_idxLink); PyTuple_SetItem(ret, 3, (PyObject *)o.o_isnull); } catch(const E& e) { ret = NULL; } Py_XDECREF(id1); Py_XDECREF(id2); Py_XDECREF(m1); Py_XDECREF(m2); return ret; }
int main() { int i; char temp[25]; int base[3]; // //创建一个牌桌 // GlobalTable *table = create_table(); // //创建三个玩家 // Player *player1 = create_player("user1"); // Player *player2 = create_player("user2"); // Player *player3 = create_player("user3"); // //三个玩家加入牌桌 // table_join(table, player1); // table_join(table, player2); // table_join(table, player3); // //给三个人发牌 // emitCard(player1->cards, player2->cards, player3->cards, base); // //有一个人叫地主,拿走三张牌 // call_banker(player1, base); // dumpPlayer(player1); // dumpPlayer(player2); // dumpPlayer(player3); // int cards[5] = {303,304,405,106,107}; // CardCombine *cc = getCardCombine(cards, 5); // printf("card type %d value %d\n", cc->type, cc->val); char command[20]; char arg[20]; int user_online = 0; Player *wait[10]; GlobalTable *table; while (1) { scanf("%s %s", command, arg); if (strcmp(command, "join")==0) { Player *p = create_player(arg); printf("welcome %s join\n", arg); wait[user_online] = p; user_online ++; if (user_online == 3) { printf("人数达到游戏数量\n"); table = create_table(); table_join(table, wait[user_online]); user_online--; table_join(table, wait[user_online]); user_online--; table_join(table, wait[user_online]); user_online--; printf("发牌完成\n"); emitCard(table->players[0]->cards, table->players[1]->cards, table->players[2]->cards, base); while (table->end == 0) { if (table->banker == null) { printf("是否叫地主?"); scanf("%s", command); if (strcmp(command, "yes")==0) { table->banker = table->players[table->playerTurn]; table->base *= 2; } } printf("welcome %s join\n", arg); } } } } return 0; }