private object PlaceRobot(PlaceOptions opts) { var placementActionResult = GetPlacementDirection(opts.PlacementCommandArgument); if (placementActionResult != null) { return(_robo.SetPositionOnBoard(placementActionResult.LocationX, placementActionResult.LocationY, placementActionResult.Direction)); } return(new MovementActionResult(MovementStatus.RobotPlaceInvalidCommandParsed)); }
private object DoPlace(PlaceOptions options, RootComponent scene) { if (_robot == null) { _robot = new RobotEntity(); _robot.AttachTo(scene); } _robot.Place(new Vector(options.PosX, options.PosY, 0f), options.Facing); Console.WriteLine($"Robot is at {_robot.GetPosition().X}, {_robot.GetPosition().Y} " + $"facing {Orientation.FromVector(_robot.GetOrientation()).CardinalDirection}"); return(null); }
/// <summary> /// 進行排名。 /// </summary> /// <param name="scoreParser">要被排名的成績計算邏輯。</param> /// <param name="option">排名選項,接序 or 不接序排名。</param> /// <param name="placeNamespace">存放排名結果的 Namespace。</param> public void Rank(IScoreParser <T> scoreParser, PlaceOptions option) { //取得有成績的學生。 List <ScoredStudent> students = GetScoredStudents(scoreParser); //排序名次。 students.Sort(delegate(ScoredStudent x, ScoredStudent y) { decimal X = x.Score; decimal Y = y.Score; //反過來排,由大到小。 return(Y.CompareTo(X)); }); //決定排序。 IPlaceAlgorithm algorithm = null; if (option == PlaceOptions.Sequence) { algorithm = new Sequence(); } else { algorithm = new Unsequence(); } int radix = students.Count; string scorename = scoreParser.Name; foreach (ScoredStudent each in students) { int level = algorithm.NextLevel(each.Score); T student = _students[each.Id]; PlaceCollection places = GetPlaceCollection(student); if (places.Contains(scorename)) { places[scorename] = new Place(level, each.Score, radix); } else { places.Add(scorename, new Place(level, each.Score, radix)); } } }
/// <summary> /// Расчет площадки /// </summary> public List <Tile> CalcPlace(Place place) { List <Tile> tiles; dictLevels = new Dictionary <double, TileLevel>(); placeOptions = place.PlaceModel.Options; levels = placeOptions.Levels.OrderByDescending(o => o.TotalTimeMin).ToList(); model = place.PlaceModel.Model; step = placeOptions.TileSize; stepHalf = step * 0.5; stepQuart = step * 0.25; using (pl = place.PlaceId.Open(OpenMode.ForRead) as Polyline) { place.Area = NetLib.DoubleExt.Round(pl.Area, 2); // Нарезка площадки на ячейки (tiles) tiles = DividePlace(); // расчет каждой ячейке (точка - без оуна и без здания) var insPt = new InsPoint(); insPt.Model = model; insPt.Window = null; insPt.Building = null; insPt.Height = 0; foreach (var tile in tiles) { insPt.Point = tile.Point.Convert3d(); try { var illums = calcTrees.CalcPoint(insPt, false); tile.InsValue = calcService.CalcTimeAndGetRate(illums, Elements.Buildings.BuildingTypeEnum.Living); tile.Level = DefineLevel(tile.InsValue.TotalTime); } catch (UserBreakException) { throw; } catch { tile.InsValue = InsValue.Empty; tile.Level = TileLevel.Empty; // На угловых точках - может не рассчитаться пока // Пропустить!? } } } return(tiles); }
public PlaceOptionsViewModel(PlaceOptions placeOptions) { PlaceOptions = placeOptions; TileSize = placeOptions.TileSize; TransparenceInvert = (byte)(255 - placeOptions.Transparent); Levels = new ObservableCollection <TileLevel>(placeOptions.Levels); SelectColor = new RelayCommand <TileLevel>(OnSelectColorExecute); DeleteLevel = new RelayCommand <TileLevel>(OnDeleteLevelExecute, OnDeleteLevelCanExecute); AddLevel = new RelayCommand(OnAddLevelExecute, OnAddLevelCanExecute); OK = new RelayCommand(OnOkExecute); ResetLevels = new RelayCommand(OnResetLevelsExecute); foreach (var item in Levels) { item.PropertyChanged += Item_PropertyChanged; } }
/// <summary> /// 進行排名。 /// </summary> /// <param name="scoreParser">要被排名的成績計算邏輯。</param> /// <param name="option">排名選項,接序 or 不接序排名。</param> /// <param name="provider">當相同名次時決定先後成績資料,所有排名範圍內的學生都應該供相同順序與數量的成績資料,否則會產生無法預期的結果。</param> public void Rank(IScoreParser <T> scoreParser, PlaceOptions option) { //取得有成績的學生。 List <ScoredStudent> students = GetScoredStudents(scoreParser); //沒有成績就不用排名了。 if (students.Count <= 0) { return; } //排序名次。 students.Sort(delegate(ScoredStudent x, ScoredStudent y) { if (scoreParser is IScoresParser <T> ) { IScoresParser <T> p2 = scoreParser as IScoresParser <T>; if (x.SecondScores.Count <= 0) { x.SecondScores = p2.GetSecondScores(x.Source); } if (y.SecondScores.Count <= 0) { y.SecondScores = p2.GetSecondScores(y.Source); } } return(y.CompareTo(x)); }); int radix = students.Count; //基數。 string scorename = scoreParser.Name; //排名的名稱。 //先把之前的排名結果清掉。 foreach (T each in this) { PlaceCollection places = GetPlaceCollection(each); if (places.Contains(scorename)) { places.Remove(scorename); } } //決定排序。 IPlaceAlgorithm placeAlg = null; if (option == PlaceOptions.Sequence) { placeAlg = new Sequence(); } else { placeAlg = new Unsequence(); } StandardPercentage percenAlg = new StandardPercentage(); percenAlg.Initital(students.Count); foreach (ScoredStudent each in students) { int level = placeAlg.NextLevel(each); int percen = percenAlg.NextPercentage(level); T student = _students[each.Id]; PlaceCollection places = GetPlaceCollection(student); if (places.Contains(scorename)) { places[scorename] = new Place(level, percen, each.Score, radix, this.Count); } else { places.Add(scorename, new Place(level, percen, each.Score, radix, this.Count)); } } }