Пример #1
0
/* suspiciously similar to ScanHash* from bitcoin */
bool scanhash_c(struct thr_info*thr, const unsigned char *midstate, unsigned char *data,
	        unsigned char *hash1, unsigned char *hash,
		const unsigned char *target,
	        uint32_t max_nonce, uint32_t *last_nonce,
		uint32_t n)
{
	uint32_t *hash32 = (uint32_t *) hash;
	uint32_t *nonce = (uint32_t *)(data + 76);
	unsigned long stat_ctr = 0;

	data += 64;

	while (1) {
		n++;
		*nonce = n;

		runhash(hash1, data, midstate);
		runhash(hash, hash1, sha256_init_state);

		stat_ctr++;

		if (unlikely((hash32[7] == 0) && fulltest(hash, target))) {
			*last_nonce = n;
			return true;
		}

		if ((n >= max_nonce) || thr->work_restart) {
			*last_nonce = n;
			return false;
		}
	}
}
Пример #2
0
/* suspiciously similar to ScanHash* from bitcoin */
bool scanhash_c(const unsigned char *midstate, unsigned char *data,
	        unsigned char *hash, const unsigned char *target,
	        uint32_t max_nonce, unsigned long *hashes_done)
{
	uint32_t *hash32 = (uint32_t *) hash;
	uint32_t *nonce = (uint32_t *)(data + 12);
	uint32_t n = 0;
	unsigned long stat_ctr = 0;


	while (1) {
		unsigned char hash1[32];

		n++;
		*nonce = n;

		runhash(hash1, data, midstate);
		runhash(hash, hash1, sha256_init_state);

		stat_ctr++;

		if ( hash32[7] == 0 && fulltest(hash, target) ) {
			*hashes_done = stat_ctr;
			return true;
		}

		if ((n >= max_nonce)) {
			*hashes_done = stat_ctr;
			return false;
		}
	}
}
Пример #3
0
/* suspiciously similar to ScanHash* from bitcoin */
bool scanhash_c(int thr_id, const unsigned char *midstate, unsigned char *data,
	        unsigned char *hash1, unsigned char *hash,
		const unsigned char *target,
	        uint32_t max_nonce, unsigned long *hashes_done)
{
	uint32_t *hash32 = (uint32_t *) hash;
	uint32_t *target32 = (uint32_t *) target;
	uint32_t *nonce = (uint32_t *)(data + 12);
	uint32_t n = 0;
	unsigned long stat_ctr = 0;

	work_restart[thr_id].restart = 0;

	printf("H <= %i\n", target32[7]);

	while (1) {
		n++;
		*nonce = n;

		runhash(hash1, data, midstate);
		runhash(hash, hash1, sha256_init_state);

		stat_ctr++;

		if (unlikely((swab32(hash32[7]) <= target32[7]) && fulltest(hash, target))) {
			*hashes_done = stat_ctr;
			return true;
		}

		if ((n >= max_nonce) || work_restart[thr_id].restart) {
			*hashes_done = stat_ctr;
			return false;
		}
	}
}
Пример #4
0
static void smooth_island(region_list * island)
{
    region *rn[MAXDIRECTIONS];
    region_list *rlist = NULL;
    for (rlist = island; rlist; rlist = rlist->next) {
        region *r = rlist->data;
        int n, nland = 0;

        if (r->land) {
            get_neighbours(r, rn);
            for (n = 0; n != MAXDIRECTIONS && nland <= 1; ++n) {
                if (rn[n]->land) {
                    ++nland;
                    r = rn[n];
                }
            }

            if (nland == 1) {
                get_neighbours(r, rn);
                oceans_around(r, rn);
                for (n = 0; n != MAXDIRECTIONS; ++n) {
                    int n1 = (n + 1) % MAXDIRECTIONS;
                    int n2 = (n + 1 + MAXDIRECTIONS) % MAXDIRECTIONS;
                    if (!rn[n]->land && rn[n1] != r && rn[n2] != r) {
                        r = rlist->data;
                        runhash(r);
                        runhash(rn[n]);
                        SWAP_INTS(r->x, rn[n]->x);
                        SWAP_INTS(r->y, rn[n]->y);
                        rhash(r);
                        rhash(rn[n]);
                        rlist->data = r;
                        oceans_around(r, rn);
                        break;
                    }
                }
            }
        }
    }
}
Пример #5
0
void free_regions(void)
{
    memset(uidhash, 0, sizeof(uidhash));
    while (deleted_regions) {
        region *r = deleted_regions;
        deleted_regions = r->next;
        free_region(r);
    }
    while (regions) {
        region *r = regions;
        regions = r->next;
        runhash(r);
        free_region(r);
    }
    max_index = 0;
    last = NULL;
}
Пример #6
0
void remove_region(region ** rlist, region * r)
{

    while (r->units) {
        unit *u = r->units;
        i_freeall(&u->items);
        remove_unit(&r->units, u);
    }

    runhash(r);
    unhash_uid(r);
    while (*rlist && *rlist != r)
        rlist = &(*rlist)->next;
    assert(*rlist == r);
    *rlist = r->next;
    r->next = deleted_regions;
    deleted_regions = r;
}
Пример #7
0
static void move_iceberg(region * r)
{
  attrib *a;
  direction_t dir;
  region *rc;

  a = a_find(r->attribs, &at_iceberg);
  if (!a) {
    dir = (direction_t) (rng_int() % MAXDIRECTIONS);
    a = a_add(&r->attribs, make_iceberg(dir));
  } else {
    if (rng_int() % 100 < 20) {
      dir = (direction_t) (rng_int() % MAXDIRECTIONS);
      a->data.i = dir;
    } else {
      dir = (direction_t) a->data.i;
    }
  }

  rc = rconnect(r, dir);

  if (rc && !fval(rc->terrain, ARCTIC_REGION)) {
    if (fval(rc->terrain, SEA_REGION)) {        /* Eisberg treibt */
      ship *sh, *shn;
      unit *u;
      int x, y;

      for (u = r->units; u; u = u->next)
        freset(u->faction, FFL_SELECT);
      for (u = r->units; u; u = u->next)
        if (!fval(u->faction, FFL_SELECT)) {
          fset(u->faction, FFL_SELECT);
          ADDMSG(&u->faction->msgs, msg_message("iceberg_drift",
              "region dir", r, dir));
        }

      x = r->x;
      y = r->y;

      runhash(r);
      runhash(rc);
      r->x = rc->x;
      r->y = rc->y;
      rc->x = x;
      rc->y = y;
      rhash(rc);
      rhash(r);

      /* rc ist der Ozean (Ex-Eisberg), r der Eisberg (Ex-Ozean) */

      /* Schiffe aus dem Zielozean werden in den Eisberg transferiert
       * und nehmen Schaden. */

      for (sh = r->ships; sh; sh = sh->next)
        freset(sh, SF_SELECT);

      for (sh = r->ships; sh; sh = sh->next) {
        /* Meldung an Kapitän */
        float dmg =
          get_param_flt(global.parameters, "rules.ship.damage.intoiceberg",
          0.10F);
        damage_ship(sh, dmg);
        fset(sh, SF_SELECT);
      }

      /* Personen, Schiffe und Gebäude verschieben */
      while (rc->buildings) {
        rc->buildings->region = r;
        translist(&rc->buildings, &r->buildings, rc->buildings);
      }
      while (rc->ships) {
        float dmg =
          get_param_flt(global.parameters, "rules.ship.damage.withiceberg",
          0.10F);
        fset(rc->ships, SF_SELECT);
        damage_ship(rc->ships, dmg);
        move_ship(rc->ships, rc, r, NULL);
      }
      while (rc->units) {
        building *b = rc->units->building;
        u = rc->units;
        u->building = 0; /* prevent leaving in move_unit */
        move_unit(rc->units, r, NULL);
        u_set_building(u, b); /* undo leave-prevention */
      }

      /* Beschädigte Schiffe können sinken */

      for (sh = r->ships; sh;) {
        shn = sh->next;
        if (fval(sh, SF_SELECT)) {
          u = ship_owner(sh);
          if (sh->damage >= sh->size * DAMAGE_SCALE) {
            if (u != NULL) {
              ADDMSG(&u->faction->msgs, msg_message("overrun_by_iceberg_des",
                  "ship", sh));
            }
            remove_ship(&sh->region->ships, sh);
          } else if (u != NULL) {
            ADDMSG(&u->faction->msgs, msg_message("overrun_by_iceberg",
                "ship", sh));
          }
        }
        sh = shn;
      }

    } else if (rng_int() % 100 < 20) {  /* Eisberg bleibt als Gletscher liegen */
      unit *u;

      rsetterrain(r, T_GLACIER);
      a_remove(&r->attribs, a);

      for (u = r->units; u; u = u->next)
        freset(u->faction, FFL_SELECT);
      for (u = r->units; u; u = u->next)
        if (!fval(u->faction, FFL_SELECT)) {
          fset(u->faction, FFL_SELECT);
          ADDMSG(&u->faction->msgs, msg_message("iceberg_land", "region", r));
        }
    }
  }
}
Пример #8
0
int scanhash_quark(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
	uint32_t max_nonce, unsigned long *hashes_done)
{
	uint32_t n = pdata[19] - 1;
	const uint32_t first_nonce = pdata[19];
	const uint32_t Htarg = ptarget[7];
//	unsigned long stat_ctr = 0;
	//unsigned char hash64[64];
	uint32_t hash64[8] __attribute__((aligned(32)));
	uint32_t endiandata[32];
	
//	char testdata[] = {"\x70\x00\x00\x00\x5d\x38\x5b\xa1\x14\xd0\x79\x97\x0b\x29\xa9\x41\x8f\xd0\x54\x9e\x7d\x68\xa9\x5c\x7f\x16\x86\x21\xa3\x14\x20\x10\x00\x00\x00\x00\x57\x85\x86\xd1\x49\xfd\x07\xb2\x2f\x3a\x8a\x34\x7c\x51\x6d\xe7\x05\x2f\x03\x4d\x2b\x76\xff\x68\xe0\xd6\xec\xff\x9b\x77\xa4\x54\x89\xe3\xfd\x51\x17\x32\x01\x1d\xf0\x73\x10\x00"};

	
	//we need bigendian data...
	//lessons learned: do NOT endianchange directly in pdata, this will all proff-of-works be considered as stale from minerd.... 
	int kk=0;
	for (; kk < 32; kk++)
	{
		be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]);
	};
	
