public static void GameOfLife(int[][] board) { for (int i = 0; i < board.Length; i++) { for (int j = 0; j < board[0].Length; j++) { Postion p = new Postion(i, j, board); board[i][j] = p.setNewState(); } } for (int i = 0; i < board.Length; i++) { for (int j = 0; j < board[0].Length; j++) { if (board[i][j] == 2) { board[i][j] = 1; } else if (board[i][j] == 3) { board[i][j] = 0; } } } }
public RasterOp Calculator(Postion startPostion) { if (!Read(startPostion.XIndex, startPostion.YIndex).HasValue) { throw new ArgumentOutOfRangeException("起始位置不含有数据"); } RasterPositionValue[,] cost = new RasterPositionValue[Width, Height]; //初始化操作 InitializeValues(cost); InitializeStart(startPostion, cost); //使用orderbag,是的每次取出的最小值 OrderedBag <RasterPositionValue> bag = new OrderedBag <RasterPositionValue>(); bag.Add(cost[startPostion.XIndex, startPostion.YIndex]); while (bag.Count != 0) { RasterPositionValue pos = bag.RemoveFirst(); var postions = Sourround(cost, pos); foreach (var postion in postions) { double relativeCost = Read(postion.XIndex, postion.YIndex).GetValueOrDefault() * 0.5 + Read(postion.XIndex, postion.YIndex).GetValueOrDefault() * 0.5; if (pos.XIndex != postion.XIndex && pos.YIndex != postion.YIndex) { relativeCost *= Math.Sqrt(2); } cost[postion.XIndex, postion.YIndex].Visited = true; cost[postion.XIndex, postion.YIndex].HasValue = true; cost[postion.XIndex, postion.YIndex].RasterValue = (float)relativeCost + cost[pos.XIndex, pos.YIndex].RasterValue; bag.Add(cost[postion.XIndex, postion.YIndex]); } } return(Result(cost)); }
public bool IsValidSudoku(char[,] board) { if(board==null || board.GetLength(0)!=9 || board.GetLength(1)!=9) return false; Dictionary<char,List<Postion>> dic=new Dictionary<char,List<Postion>>(9); for(int i=0;i<9;i++) { for(int j=0;j<9;j++) { char cell=board[i,j]; if(IsNumber(cell)) { Postion pos=new Postion(i,j); if(!dic.ContainsKey(cell)) { dic.Add(cell,new List<Postion>(){pos}); } //包含key else { for(int k=0;k<dic[cell].Count;k++) { if(!dic[cell][k].Valid(pos)) return false; } dic[cell].Add(pos); } } } } return true; }
// Reason for not using an array is for clarity private void Pouplate ( int NumberOfCircles, int NumberOfTriangles, int NumberOfHexagons, int NumberOfSquares, int NumberOfMines, Postion PostionType ) { for (int i = 0; i < NumberOfCircles; i++) { Add(_factory.CreateCircle(PostionType())); } for (int i = 0; i < NumberOfTriangles; i++) { Add(_factory.CreateTriangle(PostionType())); } for (int i = 0; i < NumberOfHexagons; i++) { Add(_factory.CreateHexagon(PostionType())); } for (int i = 0; i < NumberOfSquares; i++) { Add(_factory.CreateBeliver(new Rectangle(PostionType(), 0))); } for (int i = 0; i < NumberOfMines; i++) { Add(_factory.CreateMine(PostionType())); } }
/// <summary> /// 获取某一个城市到某个网格点的直线距离所需的是时间 /// </summary> /// <param name="i"></param> /// <param name="j"></param> /// <param name="cityName"></param> /// <returns></returns> public float ShortestTimeCost(int i, int j, Postion cityPos) { double x = Math.Abs(i - cityPos.XIndex) * Info.XCellSize; double y = Math.Abs(j - cityPos.YIndex) * Info.YCellSize; double distance = Math.Sqrt(x * x + y * y) / 1000; return((float)(distance / Speed * 60)); }
public bool Valid(Postion other) { if(other.x==x || other.y==y) return false; if(other.x/3==x/3 && other.y/3==y/3) return false; return true; }
/// <summary> /// 计算一个高铁城市的在高铁未通车的时间成本 /// </summary> /// <returns>时间成本操作</returns> private RasterOp CalculationCity(string cityName) { RasterOp rasterOp = new RasterOp(_rasterReader); City city = _allCities.First(item => item.Name == cityName); Postion pos = _rasterReader.Coordinate(city.XCoord, city.YCoord); return(rasterOp.Calculator(pos)); }
private void InitializeStart(Postion startPostion, RasterPositionValue[,] cost) { //startPostion.HasValue = true; //startPostion.RasterValue = 0; //startPostion.Visited = true; cost[startPostion.XIndex, startPostion.YIndex].HasValue = true; cost[startPostion.XIndex, startPostion.YIndex].Visited = true; cost[startPostion.XIndex, startPostion.YIndex].RasterValue = 0; }
private void Run(RasterReader reader, CalculatorCity city, string folderPath) { RasterOp rasterOp = new RasterOp(reader); Postion pos = reader.Coordinate(city.XCoord, city.YCoord); var result = rasterOp.Calculator(pos); RasterWriter writer = new RasterWriter(folderPath, city.Name + "_高铁未通车", reader.RasterInfo); result.WriteRaster(writer, "TIFF"); }
private bool VisistedValid(RasterPositionValue[,] cost, Postion pos) { //return ValueValid(pos.XIndex, pos.YIndex) // &&!cost[pos.XIndex,pos.YIndex].Visited; return(pos.XIndex >= 0 && pos.XIndex < Width && pos.YIndex >= 0 && pos.YIndex < Height && _raster[pos.XIndex, pos.YIndex].HasValue && cost[pos.XIndex, pos.YIndex].Visited == false); }
void Awake() { _Access = new ComponentAccesser(gameObject); _Postion = new Postion(gameObject); _Postion.Z = CalcZPos(); // 整数に変更 _Postion.ToInteger(); }
public override bool Equals(object obj) { Postion pos = (Postion)obj; if (pos != null) { return(pos.XIndex == XIndex && pos.YIndex == YIndex); } return(false); }
//转化成Protobuffer类型函数 public DramaModuleTransformV1 ToPB() { DramaModuleTransformV1 v = new DramaModuleTransformV1(); v.Postion = Postion.ToPB(); v.Rotation = Rotation.ToPB(); v.Scale = Scale.ToPB(); return(v); }
//从Protobuffer类型初始化 public void FromPB(DramaModuleTransformV1 v) { if (v == null) { return; } Postion.FromPB(v.Postion); Rotation.FromPB(v.Rotation); Scale.FromPB(v.Scale); }
public bool Valid(Postion other) { if (other.x == x || other.y == y) { return(false); } if (other.x / 3 == x / 3 && other.y / 3 == y / 3) { return(false); } return(true); }
void Awake() { _Access = new ComponentAccesser(gameObject); _Postion = new Postion(gameObject); _Postion.IntZ = -9; // 整数に変更 _Postion.ToInteger(); // 非表示にする //_Access.Renderer.enabled = false; }
public void Connect() { var tid = Thread.CurrentThread.ManagedThreadId; //var hash = tcpClient.GetStream().GetHashCode(); tcpClient = Tcp_client; tcpStream.TryAdd(tid, tcpClient.GetStream()); Postion.TryAdd(tid, new[] { 0, 0 }); Screen.TryAdd(tid, new[] { 0, 0 }); Connected.TryAdd(tid, true); TelnetShell.StartCmd(); }
private void SetUpWorldObjects() { // Amount of objects differs between Screen only and not if (Settings.SCREENONLY) { _spawnPostion = new Postion(Utils.RandomScreenPoint); Pouplate(0, 0, 0, 10, 1, _spawnPostion); } else { _spawnPostion = new Postion(Utils.RandomWorldPoint); Pouplate(10, 10, 10, 10, 20, _spawnPostion); } }
public bool IsValidSudoku(char[,] board) { if (board == null || board.GetLength(0) != 9 || board.GetLength(1) != 9) { return(false); } Dictionary <char, List <Postion> > dic = new Dictionary <char, List <Postion> >(9); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { char cell = board[i, j]; if (IsNumber(cell)) { Postion pos = new Postion(i, j); if (!dic.ContainsKey(cell)) { dic.Add(cell, new List <Postion>() { pos }); } //包含key else { for (int k = 0; k < dic[cell].Count; k++) { if (!dic[cell][k].Valid(pos)) { return(false); } } dic[cell].Add(pos); } } } } return(true); }
public IEnumerable <Postion> Sourround(RasterPositionValue[,] cost, Postion postion) { if (VisistedValid(cost, postion.LeftTop())) { yield return(postion.LeftTop()); } if (VisistedValid(cost, postion.Top())) { yield return(postion.Top()); } if (VisistedValid(cost, postion.RightTop())) { yield return(postion.RightTop()); } if (VisistedValid(cost, postion.Right())) { yield return(postion.Right()); } if (VisistedValid(cost, postion.RightButtom())) { yield return(postion.RightButtom()); } if (VisistedValid(cost, postion.Buttom())) { yield return(postion.Buttom()); } if (VisistedValid(cost, postion.LeftButtom())) { yield return(postion.LeftButtom()); } if (VisistedValid(cost, postion.Left())) { yield return(postion.Left()); } }
public void Do(IAsyncResult result) { var action = ((((AsyncResult)result).AsyncDelegate) as Func <IEnumerator <CustomAction>, CustomAction>).EndInvoke(result); if (action == null) { _isComplete.Set(); Status = DriverState.Stop; return; } try { // Move and Click the first chip. this.Actions.MoveToElement(ActionElement, Postion.One.X, Postion.One.Y).Click().Perform(); if (action.BetType != Bet.停) { double balance = -1; // Check if the user's balance has reached the maximum threshold. if (Config.IsMoneyWarning && !string.IsNullOrEmpty(Config.StopMoney)) { var response = Config.GetBalanceAsync(); var isMatch = double.TryParse(response.Result, out balance); // Return HTML code maybe. if (isMatch) { if (balance - Convert.ToDouble(action.Money) < Convert.ToDouble(Config.StopMoney)) { _isComplete.Set(); Status = DriverState.Stop; return; } } } var action_ChipCount = Math.Round(Convert.ToDouble(action.Money) / 10); var action_Bet = this.Actions; for (int i = 0; i < action_ChipCount; i++) { var postion = Postion.BetPoint(action.BetType); action_Bet.MoveToElement(ActionElement, postion.X, postion.Y) .Click(); } action_Bet.Perform(); this.Actions.MoveToElement(ActionElement, Postion.Confirm.X, Postion.Confirm.Y) .Click() .Perform(); } // Custom delay. Thread.Sleep(Convert.ToInt32(action.Delay)); // Call back. StartCallerAsync.BeginInvoke(_actionsQueue, new AsyncCallback(Do), "Async:Callback"); } catch (Exception e) { Status = DriverState.Stop; LogHelper.Error(e); return; } }
private void Run(object p) { Hashtable para = p as Hashtable; var wait = para["wait"] as ProgressWait; string folderPath = para["folderPath"].ToString(); int totalCount = Cities.Count(item => item.IsSelected); int count = 0; try { wait.SetWaitCaption("计算高铁城市空间可达性"); foreach (string city in _dijkstra.GetCityEnumerator()) { wait.SetProgress((double)count++ / _dijkstra.Count); _highTrainStation.Add(city, CalculationCity(city)); } Dictionary <string, RasterOp> backup = new Dictionary <string, RasterOp>(_highTrainStation.Count); //backup foreach (var keyValue in _highTrainStation) { backup.Add(keyValue.Key, new RasterOp(keyValue.Value)); } //*********************************** wait.SetProgress(0); wait.SetWaitCaption("计算高铁城市叠加效应"); count = 0; foreach (string city in _dijkstra.GetCityEnumerator()) { wait.SetProgress((double)count++ / _dijkstra.Count); float[] times = _dijkstra.Dijkstra(city); foreach (var otherCity in _dijkstra.GetCityEnumerator()) { if (city != otherCity) { int cityIndex = _dijkstra.GetCityIndex(otherCity); backup[otherCity].Overlay(item => item + times[cityIndex]); _highTrainStation[city].Overlay(backup[otherCity], Math.Min); backup[otherCity].Overlay(item => item - times[cityIndex]); } } } //**************************************** backup.Clear(); //foreach (var keyValue in _highTrainStation) //{ // backup.Add(keyValue.Key, new RasterOp(keyValue.Value)); //} wait.SetWaitCaption("计算所有城市空间可达性"); wait.SetProgress(0); count = 0; foreach (var calculatorCity in Cities) { if (calculatorCity.IsSelected) { wait.SetProgress((double)count++ / totalCount); RasterOp res; if (_highTrainStation.ContainsKey(calculatorCity.Name)) { res = _highTrainStation[calculatorCity.Name]; } else { res = CalculationCity(calculatorCity.Name); RasterOp back = res.Clone(); foreach (var station in _highTrainStation) { //RasterOp op = back.Clone(); City city = _allCities.First(item => item.Name == station.Key); Postion pos = _rasterReader.Coordinate(city.XCoord, city.YCoord); float timecost = (float)back.Read(pos.XIndex, pos.YIndex); _highTrainStation[station.Key].Overlay(item => item + timecost); res.Overlay(_highTrainStation[station.Key], Math.Min); _highTrainStation[station.Key].Overlay(item => item - timecost); } } RasterWriter writer = new RasterWriter(folderPath, calculatorCity.Name + "_高铁通车后", _rasterReader.RasterInfo); res.WriteRaster(writer, "TIFF"); } } para["ret"] = true; } catch (Exception e) { _log.Error(e.Message + e.StackTrace); para["ret"] = false; } finally { wait.CloseWait(); } }
public CircleF ToMonogameCircle() { return(new CircleF(Postion.ToPoint2(), (float)Radius)); }
//#region Member //public int Index { get; set; } //#endregion void Awake() { _Access = new ComponentAccesser(gameObject); _Postion = new Postion(gameObject); }