// Add the matrix data to the grid public void AddDataToGrid() { int t_row = 0; // Clear the grid ClearGrid(); // Add the columns header AddHeaderToGrid(); foreach (var kv_vector in _theMatrix._Vectors) { var kv_vector_key = kv_vector.Key; var kv_vector_value = kv_vector.Value; int index = _theDataGrid.Rows.Add(); int t_col = 0; foreach (var kv_cell in kv_vector_value._Cells) { CCell theCell = kv_cell.Value; _theDataGrid.Rows[t_row].Cells[t_col].Value = theCell._value; _theDataGrid.Rows[t_row].Cells[t_col].Tag = theCell; t_col++; } t_row++; } }
protected IEnumerator CreateNewGraph(int vertexCount) { processRunning = true; CCell newCell = null; CVertex newNode = null; Vector3 mPos = mazePos.position; Vector3 gPos = graphPos.position; int count = 0; for (int row = 0; row < mazeSize; row++) { mPos = new Vector3(mazePos.position.x, mazePos.position.y - row * cellOffset); gPos = new Vector3(graphPos.position.x, graphPos.position.y - row * nodeOffset); for (int col = 0; col < mazeSize; col++) { mPos = new Vector3(mazePos.position.x + col * cellOffset, mPos.y); gPos = new Vector3(graphPos.position.x + col * nodeOffset, gPos.y); newCell = Instantiate(cellPrefab, mPos, cellPrefab.transform.rotation).GetComponent <CCell>(); newNode = Instantiate(nodePrefab, gPos, nodePrefab.transform.rotation).GetComponent <CVertex>(); newNode.Init(count.ToString()); newCell.Init(row, col); graph.InsertVertex(newCell); mazeGameO.Add(newCell); graphGameO.Add(newNode); count++; yield return(animationWait); } } // reset position of drawing reference points mazePos.position = transform.position; graphPos.position = transform.position; StartCoroutine(GenerateMaze()); }
/// <summary> /// TraverseBack /// </summary> /// <param name="T">the table</param> /// <param name="intI">the index of current segment on polyline frcpl</param> /// <param name="intJ">the index of current segment on polyline tocpl</param> /// <param name="frcptlt">point list of frcpl</param> /// <param name="tocptlt">point list of tocpl</param> /// <param name="intMinBackKforI">We will traverse back one segment by one segment from intI-intMinBackKforI to intI-intMaxBackKforI</param> /// <param name="intMaxBackKforI">We will traverse back one segment by one segment from intI-intMinBackKforI to intI-intMaxBackKforI</param> /// <param name="intMinBackKforJ">We will traverse back one segment by one segment from intJ-intMinBackKforJ to intJ-intMaxBackKforJ</param> /// <param name="intMaxBackKforJ">We will traverse back one segment by one segment from intJ-intMinBackKforJ to intJ-intMaxBackKforJ</param> /// <returns>the CCell with minimum dblEvaluation among all the CTables</returns> private CCell TraverseBack(ref CTable T, int intI, int intJ, List <CPoint> frcptlt, List <CPoint> tocptlt, int intMinBackKforI, int intMaxBackKforI, int intMinBackKforJ, int intMaxBackKforJ) { var minCCell = new CCell(0, 0, CConstants.dblHalfDoubleMax); if (intMinBackKforI == 0) //we do this separately because we don't need to traverse when k1==0 { minCCell = CHelpFunc.Min(CalCell(ref T, intI, intJ, 0, 1, frcptlt, tocptlt), minCCell, ccell => ccell.dblCost); intMinBackKforI++; } if (intMinBackKforJ == 0) //we do this separately because we don't need to traverse when k2==0 { minCCell = CHelpFunc.Min(CalCell(ref T, intI, intJ, 1, 0, frcptlt, tocptlt), minCCell, ccell => ccell.dblCost); intMinBackKforJ++; } for (int k1 = intMinBackKforI; k1 <= intMaxBackKforI; k1++) { for (int k2 = intMinBackKforJ; k2 <= intMaxBackKforJ; k2++) { //k1 and k2 can be 0 at the same time because we have already set T.aCell[i, j].dblEvaluation = double.MaxValue. //So it doesn't matter minCCell = CHelpFunc.Min(CalCell(ref T, intI, intJ, k1, k2, frcptlt, tocptlt), minCCell, ccell => ccell.dblCost); } } //find the minimum one return(minCCell); }
public void GetQueryCachedValues(CQuerieResult query) { Services.IDatabase cachedb = Services.XServices.Instance.GetService <Services.IDatabase>(); ViewModels.ProjectData ProjectData = Services.XServices.Instance.GetService <ViewModels.ProjectData>(); foreach (var row in query.Rows) { for (int i = 0; i < row.Items.Length; i++) { string uid = row.Items[0].UID; CCell item = row.Items[i]; string cachedvalue = cachedb.ReadCacheSpecValue(uid, "", ProjectData.SelectedProject.ProjectUID, ProjectData.SelectedLayer.UID, query.Columns[i].DisplayDescription); if (cachedvalue != "") { int result = 0; item.Text = cachedvalue; if (int.TryParse(cachedvalue, out result)) { item.NumericValue = result; } item.IsCachedValue = true; } } } }
private void InfectGerm() { for (int i = -1; i < 2; ++i) { for (int j = -1; j < 2; ++j) { var moveIndexX = _moveCell.CellIndexX; var moveIndexY = _moveCell.CellIndexY; if (moveIndexY + i < 0 || moveIndexY + i > 6 || moveIndexX + j < 0 || moveIndexX + j > 6) { continue; } else { var cell = CGameDataStorage.Instance.CellObjectList[moveIndexX + j, moveIndexY + i].GetComponent <CCell>(); if (cell.CellStatus != EGermColor.NONE && cell.CellStatus != _moveCell.CellStatus) { cell.ChangeGermColor(_moveCell.CellStatus); } } } } _selectCell = null; _moveCell = null; CGameDataStorage.Instance.GamePhase = EGamePhase.TURNCHANGE; }
// Event relay - double click on a cell public void CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex >= 0) { var val = _theDataGrid.Rows[e.RowIndex].Cells[e.ColumnIndex]; var tag = _theDataGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag; if (tag is CCell) { CCellMatrix theMatrix = BuildMatrixFromGrid(); CCell theCurrentCell = (CCell)tag; using (var modal = new FormDialogCCel(theCurrentCell, theMatrix)) { modal.ShowDialog(); if (modal.DialogResult == DialogResult.OK) { // refresh grid ClearGrid(); AddHeaderToGrid(); AddDataToGrid(); } } } } }
public CCommandCellEnterNumber(CCell cell, int value) { m_lValue = value; m_Cell = cell; m_lOldValue = cell.DisplayValue; m_OldMarks = cell.Marks.ToArray(); }
private void AddDataToGrid(DataGridView pGrid, CCellMatrix pTheMatrix) { int t_row = 0; pGrid.Rows.Clear(); pGrid.Columns.Clear(); AddCellToGrid(pGrid, pTheMatrix._cellHeaderVector); foreach (var kv_vector in pTheMatrix._Vectors) { var kv_vector_key = kv_vector.Key; var kv_vector_value = kv_vector.Value; int index = pGrid.Rows.Add(); int t_col = 0; foreach (var kv_cell in kv_vector_value._Cells) { CCell theCell = kv_cell.Value; pGrid.Rows[t_row].Cells[t_col].Value = theCell._value; pGrid.Rows[t_row].Cells[t_col].Tag = theCell; t_col++; } t_row++; } }
private void RefreshSlaveHeaders(CCell pCell, ListView pListView) { pListView.Clear(); pListView.View = View.Details; pListView.GridLines = true; pListView.Columns.Add("Header"); pListView.Columns.Add("Name"); pListView.Columns.Add("Type"); pListView.Columns.Add("Description"); pListView.Columns.Add("Script"); pListView.Columns[0].Width = 80; pListView.Columns[1].Width = 100; pListView.Columns[2].Width = 60; pListView.Columns[3].Width = 200; pListView.Columns[4].Width = 200; string tHeader = ""; string tName = ""; string tType = ""; string tScript = ""; string tDescriptiom = ""; foreach (var tColHeader in _theMatrix.ColumnsHeader) { tHeader = tColHeader._header; tName = tColHeader._name; tType = (tColHeader._type == ECellType.Input) ? "Input" : "Script"; tDescriptiom = tColHeader._description; tScript = tColHeader._script; pListView.Items.Add(new ListViewItem(new string[] { tHeader, tName, tType, tDescriptiom, tScript })); } }
/// <summary>创建T矩阵</summary> /// <param name="frcpl">大比例尺线状要素</param> /// <param name="tocpl">小比例尺线状要素</param> /// <param name="intMaxBackKforI">回溯系数</param> /// <returns>T矩阵</returns> public virtual CTable CreatTableOptCor(List <CPoint> frcptlt, List <CPoint> tocptlt, int intMaxBackKforI, int intMaxBackKforJ) { int intFrPtNum = frcptlt.Count; int intToPtNum = tocptlt.Count; //it would be nice if we could calculate these arrays previously, but we don't have so much memory //CPolyline[,] afrsubcpl = CreateSubCpl(frcpl, intMaxBackKforI); //CPolyline[,] atosubcpl = CreateSubCpl(tocpl, intMaxBackKforJ); //T.aCell[i, j].dblEvaluation is actually the cost till the ends of i segments on polyline frcpl and j segments on polyline tocpl CTable Table = new CTable(intFrPtNum, intToPtNum); //we do this separately because we don't need to traverse back for the first row and first col CalTFisrtRowCol(ref Table, frcptlt, tocptlt); for (int i = 1; i < intFrPtNum; i++) //计算各空格值 { int intBackKforI = Math.Min(i, intMaxBackKforI); //程序刚开始执行时,之前已遍历过线段数较少,可能小于intMaxBackKforI for (int j = 1; j < intToPtNum; j++) { int intBackKforJ = Math.Min(j, intMaxBackKforJ); //程序刚开始执行时,之前已遍历过线段数较少,可能小于intMaxBackKforI var minCCell = new CCell(0, 0, CConstants.dblHalfDoubleMax); minCCell = CHelpFunc.Min(TraverseBack(ref Table, i, j, frcptlt, tocptlt, 0, 1, 0, 1), minCCell, ccell => ccell.dblCost); //including 0 to 1, 1 to 0, 1 to 1 minCCell = CHelpFunc.Min(TraverseBack(ref Table, i, j, frcptlt, tocptlt, 2, intBackKforI, 1, 1), minCCell, ccell => ccell.dblCost); //including 2 to 1 until intBackKforI to 1 minCCell = CHelpFunc.Min(TraverseBack(ref Table, i, j, frcptlt, tocptlt, 1, 1, 2, intBackKforJ), minCCell, ccell => ccell.dblCost); //including 1 to 2 until 1 to intBackKforJ Table.aCell[i, j] = minCCell; } } return(Table); }
public FormDialogCCel(CCell pCell, CCellMatrix pCellMatrix) { InitializeComponent(); _cell = pCell; _cellMatrix = pCellMatrix; InitGui(); _lastFeedback = _cell._calculationFeedback; }
public Vector3 GetIconCenterByCell(CCell cell) { return(new Vector3( startPosX + cell.x * outX, startPosY - cell.y * outY, this.transform.position.z )); }
public virtual void AddCell(int x, int y, CCell cell) { this.InitCell(x, y, cell); if (this.m_Grid.Contains(cell) == false) { this.m_Grid.Add(cell); } }
public virtual void AddCell(CCell value) { if (this.IsCurrentCell(value) == false) { this.m_Cells.Add(value); this.Draw(); } }
private void RefreshSlave(CCell pCell) { RefreshSlaveCellDetails(pCell); RefreshSlaveHeaders(pCell, this._parentFormSheet.ListViewField); RefreshSlavePrimitives(pCell); RefreshSlaveHistoric(pCell); RefreshSlaveMonitors(pCell, this._parentFormSheet.ListViewMonitor); }
private void RefreshSlaveCellDetails(CCell pCell) { // 1. value this._parentFormSheet.SlaveCurrentCellValue = pCell._value; // 2. input/script if (pCell._type == ECellType.Input) { this._parentFormSheet.SlaveRadioButtonInput = true; this._parentFormSheet.SlaveRadioButtonScript = false; } else { this._parentFormSheet.SlaveRadioButtonInput = false; this._parentFormSheet.SlaveRadioButtonScript = true; } //.3 Cell status switch (pCell._status) { case ECellStatus.Clean: this._parentFormSheet.SlaveMainStatus = "Clean"; break; case ECellStatus.Dirty: this._parentFormSheet.SlaveMainStatus = "Dirty"; break; case ECellStatus.Error: this._parentFormSheet.SlaveMainStatus = "Error"; break; case ECellStatus.N_A: this._parentFormSheet.SlaveMainStatus = "N_A"; break; default: this._parentFormSheet.SlaveMainStatus = "Other"; break; } //4. Script string tScript = ""; try // This is the Script at header level { tScript = (_theMatrix._cellHeaderVector._cellHeaders.First(s => s._name == pCell._cellHeader._name))._script; } catch (Exception) { tScript = ""; } // Much better than linq.FirstOrDefault: in case of nothing found then empty script this._parentFormSheet.SlaveScript = tScript; //5. Evaluation this._parentFormSheet.SlaveEvaluation = pCell._calculationFeedback; //6. Overidde this._parentFormSheet.SlaveOverridde = pCell._overRidden; }
public CGameViewObject RegisterIcon(CCell pos) { CGameViewObject box = Instantiate(boxPrefab); box.transform.localScale = Vector3.one; box.transform.position = GetIconCenterByCell(pos); return(box); }
private CCell CalCell(ref CTable T, int intI, int intJ, int k1, int k2, List <CPoint> frcptlt, List <CPoint> tocptlt) { double dblEvaluation = T.aCell[intI - k1, intJ - k2].dblCost + CalDistance(frcptlt.GetRange(intI - k1, k1 + 1), tocptlt.GetRange(intJ - k2, k2 + 1)); var ccell = new CCell(k1, k2, dblEvaluation); //tableij.CorrCptsLt = CorrCptsLtij; //to use memory as little as possible, we don't record CorrCptsLtij return(ccell); }
public Vector3 GetIconCenterByCell(CCell cell) { var config = CGame.Config.match.field; return(new Vector3( config.from.x + cell.col * config.offset.x, config.from.y + cell.row * config.offset.y, this.transform.position.z )); }
public virtual void RemoveCell(CCell value) { var index = this.m_Cells.IndexOf(value); if (index != -1) { this.m_Cells.RemoveRange(index, this.m_Cells.Count - index); this.m_Cells.TrimExcess(); this.Draw(); } }
public virtual CLine ContainLine(CCell value) { for (int i = 0; i < this.m_Lines.Count; i++) { var line = this.m_Lines [i]; if (line.IsCurrentCell(value)) { return(line); } } return(null); }
public ICell GetCell(SPoint position) { var cell = new CCell(position.X, position.Y); XElement cellData = GetCellElement(position); String terrainType = cellData?.Attribute("terrain")?.Value; cell.Terrain = GetTerrain(terrainType); return(cell); }
/// <summary> /// use a dynamic programming algorithm to compute correspondences between two polylines /// </summary> /// <param name="frcpl">the larger-scale polyline</param> /// <param name="tocpl">the smaller-scale polyline</param> /// <param name="intMaxBackKforI">look-back parameter for the larger-scale polyline</param> /// <param name="intMaxBackKforJ">look-back parameter for the smaller-scale polyline</param> /// <param name="StandardVectorCpt">if frcpl and tocpl are not in the same place, we use StandardVectorCpt to offset their distance</param> /// <returns>two dimensional table which we can traverse back to construct correspondences between the two polylines</returns> /// <remarks>to guarantee that there are the same number of points on the two polylines after interpolation, /// we only allow correspondences of one segment to one segment, or one segment to multi-segment; /// we do NOT allow a correspondence of one segment to a single point.</remarks> public virtual CTable CreatTableOptCorSimplified(List <CPoint> frcptlt, List <CPoint> tocptlt, int intMaxBackKforI, int intMaxBackKforJ) { int intFrPtNum = frcptlt.Count; int intToPtNum = tocptlt.Count; //if we used a relatively small intMaxBackKforJ, //then we check whether this intMaxBackKforJ would be enough to avoid point-segment correspondences AdjustMaxBackK(ref intMaxBackKforI, intMaxBackKforI, intFrPtNum, intToPtNum); AdjustMaxBackK(ref intMaxBackKforJ, intMaxBackKforI, intToPtNum, intFrPtNum); //T is the two dimensional table, which will be returned as the result. //T.aCell[i, j].dblEvaluation is actually the cost till the ends of i segments on polyline frcpl and j segments on polyline tocpl CTable Table = new CTable(intFrPtNum, intToPtNum); //we compute the first row and column of table Table here because we don't need to traverse back CalTFisrtRowCol(ref Table, frcptlt, tocptlt); //We do this to handle the case that the look-back parameter is not enough, then we will have to allow segment-point matching. //For example: if there are 25 segments on frcpl and 5 segments on tocpl, then we need intMaxBackKforI >= 5; //if our intMaxBackKforI == 3, then we can only build the correspondences between the last 15 segments of frcpl and the 5 segments of tocpl. //The first 10 segments of frcpl have to correspond to the first point of tocpl. for (int i = 1; i < intFrPtNum; i++) { Table.aCell[i, 0].dblCost = Table.aCell[i, 0].dblCost + CConstants.dblHalfDoubleMax; //CConstants.dblHalfDoubleMax is a very large number } for (int j = 1; j < intToPtNum; j++) { Table.aCell[0, j].dblCost = Table.aCell[0, j].dblCost + CConstants.dblHalfDoubleMax; //CConstants.dblHalfDoubleMax is a very large number } //compute other rows and columns of table Table for (int i = 1; i < intFrPtNum; i++) { int intBackKforI = Math.Min(i, intMaxBackKforI); //at some beginning steps, the number of traversed segments is smaller than the look-back parameter for (int j = 1; j < intToPtNum; j++) { int intBackKforJ = Math.Min(j, intMaxBackKforJ); //at some beginning steps, the number of traversed segments is smaller than the look-back parameter var minCCell = new CCell(0, 0, CConstants.dblHalfDoubleMax); minCCell = CHelpFunc.Min(TraverseBack(ref Table, i, j, frcptlt, tocptlt, 1, 1, 1, 1), minCCell, ccell => ccell.dblCost); //only including 1 segment to 1 segment minCCell = CHelpFunc.Min(TraverseBack(ref Table, i, j, frcptlt, tocptlt, 2, intBackKforI, 1, 1), minCCell, ccell => ccell.dblCost); //including 2 segments to 1 segment until intBackKforI segments to 1 segment minCCell = CHelpFunc.Min(TraverseBack(ref Table, i, j, frcptlt, tocptlt, 1, 1, 2, intBackKforJ), minCCell, ccell => ccell.dblCost); //including 1 segment to 2 segments until 1 segment to intBackKforJ segments Table.aCell[i, j] = minCCell; } } return(Table); }
public void SetVertexB(CCell c) { cellB = c; vertexB = cellB.myVertex; if (cellOutlineB == null) { cellOutlineB = Instantiate(cellOutlinePrefab, cellB.transform.position, cellOutlinePrefab.transform.rotation); } else { cellOutlineB.transform.position = cellB.transform.position; } }
public void SetVertexA(CCell c) { cellA = c; vertexA = cellA.myVertex; if (cellOutlineA == null) { cellOutlineA = Instantiate(cellOutlinePrefab, cellA.transform.position, cellOutlinePrefab.transform.rotation); } else { cellOutlineA.transform.position = cellA.transform.position; } }
public CCell GenerateTile(float x, float y, float z, int value, CCell prefab) { var cell = Instantiate(prefab); cell.transform.SetParent(this.m_MapRoot); cell.transform.localPosition = new Vector3(x, y, z); cell.x = x; cell.y = y; cell.z = z; cell.value = value; cell.name = string.Format("Cell {0}:{1}:{2}", x, y, z); return(cell); }
private CCellMatrix BuildMatrixFromGrid(DataGridView pDataGrid) { CCellMatrix theMatrix = new CCellMatrix(); CCellVector theCellVector; int i_row = 0; int i_col = 0; foreach (DataGridViewRow row in pDataGrid.Rows) { theCellVector = new CCellVector(); //theMatrix.AddVector(i_row, theCellVector); i_col = 0; bool last_empty_line = true; foreach (DataGridViewCell cell in row.Cells) { string colName = _theMatrix._cellHeaderVector._cellHeaders[i_col]._name; // check if the last row is completely empty in order to insert the vector if (!(cell.Value is null)) { last_empty_line = false; } double cell_value = Convert.ToDouble(cell.Value); //CCell cellToInsert = new CCell(0, cell_value); CCell cellToInsert = new CCell(cell_value.ToString(), i_row); var x = _theMatrix._cellHeaderVector._cellHeaders[i_col]; cellToInsert._cellHeader = _theMatrix._cellHeaderVector._cellHeaders[i_col]; theCellVector.Add(colName, cellToInsert); i_col++; } if (!last_empty_line) { theMatrix.AddVector(i_row, theCellVector); } i_row++; } return(theMatrix); }
public virtual void AddCell(CCell value) { if (this.m_CurrentLine == null) { return; } CLine line = this.ContainLine(value); if (line != null) { line.RemoveCell(value); } this.m_CurrentLine.AddCell(value); }
protected bool numerationCompleted; // flag to indicate when the numeration process is completed private void Awake() { if (instance == null) { instance = this; } graph = new Graph <CCell>(); mazeGameO = new List <CCell>(); graphGameO = new List <CVertex>(); edgeGameO = new List <GameObject>(); pathEdgesGameO = new List <GameObject>(); animationWait = new WaitForSeconds(animationSpeed); cellA = cellB = null; }
public override void StartAction() { var move = new CMove(); CCell cell = selected.cell.Clone(); field.SetIconAt(targeted.cell, selected); field.SetIconAt(cell, targeted); move.AddMove(selected, field.GetIconCenterByCell(selected.cell)); move.AddMove(targeted, field.GetIconCenterByCell(targeted.cell)); move.SetObserver(this); }
/// <summary> /// Выполняет инициализацию массивов. /// До выполенения данного метода не позволяет считывать кубы. /// </summary> /// <param name="i"></param> /// <param name="j"></param> /// <param name="k"></param> public void SetSize(int i, int j, int k) { NI = i; NJ = j; NK = k; KRange = new int[2] { 0, k - 1 }; SelectedI = NI / 2; SelectedJ = NJ / 2; coord = new CCoord(NI, NJ, NK); ViewCenter = new tXYZ(); ViewOffset = new tXYZ(); zcorn = new CZcorn(NI, NJ, NK); actnum = new CActnum(NI, NJ, NK, this); MapColor = new Single[NI, NJ]; InterColor = new Single[NI, NJ, NK]; zmin = double.MaxValue; zmax = double.MinValue; PaintI = true; //IsInitialized = true; Cell = new CCell(this); Bulleye = new CBulleye(this); Reduce = new CReduce(this); Restore = new CRestore(this); Picker = new CPicker(this); }