public override List <Directions> GetPossibleDirections(PacManEnvironment environment) { char[,] board = environment.Board; int x = environment.PacManPositionX; int y = environment.PacManPositionY; int[] values = new int[4]; List <Directions> listDirectionsAvailable = new List <Directions>(); List <Directions> listDirectionsIsBetter = new List <Directions>(); if (Board.DownMove(x, y, board.GetUpperBound(0) + 1, board)) { listDirectionsAvailable.Add(Directions.Down); values[0] = Board.BestLineDown(x, y, board); } if (Board.UpMove(x, y, board)) { listDirectionsAvailable.Add(Directions.Up); values[1] = (Board.BestLineUp(x, y, board)); } if (Board.LeftMove(x, y, board)) { listDirectionsAvailable.Add(Directions.Left); values[2] = Board.BestLineLeft(x, y, board); } if (Board.RightMove(x, y, board.GetUpperBound(1) + 1, board)) { listDirectionsAvailable.Add(Directions.Right); values[3] = Board.BestLineRight(x, y, board); } if (Board.BestLine(values) == 0) { listDirectionsIsBetter.Add(Directions.Down); } if (Board.BestLine(values) == 1) { listDirectionsIsBetter.Add(Directions.Up); } if (Board.BestLine(values) == 2) { listDirectionsIsBetter.Add(Directions.Left); } if (Board.BestLine(values) == 3) { listDirectionsIsBetter.Add(Directions.Right); } if (listDirectionsIsBetter.Count > 0) { return(listDirectionsIsBetter); } else { return(listDirectionsAvailable); } }
public override List <Directions> GetPossibleDirections(PacManEnvironment environment) { char[,] board = environment.Board; int x = environment.PacManPositionX; int y = environment.PacManPositionY; List <Directions> listDirectionsAvailable = new List <Directions>(); List <Directions> listDirectionsIsFood = new List <Directions>(); if (Board.DownMove(x, y, board.GetUpperBound(0) + 1, board)) { listDirectionsAvailable.Add(Directions.Down); } if (Board.UpMove(x, y, board)) { listDirectionsAvailable.Add(Directions.Up); } if (Board.LeftMove(x, y, board)) { listDirectionsAvailable.Add(Directions.Left); } if (Board.RightMove(x, y, board.GetUpperBound(1) + 1, board)) { listDirectionsAvailable.Add(Directions.Right); } if (Board.FoodSideDown(x, board)) { listDirectionsIsFood.Add(Directions.Down); } if (Board.FoodSideLeft(y, board)) { listDirectionsIsFood.Add(Directions.Left); } if (Board.FoodSideRight(y, board)) { listDirectionsIsFood.Add(Directions.Right); } if (Board.FoodSideUp(x, board)) { listDirectionsIsFood.Add(Directions.Up); } if (listDirectionsIsFood.Count > 0) { return(listDirectionsIsFood); } else { return(listDirectionsAvailable); } }
public override List <Directions> GetPossibleDirections(PacManEnvironment environment) { char[,] board = environment.Board; int x = environment.PacManPositionX; int y = environment.PacManPositionY; List <Directions> listDirectionsAvailable = new List <Directions>(); List <Directions> listDirectionsNotGhost = new List <Directions>(); if (Board.DownMove(x, y, board.GetUpperBound(0) + 1, board)) { listDirectionsAvailable.Add(Directions.Down); if (!Board.IsGhostAround(x + 1, y, board)) { listDirectionsNotGhost.Add(Directions.Down); } } if (Board.UpMove(x, y, board)) { listDirectionsAvailable.Add(Directions.Up); if (!Board.IsGhostAround(x - 1, y, board)) { listDirectionsNotGhost.Add(Directions.Up); } } if (Board.LeftMove(x, y, board)) { listDirectionsAvailable.Add(Directions.Left); if (!Board.IsGhostAround(x, y - 1, board)) { listDirectionsNotGhost.Add(Directions.Left); } } if (Board.RightMove(x, y, board.GetUpperBound(1) + 1, board)) { listDirectionsAvailable.Add(Directions.Right); if (!Board.IsGhostAround(x, y + 1, board)) { listDirectionsNotGhost.Add(Directions.Right); } } if (listDirectionsNotGhost.Count > 0) { return(listDirectionsNotGhost); } else { return(listDirectionsAvailable); } }
public Directions?GetMoveDirection(PacManEnvironment environment) { Random rnd = new Random(); Directions? directions = null; List <Directions> listCurrent = null; foreach (var gene in GenesActive) { var possibleDirections = ((PacManEnvironmentAwareGene)gene).GetPossibleDirections(environment); if (listCurrent == null) { listCurrent = possibleDirections; } else { List <Directions> listTemp = new List <Directions>(); foreach (var direct in possibleDirections) { if (listCurrent.Contains(direct)) { listTemp.Add(direct); } } listCurrent = listTemp; } } if (listCurrent == null || listCurrent.Count == 0) { directions = null; } else { directions = listCurrent[rnd.Next(listCurrent.Count)]; } return(directions); }
public override List <Directions> GetPossibleDirections(PacManEnvironment environment) { char[,] board = environment.Board; int Px = environment.PacManPositionX; int Py = environment.PacManPositionY; int Gx = environment.GhostPositionX; int Gy = environment.GhostPositionY; int dx = Gx - Px; //delta X int dy = Gy - Py; //delta Y double tg = 0.0; List <Directions> listDirectionsAvailable = new List <Directions>(); List <Directions> listDirectionsNoGhost = new List <Directions>(); if (Board.DownMove(Px, Py, board.GetUpperBound(0) + 1, board)) { listDirectionsAvailable.Add(Directions.Down); } if (Board.UpMove(Px, Py, board)) { listDirectionsAvailable.Add(Directions.Up); } if (Board.LeftMove(Px, Py, board)) { listDirectionsAvailable.Add(Directions.Left); } if (Board.RightMove(Px, Py, board.GetUpperBound(1) + 1, board)) { listDirectionsAvailable.Add(Directions.Right); } if (Board.DistanceAtoB(Px, Py, Gx, Gy) < 10) { if (dx == 0 || dy == 0) { if (dy > 0) { listDirectionsNoGhost.Add(Directions.Down); listDirectionsNoGhost.Add(Directions.Left); listDirectionsNoGhost.Add(Directions.Up); } if (dy < 0) { listDirectionsNoGhost.Add(Directions.Up); listDirectionsNoGhost.Add(Directions.Down); listDirectionsNoGhost.Add(Directions.Right); } if (dx > 0) { listDirectionsNoGhost.Add(Directions.Right); listDirectionsNoGhost.Add(Directions.Left); listDirectionsNoGhost.Add(Directions.Up); } if (dx < 0) { listDirectionsNoGhost.Add(Directions.Down); listDirectionsNoGhost.Add(Directions.Left); listDirectionsNoGhost.Add(Directions.Right); } } else { tg = dy / (dx * 1.0f); } if (dx > 0 && dy > 0) { if (tg == 1) { listDirectionsNoGhost.Add(Directions.Up); listDirectionsNoGhost.Add(Directions.Left); } if (tg < 1) { listDirectionsNoGhost.Add(Directions.Right); listDirectionsNoGhost.Add(Directions.Left); listDirectionsNoGhost.Add(Directions.Up); } if (tg > 1) { listDirectionsNoGhost.Add(Directions.Down); listDirectionsNoGhost.Add(Directions.Left); listDirectionsNoGhost.Add(Directions.Up); } } if (dx < 0 && dy > 0) { if (tg == 1) { listDirectionsNoGhost.Add(Directions.Down); listDirectionsNoGhost.Add(Directions.Left); } if (tg < 1) { listDirectionsNoGhost.Add(Directions.Down); listDirectionsNoGhost.Add(Directions.Right); listDirectionsNoGhost.Add(Directions.Left); } if (tg > 1) { listDirectionsNoGhost.Add(Directions.Down); listDirectionsNoGhost.Add(Directions.Left); listDirectionsNoGhost.Add(Directions.Up); } } if (dx < 0 && dy < 0) { if (tg == 1) { listDirectionsNoGhost.Add(Directions.Down); listDirectionsNoGhost.Add(Directions.Right); } if (tg < 1) { listDirectionsNoGhost.Add(Directions.Down); listDirectionsNoGhost.Add(Directions.Right); listDirectionsNoGhost.Add(Directions.Left); } if (tg > 1) { listDirectionsNoGhost.Add(Directions.Up); listDirectionsNoGhost.Add(Directions.Down); listDirectionsNoGhost.Add(Directions.Right); } } if (dx > 0 && dy < 0) { if (tg == 1) { listDirectionsNoGhost.Add(Directions.Up); listDirectionsNoGhost.Add(Directions.Right); } if (tg < 1) { listDirectionsNoGhost.Add(Directions.Right); listDirectionsNoGhost.Add(Directions.Left); listDirectionsNoGhost.Add(Directions.Up); } if (tg > 1) { listDirectionsNoGhost.Add(Directions.Up); listDirectionsNoGhost.Add(Directions.Down); listDirectionsNoGhost.Add(Directions.Right); } } } if (listDirectionsNoGhost.Count > 0) { return(listDirectionsNoGhost); } else { return(listDirectionsAvailable); } }
public abstract List <Directions> GetPossibleDirections(PacManEnvironment environment);
public override List <Directions> GetPossibleDirections(PacManEnvironment environment) { char[,] board = environment.Board; int x = environment.PacManPositionX; int y = environment.PacManPositionY; int?xPrv = environment.PacManPreviousPositionX; int?yPrv = environment.PacManPreviousPositionY; List <Directions> listDirectionsAvailable = new List <Directions>(); List <Directions> listDirectionsNotPrevious = new List <Directions>(); if (Board.DownMove(x, y, board.GetUpperBound(0) + 1, board)) { listDirectionsAvailable.Add(Directions.Down); if (xPrv == null || yPrv == null) { listDirectionsNotPrevious.Add(Directions.Down); } else if (x - 1 == xPrv && y == yPrv) { listDirectionsNotPrevious.Add(Directions.Down); } } if (Board.UpMove(x, y, board)) { listDirectionsAvailable.Add(Directions.Up); if (xPrv == null || yPrv == null) { listDirectionsNotPrevious.Add(Directions.Up); } else if (x + 1 == xPrv && y == yPrv) { listDirectionsNotPrevious.Add(Directions.Up); } } if (Board.LeftMove(x, y, board)) { listDirectionsAvailable.Add(Directions.Left); if (xPrv == null || yPrv == null) { listDirectionsNotPrevious.Add(Directions.Left); } else if (x == xPrv && y + 1 == yPrv) { listDirectionsNotPrevious.Add(Directions.Left); } } if (Board.RightMove(x, y, board.GetUpperBound(1) + 1, board)) { listDirectionsAvailable.Add(Directions.Right); if (xPrv == null || yPrv == null) { listDirectionsNotPrevious.Add(Directions.Right); } else if (x == xPrv && y - 1 == yPrv) { listDirectionsNotPrevious.Add(Directions.Right); } } if (listDirectionsNotPrevious.Count > 0) { return(listDirectionsNotPrevious); } else { return(listDirectionsAvailable); } }