void doThings(lua_State* L) { ///////// create the meta table for character class ///////// luaL_newmetatable(L, "UnitMT"); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); lua_pushcfunction(L, function_unit_getDamage); lua_setfield(L, -2, "getDamage"); lua_pushcfunction(L, function_unit_dealtDamage); lua_setfield(L, -2, "dealtDamage"); lua_pushcfunction(L, function_unit_health); lua_setfield(L, -2, "health"); lua_pop(L, 1); // // // // // create new meta table for Character luaL_newmetatable(L, "CharacterMT"); // set the meta table of the character meta table to be itself // lua_pushvalue(L, -1); // instead of referencing itself, we reference the unit mt as "parent" luaL_getmetatable(L, "UnitMT"); lua_setfield(L, -2, "__index"); // pop the meta table from the stack lua_pop(L, 1); // create the 2 character Character attacker("Attacker", 3, 10); Unit defender(1, 20); // print the state before the call std::cout << "[C++] [Before damage] Attacker Hp : " << attacker.health << " Defender Hp : " << defender.health << std::endl; std::cout << "[C++] Calling damage function from lua" << std::endl; // manually do it here, to test the polymorphism // put the function on the stack lua_getglobal(L, "applyDamage"); // create a new user data on the stack, and assign the attacker pointer to it putCharacter(L, attacker); // create a new user data on the stack, and assign the defender pointer to it putUnit(L, defender); // call the function lua_call(L, 2, 0); // shouldn't have anything to pop assert(lua_gettop(L) == 0); // print the state after the call std::cout << "[C++] [After damage] Attacker Hp : " << attacker.health << " Defender Hp : " << defender.health << std::endl; lua_getglobal(L, "testcharacter"); putCharacter(L, attacker); lua_call(L, 1, 0); lua_getglobal(L, "testcharacter"); putUnit(L, defender); lua_call(L, 1, 0); }
void testFullyExpandLiveStoneIntoGroup() { int boardWidth = 9; BitBoard stonesWithLiberties(boardWidth); BitBoard defender(boardWidth); defender.putStone(9, 'a'); complexOpps::fullyExpandLiveStoneIntoGroup(&stonesWithLiberties, &defender); if (stonesWithLiberties.bitCount()>0) { cout << "fail: testFullyExpandLiveStoneIntoGroup" << endl; } else { cout << "pass: testFullyExpandLiveStoneIntoGroup" << endl; } }
void testFindStonesAdjacentLiberties() { int boardWidth = 9; BitBoard liberties(boardWidth); BitBoard defender(boardWidth); defender.putStone(9, 'a'); BitBoard* stonesAdjLibs = complexOpps::findStonesAdjacentLiberties(&liberties, &defender); if (stonesAdjLibs->bitCount()>0) { cout << "fail: testFindStonesAdjacentLiberties" << endl; } else { cout << "pass: testFindStonesAdjacentLiberties" << endl; } delete stonesAdjLibs; }
void testFindStonesWithLiberties() { int boardWidth = 9; BitBoard attacker(boardWidth); attacker.putStone(8, 'a'); attacker.putStone(9, 'b'); BitBoard defender(boardWidth); defender.putStone(9, 'a'); BitBoard* stonesWithLibs = complexOpps::findStonesWithLiberties(&attacker, &defender); if (stonesWithLibs->bitCount()>0) { cout << "fail: testFindStonesWithLiberties" << endl; } else { cout << "pass: testFindStonesWithLiberties" << endl; } delete stonesWithLibs; }
void testFindLibertiesAdjacentStones() { int boardWidth = 9; BitBoard attacker(boardWidth); attacker.putStone(8, 'a'); attacker.putStone(9, 'b'); BitBoard defender(boardWidth); defender.putStone(9, 'a'); BitBoard* libsAdjStones = complexOpps::findLibertiesAdjacentStones(&defender, &attacker); if (libsAdjStones->bitCount()>0) { cout << "fail: testFindLibertiesAdjacentStones" << endl; } else { cout << "pass: testFindLibertiesAdjacentStones" << endl; } delete libsAdjStones; }
// Write your strategy here in game function. // You can also make new functions and call them from game function. void game(BeliefState *state) { //curTeamState->Enter(curPlayerStates); curTeamState->Act(state, curPlayerStates); int i; for (i = 1; i < 3; ++i) { //std::string s = curPlayerStates[i]->StateName(); //print("%s", s); curPlayerStates[i]->StateName(); PlayerSt * newPlSt = curPlayerStates[i]->Act(state); if (newPlSt != NULL) { //changePlayerState(curPlayerStates, i, newPlSt); curPlayerStates[i] = newPlSt; curPlayerStates[i]->Act(state); } } return; //storePositions(state); //attacker(state,2); for (int i = 0; i < 5; i++) { //state->homeAngle[i] = acos(state->homeVel[i].dot(Vector2D<float>(0, 1)) / state->homeVel[i].abs()); } if (state->ballPos.x >= -100) { if (Vec2D::dist(state->homePos[2], state->ballPos) < Vec2D::dist(state->homePos[1], state->ballPos)) { attacker_id = 2; supporter_id = 1; } else { attacker_id = 1; supporter_id = 2; } attacker(state, attacker_id); attacksupporter(state, supporter_id); } else { if (Vec2D::dist(state->homePos[2], state->ballPos) < Vec2D::dist(state->homePos[1], state->ballPos)) { defender(state, 1); attacker(state, 2); } else { defender(state, 2); attacker(state, 1); } } goalkeeper(state,0); Vec2D bp = state->ballPos; /* if (state->pr_balInOurCorner) { int closestBotId = state->ourBotNearestToBall; GoToPoint(1, state, state->homePos[0], 0, true, true); } if (Vec2D::dist(prevPos[2], state->homePos[2]) < 2) { Vec2D newPos = state->homePos[2]; newPos.x += rand() % 5; newPos.y += rand() % 5; GoToPoint(2, state, newPos, 0, true, true); } if (Vec2D::dist(prevPos[1], state->homePos[1]) < 2) { Vec2D newPos = state->homePos[1]; newPos.x += rand() % 5; newPos.y += rand() % 5; GoToPoint(1, state, newPos, 0, true, true); } */ }