internal void InitializeSnake() { int auxX = Matrix.GetLength(0) / 2; int auxY = Matrix.GetLength(1) / 2; Snake = new SnakeBlock(Matrix[auxX, auxY]); SnakeBlock Next = Snake; //for (int i = 1; i < 6; i++) //{ // auxY += Direction.Y; // auxX += Direction.X; // Next.Next = new SnakeBlock(Matrix[auxX, auxY]); // Next.Next.Previous = Next; // Next = Next.Next; //} Next.Next = new EmptySnakeBlock(Matrix[auxX, auxY + 1]); Next.Next.Previous = Next; AddToMatrix(Snake, new int[] { auxX, auxY }); MoveSnake(); Snake.Eat(game); MoveSnake(); Snake.Eat(game); MoveSnake(); Snake.Eat(game); MoveSnake(); Snake.Eat(game); MoveSnake(); Snake.Eat(game); }
public static List <double> FindAppleIn4Directions(List <Apple> apples, SnakeBlock head) { double[] inputs = new double[] { 0, 0, 0, 0 }; //T if (apples.Where(x => (x.Position.X == head.ActualPosition.X) && x.Position.Y < head.ActualPosition.Y).Count() > 0) { inputs[1] = head.ActualPosition.Y - apples.Where(x => (x.Position.X == head.ActualPosition.X) && x.Position.Y < head.ActualPosition.Y).First().Position.Y; } //R if (apples.Where(x => (x.Position.Y == head.ActualPosition.Y) && x.Position.X > head.ActualPosition.X).Count() > 0) { inputs[2] = apples.Where(x => (x.Position.Y == head.ActualPosition.Y) && x.Position.X > head.ActualPosition.X).First().Position.X - head.ActualPosition.X; } //B if (apples.Where(x => (x.Position.X == head.ActualPosition.X) && x.Position.Y > head.ActualPosition.Y).Count() > 0) { inputs[0] = apples.Where(x => (x.Position.X == head.ActualPosition.X) && x.Position.Y > head.ActualPosition.Y).First().Position.Y - head.ActualPosition.Y; } //L if (apples.Where(x => (x.Position.Y == head.ActualPosition.Y) && x.Position.X < head.ActualPosition.X).Count() > 0) { inputs[3] = head.ActualPosition.X - apples.Where(x => (x.Position.Y == head.ActualPosition.Y) && x.Position.X < head.ActualPosition.X).First().Position.X; } return(inputs.ToList()); }
public static List <double> FindWallIn4Directions(SnakeBlock head) { return(new double[] { head.ActualPosition.X, Settings.Default.GameWidth - head.ActualPosition.X, head.ActualPosition.Y, Settings.Default.GameHeight - head.ActualPosition.Y, }.ToList()); }
public void displayCrash(Vector2 crashPos) { Position2D extraPos = new Position2D() { x = 0, y = 0 }; Position2D pos = setBlockCoords(crashPos, ref extraPos); SnakeBlock block = getBlockFromPos(pos); Vector3 spawnPos = block.transform.position + new Vector3(extraPos.x, 2, extraPos.y); Instantiate(collisionBlock, spawnPos, Quaternion.identity); }
public static List <bool> FindBinaryAppleIn4Directions(List <Apple> apples, SnakeBlock head) { return(ConvertDistToBool(FindAppleIn4Directions(apples, head))); }