当前位置: 首页 > news >正文

UnityAI——动物迁徙中的跟随实现实例

  大家好,我是七七,今天来给大家介绍的是Unity中用操控行为实现的跟随领队行为。

看本文若是想了解和实现,只看本文即可,若是想彻底弄透,建议从七七的游戏AI专栏开始看。

废话不多说,先上视频:

跟随队长

我们的目标是让后面的人跟着领头的人,并遵循一些规则

对于领头的人:

  1. 随机地移动
  2. 检测前方是否有人

对于跟随的人;

  1. 跟的不要太近
  2. 人与人直接不要拥挤
  3. 如果发现挡道领头人路了,赶紧让开 

 我们只需要实现这些规则,就可以得到理想的效果,这与神经网络的思想类似,下面我们就来实现这些规则。

规则1

这个脚本是挂载领头人身上的,目的是在前方LEADER_BEHIND_DIST处画一个圆球,若是说前方有人,则让这些人避开。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class DrawGizmos : MonoBehaviour
{public float evadeDistance;public Vector3 center;private Vehicle vehicleScript;private float LEADER_BEHIND_DIST;void Start(){vehicleScript = GetComponent<Vehicle>();LEADER_BEHIND_DIST = 2.0f;}void Update(){center = transform.position + vehicleScript.velocity.normalized * LEADER_BEHIND_DIST;}void OnDrawGizoms(){Gizmos.DrawWireSphere(center, evadeDistance);}
}

规则2

这个脚本是挂在一个空物体上的,目的是生成多个跟随者

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class GenerateBotsForFollowLeader : MonoBehaviour
{public GameObject botPrefab;public GameObject leader;public int botCount;public float minX = -5f;public float maxX = 5.0f;public float minZ = -5.0f;public float maxZ = 5.0f;public float Yvalue = 1.026003f;void Start(){Vector3 spawnPosition;GameObject bot;for(int i = 0; i < botCount; i++){spawnPosition = new Vector3(Random.Range(minX, maxX), Yvalue, Random.Range(minZ, maxZ));//随机产生一个生成位置bot = Instantiate(botPrefab, spawnPosition, Quaternion.identity) as GameObject;bot.GetComponent<SteeringForLeaderFollowing>().leader = leader;bot.GetComponent<SteeringForEvade>().target = leader;bot.GetComponent<SteeringForEvade>().enabled = false;bot.GetComponent<EvadeController>().leader = leader;}}
}

规则3

这个脚本是挂在跟随者身上的,是为了确定跟随者的路径目标点,即领导人身后LEADER_BEHIND_DIST处

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(SteeringForArrive))]
public class SteeringForLeaderFollowing : Steering
{public Vector3 target;private Vector3 desiredVelocity;//预期速度private Vehicle m_vehicle;//获得被操控的AI角色private float maxSpeed;private bool isPlanar;public GameObject leader;private Vehicle leaderController;private Vector3 leaderVelocity;private float LEADER_BEHIND_DIST=2.0f;private SteeringForArrive arriveScript;private Vector3 randomOffset;void Start(){m_vehicle = GetComponent<Vehicle>();maxSpeed = m_vehicle.maxSpeed;isPlanar = m_vehicle.isPlanar;leaderController=leader.GetComponent<Vehicle>();arriveScript= GetComponent<SteeringForArrive>();//为抵达行为指定目标点arriveScript.target = new GameObject("arriveTarget");arriveScript.target.transform.position = leader.transform.position;}public override Vector3 Force(){leaderVelocity = leaderController.velocity;target=leader.transform.position+LEADER_BEHIND_DIST*(-leaderVelocity).normalized;//计算目标点arriveScript.target.transform.position = target;return new Vector3(0, 0, 0);}
}

 规则4

