public (CellItemType, Beacon) MoveWithStrategy(Game game) { CellItemType retVal; Beacon beaconValue = new Beacon(); var poppedNode = new Node(); if (game.CurrentNode.Children.Count > 0) { poppedNode = game.CurrentNode.Children.Pop(); Position.Row = poppedNode.Position.Row; Position.Column = poppedNode.Position.Column; game.CurrentNode = poppedNode; retVal = poppedNode.CellItemType; } else { poppedNode = game.CurrentNode.Parent; Position.Row = poppedNode.Position.Row; Position.Column = poppedNode.Position.Column; game.CurrentNode = poppedNode; retVal = poppedNode.CellItemType; Metrics.backtrackCount++; } Metrics.moveCount++; if (retVal == CellItemType.Beacon) { BaseCellItem cell = game.Map[poppedNode.Position.Row, poppedNode.Position.Column]; beaconValue = cell as Beacon; if (beaconValue != null && beaconValue.Value < 1) { retVal = CellItemType.Empty; beaconValue = null; } } if (retVal == CellItemType.GoldenSquare) { // fix facing Symbol = "\u2133"; } game.AssignPlayerToCell(this); return(retVal, beaconValue); }
public bool DiscoverUsingBeacon(Game game, BaseCellItem cell, List <(Node, double)> priorityChildren, List <(int, int, Direction)> genTargets)
public BaseCellItem MoveForward(Game game, bool random, int gameSpeed) { int times = 1; if (random) { times = Randomizer.RandomizeNumber(1, game.Size); } Console.WriteLine(string.Format("The player will move to the {0} for {1} time(s)!", Facing.ToString(), times)); BaseCellItem cell = null; for (int i = 0; i < times; i++) { Thread.Sleep(gameSpeed); cell = ScanForward(game); //scanCount += 1; if (cell.CellItemType == CellItemType.Wall) { Console.WriteLine("The player ran into a thick wall and cannot move forward. Aborting the remaining moves, if any."); break; } // remove the player from its current cell game.ClearCell(Position.Row, Position.Column); // assign new coordinates to the player Position.Row = cell.Position.Row; Position.Column = cell.Position.Column; game.AssignPlayerToCell(this); var newCoordinates = new Tuple <int, int>(Position.Row, Position.Column); Console.WriteLine(string.Format("Player moved to coordinates [{0},{1}]", Position.Row, Position.Column)); if (PositionHistory.Contains(newCoordinates)) { Metrics.backtrackCount++; } PositionHistory.Add(newCoordinates); //moveCount += 1; Metrics.moveCount++; if (cell.CellItemType == CellItemType.Pit) { // die Console.WriteLine("The player died a horrible death."); break; } else if (cell.CellItemType == CellItemType.GoldenSquare) { // win Console.WriteLine("The player has struck gold."); break; } else if (cell.CellItemType == CellItemType.Beacon) { // clue Console.WriteLine("The player has found a beacon."); break; } } return(cell); }