Beispiel #1
0
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);
}
Beispiel #2
0
void *attacker_t(void* data) //@ : pthread_run_joinable
  //@ requires pthread_run_pre(attacker_t)(data, ?info);
  //@ ensures false;
{
  //@ open pthread_run_pre(attacker_t)(data, info);
  struct ss_auth_args *args = (void*) data;
  attacker(args->attacker, args->keypair);
  return 0;
}
Beispiel #3
0
void run(const char *log_path, unsigned int text_max)
{
	LogHelper log_helper(log_path);

	AttackProgram attacker(text_max);
	CryptoProgram crypto;

	crypto.random_key();

	attacker.attack(crypto);
	attacker.last_round_key_recover();
	attacker.secret_key_recover();
}
Beispiel #4
0
void Critter::MaybeReproduce(std::list<Critter *> &group) {
  if (!attacker() && food >= 0.5 && ofRandomuf() < reproductivity() && group.size() < kMaxPopulation) {
    area *= kChildScaleFactor;
    food -= 0.5;
    age = 0;
    const ofVec2f epsilon = ofVec2f(0.1, 0.1);
    Critter *critter = new Critter(player, 0, mass, area, position + epsilon, velocity);
    group.push_back(critter);
  }
  const float cell_mortality = radius() <= kBreederSize ? mortality() : kWallMortality;
  if (ofRandomuf() < cell_mortality * age * age * age) {
    area = 0;
  }
}
Beispiel #5
0
void *attacker_t(void* data) //@ : pthread_run_joinable
  //@ requires pthread_run_pre(attacker_t)(data, ?info);
  //@ ensures  false;
{
  while(true)
    //@ invariant pthread_run_pre(attacker_t)(data, info);
  {
    //@ open pthread_run_pre(attacker_t)(data, info);
    //@ close enc_then_hmac_proof_pred();
    attacker();
    //@ open enc_then_hmac_proof_pred();
    //@ close pthread_run_pre(attacker_t)(data, info);
  }
   
  return 0;
}
Beispiel #6
0
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;
}
Beispiel #7
0
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;
}
Beispiel #8
0
  // 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);
	  }
	  */
  }
Beispiel #9
0
void symbolic_attacker(int attacker_id, struct keypair* keypair)
  /*@ requires [?f]world(?pub, ?key_clsfy) &*&
               true == bad(attacker_id) &*&
               principal(attacker_id, ?count) &*&
               keypair(keypair, attacker_id, ?id, ?info, pub); @*/
  //@ ensures false;
{
  //@ retreive_proof_obligations();

  for (;;)
    /*@ invariant [f]world(pub, key_clsfy) &*&
                  proof_obligations(pub) &*&
                  principal(attacker_id, _) &*&
                  keypair(keypair, attacker_id, id, info, pub); @*/
  {
    struct network_status *net_stat = 0;
    int net_choise = random_int_();
    int port = random_int_();
    if (net_choise % 2 == 0)
      net_stat = network_bind_and_accept(port % 65536);
    else
      net_stat = network_connect("localhost", port % 65536);

    {
      int action = random_int_();
      int *counter;
      switch (action % 13)
      {
        case 0:
          //@ open [f]world(pub, key_clsfy);
          //@ assert [_]is_key_classifier(_, pub, key_clsfy);
          //@ retreive_public_invariant_constraints(key_clsfy);
          //@ duplicate_lemma_function_pointer_chunk(key_classifier);
          /*@ {
                lemma void public_key_classifier(cryptogram key, int p, int c,
                                                bool symmetric)
                  requires polarssl_proof_pred(pub, key_clsfy)() &*&
                          [_]polarssl_pub(pub)(key) &*&
                          symmetric ?
                            key == cg_symmetric_key(p, c)
                          :
                            key == cg_private_key(p, c);
                  ensures polarssl_proof_pred(pub, key_clsfy)() &*&
                          col || true == key_clsfy(p, c, symmetric);
                {
                  open [_]polarssl_pub(pub)(key);
                  item k;
                  if (symmetric)
                    k = symmetric_key_item(p, c);
                  else
                    k = private_key_item(p, c);
                  
                  open polarssl_proof_pred(pub, key_clsfy)();
                  assert is_key_classifier(?proof, pub, key_clsfy);
                  proof(k, p, c, symmetric);
                  close polarssl_proof_pred(pub, key_clsfy)();
                }
                produce_lemma_function_pointer_chunk(public_key_classifier) :
                  public_key_classifier(polarssl_pub(pub), key_clsfy,
                                        polarssl_proof_pred(pub, key_clsfy))
                                        (key__, p__, c__, sym__)
                  { call(); }
                  {duplicate_lemma_function_pointer_chunk(public_key_classifier);};
              }
          @*/
          //@ close polarssl_proof_pred(pub, key_clsfy)();
          attacker();
          //@ open polarssl_proof_pred(pub, key_clsfy)();
          //@ close [f]world(pub, key_clsfy);
          //@ leak public_invariant_constraints(_, _);
          //@ leak is_public_key_classifier(_, _, _, _);
          //@ leak is_key_classifier(_, _, _);
          break;
        case 1:
          // Anyone can publish arbitrary data items...
          send_data(net_stat);
          break;
        case 2:
          // Anyone can create pairs of public items...
          send_pair_composed(net_stat);
          break;
        case 3:
         // Anyone can deconstruct a public pair...
          send_pair_decomposed(net_stat);
          break;
        case 4:
          // Bad principals can publish generated nonce items...
          send_nonce(net_stat);
          break;
        case 5:
          // Bad principals can increment public nonces...
          increment_and_send_nonce(net_stat);
          break;
        case 6:
          // Bad principals can leak their keys...
          send_keys(net_stat, keypair);
          break;
        case 7:
          // Anyone can hmac public payload with public key
          send_hmac(net_stat, keypair);
          break;
        case 8:
          // Anyone can symmteric encrypt public payload with public key
          send_symmetric_encrypted(net_stat, keypair);
          break;
        case 9:
          // Anyone can symmteric decrypt message with public key
          send_symmetric_decrypted(net_stat, keypair);
          break;
        case 10:
          // Anyone can asymmteric encrypt public payload with public key
          send_asymmetric_encrypted(net_stat, keypair);
          break;
        case 11:
          // Anyone can asymmteric decrypt message with public key
          send_asymmetric_decrypted(net_stat, keypair);
          break;
        case 12:
          // Anyone can asymmteric sign public payload with public key
          send_asymmetric_signature(net_stat, keypair);
      }
    }
    network_disconnect(net_stat);
  }
  //@ leak proof_obligations(pub);
}