这个脚本是挂在跟随者身上的,目的是为了避免跟随者挡住领导人的路

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class EvadeController : MonoBehaviour
{public GameObject leader;private Vehicle leaderLocomotion;private Vehicle m_vehicle;private bool isPlanar;private Vector3 leaderAhead;private float LEADER_BEHIND_DIST;private Vector3 dist;public float evadeDistance;private float sqrEvadeDistance;private SteeringForEvade evadeScript;void Start(){leaderLocomotion = leader.GetComponent<Vehicle>();evadeScript= GetComponent<SteeringForEvade>();m_vehicle= GetComponent<Vehicle>();isPlanar=m_vehicle.isPlanar;LEADER_BEHIND_DIST = 2.0f;sqrEvadeDistance=sqrEvadeDistance*sqrEvadeDistance;}void Update(){leaderAhead=leader.transform.position+leaderLocomotion.velocity.normalized*LEADER_BEHIND_DIST;  //计算领队前方的一个点dist = transform.position - leaderAhead;if (isPlanar){dist.y = 0;}if(dist.sqrMagnitude < sqrEvadeDistance){evadeScript.enabled = true;Debug.DrawLine(transform.position, leader.transform.position);}else{evadeScript.enabled = false;}}
}

实现

前提

有3个基类

UnityAI——操控行为编程的主要基类-CSDN博客

第一步

创建一个场景,一个Plane

第二步

创建一个Cube作为领队,起名为Leader,为其挂上三个脚本,如下所示:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class AILocomotion : Vehicle
{private CharacterController controller;  //AI�Ľ�ɫ������private Rigidbody theRigidbody;private Vector3 moveDistance;//AI��ɫÿ�ε��ƶ�����void Start(){controller = GetComponent<CharacterController>();theRigidbody = GetComponent<Rigidbody>();moveDistance = new Vector3(0, 0, 0);base.Start();//���û����start��������������ij�ʼ��}//������ز�����FixedUpdate�и���void FixedUpdate(){velocity += acceleration * Time.fixedDeltaTime;//�����ٶ�if (velocity.sqrMagnitude > sqrMaxSpeed)   //��������ٶ�velocity = velocity.normalized * maxSpeed;moveDistance = velocity * Time.fixedDeltaTime;if (isPlanar)  {velocity.y = 0;moveDistance.y = 0;}if (controller != null)//����Ѿ�ΪAI��ɫ���ӽ�ɫ����������ô���ý�ɫ������ʹ���ƶ�controller.SimpleMove(velocity);//�����ɫ��û��ɫ��������ҲûRigidbody//����Rigidbody����Ҫ�ɶ���ѧ�ķ�ʽ�������ƶ�else if (theRigidbody == null || !theRigidbody.isKinematic)transform.position += moveDistance;else //��Rigidbody���ƽ�ɫ���˶�theRigidbody.MovePosition(theRigidbody.position+moveDistance);if(velocity.sqrMagnitude>0.00001)//���³�������ٶȴ���һ����ֵ��Ϊ�˷�ֹ������{Vector3 newForward = Vector3.Slerp(transform.forward, velocity, damping * Time.deltaTime);if(isPlanar)newForward.y = 0;transform.forward = newForward;}//�������߶���gameObject.GetComponent<Animation>().Play("walk");}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class SteeringForWander : Steering
{public float wanderRadius; //徘徊半径public float wanderDistance; //徘徊距离public float wanderJitter; //每秒加到目标的随即位移的最大值public bool isPlanar;private Vector3 desiredVelocity;//预期速度private Vehicle m_vehicle;//获得被操控的AI角色private float maxSpeed;private Vector3 circleTarget;private Vector3 wanderTarget;void Start(){m_vehicle = GetComponent<Vehicle>();maxSpeed = m_vehicle.maxSpeed;isPlanar = m_vehicle.isPlanar;circleTarget = new Vector3(wanderRadius * 0.707f, 0, wanderRadius * 0.707f);  //选取与安全上的一个点作为初始点}public override Vector3 Force(){Vector3 randomDisplacement = new Vector3((Random.value - 0.5f) * 2 * wanderJitter, (Random.value - 0.5f) * 2 * wanderJitter, (Random.value - 0.5f) * 2 * wanderJitter);if (isPlanar)randomDisplacement.y = 0;circleTarget+=randomDisplacement;//将随机位移加到初始点上circleTarget = wanderRadius * circleTarget.normalized;//由于新位置很可能不在圆周上,因此需要投影到圆周上wanderTarget = m_vehicle.velocity.normalized * wanderDistance + circleTarget + transform.position;//之前计算出的值是相对于AI的,需要转换为世界坐标desiredVelocity = (wanderTarget - transform.position).normalized * maxSpeed;return (desiredVelocity - m_vehicle.velocity);}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class DrawGizmos : MonoBehaviour
{public float evadeDistance;public Vector3 center;private Vehicle vehicleScript;private float LEADER_BEHIND_DIST;void Start(){vehicleScript = GetComponent<Vehicle>();LEADER_BEHIND_DIST = 2.0f;}void Update(){center = transform.position + vehicleScript.velocity.normalized * LEADER_BEHIND_DIST;}void OnDrawGizoms(){Gizmos.DrawWireSphere(center, evadeDistance);}
}

第三步

创建一个空物体,起名为follersGenerator,用于生成跟随者,并添加脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class GenerateBotsForFollowLeader : MonoBehaviour
{public GameObject botPrefab;public GameObject leader;public int botCount;public float minX = -5f;public float maxX = 5.0f;public float minZ = -5.0f;public float maxZ = 5.0f;public float Yvalue = 1.026003f;void Start(){Vector3 spawnPosition;GameObject bot;for(int i = 0; i < botCount; i++){spawnPosition = new Vector3(Random.Range(minX, maxX), Yvalue, Random.Range(minZ, maxZ));//随机产生一个生成位置bot = Instantiate(botPrefab, spawnPosition, Quaternion.identity) as GameObject;bot.GetComponent<SteeringForLeaderFollowing>().leader = leader;bot.GetComponent<SteeringForEvade>().target = leader;bot.GetComponent<SteeringForEvade>().enabled = false;bot.GetComponent<EvadeController>().leader = leader;}}
}

第四步

创建一个方块预设,作为跟随者,挂上下列脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class AILocomotion : Vehicle
{private CharacterController controller;  //AI�Ľ�ɫ������private Rigidbody theRigidbody;private Vector3 moveDistance;//AI��ɫÿ�ε��ƶ�����void Start(){controller = GetComponent<CharacterController>();theRigidbody = GetComponent<Rigidbody>();moveDistance = new Vector3(0, 0, 0);base.Start();//���û����start��������������ij�ʼ��}//������ز�����FixedUpdate�и���void FixedUpdate(){velocity += acceleration * Time.fixedDeltaTime;//�����ٶ�if (velocity.sqrMagnitude > sqrMaxSpeed)   //��������ٶ�velocity = velocity.normalized * maxSpeed;moveDistance = velocity * Time.fixedDeltaTime;if (isPlanar)  {velocity.y = 0;moveDistance.y = 0;}if (controller != null)//����Ѿ�ΪAI��ɫ���ӽ�ɫ����������ô���ý�ɫ������ʹ���ƶ�controller.SimpleMove(velocity);//�����ɫ��û��ɫ��������ҲûRigidbody//����Rigidbody����Ҫ�ɶ���ѧ�ķ�ʽ�������ƶ�else if (theRigidbody == null || !theRigidbody.isKinematic)transform.position += moveDistance;else //��Rigidbody���ƽ�ɫ���˶�theRigidbody.MovePosition(theRigidbody.position+moveDistance);if(velocity.sqrMagnitude>0.00001)//���³�������ٶȴ���һ����ֵ��Ϊ�˷�ֹ������{Vector3 newForward = Vector3.Slerp(transform.forward, velocity, damping * Time.deltaTime);if(isPlanar)newForward.y = 0;transform.forward = newForward;}//�������߶���gameObject.GetComponent<Animation>().Play("walk");}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class SteeringForArrive : Steering
{public bool isPlanar = true;public float arrivalDistance = 0.3f;public float characterRadius = 1.2f;public float slowDownDistance;public GameObject target;private Vector3 desiredVelocity;//预期速度private Vehicle m_vehicle;//获得被操控的AI角色private float maxSpeed;void Start(){m_vehicle = GetComponent<Vehicle>();maxSpeed = m_vehicle.maxSpeed;isPlanar = m_vehicle.isPlanar;}public override Vector3 Force(){Vector3 toTarget = target.transform.position - transform.position;Vector3 desiredVelocity;Vector3 returnForce;if (isPlanar)toTarget.y = 0;float distance = toTarget.magnitude;if (distance > slowDownDistance){desiredVelocity = toTarget.normalized * maxSpeed;returnForce = desiredVelocity - m_vehicle.velocity;}else{desiredVelocity = toTarget - m_vehicle.velocity;returnForce = desiredVelocity - m_vehicle.velocity;}return returnForce;}void OnDrawGizmos(){Gizmos.DrawWireSphere(target.transform.position, slowDownDistance);}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(SteeringForArrive))]
public class SteeringForLeaderFollowing : Steering
{public Vector3 target;private Vector3 desiredVelocity;//预期速度private Vehicle m_vehicle;//获得被操控的AI角色private float maxSpeed;private bool isPlanar;public GameObject leader;private Vehicle leaderController;private Vector3 leaderVelocity;private float LEADER_BEHIND_DIST=2.0f;private SteeringForArrive arriveScript;private Vector3 randomOffset;void Start(){m_vehicle = GetComponent<Vehicle>();maxSpeed = m_vehicle.maxSpeed;isPlanar = m_vehicle.isPlanar;leaderController=leader.GetComponent<Vehicle>();arriveScript= GetComponent<SteeringForArrive>();//为抵达行为指定目标点arriveScript.target = new GameObject("arriveTarget");arriveScript.target.transform.position = leader.transform.position;}public override Vector3 Force(){leaderVelocity = leaderController.velocity;target=leader.transform.position+LEADER_BEHIND_DIST*(-leaderVelocity).normalized;//计算目标点arriveScript.target.transform.position = target;return new Vector3(0, 0, 0);}
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Radar : MonoBehaviour
{private Collider[] colliders;//碰撞体的组数private float timer = 0;//计时器public List<GameObject> neighbors;public float checkInterval = 0.3f;//设置检测的时间间隔public float detectRadius = 10f;//设置邻域半径public LayerMask layersChecked;//设置检测哪一层的游戏对象void Start(){neighbors = new List<GameObject>();}void Update(){timer += Time.deltaTime;if(timer > checkInterval){neighbors.Clear();colliders = Physics.OverlapSphere(transform.position, detectRadius, layersChecked);//查找当前AI角色邻域内的所有碰撞体for(int i = 0; i < colliders.Length; i++)//对于每个检测到的碰撞体,获取Vehicle组件,并且加入邻居列表钟{if (colliders[i].GetComponent<Vehicle>())neighbors.Add(colliders[i].gameObject);}timer = 0;}}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class SteeringForSeparation : Steering
{public float comforDistance = 1;//可接受的距离public float multiplierInsideComfortDistance = 2;//当AI角色与邻居距离过近时的惩罚因子public override Vector3 Force(){Vector3 steeringForce = new Vector3(0, 0, 0);foreach(GameObject s in GetComponent<Radar>().neighbors)//遍历这个AI角色的邻居列表中的每个邻居{if ((s != null) && (s != this.gameObject)){Vector3 toNeighbor = transform.position - s.transform.position;//计算当前AI角色与邻居s之间的距离float length=toNeighbor.magnitude;steeringForce += toNeighbor.normalized / length;//计算这个邻居引起的操控力if (length < comforDistance)steeringForce *= multiplierInsideComfortDistance;}}return steeringForce;}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class SteeringForEvade :Steering
{public GameObject target;private Vector3 desiredVelocity;//预期速度private Vehicle m_vehicle;//获得被操控的AI角色private float maxSpeed;void Start(){m_vehicle = GetComponent<Vehicle>();maxSpeed = m_vehicle.maxSpeed;}public override Vector3 Force(){Vector3 toTarget = target.transform.position - transform.position;float lookaheadTime = toTarget.magnitude / (maxSpeed + target.GetComponent<Vehicle>().velocity.magnitude);//向前预测的时间desiredVelocity = (transform.position - (target.transform.position+target.GetComponent<Vehicle>().velocity*lookaheadTime)).normalized * maxSpeed;return (desiredVelocity - m_vehicle.velocity);}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class EvadeController : MonoBehaviour
{public GameObject leader;private Vehicle leaderLocomotion;private Vehicle m_vehicle;private bool isPlanar;private Vector3 leaderAhead;private float LEADER_BEHIND_DIST;private Vector3 dist;public float evadeDistance;private float sqrEvadeDistance;private SteeringForEvade evadeScript;void Start(){leaderLocomotion = leader.GetComponent<Vehicle>();evadeScript= GetComponent<SteeringForEvade>();m_vehicle= GetComponent<Vehicle>();isPlanar=m_vehicle.isPlanar;LEADER_BEHIND_DIST = 2.0f;sqrEvadeDistance=sqrEvadeDistance*sqrEvadeDistance;}void Update(){leaderAhead=leader.transform.position+leaderLocomotion.velocity.normalized*LEADER_BEHIND_DIST;  //计算领队前方的一个点dist = transform.position - leaderAhead;if (isPlanar){dist.y = 0;}if(dist.sqrMagnitude < sqrEvadeDistance){evadeScript.enabled = true;Debug.DrawLine(transform.position, leader.transform.position);}else{evadeScript.enabled = false;}}
}

收尾

最后再给各个角色装上刚体,设置好Leader等参数就可以了。

很多行为我们都可以通过设定规则来实现,可能乍一看行为很难摸索,但慢慢分析出其中的规则并逐一实现后,问题往往就会被解决

相关文章:

UnityAI——动物迁徙中的跟随实现实例

大家好&#xff0c;我是七七&#xff0c;今天来给大家介绍的是Unity中用操控行为实现的跟随领队行为。 看本文若是想了解和实现&#xff0c;只看本文即可&#xff0c;若是想彻底弄透&#xff0c;建议从七七的游戏AI专栏开始看。 废话不多说&#xff0c;先上视频&#xff1a; …...

堆的应用-----Top k 问题

目录 前言 Topk问题 1.问题描述 2.解决方法 3.代码实现&#xff08;C/C&#xff09; 前言 在人工智能算法岗位的面试中&#xff0c;TopK是问得最多的几个问题之一&#xff1a; 到底有几种方法&#xff1f; 这些方案里蕴含的优化思路究竟是怎么样的&#xff1f; 为啥T…...

11月14日星期二今日早报简报微语报早读

11月14日星期二&#xff0c;农历十月初二&#xff0c;早报微语早读。 1、江西南城县&#xff1a;限时发放购房补贴政策&#xff0c;三孩家庭每平方米最高补贴500元&#xff1b; 2、2023年中国内地电影市场累计票房突破500亿元&#xff1b; 3、市场监管总局&#xff1a;在全国…...

Spark读取excel文件

文章目录 一、excel数据源转成csv二、Spark读取csv文件(一)启动spark-shell(二)读取csv生成df(三)查看df内容一、excel数据源转成csv 集群bigdata - ubuntu: 192.168.191.19master(bigdata1) - centos: 192.168.23.78 slave1(bigdata2) - centos: 192.168.23.79 slave2(b…...

LLM大语言模型(典型ChatGPT)入门指南

文章目录 一、基础概念学习篇1.1 langchain视频学习笔记1.2 Finetune LLM视频学习笔记 二、实践篇2.1 预先下载模型&#xff1a;2.2 LangChain2.3 Colab demo2.3 text-generation-webui 三、国内项目实践langchain-chatchat 一、基础概念学习篇 1.1 langchain视频学习笔记 lan…...

Spring IOC - Bean的生命周期之实例化

在Spring启动流程文章中讲到&#xff0c;容器的初始化是从refresh方法开始的&#xff0c;其在初始化的过程中会调用finishBeanFactoryInitialization方法。 而在该方法中则会调用DefaultListableBeanFactory#preInstantiateSingletons方法&#xff0c;该方法的核心作用是初始化…...

前端 BUG 总结

文章目录 CSS 样式1、Chrome 89 版本期不再支持 /deep/&#xff0c;请勿使用嵌套 /deep/2、圆角按钮 button 点击后出现矩形框线3、怪异模式4、border 1 像素在手机上显示问题5、文本溢出问题 JavaScript 脚本1、移动端点击穿透2、使用parseInt时必须补全第二个参数 radix3、有…...

【蓝桥杯软件赛 零基础备赛20周】第3周——填空题

报名明年4月蓝桥杯软件赛的同学们&#xff0c;如果你是大一零基础&#xff0c;目前懵懂中&#xff0c;不知该怎么办&#xff0c;可以看看本博客系列&#xff1a;备赛20周合集 20周的完整安排请点击&#xff1a;20周计划 文章目录 00. 2023年第14届参赛数据0. 上一周答疑1. 填空…...

Pytorch自动混合精度的计算:torch.cuda.amp.autocast

1 autocast介绍 1.1 什么是AMP? 默认情况下&#xff0c;大多数深度学习框架都采用32位浮点算法进行训练。2017年&#xff0c;NVIDIA研究了一种用于混合精度训练的方法&#xff0c;该方法在训练网络时将单精度&#xff08;FP32&#xff09;与半精度(FP16)结合在一起&#xff…...

一文看懂香港优才计划和高才通计划的区别和优势?如何选?

一文看懂香港优才计划和高才通计划的区别和优势&#xff1f;如何选&#xff1f; 为什么很多人都渴望有个香港身份&#xff1f; 英文这里和内地文化相近&#xff0c;语言相通&#xff0c;同时税率较低、没有外汇管制&#xff0c;有稳定金融体制和良好的营商环境&#xff0c;诸多…...

DTC Network旗下代币DSTC大蒜头即将上线,市场热度飙升

全球数字资产领导者DTC Network宣布其代币DSTC&#xff08;大蒜头&#xff09;即将于近期上线&#xff0c;引发市场广泛关注。DTC Network以其创新性的区块链技术和多维度的网络构建&#xff0c;致力于打造一个融合Web3.0、元宇宙和DAPP应用的去中心化聚合公共平台&#xff0c;…...

高通SDX12:ASoC 音频框架浅析

一、简介 ASoC–ALSA System on Chip ,是建立在标准ALSA驱动层上,为了更好地支持嵌入式处理器和移动设备中的音频Codec的一套软件体系。 本文基于高通SDX12平台,对ASoC框架做一个分析。 二、整体框架 1. 硬件层面 嵌入式Linux设备的Audio subsystem可以划分为Machine(板…...

国际化:i18n

什么是国际化&#xff1f; 国际化也称作i18n&#xff0c;其来源是英文单词 internationalization的首末字符和n&#xff0c;18为中间的字符数。由于软件发行可能面向多个国家&#xff0c;对于不同国家的用户&#xff0c;软件显示不同语言的过程就是国际化。通常来讲&#xff0…...

【机器学习5】无监督学习聚类

相比于监督学习&#xff0c; 非监督学习的输入数据没有标签信息&#xff0c; 需要通过算法模型来挖掘数据内在的结构和模式。 非监督学习主要包含两大类学习方法&#xff1a; 数据聚类和特征变量关联。 1 K均值聚类及优化及改进模型 1.1 K-means 聚类是在事先并不知道任何样…...

风景照片不够清晰锐利,四招帮你轻松解决

我们大家在拍摄风景照的时候都希望能够拍摄出清晰锐利的照片。可能会有人问&#xff1a;“什么是锐利&#xff1f;”我们可以从锐度来给大家简单解说下。锐度是反映图片平面清晰度和图像边缘对比度的一个参数。锐度较高的画面&#xff0c;微小的细节部分也会表现得很清晰&#…...

List中的迭代器实现【C++】

List中的迭代器实现【C】 一. list的结构二. 迭代器的区别三. 迭代器的实现i. 类的设计ii. 重载iii. !重载iiii. begin()iiiii. end()iiiii. operator* 四.测试五. const迭代器的实现i. 实现ii 优化实现 六. 整体代码 一. list的结构 其实按照习惯来说&#xff0c;应该要专门出…...

VB.NET三层之用户查询窗体

目录 前言: 过程: UI层代码展示: BLL层代码展示: DAL层代码展示: 查询用户效果图:​ 总结: 前言: 想要对用户进行查询&#xff0c;需要用到控件DataGrideView&#xff0c;通过代码的形式将数据库表中的数据显示在DataGrideview控件中&#xff0c;不用对DatGridView控件…...

Django之路由层

文章目录 路由匹配语法路由配置注意事项转换器注册自定义转化器 无名分组和有名分组无名分组有名分组 反向解析简介普通反向解析无名分组、有名分组之反向解析 路由分发简介为什么要用路由分发&#xff1f;路由分发实现 伪静态的概念名称空间虚拟环境什么是虚拟环境&#xff1f…...

【06】VirtualService高级流量功能

5.3 weight 部署demoapp v10和v11版本 --- apiVersion: apps/v1 kind: Deployment metadata:labels:app: demoappv10version: v1.0name: demoappv10 spec:progressDeadlineSeconds: 600replicas: 3selector:matchLabels:app: demoappversion: v1.0template:metadata:labels:app…...

322. 零钱兑换

给你一个整数数组 coins &#xff0c;表示不同面额的硬币&#xff1b;以及一个整数 amount &#xff0c;表示总金额。 计算并返回可以凑成总金额所需的 最少的硬币个数 。如果没有任何一种硬币组合能组成总金额&#xff0c;返回 -1 。 你可以认为每种硬币的数量是无限的。 示…...

idea大量爆红问题解决

问题描述 在学习和工作中&#xff0c;idea是程序员不可缺少的一个工具&#xff0c;但是突然在有些时候就会出现大量爆红的问题&#xff0c;发现无法跳转&#xff0c;无论是关机重启或者是替换root都无法解决 就是如上所展示的问题&#xff0c;但是程序依然可以启动。 问题解决…...

docker详细操作--未完待续

docker介绍 docker官网: Docker&#xff1a;加速容器应用程序开发 harbor官网&#xff1a;Harbor - Harbor 中文 使用docker加速器: Docker镜像极速下载服务 - 毫秒镜像 是什么 Docker 是一种开源的容器化平台&#xff0c;用于将应用程序及其依赖项&#xff08;如库、运行时环…...

椭圆曲线密码学(ECC)

一、ECC算法概述 椭圆曲线密码学&#xff08;Elliptic Curve Cryptography&#xff09;是基于椭圆曲线数学理论的公钥密码系统&#xff0c;由Neal Koblitz和Victor Miller在1985年独立提出。相比RSA&#xff0c;ECC在相同安全强度下密钥更短&#xff08;256位ECC ≈ 3072位RSA…...

Golang 面试经典题:map 的 key 可以是什么类型?哪些不可以?

Golang 面试经典题&#xff1a;map 的 key 可以是什么类型&#xff1f;哪些不可以&#xff1f; 在 Golang 的面试中&#xff0c;map 类型的使用是一个常见的考点&#xff0c;其中对 key 类型的合法性 是一道常被提及的基础却很容易被忽视的问题。本文将带你深入理解 Golang 中…...

1.3 VSCode安装与环境配置

进入网址Visual Studio Code - Code Editing. Redefined下载.deb文件&#xff0c;然后打开终端&#xff0c;进入下载文件夹&#xff0c;键入命令 sudo dpkg -i code_1.100.3-1748872405_amd64.deb 在终端键入命令code即启动vscode 需要安装插件列表 1.Chinese简化 2.ros …...

【AI学习】三、AI算法中的向量

在人工智能&#xff08;AI&#xff09;算法中&#xff0c;向量&#xff08;Vector&#xff09;是一种将现实世界中的数据&#xff08;如图像、文本、音频等&#xff09;转化为计算机可处理的数值型特征表示的工具。它是连接人类认知&#xff08;如语义、视觉特征&#xff09;与…...

【C语言练习】080. 使用C语言实现简单的数据库操作

080. 使用C语言实现简单的数据库操作 080. 使用C语言实现简单的数据库操作使用原生APIODBC接口第三方库ORM框架文件模拟1. 安装SQLite2. 示例代码:使用SQLite创建数据库、表和插入数据3. 编译和运行4. 示例运行输出:5. 注意事项6. 总结080. 使用C语言实现简单的数据库操作 在…...

tree 树组件大数据卡顿问题优化

问题背景 项目中有用到树组件用来做文件目录&#xff0c;但是由于这个树组件的节点越来越多&#xff0c;导致页面在滚动这个树组件的时候浏览器就很容易卡死。这种问题基本上都是因为dom节点太多&#xff0c;导致的浏览器卡顿&#xff0c;这里很明显就需要用到虚拟列表的技术&…...

Mobile ALOHA全身模仿学习

一、题目 Mobile ALOHA&#xff1a;通过低成本全身远程操作学习双手移动操作 传统模仿学习&#xff08;Imitation Learning&#xff09;缺点&#xff1a;聚焦与桌面操作&#xff0c;缺乏通用任务所需的移动性和灵活性 本论文优点&#xff1a;&#xff08;1&#xff09;在ALOHA…...

rnn判断string中第一次出现a的下标

# coding:utf8 import torch import torch.nn as nn import numpy as np import random import json""" 基于pytorch的网络编写 实现一个RNN网络完成多分类任务 判断字符 a 第一次出现在字符串中的位置 """class TorchModel(nn.Module):def __in…...