示例#1
0
//安全状态的判断函数
int safe(int location) {
    // 若状态安全则返回true
    if ((goat(location) == cabbage(location)) && (goat(location) != farmer(location)) )	 // 羊吃白菜
        return 0;

    if ((goat(location) == wolf(location)) && (goat(location) != farmer(location)))	 // 狼吃羊
        return 0;
    return 1;   // 其他状态是安全的
}
示例#2
0
文件: main1.c 项目: testfile2/Wolf
int			main(void)
{
	t_env	env;

	get_map_size(&env, "map");
	makeparams(&env);
	wolf(&env);
	mlx_hook(env.win, 2, (1L << 0), get_key_event, &env);
	mlx_loop(env.mlx);
	return (0);
}
示例#3
0
void
wolf::reproduce() {
  //++fertility;
  if (fertility < 1) return;
  if (!similars_around() ) return;

  wolf wf(grid, pos);
  std::thread wolf(wf);
  wolf.detach();
  fertility -= 1;
}
示例#4
0
文件: main1.c 项目: testfile2/Wolf
int		get_key_event(int keycode, t_env *env)
{
	double	olddirx;
	double	oldplanex;
	t_env	env1;

	if (keycode == 53)
	{
		free(env->img);
		free(env->data);
		exit(0);
	}
	if (keycode == 126)
	{
		mlx_clear_window(env->mlx, env->win);
		mlx_destroy_image(env->mlx, env->img);
		env->img = mlx_new_image(env->mlx, 800, 800);
		env->data = \
		mlx_get_data_addr(env->img, &env->bpp, &env->sizeline, &env->endian);
		if (env->worldmap[(int)(env->posX + env->dirX * 0.5)][(int)(env->posY)] == '0')
			env->posX += env->dirX * 0.5;
		if (env->worldmap[(int)(env->posX)][(int)(env->posY + env->dirY * 0.5)] == '0')
			env->posY += env->dirY * 0.5;
		env1 = *env;
		*env = env1;
		wolf(&env1);
	}
	if (keycode == 125)
	{
		mlx_clear_window(env->mlx, env->win);
		mlx_destroy_image(env->mlx, env->img);
		env->img = mlx_new_image(env->mlx, 800, 800);
		env->data = \
		mlx_get_data_addr(env->img, &env->bpp, &env->sizeline, &env->endian);
		if (env->worldmap[(int)(env->posX - env->dirX * 0.5)][(int)(env->posY)] == '0')
			env->posX -= env->dirX * 0.5;
		if (env->worldmap[(int)(env->posX)][(int)(env->posY - env->dirY * 0.5)] == '0')
			env->posY -= env->dirY * 0.5;
		env1 = *env;
		*env = env1;
		wolf(&env1);
	}
	if (keycode == 124)
	{
		mlx_clear_window(env->mlx, env->win);
		mlx_destroy_image(env->mlx, env->img);
		env->img = mlx_new_image(env->mlx, 800, 800);
		env->data = \
		mlx_get_data_addr(env->img, &env->bpp, &env->sizeline, &env->endian);
		olddirx = env->dirX;
		env->dirX = env->dirX * cos(-0.3) - env->dirY * sin(-0.3);
		env->dirY = olddirx * sin(-0.3) + env->dirY * cos(-0.3);
		oldplanex = env->planeX;
		env->planeX = env->planeX * cos(-0.3) - env->planeY * sin(-0.3);
		env->planeY = oldplanex * sin(-0.3) + env->planeY * cos(-0.3);
		env1 = *env;
		*env = env1;
		wolf(&env1);
	}
	if (keycode == 123)
	{
		mlx_clear_window(env->mlx, env->win);
		mlx_destroy_image(env->mlx, env->img);
		env->img = mlx_new_image(env->mlx, 800, 800);
		env->data = \
		mlx_get_data_addr(env->img, &env->bpp, &env->sizeline, &env->endian);
		olddirx = env->dirX;
		env->dirX = env->dirX * cos(0.3) - env->dirY * sin(0.3);
		env->dirY = olddirx * sin(0.3) + env->dirY * cos(0.3);
		oldplanex = env->planeX;
		env->planeX = env->planeX * cos(0.3) - env->planeY * sin(0.3);
		env->planeY = oldplanex * sin(0.3) + env->planeY * cos(0.3);
		env1 = *env;
		*env = env1;
		wolf(&env1);
	}
	return (0);
}