获取当前事件的节点等等

var entbut=event.srcElement;//获取该节点

var fjd=entbut.parentNode;//获取父节点

var zjd=fjd.childNodes;//获取父节点下面所以子节点

for(var i=0;i<zjd.length;i++){

if(zjd[i].type=="button" && zjd[i].nodeName=="INPUT");//判断该子节点的类型 和属性 

{

zjd[i].disabled=true;//把button的状态屏蔽

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
A*算法需要先定义一个节点类,用于表示每个状态。节点类需要包含以下信息: 1. 当前状态的表示(可以是一个数组、一个字符串等等)。 2. 当前状态的代价(也就是从起始状态到当前状态的路径长度)。 3. 当前状态的估价(也就是从当前状态到目标状态的估计距离)。 4. 当前状态的父节点(也就是在搜索树中,指向当前状态的前一个状态)。 定义好节点类后,我们可以使用以下代码来获取当前节点状态: ```python class Node: def __init__(self, state, parent=None, cost=0, heuristic=0): self.state = state # 当前状态的表示 self.parent = parent # 当前状态的父节点 self.cost = cost # 当前状态的代价 self.heuristic = heuristic # 当前状态的估价 def a_star(start_state, goal_state): start_node = Node(start_state) goal_node = Node(goal_state) # 将起始状态加入 open 列表中 open_list = [start_node] while open_list: # 在 open 列表中选择 f 值最小的节点 current_node = min(open_list, key=lambda x: x.cost + x.heuristic) # 如果当前节点是目标节点,则返回路径 if current_node.state == goal_state: path = [] while current_node: path.append(current_node.state) current_node = current_node.parent return path[::-1] # 返回逆序的路径 # 将当前节点从 open 列表中移除,并加入 close 列表中 open_list.remove(current_node) close_list.append(current_node) # 对当前节点的所有邻居节点进行搜索 for neighbor_state in get_neighbors(current_node.state): neighbor_node = Node(neighbor_state, current_node, current_node.cost + 1, heuristic(neighbor_state, goal_state)) # 如果邻居节点已经在 close 列表中,则忽略 if neighbor_node in close_list: continue # 如果邻居节点不在 open 列表中,则加入 open 列表 if neighbor_node not in open_list: open_list.append(neighbor_node) # 否则更新邻居节点的代价和父节点 else: index = open_list.index(neighbor_node) if neighbor_node.cost < open_list[index].cost: open_list[index].cost = neighbor_node.cost open_list[index].parent = neighbor_node.parent ``` 在上面的代码中,定义了一个节点类 `Node`,包含了当前状态的表示、父节点、代价和估价等信息。在 A* 算法中,每次从 open 列表中选择 f 值最小的节点进行扩展,然后将其从 open 列表中移除并加入 close 列表中。对于每个扩展出来的邻居节点,如果它已经在 close 列表中,则不做处理,否则如果它不在 open 列表中,则直接加入 open 列表;如果它已经在 open 列表中,但是路径更短,则更新它的代价和父节点
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值