Ejemplo n.º 1
0
void Chromosome::Mutation()
{
	srand(time(NULL));
	float ratio = Random_Ratio();

	if (ratio < MUTATION)
	{
		int number = Buy_Sell_Rule::LENGTH * 2 + Common_Rule::LENGTH;
		srand(time(NULL));
		int bit = Random_Int(number);

		if (bit < Buy_Sell_Rule::LENGTH)
		{
			int index = bit / Buy_Sell_Rule::GEN_LEN1;
			int shift = Buy_Sell_Rule::GEN_LEN1 - 1 - (bit % Buy_Sell_Rule::GEN_LEN1);

			buy.gen1[index] ^= 1 << shift;
		}
		else if(bit < Buy_Sell_Rule::LENGTH * 2)
		{
			bit -= Buy_Sell_Rule::LENGTH;

			int index = bit / Buy_Sell_Rule::GEN_LEN1;
			int shift = Buy_Sell_Rule::GEN_LEN1 - 1 - (bit % Buy_Sell_Rule::GEN_LEN1);

			sell.gen1[index] ^= 1 << shift;
		}
		else if(bit < Buy_Sell_Rule::LENGTH * 2 + Common_Rule::LENGTH)
		{
			bit -= Buy_Sell_Rule::LENGTH * 2;

			if (bit < Common_Rule::LENGTH1)
			{
				int index = bit / Common_Rule::GEN_LEN1;
				int shift = Common_Rule::GEN_LEN1 - 1 - (bit % Common_Rule::GEN_LEN1);

				common.gen1[index] ^= 1 << shift;
			}
			else if (bit < Common_Rule::LENGTH1 + Common_Rule::LENGTH2)
			{
				bit -= Common_Rule::LENGTH1;

				int index = bit / Common_Rule::GEN_LEN2;
				int shift = Common_Rule::GEN_LEN2 - 1 - (bit % Common_Rule::GEN_LEN2);

				common.gen2[index] ^= 1 << shift;
			}
			else if (bit < Common_Rule::LENGTH1 + Common_Rule::LENGTH2 + Common_Rule::LENGTH3)
			{
				bit -= Common_Rule::LENGTH1 + Common_Rule::LENGTH2;

				int index = bit / Common_Rule::GEN_LEN3;
				int shift = Common_Rule::GEN_LEN3 - 1 - (bit % Common_Rule::GEN_LEN3);

				common.gen3[index] ^= 1 << shift;
			}
		}
	}
}
Ejemplo n.º 2
0
BaseRoleData * JsonHelp::RandomBaseRoleData()
{
	int nCount = BaseRoleVector.size();

	int nRandom = Random_Int(0,nCount-1);

	return BaseRoleVector.at(nRandom);
}
Ejemplo n.º 3
0
//
//  Shuffle_String: C
//
// Randomize a string. Return a new string series.
// Handles both BYTE and UNICODE strings.
//
void Shuffle_String(REBVAL *value, bool secure)
{
    REBSTR *s = VAL_STRING(value);
    REBCNT idx = VAL_INDEX(value);

    REBCNT n;
    for (n = VAL_LEN_AT(value); n > 1;) {
        REBCNT k = idx + cast(REBCNT, Random_Int(secure)) % n;
        n--;
        REBUNI swap = GET_CHAR_AT(s, k);
        SET_CHAR_AT(s, k, GET_CHAR_AT(s, n + idx));
        SET_CHAR_AT(s, n + idx, swap);
    }
}
Ejemplo n.º 4
0
//
//  Shuffle_String: C
// 
// Randomize a string. Return a new string series.
// Handles both BYTE and UNICODE strings.
//
void Shuffle_String(REBVAL *value, REBOOL secure)
{
    REBCNT n;
    REBCNT k;
    REBSER *series = VAL_SERIES(value);
    REBCNT idx     = VAL_INDEX(value);
    REBUNI swap;

    for (n = VAL_LEN_AT(value); n > 1;) {
        k = idx + (REBCNT)Random_Int(secure) % n;
        n--;
        swap = GET_ANY_CHAR(series, k);
        SET_ANY_CHAR(series, k, GET_ANY_CHAR(series, n + idx));
        SET_ANY_CHAR(series, n + idx, swap);
    }
}
Ejemplo n.º 5
0
*/	void Shuffle_Block(REBVAL *value, REBFLG secure)
/*
***********************************************************************/
{
	REBCNT n;
	REBCNT k;
	REBCNT idx = VAL_INDEX(value);
	REBVAL *data = VAL_BLK(value);
	REBVAL swap;

	for (n = VAL_LEN(value); n > 1;) {
		k = idx + (REBCNT)Random_Int(secure) % n;
		n--;
		swap = data[k];
		data[k] = data[n + idx];
		data[n + idx] = swap;
	}
}
Ejemplo n.º 6
0
*/	void Shuffle_String(REBVAL *value, REBFLG secure)
/*
**		Randomize a string. Return a new string series.
**		Handles both BYTE and UNICODE strings.
**
***********************************************************************/
{
	REBCNT n;
	REBCNT k;
	REBSER *series = VAL_SERIES(value);
	REBCNT idx     = VAL_INDEX(value);
	REBUNI swap;

	for (n = VAL_LEN(value); n > 1;) {
		k = idx + (REBCNT)Random_Int(secure) % n;
		n--;
		swap = GET_ANY_CHAR(series, k);
		SET_ANY_CHAR(series, k, GET_ANY_CHAR(series, n + idx));
		SET_ANY_CHAR(series, n + idx, swap);
	}
}
Ejemplo n.º 7
0
//
//  Shuffle_Vector: C
//
void Shuffle_Vector(REBVAL *vect, REBOOL secure)
{
    REBCNT n;
    REBCNT k;
    REBU64 swap;
    REBYTE *data = SER_DATA_RAW(VAL_SERIES(vect));
    REBCNT type = VECT_TYPE(VAL_SERIES(vect));
    REBCNT idx = VAL_INDEX(vect);

    // We can do it as INTS, because we just deal with the bits:
    if (type == VTSF32) type = VTUI32;
    else if (type == VTSF64) type = VTUI64;

    for (n = VAL_LEN_AT(vect); n > 1;) {
        k = idx + (REBCNT)Random_Int(secure) % n;
        n--;
        swap = get_vect(type, data, k);
        set_vect(type, data, k, get_vect(type, data, n + idx), 0);
        set_vect(type, data, n + idx, swap, 0);
    }
}
Ejemplo n.º 8
0
void Chromosome::Crossover(Chromosome &c)
{
	srand(time(NULL));
	float ratio = Random_Ratio();

	if (ratio < CROSS_OVER)
	{
		int number = Buy_Sell_Rule::NUMBER * 2 + Common_Rule::NUMBER;
		srand(time(NULL));
		int divide = Random_Int(number);

		if (number >= Buy_Sell_Rule::NUMBER)
		{
			for (int i = 0; i < Buy_Sell_Rule::NUMBER1; i++)
			{
				unsigned int temp = buy.gen1[i];
				buy.gen1[i] = c.buy.gen1[i];
				c.buy.gen1[i] = temp;
			}
		}
		if (number >= Buy_Sell_Rule::NUMBER * 2)
		{
			for (int i = 0; i < Buy_Sell_Rule::NUMBER1; i++)
			{
				unsigned int temp = sell.gen1[i];
				sell.gen1[i] = c.sell.gen1[i];
				c.sell.gen1[i] = temp;
			}
		}
		if (number >= Buy_Sell_Rule::NUMBER * 2 + Common_Rule::NUMBER1)
		{
			for (int i = 0; i <= Common_Rule::NUMBER1; i++)
			{
				unsigned int temp = common.gen1[i];
				common.gen1[i] = c.common.gen1[i];
				c.common.gen1[i] = temp;
			}
		}
		if (number >= Buy_Sell_Rule::NUMBER * 2 + Common_Rule::NUMBER1 + Common_Rule::NUMBER2)
		{
			for (int i = 0; i <= Common_Rule::NUMBER2; i++)
			{
				unsigned int temp = common.gen2[i];
				common.gen2[i] = c.common.gen2[i];
				c.common.gen2[i] = temp;
			}
		}


		if (number < Buy_Sell_Rule::NUMBER)
		{
			for (int i = 0; i <= number; i++)
			{
				unsigned int temp = buy.gen1[i];
				buy.gen1[i] = c.buy.gen1[i];
				c.buy.gen1[i] = temp;
			}
		}
		else if (number < Buy_Sell_Rule::NUMBER * 2)
		{
			number -= Buy_Sell_Rule::NUMBER;
			for (int i = 0; i <= number; i++)
			{
				unsigned int temp = sell.gen1[i];
				sell.gen1[i] = c.sell.gen1[i];
				c.sell.gen1[i] = temp;
			}
		}
		else if (number < Buy_Sell_Rule::NUMBER * 2 + Common_Rule::NUMBER1)
		{
			number -= Buy_Sell_Rule::NUMBER * 2;
			for (int i = 0; i <= number; i++)
			{
				unsigned int temp = common.gen1[i];
				common.gen1[i] = c.common.gen1[i];
				c.common.gen1[i] = temp;
			}
		}
		else if (number < Buy_Sell_Rule::NUMBER * 2 + Common_Rule::NUMBER1 + Common_Rule::NUMBER2)
		{
			number -= Buy_Sell_Rule::NUMBER * 2 + Common_Rule::NUMBER1;
			for (int i = 0; i <= number; i++)
			{
				unsigned int temp = common.gen2[i];
				common.gen2[i] = c.common.gen2[i];
				c.common.gen2[i] = temp;
			}
		}
		else if (number < Buy_Sell_Rule::NUMBER * 2 + Common_Rule::NUMBER1 + Common_Rule::NUMBER2 + Common_Rule::NUMBER3)
		{
			number -= Buy_Sell_Rule::NUMBER * 2 + Common_Rule::NUMBER1 + Common_Rule::NUMBER2;
			for (int i = 0; i <= number; i++)
			{
				unsigned int temp = common.gen3[i];
				common.gen3[i] = c.common.gen3[i];
				c.common.gen3[i] = temp;
			}
		}
	}
}
Ejemplo n.º 9
0
void TMagicEff::Create(int id,int effnum,int sx,int sy,int tx,int ty,TMagicType mtype,
	bool Recusion,int anitime)
{
	ImgLib = nullptr;
	use16dir = false;
	useImgLib1 = false;
	switch(mtype)
	{
	case TMagicType::mtFly:
	case TMagicType::mtBujaukGroundEffect:
	case TMagicType::mtExploBujauk:
		{
			start = 0;
			frame = 6;
			curframe = start;
			FixedEffect = false;
			Repetition = Recusion;
			ExplosionFrame = 10;
			if(id == 38)
			{
				frame = 10;
			}
			if(id == 39)
			{
				frame = 4;
				ExplosionFrame = 8;
			}
			if(id == 63)
			{
				MagExplosionBase = 780;
				ExplosionFrame = 36;
			}
			if(id - 81 - 3 < 0)
			{
				bt80 = 1;
				Repetition = true;
				if(id == 81)
				{
					if(g_MySelf->m_nCurrX >= 84)
					{
						EffectBase = 130;
					}else
					{
						EffectBase = 140;
					}
					bt81 = 1;
				}
				if(id == 82)
				{
					if(g_MySelf->m_nCurrX >= 78 &&
						g_MySelf->m_nCurrY >= 48)
					{
						EffectBase = 150;
					}else
					{
						EffectBase = 160;
					}
					bt81 = 2;
				}
				if(id == 83)
				{
					EffectBase = 180;
					bt81 = 3;
				}
				start = 0;
				frame = 10;
				MagExplosionBase = 190;
				ExplosionFrame = 10;
			}
			break;
		}
	case TMagicType::mt12:
		{
			start = 0;
			frame = 6;
			curframe = start;
			FixedEffect = false;
			Repetition = Recusion;
			ExplosionFrame = 1;
			break;
		}
	case TMagicType::mt13:
		{
			start = 0;
			frame = 20;
			curframe = start;
			FixedEffect = true;
			Repetition = false;
			ExplosionFrame = 20;
			break;
		}
	case mtExplosion:
	case mtThunder:
	case mtLightingThunder:
		{
			start = 0;
			frame = -1;
			ExplosionFrame = 10;
			curframe = start;
			FixedEffect = true;
			Repetition = false;
			if(id == 80)
			{
				bt80 = 2;
				switch(Random_Int(0,6))
				{
				case 0:
				case 3:
					{
						EffectBase = 230;
						break;
					}
				case 1:
				case 4:
					{
						EffectBase = 240;
						break;
					}
				case 2:
				case 5:
					{
						EffectBase = 250;
						break;
					}
				}
				Light = 4;
				ExplosionFrame = 5;
			}
			if(id == 70)
			{
				bt80 = 3;
				switch(Random_Int(0,3))
				{
				case 0:
					{
						EffectBase = 400;
						break;
					}
				case 1:
					{
						EffectBase = 410;
						break;
					}
				case 2:
					{
						EffectBase = 420;
						break;
					}
				}
				Light = 4;
				ExplosionFrame = 5;
			}
			if(id == 71)
			{
				bt80 = 3;
				ExplosionFrame = 20;
			}
			if(id == 72)
			{
				bt80 = 3;
				Light = 3;
				ExplosionFrame = 10;
			}
			if(id == 73)
			{
				bt80 = 3;
				Light = 5;
				ExplosionFrame = 20;
			}
			if(id == 74)
			{
				bt80 = 3;
				Light = 4;
				ExplosionFrame = 35;
			}
			if(id == 90)
			{
				MagExplosionBase = 350;
				ExplosionFrame = 30;
			}
			break;
		}
	case TMagicType::mt14:
		{
			start = 0;
			frame = -1;
			curframe = start;
			FixedEffect = true;
			Repetition = false;
			break;
		}
	case TMagicType::mtFlyAxe:
		{
			start = 0;
			frame = 3;
			curframe = start;
			FixedEffect = false;
			Repetition = Recusion;
			ExplosionFrame = 3;
			break;
		}
	case TMagicType::mtFlyArrow:
		{
			start = 0;
			frame = 1;
			curframe = start;
			FixedEffect = false;
			Repetition = Recusion;
			ExplosionFrame = 1;
			break;
		}
	case TMagicType::mt15:
		{
			start = 0;
			frame = 6;
			curframe = start;
			FixedEffect = false;
			Repetition = Recusion;
			ExplosionFrame = 2;
			break;
		}
	case TMagicType::mt16:
		{
			start = 0;
			frame = 1;
			curframe = start;
			FixedEffect = false;
			Repetition = Recusion;
			ExplosionFrame = 1;
			break;
		}
	}
	int n7c = 0;
	ServerMagicId = id;
	EffectBase = effnum;
	targetx = tx;
	targety = ty;
	if(bt80 == 1)
	{
		if(id == 81)
		{
			sx -= 14; sy += 20;
		}
		if(id == 81)
		{
			sx -= 70; sy -= 10;
		}
		if(id == 83)
		{
			sx -= 60; sy -= 70;
		}
		PlaySound_(8208);
	}
	int tax,tay;
	fireX = sx;
	fireY = sy;
	FlyX = sx;
	FlyY = sy;
	OldFlyX = sx;
	OldFlyY = sy;
	FlyXf = sx;
	FlyYf = sy;
	FireMyselfX = g_MySelf->m_nRx * UNITX + g_MySelf->m_nShiftX;
	FireMyselfY = g_MySelf->m_nRy * UNITY + g_MySelf->m_nShiftY;
	if( bt80 == 0 )
	{
		MagExplosionBase = EffectBase + EXPLOSIONBASE;
	}
	Light = 1;
	if(fireX != targetx)
	{
		tax = abs(targetx - fireX);
	}else tax = 1;
	if(fireY != targety)
	{
		tay = abs(targety - fireY);
	}else tay = 1;
	if(abs(fireX - targetx) > abs(fireY - targety))
	{
		firedisX = int((targetx - fireX) * (500 / tax));
		firedisY = int((targety - fireY) * (500 / tax));
	}else
	{
		firedisX = int((targetx - fireX) * (500 / tay));
		firedisY = int((targety - fireY) * (500 / tay));
	}
	NextFrameTime = 50;
	m_dwFrameTime = GetTickCount();
	m_dwStartTime = GetTickCount();
	steptime = GetTickCount();
	repeattime = anitime;
	Dir16 = GetFlyDirection16(sx, sy, tx, ty);
	Dir8 = GetNextDirection(sx, sy, tx, ty);
	OldDir16 = Dir16;
	NextEffect = nullptr;
	m_boActive = true;
	prevdisx = 99999;
	prevdisy = 99999;

}