/// <summary> /// Iteration on explored map /// </summary> /// <returns>action for robot to perform</returns> private ActionType Phase2Iteration() { Tile[,] map = SmallMap; Point currentPos = CurrentPos, temp; //Greedy algorithm to choose next tile NeighbourAction[] actions = new NeighbourAction[4]; NeighbourActions.CopyTo(actions, 0); actions[0].LastVisit = map[currentPos.Row - 1, currentPos.Col].LastVisit; actions[1].LastVisit = map[currentPos.Row, currentPos.Col + 1].LastVisit; actions[2].LastVisit = map[currentPos.Row + 1, currentPos.Col].LastVisit; actions[3].LastVisit = map[currentPos.Row, currentPos.Col - 1].LastVisit; System.Array.Sort(actions); for (int i = 0; i < 4; ++i) { temp = currentPos + actions[i].Offset; if ((map[temp.Row, temp.Col].State & TileStates.Wall) == 0) { CurrentPos = temp; return(actions[i].Action); } } return(ActionType.actIDLE); }
/// <summary> /// Iteration on explored map /// </summary> /// <returns>action for robot to perform</returns> private ActionType Phase2Iteration() { Tile[,] map = SmallMap; Point currentPos = CurrentPos, temp; //Trying to use dirt exptectation to pause the robot sometimes and save some energy bool needIteration = false; for (int row = 0; row < Environment.mazeSize_; ++row) { for (int col = 0; col < Environment.mazeSize_; ++col) { if ((map[row, col].State & TileStates.Wall) == 0 && CurrentIteration - map[row, col].LastVisit + (currentPos.ManhattanDistance(row, col) * DistanceFactor) > DirtExpectation) { needIteration = true; } } } if (!needIteration) { return(ActionType.actIDLE); } //Greedy algorithm to choose next tile NeighbourAction[] actions = new NeighbourAction[4]; NeighbourActions.CopyTo(actions, 0); actions[0].LastVisit = map[currentPos.Row - 1, currentPos.Col].LastVisit; actions[1].LastVisit = map[currentPos.Row, currentPos.Col + 1].LastVisit; actions[2].LastVisit = map[currentPos.Row + 1, currentPos.Col].LastVisit; actions[3].LastVisit = map[currentPos.Row, currentPos.Col - 1].LastVisit; System.Array.Sort(actions); for (int i = 0; i < 4; ++i) { temp = currentPos + actions[i].Offset; if ((map[temp.Row, temp.Col].State & TileStates.Wall) == 0) { CurrentPos = temp; return(actions[i].Action); } } return(ActionType.actIDLE); }
/// <summary> /// Iteration on explored map /// </summary> /// <returns>action for robot to perform</returns> private ActionType Phase2Iteration() { Tile[,] map = SmallMap; Point currentPos = CurrentPos, temp; //Trying to use dirt exptectation to pause the robot sometimes and save some energy bool needIteration = false; for (int row = 0; row < Environment.mazeSize_; ++row) for (int col = 0; col < Environment.mazeSize_; ++col) if ((map[row, col].State & TileStates.Wall) == 0 && CurrentIteration - map[row, col].LastVisit + (currentPos.ManhattanDistance(row, col) * DistanceFactor) > DirtExpectation) needIteration = true; if (!needIteration) return ActionType.actIDLE; //Greedy algorithm to choose next tile NeighbourAction[] actions = new NeighbourAction[4]; NeighbourActions.CopyTo(actions, 0); actions[0].LastVisit = map[currentPos.Row - 1, currentPos.Col].LastVisit; actions[1].LastVisit = map[currentPos.Row, currentPos.Col + 1].LastVisit; actions[2].LastVisit = map[currentPos.Row + 1, currentPos.Col].LastVisit; actions[3].LastVisit = map[currentPos.Row, currentPos.Col - 1].LastVisit; System.Array.Sort(actions); for (int i = 0; i < 4; ++i) { temp = currentPos + actions[i].Offset; if ((map[temp.Row, temp.Col].State & TileStates.Wall) == 0) { CurrentPos = temp; return actions[i].Action; } } return ActionType.actIDLE; }
/// <summary> /// Iteration on explored map /// </summary> /// <returns>action for robot to perform</returns> private ActionType Phase2Iteration() { Tile[,] map = SmallMap; Point currentPos = CurrentPos, temp; //Greedy algorithm to choose next tile NeighbourAction[] actions = new NeighbourAction[4]; NeighbourActions.CopyTo(actions, 0); actions[0].LastVisit = map[currentPos.Row - 1, currentPos.Col].LastVisit; actions[1].LastVisit = map[currentPos.Row, currentPos.Col + 1].LastVisit; actions[2].LastVisit = map[currentPos.Row + 1, currentPos.Col].LastVisit; actions[3].LastVisit = map[currentPos.Row, currentPos.Col - 1].LastVisit; System.Array.Sort(actions); for (int i = 0; i < 4; ++i) { temp = currentPos + actions[i].Offset; if ((map[temp.Row, temp.Col].State & TileStates.Wall) == 0) { CurrentPos = temp; return actions[i].Action; } } return ActionType.actIDLE; }