Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 查找列表中的下一个障碍_Python_Python 3.x - Fatal编程技术网

Python 查找列表中的下一个障碍

Python 查找列表中的下一个障碍,python,python-3.x,Python,Python 3.x,我正在尝试创建一个移动到正方形末端的游戏。在游戏中,我通过列出真假=障碍来设置障碍。我有但没有发布的是,只有当用户降落在障碍物上时,才会检测到障碍物。但是,我想找到一种方法,在用户下一步行动之前检测障碍物,如果下一个点是障碍物,则使其保持原位。换句话说,我想在继续之前找到列表的下一个索引。下面是一些伪代码,以获得更好的图片: if next_left != [[False]]: # if there is no obstacle officially_move_left else: #

我正在尝试创建一个移动到正方形末端的游戏。在游戏中,我通过列出真假=障碍来设置障碍。我有但没有发布的是,只有当用户降落在障碍物上时,才会检测到障碍物。但是,我想找到一种方法,在用户下一步行动之前检测障碍物,如果下一个点是障碍物,则使其保持原位。换句话说,我想在继续之前找到列表的下一个索引。下面是一些伪代码,以获得更好的图片:

if next_left != [[False]]: # if there is no obstacle
    officially_move_left
else: # if there is an obstacle
    user_do_nothing
我所拥有的伪:

 def moving_pos(user):       
   copy_user.pos = user.pos
   if  copy_user.pos +1 == [True]
       user.pos += 1
       copy_user.pos += 1
    else:
        return user.pos
也就是说,移动播放器,检测对象,再次移动播放器。如果看不到实际的实施情况,很难提供帮助

编辑:好的,在你的新编辑中,我看不出程序有这样的限制的任何原因。不过,让我提出一些新的建议-

obstacle_index = [obs1, obs2, obs3...]
if user_position+1 in obstacle_index:
    do_nothing;
else
    user_move_forward;

您可以发布实际的最小工作代码,或者至少发布实现的更详细的伪代码吗

因此,您希望找到列表中哪些位置的值为False。?/我认为您的实现中的一些更详细的信息会有所帮助,您如何保持true/False?你的角色是否在固定区域内移动?我们知道它当前在哪里吗,坐标方面?如果用户向左、向右、向前或向后移动,我希望它检测他们想要移动到的下一个位置是真还是假。例如,如果用户想要向右移动,则他们想要移动到的位置必须没有障碍物。如果是的话,他们会呆在原地。他们一次移动一个正方形吗?是的,他们一次移动一个正方形。
obstacle_index = [obs1, obs2, obs3...]
if user_position+1 in obstacle_index:
    do_nothing;
else
    user_move_forward;