public Direction SuggestNextDirection(BotGame game) { _game = game; var currentLocation = _graph.GetNodeForLocation(_game.PacMan.Location); var shortestDistances = DistancesCalculator.CalculateDistances(_game, _graph, currentLocation); var nearestCoin = FindNearestCoin(_game.Coins, shortestDistances); Direction bestDirectionToNearestCoin; if (nearestCoin == CellLocation.TopLeft) { // No more coins are available, game is meant to be finished. Pick any direction // and hope to stay away from the ghosts bestDirectionToNearestCoin = currentLocation.AvailableMoves.First().Direction; } else { bestDirectionToNearestCoin = shortestDistances.DirectionToTarget(nearestCoin); } var nearestGhost = FindNearestGhost(_game.Ghosts, shortestDistances); bestDirectionToNearestCoin = AvoidGhost(currentLocation, shortestDistances, bestDirectionToNearestCoin, nearestGhost); return(bestDirectionToNearestCoin); }
public void Run() { int player1Wins = 0, player2Wins = 0; Console.WriteLine("How many games do you want to play?"); var numGames = int.Parse(Console.ReadLine()); for (int i = 0; i < numGames; i++) { BotGame game1 = new BotGame(); game1.PlayToTheEnd(); if (game1.Player1.HasLost) { player2Wins++; } else { player1Wins++; } } Console.WriteLine("Player 1 Wins: " + player1Wins.ToString()); Console.WriteLine("Player 2 Wins: " + player2Wins.ToString()); Console.ReadLine(); }
public bool Activate(AutomatedGame game) { this.game = game as BotGame; if (this.game == null) return false; ScheduledBegging(); return true; }
public bool Activate(AutomatedGame game) { this.game = game as BotGame; if (this.game == null) { return(false); } ScheduledBegging(); return(true); }
public static Distances CalculateDistances(BotGame game, Graph.Graph graph, LinkedCell currentLocation) { //1 var width = game.Board.Width; var height = game.Board.Height; var shortestDistances = new int[width, height]; var visited = new bool[width, height]; for (int r = 0; r < height; r++) { for (int c = 0; c < width; c++) { shortestDistances[c, r] = int.MaxValue; } } //2 shortestDistances[currentLocation.Location.X, currentLocation.Location.Y] = 0; visited[currentLocation.Location.X, currentLocation.Location.Y] = true; //3 CellLocation?currentNode = currentLocation.Location; while (currentNode is object) { var distanceToCurrentNode = shortestDistances[currentNode.Value.X, currentNode.Value.Y]; var linkedCell = graph.GetNodeForLocation(currentNode.Value); foreach (var(_, newLocation) in linkedCell.AvailableMoves) { if (!visited[newLocation.Location.X, newLocation.Location.Y]) { var tentativeDistance = distanceToCurrentNode + 1; var currentValue = shortestDistances[newLocation.Location.X, newLocation.Location.Y]; shortestDistances[newLocation.Location.X, newLocation.Location.Y] = Math.Min(tentativeDistance, currentValue); } } //4 visited[currentNode.Value.X, currentNode.Value.Y] = true; var bestScore = int.MaxValue; currentNode = null; for (int r = 0; r < height; r++) { for (int c = 0; c < width; c++) { var seen = visited[c, r]; if (!seen) { if (shortestDistances[c, r] < bestScore) { bestScore = shortestDistances[c, r]; currentNode = new CellLocation(c, r); } } } } } return(new Distances(shortestDistances, graph)); }