Example #1
0
void simulation::resolve_collisons() {
	std::string srcname, tgtname;
	while ( find_collison(srcname, tgtname) ) {
		car &source = cars[srcname];
		car &target = cars[tgtname];
		target.x = source.x + 0.25*(source.length + target.length) + 0.000000001;
		correct_x(target);
		std::swap(source.v, target.v);
	}
}
Example #2
0
int sign_point(int x, int y, char a)
{
	int i = 0;
	int j = 0;

	i = correct_x(x);
	j = correct_y(y);

	point_state[i + j*Size_X] = a;    // a is 1 or 2 :signed who place the chessman
//	printf("x = %d\ty = %d\twho = %d\n",i,j,point_state[i + j*Size_X])	;
	return 0;
}
Example #3
0
void simulation::update_one_step(car& ic) {
	double radius = fabs(piecerad.getRad(ic.p, ic.startLane, ic.endLane, ic.x));
	double alpha = - 0.00125*ic.v*ic.angle- 0.1*ic.w;
	double torque = 0;
	if (pieces[ic.p].type == CURVED && ic.v > (0.3/A)*sqrt(radius)) {
		if (pieces[ic.p].angle > 0) 	torque = A/sqrt(radius)*ic.v*ic.v - 0.3*ic.v;
		else							torque = - A/sqrt(radius)*ic.v*ic.v + 0.3*ic.v;
	}
	alpha += torque;
	ic.w += alpha;
	ic.angle += ic.w;

	double a;
	if (ic.onTurbo) 		a = k1*ic.throttle*turboFactor - k2*ic.v;
	else					a = k1*ic.throttle - k2*ic.v;
	ic.v += a;
	ic.x += ic.v;

	correct_x(ic);
}