Exemple #1
0
/**
 * @brief A simple, but effective AI function which will attack the player or other hostile creatures - or chase them if necessary!
 *
 * @param m The monster/actor which is performing this hostility.
 */
void hostile_ai(actor_t *m)
{
        int oy, ox;
        co c;

        oy = m->y;
        ox = m->x;

        if(m->attacker && next_to(m, m->attacker)) {
                attack(m, m->attacker);
                return;
        }

        if(next_to(m, player) && !is_invisible(player)) {
                m->attacker = player;
                attack(m, m->attacker);
                return;
        }

        if(actor_in_lineofsight(m, player)) {
                m->goalx = player->x;
                m->goaly = player->y;
        } else {
                m->attacker = NULL;
                do {
                        m->goalx = ri(1, world->curlevel->xsize-1);
                        m->goaly = ri(1, world->curlevel->ysize-1);
                } while(!monster_passable(world->curlevel, m->goaly, m->goalx));
        }

        c = get_next_step(m);
        if(c.x == 0 && c.y == 0) {
                return;
        } else {
                m->y = c.y;
                m->x = c.x;
                world->cmap[oy][ox].monster = NULL;
                world->cmap[m->y][m->x].monster = m;
        }
}
void heston_kernel_ml(const params_ml params, hls::stream<calc_t> &gaussian_rn1,
		hls::stream<calc_t> &gaussian_rn2, hls::stream<calc_t> &prices) {
	#pragma HLS interface ap_none port=params
	#pragma HLS resource core=AXI4LiteS metadata="-bus_bundle params" \
			variable=params
	#pragma HLS interface ap_fifo port=gaussian_rn1
	#pragma HLS resource core=AXI4Stream variable=gaussian_rn1
	#pragma HLS interface ap_fifo port=gaussian_rn2
	#pragma HLS resource core=AXI4Stream variable=gaussian_rn2
	#pragma HLS interface ap_fifo port=prices
	#pragma HLS resource core=AXI4Stream variable=prices
	#pragma HLS resource core=AXI4LiteS metadata="-bus_bundle params" \
			variable=return

	// write block size to stream
	prices.write(BLOCK_SIZE);

	state_t state_coarse[BLOCK_SIZE];
	#pragma HLS data_pack variable=state_coarse
	state_t state_fine[BLOCK_SIZE];
	#pragma HLS data_pack variable=state_fine
	w_both_t w_both[BLOCK_SIZE];
	#pragma HLS data_pack variable=w_both

	ap_uint<6> upper_j = params.ml_constant + (params.do_multilevel ? 1 : 0);

	for (uint32_t path = 0; path < params.path_cnt; path += BLOCK_SIZE) {
		for (uint32_t step = 0; step != params.step_cnt_coarse; ++step) {
			for (ap_uint<6> j = 0; j != upper_j; ++j) {
				for (ap_uint<10> block_i = 0; block_i != BLOCK_SIZE;
						++block_i) {
					#pragma HLS PIPELINE II=1

					bool is_fine = j != params.ml_constant;

					//
					// initialize
					//
					state_t l_state_coarse, l_state_fine;
					w_both_t l_w_both;
					if (step == 0 && j == 0) {
						l_state_coarse = get_init_state(params);
						l_state_fine = get_init_state(params);
						l_w_both = get_w_zero();
					} else {
						l_state_coarse = state_coarse[block_i];
						l_state_fine = state_fine[block_i];
						l_w_both = w_both[block_i];
					}

					//
					// calculate next step
					//
					state_t n_state_coarse, n_state_fine;
					w_both_t n_w_both;

					if (is_fine) {
						// step fine
						float w_stock = gaussian_rn1.read();
						float w_vola = gaussian_rn2.read();
						n_state_fine = get_next_step(params, l_state_fine,
								w_stock, w_vola, true);
						n_state_coarse = l_state_coarse;
						// accumulate random numbers
						n_w_both.w_stock = l_w_both.w_stock + w_stock;
						n_w_both.w_vola = l_w_both.w_vola + w_vola;
					} else {
						// step coarse
						n_state_coarse = get_next_step(params, l_state_coarse,
								l_w_both.w_stock, l_w_both.w_vola, false);
						n_state_fine = l_state_fine;
						n_w_both = get_w_zero();
					}

					state_coarse[block_i] = n_state_coarse;
					state_fine[block_i] = n_state_fine;
					w_both[block_i] = n_w_both;

					//
					// write out
					//
					if ((step + 1 == params.step_cnt_coarse) &&
							(j + 1 >= params.ml_constant)) {
						if (is_fine) {
							prices.write(get_log_price(n_state_fine));
						} else {
							prices.write(get_log_price(n_state_coarse));
						}
					}
				}
			}
		}
	}
}