/*	int jj = 0;
	for (jj=0;jj<80;jj++)
	{
		((uint8_t*)pdata)[jj] = testdata[jj];
	}
*/	
/*
	int ii=0;
	for (; ii < 128; ii++)
	{
		printf ("%.2x",((uint8_t*)pdata)[ii]);
	};
	printf ("\n");

	ii=0;
	for (; ii < 32; ii++)
	{
		printf ("%.8x ",((uint32_t*)pdata)[ii]);
	};
	printf ("\n");
    printf ("\n");
	
	ii=0;
	for (; ii < 32; ii++)
	{
		printf ("%.2x",((uint8_t*)ptarget)[ii]);
	};
	printf ("\n");
	ii=0;
	for (; ii < 8; ii++)
	{
		printf ("%.8x ",((uint32_t*)ptarget)[ii]);
	};
	printf ("\n");	
*/	
	if (opt_debug) {
	
		applog(LOG_DEBUG, "Thr: %02d, firstN: %08x, maxN: %08x, ToDo: %d", thr_id, first_nonce, max_nonce, max_nonce-first_nonce);
	}
	
//	exit(1);
	
	
	
	do {
	
		pdata[19] = ++n;
		be32enc(&endiandata[19], n); 
//		runhash(hash64, pdata);
		runhash(hash64, &endiandata);
        if (((hash64[7]&0xFFFFFF00)==0) && 
				fulltest(hash64, ptarget)) {
            *hashes_done = n - first_nonce + 1;
			return true;
		}
	} while (n < max_nonce && !work_restart[thr_id].restart);
	
	*hashes_done = n - first_nonce + 1;
	pdata[19] = n;
	return 0;
}