我应该在此javascript游戏中实施的方式和类型

我真的对AI陌生。 (只看过一些视频/教程) 我了解基本知识...所以我决定从事一个项目..

所以这是我的游戏...我还没有添加计分板和其他东西。

我正在尝试将红球打成ai ...这样它可以得知与蓝色球相撞并不好...所以应该继续躲避那些...即使我看到有人在做不同的事情我不了解如何使用这些知识的项目...我正在考虑用蓝球的坐标制作一个qtable ...这就是我现在能想到的一切...

我基本上需要一个如何在此特定项目中实现AI的演练...请帮助

const canvas = document.getElementById("game");
const context = canvas.getContext("2d");

canvas.width = window.innerWidth-20;
canvas.height = window.innerHeight-20;

let gameover = false;
let x = canvas.width / 2;
let y = canvas.height / 2;
let dx = 0;
let dy = 0;

x3=y3=flag=c=0;
virx = new Array();
viry = new Array();

for (i=0; i<9; i++)
{
	virx.push(Math.floor((Math.random() * window.innerWidth-40) + 20));
	viry.push(Math.floor((Math.random() * window.innerHeight-40) + 20));
}

const state = {
  "ArrowRight": false,
  "ArrowLeft": false,
  "ArrowUp": false,
  "ArrowDown": false
}



function draw() {
  context.clearRect(0, 0, canvas.width, canvas.height);
  context.beginPath();
  context.arc(x, y, 10, 0, Math.PI * 2, false);
  context.fillStyle = "red";
  context.fill();
  context.closePath();
  
  for (i=0; i<9; i++)
  {
	newpoint();
	context.beginPath();
	context.arc(virx[i], viry[i], 10, 0, Math.PI * 2, false);
	context.fillStyle = "blue";
	context.fill();
	context.closePath();
	
	context.beginPath();
	context.moveTo(x,y);
	context.lineTo(virx[i],viry[i]);
	a=Math.pow(x-virx[i],2);
	b=Math.pow(y-viry[i],2);
	c = Math.sqrt(a+b);
	
	if (c>600) {
		context.strokeStyle = "#eee";
	}
	else if (c<600 && c>300) {
		context.strokeStyle = "green";
	}
	else if (c<300 && c>100) {
		context.strokeStyle = "yellow";
	}
	else if (c<100) {
		context.strokeStyle = "red";
	}
	context.stroke();
  }
}

function logic() {
	
  const direction = determineDirection();

  if (direction.dx) {
    dx = dx + direction.dx;
  }

  if (direction.dy) {
    dy = dy + direction.dy;
  }

  x = x + dx;
  y = y + dy;

  if (dx > 0) {
    dx -= 0.02;
  }
  if (dx < 0) {
    dx += 0.02;
  }
  if (dy > 0) {
    dy -= 0.02;
  }
  if (dy < 0) {
    dy += 0.02;
  }

}

function play() {
  draw();
  logic();
}








document.addEventListener("keydown", keyDownHandler, false);
document.addEventListener("keyup", keyUpHandler, false);

function newpoint()
{
	flag=0;
	vx= x - virx[i];
	vy= y - viry[i];
	vsize = Math.sqrt((vx*vx) + (vy*vy));
	vn_x = vx / vsize;
	vn_y = vy / vsize;

	newx = virx[i] + 0.5 * vn_x;
	newy = viry[i] + 0.5 * vn_y;
	for (j=0; j<9; j++)
	{
		if (j!=i)
		{
			a=Math.pow(virx[j]-newx,2);
			b=Math.pow(viry[j]-newy,2);
			c = Math.sqrt(a+b);
		}
		if(c<40)
		{
			// flag=1;
			while (true)
			{
				
				newx = Math.random() * (window.innerWidth-40) + 20;
				newy = Math.random() * (window.innerHeight-40) + 20;
				
				a=Math.pow(x-newx,2);
				b=Math.pow(y-newy,2);
				c = Math.sqrt(a+b);
				
				if (c>300)
				{
					break;
				}
			}
		}

	}	
	if (flag==0)
	{
		virx[i] = newx;
		viry[i] = newy;
	}
		


}

function determineDirection() {
  const {
    ArrowRight,
    ArrowLeft,
    ArrowUp,
    ArrowDown
  } = state
  if (ArrowRight && ArrowUp) {
    return {
      dx: .040,
      dy: -.040
    };
  }
  if (ArrowRight && ArrowDown) {
    return {
      dx: .040,
      dy: .040
    };
  }
  if (ArrowLeft && ArrowUp) {
    return {
      dx: -.040,
      dy: -.040
    };
  }
  if (ArrowLeft && ArrowDown) {
    return {
      dx: -.040,
      dy: .040
    };
  }
  if (ArrowLeft) {
    return {
      dx: -.040,
      dy: 0
    }
  }
  if (ArrowRight) {
    return {
      dx: .040,
      dy: 0
    }
  }
  if (ArrowUp) {
    return {
      dx: 0,
      dy: -.040
    }
  }
  if (ArrowDown) {
    return {
      dx: 0,
      dy: .040
    }
  }
  return {
    dx: 0,
    dy: 0
  }
}

function keyDownHandler({
  key
}) {
  state[key] = true;
}

function keyUpHandler({
  key
}) {
  state[key] = false;
}
setInterval(play, 10);
<html>
<head>
<title>yo ai</title>
<style>
canvas { background: #eee; }
</style>
</head>
<body>
<canvas id="game" height="600" width="1000"></canvas>
<script type="text/javascript" src="script.js"></script>
</body>
</html>