コード例 #1
0
ファイル: sort_stack.c プロジェクト: ftriquet/push_swap
void	sort_stack(t_stack *a, t_stack *b)
{
	int		min_max[2];

	if (g_v_opt)
		print_stacks(a, b);
	check_bottom(a, b);
	while (!check_top(a, b) || !check_last_push(a, b) || !empty(b))
	{
		if (get_min_max(a, min_max, min_max + 1) == 1)
			rot_to_min(a, b, min_max, 0);
		else
			rot_to_min(a, b, min_max, 1);
	}
}
コード例 #2
0
ファイル: check.c プロジェクト: kederiku/Reversi
int	verify_playable(char** map, int x, int y, int player)
{
	if (map[y][x] != 0)
		return -1;
	if (check_top(map, x, y, player) == 0)
		return 0;
	if (check_bottom(map, x, y, player) == 0)
		return 0;
	if (check_left(map, x, y, player) == 0)
		return 0;
	if (check_right(map, x, y, player) == 0)
		return 0;
	if (check_top_left(map, x, y, player) == 0)
		return 0;
	if (check_top_right(map, x, y, player) == 0)
		return 0;
	if (check_bottom_left(map, x, y, player) == 0)
		return 0;
	if (check_bottom_right(map, x, y, player) == 0)
		return 0;
	return -1;
}
コード例 #3
0
ファイル: column.cpp プロジェクト: cyrilmagsuci/freebsd
void column::justify(const justification_spec &js)
{
    check_bottom();
    js.justify(col, &bottom);
    check_bottom();
}
コード例 #4
0
ファイル: Server.cpp プロジェクト: elhobbs/spectre3ds
void Server::new_chase_dir(edict_t *actor, edict_t *enemy, float dist)
{
	float		deltax, deltay;
	float			d[3];
	float		tdir, olddir, turnaround;

	olddir = anglemod((int)(actor->v.ideal_yaw / 45) * 45);
	turnaround = anglemod(olddir - 180);

	deltax = enemy->v.origin[0] - actor->v.origin[0];
	deltay = enemy->v.origin[1] - actor->v.origin[1];
	if (deltax>10)
		d[1] = 0;
	else if (deltax<-10)
		d[1] = 180;
	else
		d[1] = DI_NODIR;
	if (deltay<-10)
		d[2] = 270;
	else if (deltay>10)
		d[2] = 90;
	else
		d[2] = DI_NODIR;

	// try direct route
	if (d[1] != DI_NODIR && d[2] != DI_NODIR)
	{
		if (d[1] == 0)
			tdir = d[2] == 90 ? 45 : 315;
		else
			tdir = d[2] == 90 ? 135 : 215;

		if (tdir != turnaround && step_direction(actor, tdir, dist))
			return;
	}

	// try other directions
	if (((rand() & 3) & 1) || abs(deltay)>abs(deltax))
	{
		tdir = d[1];
		d[1] = d[2];
		d[2] = tdir;
	}

	if (d[1] != DI_NODIR && d[1] != turnaround
		&& step_direction(actor, d[1], dist))
		return;

	if (d[2] != DI_NODIR && d[2] != turnaround
		&& step_direction(actor, d[2], dist))
		return;

	/* there is no direct path to the player, so pick another direction */

	if (olddir != DI_NODIR && step_direction(actor, olddir, dist))
		return;

	if (rand() & 1) 	/*randomly determine direction of search*/
	{
		for (tdir = 0; tdir <= 315; tdir += 45)
		if (tdir != turnaround && step_direction(actor, tdir, dist))
			return;
	}
	else
	{
		for (tdir = 315; tdir >= 0; tdir -= 45)
		if (tdir != turnaround && step_direction(actor, tdir, dist))
			return;
	}

	if (turnaround != DI_NODIR && step_direction(actor, turnaround, dist))
		return;

	actor->v.ideal_yaw = olddir;		// can't move

	// if a bridge was pulled out from underneath a monster, it may not have
	// a valid standing position at all

	if (!check_bottom(actor))
		fix_check_bottom(actor);

}
コード例 #5
0
ファイル: Server.cpp プロジェクト: elhobbs/spectre3ds
/*
=============
SV_movestep

Called by monster program code.
The move will be adjusted for slopes and stairs, but if the move isn't
possible, no move is done, false is returned, and
pr_global_struct->trace_normal is set to the normal of the blocking wall
=============
*/
bool Server::move_step(edict_t *ent, vec3_t move, bool relink)
{
	float		dz;
	vec3_t		oldorg, neworg, end;
	trace_t		trace;
	int			i;
	edict_t		*enemy;

	// try the move	
	VectorCopy(ent->v.origin, oldorg);
	VectorAdd(ent->v.origin, move, neworg);

	// flying monsters don't step up
	if ((int)ent->v.flags & (FL_SWIM | FL_FLY))
	{
		// try one move with vertical motion, then one without
		for (i = 0; i<2; i++)
		{
			VectorAdd(ent->v.origin, move, neworg);
			enemy = m_progs->prog_to_edict(ent->v.enemy);
			if (i == 0 && enemy != m_progs->m_edicts[0])
			{
				dz = ent->v.origin[2] - m_progs->prog_to_edict(ent->v.enemy)->v.origin[2];
				if (dz > 40)
					neworg[2] -= 8;
				if (dz < 30)
					neworg[2] += 8;
			}
			trace = SV_Move(ent->v.origin, ent->v.mins, ent->v.maxs, neworg, false, ent);

			if (trace.fraction == 1)
			{
				if (((int)ent->v.flags & FL_SWIM) && point_contents(trace.endpos) == CONTENTS_EMPTY)
					return false;	// swim monster left water

				VectorCopy(trace.endpos, ent->v.origin);
				if (relink)
					link_edict(ent, true);
				return true;
			}

			if (enemy == m_progs->m_edicts[0])
				break;
		}

		return false;
	}

	// push down from a step height above the wished position
	neworg[2] += STEPSIZE;
	VectorCopy(neworg, end);
	end[2] -= STEPSIZE * 2;

	trace = SV_Move(neworg, ent->v.mins, ent->v.maxs, end, false, ent);

	if (trace.allsolid)
		return false;

	if (trace.startsolid)
	{
		neworg[2] -= STEPSIZE;
		trace = SV_Move(neworg, ent->v.mins, ent->v.maxs, end, false, ent);
		if (trace.allsolid || trace.startsolid)
			return false;
	}
	if (trace.fraction == 1)
	{
		// if monster had the ground pulled out, go ahead and fall
		if ((int)ent->v.flags & FL_PARTIALGROUND)
		{
			VectorAdd(ent->v.origin, move, ent->v.origin);
			if (relink)
				link_edict(ent, true);
			ent->v.flags = (int)ent->v.flags & ~FL_ONGROUND;
			//	Con_Printf ("fall down\n"); 
			return true;
		}

		return false;		// walked off an edge
	}

	// check point traces down for dangling corners
	VectorCopy(trace.endpos, ent->v.origin);

	if (!check_bottom(ent))
	{
		if ((int)ent->v.flags & FL_PARTIALGROUND)
		{	// entity had floor mostly pulled out from underneath it
			// and is trying to correct
			if (relink)
				link_edict(ent, true);
			return true;
		}
		VectorCopy(oldorg, ent->v.origin);
		return false;
	}

	if ((int)ent->v.flags & FL_PARTIALGROUND)
	{
		//		Con_Printf ("back on ground\n"); 
		ent->v.flags = (int)ent->v.flags & ~FL_PARTIALGROUND;
	}
	ent->v.groundentity = m_progs->edict_to_prog(trace.ent);

	// the move is ok
	if (relink)
		link_edict(ent, true);
	return true;
}