基本上我是在努力改进我正在做的一个吃豆人游戏中的鬼魂在最初的Pacman中,当一个幽灵被吃掉时,当Pacman获得能量时,鬼魂的眼睛会导航回原来的区域,然后再产卵。我想这样做。它还可以帮助我实现一个幽灵人工智能,使他们移动更聪明,然后只是随机。
所以基本上这些眼睛必须通过这个:
从下面的二维数组中绘制出电路板:

  //0's = Walls or location not allowed to go
  //1's = Dot Spot
  //2's = Clear Path nothing on it but safe to move
  //3's = Power Dot
  //-1's = only ghosts can go through
  //5= Top entry spot
  //6= bottom entry point
  //7 = Cherry
  //(Spots = row - 1 same with columns = - 1. First # is row. Second is col
  public int board[][] =
  {{2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}, //1
    {2, 0, 3, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 3, 0, 2}, //2
    {2, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 2}, //3
    {2,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2}, //4
    {2,0,1,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,1,0,2}, //5
    {2,0,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,0,2}, //6
    {2,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,2}, //7
    {2,2,2,2,0,1,0,1,1,1,1,1,1,1,0,1,0,2,2,2,2}, //8
    {0,0,0,0,0,1,0,1,0,0,-1,0,0,1,0,1,0,0,0,0,0}, //9
    {5,2,2,2,2,1,1,1,0,2,2,2,0, 1 ,1,1,2,2,2,2,6}, //10 - cherry
    {0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0}, //11
    {2,2,2,2,0,1,0,1,1,1,2,1,1,1,0,1,0,2,2,2,2}, //12
    {2,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,2}, //13
    {2,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,2}, //14 - pacman on this row
    {2,0,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,1,0,2}, //15
    {2,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,2}, //16
    {2,0,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,0,2}, //17
    {2,0,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,0,2}, //18
    {2,0,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,2}, //19
    {2,0,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,0,2}, //20
    {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2}}; //21

所以我的问题是,我应该如何让眼睛以最快的速度进入中心位置而不穿过墙壁呢?

最佳答案

只需使用预先计算好的墨迹。“原点”方块标记为零然后,将标记为n的正方形的所有未分配的邻域正方形分配给标记n+1。现在你所有的“死”鬼魂要做的就是搬到一个有较低标签的相邻广场。他们最终会走最短的路回家容易的!

10-08 04:12