void PokeTeam::load() { PokeGeneral::load(); /*set the default gender & ability */ if (genderAvail() == Pokemon::NeutralAvail) { gender() = Pokemon::Neutral; } else if (genderAvail() == Pokemon::FemaleAvail) { gender() = Pokemon::Female; } else if (genderAvail() == Pokemon::MaleAvail) { gender() = Pokemon::Male; } else { gender() = true_rand() % 2 ? Pokemon::Male : Pokemon::Female; } ability() = abilities().ab(0); nickname() = PokemonInfo::Name(num()); PokeGraphics::load(gender(), false); PokeGraphics::loadIcon(num()); }
void PokeTeam::load() { PokeGeneral::load(); /*set the default gender & ability */ if (genderAvail() == Pokemon::NeutralAvail) { gender() = Pokemon::Neutral; } else if (genderAvail() == Pokemon::FemaleAvail) { gender() = Pokemon::Female; } else if (genderAvail() == Pokemon::MaleAvail) { gender() = Pokemon::Male; } else { if (gender() == Pokemon::Neutral) { /* Gen 2 has to do with IVs, so since we set max Att IV by default, it's male */ gender() = gen() <= 2 ? Pokemon::Male : (true_rand() % 2 ? Pokemon::Male : Pokemon::Female); } } if (ability() == 0 || !abilities().contains(ability())) { ability() = abilities().ab(0); } /* Crashes on headless servers / etc otherwise */ if (PokemonInfoConfig::getFillMode() == FillMode::Client) { PokeGraphics::load(gender(), false); PokeGraphics::loadIcon(num()); } }
void test_int(int flag, int bits) { SshInt a, b, c, d, e, f; int j, k, i, l; ssh_mp_init(&a); ssh_mp_init(&b); ssh_mp_init(&c); ssh_mp_init(&d); ssh_mp_init(&e); ssh_mp_init(&f); printf(" * addition/subtraction test\n"); for (j = 0; j < 1000; j++) { true_rand(&a, bits); true_rand(&b, bits); ssh_mp_sub(&c, &a, &b); ssh_mp_add(&d, &c, &b); if (ssh_mp_cmp(&d, &a) != 0) { printf("error: subtraction/addition failed.\n"); print_int("a = ", &a); print_int("a' = ", &d); exit(1); } } printf(" * addition/multiplication test\n"); for (j = 0; j < 1000; j++) { true_rand(&a, bits); ssh_mp_set_ui(&b, 0); k = random() % 1000; for (i = 0; i < k; i++) ssh_mp_add(&b, &b, &a); ssh_mp_mul_ui(&c, &a, k); if (ssh_mp_cmp(&c, &b) != 0) { printf("error: addition/multiplication failed.\n"); print_int("a = ", &a); print_int("b = ", &b); print_int("c = ", &c); printf("k = %u\n", k); exit(1); } } printf(" * subtraction/multiplication test\n"); for (j = 0; j < 1000; j++) { true_rand(&a, bits); ssh_mp_set_ui(&b, 0); k = random() % 1000; for (i = 0; i < k; i++) ssh_mp_sub(&b, &b, &a); ssh_mp_neg(&c, &a); ssh_mp_mul_ui(&c, &c, k); if (ssh_mp_cmp(&c, &b) != 0) { printf("error: subtraction/multiplication failed.\n"); print_int("a = ", &a); print_int("b = ", &b); print_int("c = ", &c); printf("k = -%u\n", k); exit(1); } } printf(" * division test\n"); for (j = 0; j < 1000; j++) { true_rand(&a, bits); true_rand(&b, bits); if (ssh_mp_cmp_ui(&b, 0) == 0 || ssh_mp_cmp_ui(&a, 0) == 0) continue; ssh_mp_mul(&c, &a, &b); ssh_mp_div(&d, &e, &c, &b); ssh_mp_div(&e, &f, &c, &a); if (ssh_mp_cmp(&d, &a) != 0 || ssh_mp_cmp(&e, &b) != 0) { printf("error: division/multiplication failed.\n"); print_int("c = ", &c); print_int("a = ", &a); print_int("a' = ", &d); print_int("b = ", &b); print_int("b' = ", &e); exit(1); } } for (j = 0; j < 1000; j++) { true_rand(&a, bits); true_rand(&b, bits); if (ssh_mp_cmp_ui(&b, 0) == 0) continue; ssh_mp_div(&c, &d, &a, &b); ssh_mp_mul(&e, &c, &b); ssh_mp_add(&e, &e, &d); if (ssh_mp_cmp(&e, &a) != 0) { printf("error: division/multiplication failed (in second test).\n"); print_int("a = ", &a); print_int("a' = ", &e); exit(1); } } printf(" * multiplication test\n"); for (j = 0; j < 1000; j++) { true_rand(&a, bits); ssh_mp_mul(&b, &a, &a); ssh_mp_square(&c, &a); if (ssh_mp_cmp(&c, &b) != 0) { printf("error: multiplication/squaring failed.\n"); ssh_mp_dump(&a); ssh_mp_dump(&b); ssh_mp_dump(&c); print_int("a*a = ", &b); ssh_mp_dump(&b); print_int("a^2 = ", &c); ssh_mp_dump(&c); exit(1); } } printf(" * multiplication/gcd tests.\n"); for (j = 0; j < 1000; j++) { true_rand(&a, bits); true_rand(&b, bits); if (ssh_mp_cmp_ui(&a, 0) == 0 || ssh_mp_cmp_ui(&b, 0) == 0) continue; /* Make positive. */ ssh_mp_abs(&a, &a); ssh_mp_abs(&b, &b); ssh_mp_mul(&c, &a, &b); ssh_mp_gcd(&d, &c, &a); ssh_mp_gcd(&e, &c, &b); if (ssh_mp_cmp(&d, &a) != 0 || ssh_mp_cmp(&e, &b) != 0) { printf("error: multiplication/gcd failed.\n"); print_int("d = ", &d); print_int("a = ", &a); print_int("e = ", &e); print_int("b = ", &b); exit(1); } } printf(" * squaring test\n"); for (j = 0; j < 1000; j++) { true_rand(&a, bits); ssh_mp_square(&b, &a); ssh_mp_sqrt(&c, &b); ssh_mp_abs(&a, &a); if (ssh_mp_cmp(&a, &c) != 0) { printf("error: square root/squaring failed.\n"); print_int("a = ", &a); print_int("a' = ", &c); exit(1); } } printf(" * exponentiation test\n"); for (j = 0; j < 10; j++) { true_rand(&a, bits); ssh_mp_abs(&a, &a); if (ssh_mp_cmp_ui(&a, 3) < 0) continue; if ((ssh_mp_get_ui(&a) & 0x1) == 0) ssh_mp_add_ui(&a, &a, 1); k = random(); ssh_mp_set_ui(&b, k); ssh_mp_mod(&b, &b, &a); ssh_mp_set(&c, &b); for (i = 1; i < 100; i++) { ssh_mp_set_ui(&e, i); ssh_mp_powm_ui(&d, k, &e, &a); if (ssh_mp_cmp(&d, &c) != 0) { printf("error: powm ui/multiplication failed.\n"); print_int("mod = ", &a); printf("g = %u\n", k); printf("exp = %u\n", i); print_int("1 = ", &d); print_int("2 = ", &c); exit(1); } ssh_mp_mul(&c, &c, &b); ssh_mp_mod(&c, &c, &a); } } printf(" * full exponentiation test\n"); for (j = 0; j < 10; j++) { true_rand(&a, bits); ssh_mp_abs(&a, &a); if (ssh_mp_cmp_ui(&a, 3) < 0) continue; if ((ssh_mp_get_ui(&a) & 0x1) == 0) ssh_mp_add_ui(&a, &a, 1); k = random(); ssh_mp_set_ui(&b, k); ssh_mp_mod(&b, &b, &a); ssh_mp_set(&c, &b); for (i = 1; i < 100; i++) { ssh_mp_set_ui(&e, i); ssh_mp_powm(&d, &b, &e, &a); if (ssh_mp_cmp(&d, &c) != 0) { printf("error: powm/multiplication failed.\n"); print_int("mod = ", &a); print_int("g = ", &b); print_int("exp = ", &e); print_int("1 = ", &d); print_int("2 = ", &c); exit(1); } ssh_mp_mul(&c, &c, &b); ssh_mp_mod(&c, &c, &a); } } for (j = 0; j < 100; j++) { true_rand(&a, bits); ssh_mp_abs(&a, &a); if (ssh_mp_cmp_ui(&a, 3) < 0) continue; if ((ssh_mp_get_ui(&a) & 0x1) == 0) ssh_mp_add_ui(&a, &a, 1); k = random(); ssh_mp_set_ui(&b, k); true_rand(&e, bits); ssh_mp_powm(&c, &b, &e, &a); ssh_mp_powm_ui(&d, k, &e, &a); if (ssh_mp_cmp(&c, &d) != 0) { printf("error: powm/powm_ui failed!\n"); print_int("mod = ", &a); print_int("exp = ", &e); print_int("g = ", &b); print_int("1 = ", &c); print_int("2 = ", &d); exit(1); } } printf(" * kronecker-jacobi-legendre symbol tests\n"); for (j = 0; j < 100; j++) { static int table[100] = {1,1,1,1,-1,1,1,1,1,1,-1,-1,1,1,-1,1,1,1,-1,1,1,1,1,-1,1,-1,-1, 1,-1,1,1,-1,-1,1,1,1,-1,1,-1,-1,1,1,1,1,1,1,1,1,-1,-1,-1,1,1,-1, 1,-1,1,1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,1,1,1,1,1,-1,-1,-1,1,1,-1, 1,-1,-1,1,-1,1,1,1,1,1,-1,1,1,1,1,1,1,1,-1,-1}; ssh_mp_set_ui(&a, j + 3); ssh_mp_set_ui(&b, 7919); if (ssh_mp_kronecker(&a, &b) != table[j]) { printf("error: kronecker-jacobi-legendre symbol failed.\n"); print_int(" a =", &a); print_int(" b =", &b); printf(" assumed %d got %d\n", table[j], ssh_mp_kronecker(&a, &b)); exit(1); } } if (flag) { printf(" * prime tests\n"); for (j = 0; j < 10; j++) { printf(" - searching... [%u bit prime]\n", bits); true_rand(&a, bits); ssh_mp_abs(&a, &a); if (ssh_mp_next_prime(&a, &a) == FALSE) continue; printf(" - probable prime found\n"); print_int(" =", &a); printf(" - testing modular sqrt\n"); for (l = 0; l < 10; l++) { true_rand(&b, bits); ssh_mp_abs(&b, &b); if (ssh_mp_mod_sqrt(&d, &b, &a) == FALSE) continue; ssh_mp_mod(&b, &b, &a); ssh_mp_square(&c, &d); ssh_mp_mod(&c, &c, &a); if (ssh_mp_cmp(&c, &b) != 0) { printf("error: modular sqrt failed.\n"); print_int(" b =", &b); print_int(" c =", &c); print_int(" d =", &d); printf(" Kronecker says: %d\n", ssh_mp_kronecker(&b, &a)); exit(1); } } } } if (flag) { printf(" * square tests\n"); for (j = 0; j < 1000; j++) { true_rand(&a, bits); ssh_mp_square(&b, &a); if (ssh_mp_is_perfect_square(&b) == 0) { printf("error: square/perfect square failed.\n"); print_int("a = ", &a); print_int("a^2 = ", &b); ssh_mp_sqrt(&c, &b); print_int("a' = ", &c); exit(1); } } } if (flag) { printf(" * gcd/gcdext tests\n"); for (j = 0; j < 1000; j++) { true_rand(&a, bits); true_rand(&b, bits); if (ssh_mp_cmp_ui(&a, 0) == 0 || ssh_mp_cmp_ui(&b, 0) == 0) continue; ssh_mp_abs(&a, &a); ssh_mp_abs(&b, &b); ssh_mp_gcd(&c, &a, &b); if (ssh_mp_cmp_ui(&c, 1) == 0) { ssh_mp_gcdext(&d, &e, &f, &a, &b); if (ssh_mp_cmp(&d, &c) != 0) { printf("error: gcd/gcdext failed.\n"); exit(1); } ssh_mp_mul(&e, &a, &e); ssh_mp_mul(&f, &b, &f); ssh_mp_add(&f, &f, &e); if (ssh_mp_cmp(&f, &d) != 0) { printf("error: gcdext failed.\n"); exit(1); } } } } printf(" * conversion testing.\n"); for (i = 0; i < 1000; i++) { char *str; int base; do { base = random() % 65; } while (base < 2); true_rand(&a, bits); str = ssh_mp_get_str(NULL, base, &a); ssh_mp_set_str(&b, str, base); if (ssh_mp_cmp(&a, &b) != 0) { printf("error: conversion to integer failed in base %d.\n", base); print_int("a = ", &a); ssh_mp_dump(&a); print_int("b = ", &b); ssh_mp_dump(&b); printf("Output: %s\n", str); ssh_xfree(str); exit(1); } ssh_xfree(str); /* Test for automatic recognition. */ switch (random() % 3) { case 0: base = 8; break; case 1: base = 10; break; case 2: base = 16; break; } str = ssh_mp_get_str(NULL, base, &a); ssh_mp_set_str(&b, str, 0); if (ssh_mp_cmp(&a, &b) != 0) { printf("error: automatic recognition of base %d.\n", base); print_int("a = ", &a); ssh_mp_dump(&a); print_int("b = ", &b); ssh_mp_dump(&b); printf("Output: %s\n", str); ssh_xfree(str); exit(1); } ssh_xfree(str); } ssh_mp_clear(&a); ssh_mp_clear(&b); ssh_mp_clear(&c); ssh_mp_clear(&d); ssh_mp_clear(&e); ssh_mp_clear(&f); }