public void StartStrategy(IAlgorythm algorythm, IPacMan pacMan, IMaze maze, IGhost ghost, Position start) { algorythm.From.X = ghost._position.X; algorythm.From.Y = ghost._position.Y; algorythm.To.X = maze.BottomRightCorner.X; algorythm.To.Y = maze.BottomRightCorner.Y; algorythm.Execute(); List <Location> rightCornerBottom = algorythm.ResultPath; foreach (var i in rightCornerBottom) { if (ghost._position.X + 1 == i.X) { ghost.direction = SidesToMove.Right; } else if (ghost._position.X - 1 == i.X) { ghost.direction = SidesToMove.Left; } else if (ghost._position.Y - 1 == i.Y) { ghost.direction = SidesToMove.Up; } else if (ghost._position.Y + 1 == i.Y) { ghost.direction = SidesToMove.Down; } } }
public void StartStrategy(IAlgorythm algorythm, IPacMan pacMan, IMaze maze, IGhost ghost, Position start) { algorythm.From.X = ghost._position.X; algorythm.From.Y = ghost._position.Y; algorythm.To.X = start.X; algorythm.To.Y = start.Y; algorythm.Execute(); List <Location> route = algorythm.ResultPath; foreach (var step in route.ToList()) { if (ghost._position.X + 1 == step.X) { ghost.direction = SidesToMove.Right; } if (ghost._position.X - 1 == step.X) { ghost.direction = SidesToMove.Left; } if (ghost._position.Y - 1 == step.Y) { ghost.direction = SidesToMove.Up; } if (ghost._position.Y + 1 == step.Y) { ghost.direction = SidesToMove.Down; } } }
public void StartStrategy(IAlgorythm algorythm, IPacMan pacMan, IMaze maze, IGhost ghost, Position Start) { algorythm.From.X = ghost._position.X; algorythm.From.Y = ghost._position.Y; if (pacMan.direction == SidesToMove.Down) { algorythm.To.X = pacMan._position.X + 2; algorythm.To.Y = pacMan._position.Y - 2; } if (pacMan.direction == SidesToMove.Up) { algorythm.To.X = pacMan._position.X + 2; algorythm.To.Y = pacMan._position.Y + 2; } if (pacMan.direction == SidesToMove.Left) { algorythm.To.X = pacMan._position.X - 2; algorythm.To.Y = pacMan._position.Y - 2; } if (pacMan.direction == SidesToMove.Right) { algorythm.To.X = pacMan._position.X + 2; algorythm.To.Y = pacMan._position.Y - 2; } algorythm.Execute(); List <Location> dir = algorythm.ResultPath; foreach (var i in dir.ToList()) { if (i != null) { if (ghost._position.X + 1 == i.X) { ghost.direction = SidesToMove.Right; } else if (ghost._position.X - 1 == i.X) { ghost.direction = SidesToMove.Left; } else if (ghost._position.Y - 1 == i.Y) { ghost.direction = SidesToMove.Up; } else if (ghost._position.Y + 1 == i.Y) { ghost.direction = SidesToMove.Down; } } } }
public Classificator(IAlgorythm algorythm) { algo = algorythm; }
public DictionaryClassificator(IAlgorythm algorythm, int numOfColumn) { algo = algorythm; numberOfColumn = numOfColumn; }
public void StartStrategy(IAlgorythm algorythm, IPacMan pacMan, IMaze maze, IGhost ghost, Position start) { Random random = new Random(); string dir = random.Next(1, 4).ToString(); if (maze.Map[ghost._position.Y - 1, ghost._position.X] == maze.Wall && maze.Map[ghost._position.Y, ghost._position.X - 1] == maze.Wall) { if (ghost.prevDirection == SidesToMove.Up) { dir = "1"; } if (ghost.prevDirection == SidesToMove.Left) { dir = "4"; } } if (maze.Map[ghost._position.Y + 1, ghost._position.X] == maze.Wall && maze.Map[ghost._position.Y, ghost._position.X - 1] == maze.Wall) { if (ghost.prevDirection == SidesToMove.Down) { dir = "1"; } if (ghost.prevDirection == SidesToMove.Left) { dir = "3"; } } if (maze.Map[ghost._position.Y - 1, ghost._position.X] == maze.Wall && maze.Map[ghost._position.Y, ghost._position.X + 1] == maze.Wall) { if (ghost.prevDirection == SidesToMove.Up) { dir = "2"; } if (ghost.prevDirection == SidesToMove.Right) { dir = "4"; } } if (maze.Map[ghost._position.Y + 1, ghost._position.X] == maze.Wall && maze.Map[ghost._position.Y, ghost._position.X + 1] == maze.Wall) { if (ghost.prevDirection == SidesToMove.Down) { dir = "2"; } if (ghost.prevDirection == SidesToMove.Right) { dir = "3"; } } if (maze.Map[ghost._position.Y - 1, ghost._position.X] != maze.Wall && maze.Map[ghost._position.Y, ghost._position.X + 1] != maze.Wall && maze.Map[ghost._position.Y, ghost._position.X - 1] != maze.Wall) { if (ghost.prevDirection == SidesToMove.Left) { dir = "3"; } if (ghost.prevDirection == SidesToMove.Right) { dir = "4"; } } if (maze.Map[ghost._position.Y - 1, ghost._position.X] != maze.Wall && maze.Map[ghost._position.Y + 1, ghost._position.X] != maze.Wall && maze.Map[ghost._position.Y, ghost._position.X - 1] != maze.Wall) { if (ghost.prevDirection == SidesToMove.Right) { dir = "4"; } if (ghost.prevDirection == SidesToMove.Down) { dir = "2"; } } if (maze.Map[ghost._position.Y, ghost._position.X + 1] != maze.Wall && maze.Map[ghost._position.Y + 1, ghost._position.X] != maze.Wall && maze.Map[ghost._position.Y, ghost._position.X - 1] != maze.Wall) { if (ghost.prevDirection == SidesToMove.Up) { dir = "1"; } } switch (dir) { case "1": if (maze.Map[ghost._position.Y, ghost._position.X + 1] != maze.Wall) { if (ghost.prevDirection != SidesToMove.Left) { ghost.direction = SidesToMove.Right; } } break; case "2": if (maze.Map[ghost._position.Y, ghost._position.X - 1] != maze.Wall) { if (ghost.prevDirection != SidesToMove.Right) { ghost.direction = SidesToMove.Left; } } break; case "3": if (maze.Map[ghost._position.Y - 1, ghost._position.X] != maze.Wall) { if (ghost.prevDirection != SidesToMove.Down) { ghost.direction = SidesToMove.Up; } } break; case "4": if (maze.Map[ghost._position.Y + 1, ghost._position.X] != maze.Wall) { if (ghost.prevDirection != SidesToMove.Up) { ghost.direction = SidesToMove.Down; } } break; } }