我创建了一个2D迷宫,我想找到红色 - 蓝色节点之间最快的路径.我不确定如何实施深度优先搜索.我知道可以使用邻接矩阵或列表来表示节点之间的连接.虽然,我不确定如何构建它.
为简洁起见:我需要返回一个列表,其中搜索了瓷砖坐标(当寻找目标节点时),因此我可以在迷宫上描绘搜索.或者我将如何为此构建一个邻接矩阵?和相应的顶点列表?
深度首先搜索一般结构
重复1 - 3直到堆栈为空
这是迷宫类的当前代码.
public class Maze {
//Tile ids
public static short OBSTICLE = 0;
public static short START_LOC_VALUE = -2;
public static short GOAL_LOC_VALUE = -3;
private int rows, cols;
private int numTiles;
private int[][] map;
private int[][] adjMatrix;
private Queue theQueue;
public Maze(int rows, int cols){
this.rows = rows;
this.cols = cols;
theQueue = new Queue();
numTiles = rows*cols;
map = new int[rows][cols];
adjMatrix …Run Code Online (Sandbox Code Playgroud) 我象征性地想知道如何将多项式解析成函数并返回导数.我将使用什么数据结构或解析多项式的方法?最好不要使用任何库,因为这个问题可能会在技术面试中出现.
polynomial-> of nth degree
def derivative(polynomial):
return derivative
Example:
f(x) = 2x^2+3x+1
f'(x) = 4x+3
Run Code Online (Sandbox Code Playgroud)
我不想要一个解决方案,这不是作业,而是一个我要从哪里开始的暗示.
我目前正在阅读"人工智能:现代方法".虽然术语因素,结构化和原子表示令人困惑但这些意味着什么呢?
关于编程......
谢谢
最近我一直在研究像游戏这样的太空入侵者,以帮助我提高我的编程技能.我陷入了一些问题.我已经研究了几天了,你将如何在keyUp上进行激光射击.
这是我到目前为止的尝试; 我可以让激光器发射,但是我发现为什么激光器不能继续向上移动......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace SpaceInvaders
{
public partial class Form1 : Form
{
public int spriteX = 226;
public int spriteY = 383;
bool bulletFire = false;
int fireTimer = 8;
int laserFired;
public Form1()
{
InitializeComponent();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
public void laserFire()
{
//on laser fire i wont the bulle to move up while …Run Code Online (Sandbox Code Playgroud) 我一直在使用C#中的一个简单程序,其中Ball [X,Y]坐标是周期性递增的.
我已经设法实现了碰撞检测方法,但我正在尝试确定如何以一个角度反射球,并选择沿着相同的线性路径反弹.
dx = -dx //This bounces the ball back along the same linear path
dy = -dy
Run Code Online (Sandbox Code Playgroud)
解决方案 三角函数
theta = range between 0<theta<=360 depending on where it bounced
x = cos(theta)*time
y= sin(theta)*time
Run Code Online (Sandbox Code Playgroud)