public static int Main() { MCell <int> c = new MCell <int>(1); MPair <int, string> p = c.GetMPair <string>("2"); c.Gather <float, long>((float)0.5, (long)0); return(100); }
public void Gather <A, B>(A a, B b) { MPair <A, B> p1 = new MPair <A, B>(a, b); MPair <T, A> p2 = new MPair <T, A>(_t, a); MPair <MPair <A, B>, MPair <T, A> > p3 = new MPair <MPair <A, B>, MPair <T, A> >(p1, p2); MPair <T, A> p4 = GetMPair <A>(a); MCell <A> c1 = new MCell <A>(a); }
// Notify Mirror Cell Dependents Event Handler void NewBalance_NotifyDependents(object sender, EventArgs e) { //Update dependents value Cell c = sender as Cell; if (c == null) { return; } string valueToSend; if (c is KCell) { KCell kc = c as KCell; if (kc.KValue != String.Empty) { valueToSend = kc.KValue; } else { valueToSend = kc.Value.ToString(); } } else if (c is MCell) { MCell mc = c as MCell; valueToSend = mc.MValue; } else { if (c.Value == null) { valueToSend = String.Empty; } else { valueToSend = c.Value.ToString(); } } // Cell's will only be dependent within the current row for (int i = 0; i < NewBalanceDataGridView.ColumnCount; i++) { MCell mc = ViewData.GetCell(c.RowIndex, i) as MCell; if (mc == null) { continue; } if (mc.IsDependent(c)) { mc.MValue = valueToSend; } } }
//distance field public void generateDistanceField(MCell cell0) { foreach (MCell c in cells) { c.cost = -1.0; // set all cells to -1 } List <MCell> front = new List <MCell>(); front.Add(cell0); // add first cell to front cell list cell0.cost = 0.0; // set its cost to 0.0 for (int i = 0; i < 100000; ++i) { if (front.Count == 0) { break; // if there are no cells in front break } MCell c = front[front.Count - 1]; // set current cell to first cell of front front.RemoveAt(front.Count - 1); // remove the cell for (int j = 0; j < c.others.Length; ++j) { if (!c.isOpen(j)) { continue; // if cell is not open in direction of j continue } MCell nc = c.others[j]; // new cell double transitionCost = (c.p - nc.p).magnitude; // calculate transition cost which is the distance between the two cell points double newOtherCost = c.cost + transitionCost; // cost is equal to current cell cost and transition cost if (nc.cost < 0.0 || newOtherCost < nc.cost) { nc.cost = newOtherCost; front.Add(nc); // add new cell to front } } } }
// Update is called once per frame void Update() { // game play experiments if (Input.GetMouseButtonDown(0)) { RaycastHit hit = new RaycastHit(); if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) { //Debug.Log(hit.point); if (hit.point.y > 2.0f) // if the same cell was hit more than 4 times - create new maze to make it unsolvable { maze.create(resolutionX, resolutionY, protos, protoBlock); } int i = (int)(hit.point.x + 0.5f); int j = (int)(hit.point.z + 0.5f); if (i >= 0 && j >= 0 && i < maze.resx && j < maze.resy) { MCell c = maze.cells[i, j]; c.setFloorColor(moo); // set the color to the one that indicates that the cell has been hit Vector3 p = c.geometry.transform.position; p.y += 0.5f; // raise the cell by 0.5 in the y axis c.geometry.transform.position = p; transform.position = c.p + new Vector3(0.0f, 5.0f, 0.0f); transform.LookAt(c.p); } } } }
public override void Draw(Node tableNode, PaintMode printMode, Color color) { if ((printMode == PaintMode.BACKGROUND)) { base.painter_.FillRectangle(tableNode); } else { if (tableNode.NotBlack()) { color = tableNode.style_.color; } if (this.table.frame == TableLineStyle.SOLID) { tableNode.box.Width = this.table.totalHorzFrameSpacing; base.painter_.Rectangle(tableNode, color); tableNode.box.Width = this.table.totalWidth; } else if (this.table.frame == TableLineStyle.DASHED) { tableNode.box.Width = this.table.totalHorzFrameSpacing; base.painter_.DrawNodeRect(tableNode, color); tableNode.box.Width = this.table.totalWidth; } for (int i = 0; i < this.table.RowCount; i++) { MRow row = this.table.GetRow(i); for (int j = 0; j < row.Count; j++) { MCell cell = (MCell)row.cells[j]; int rspan = 0; int colSpan = 0; rspan = (i + cell.rowSpan) - 1; colSpan = cell.colSpan; if (rspan < (this.table.RowCount - 1)) { int x1 = 0; int x2 = 0; int y1 = 0; if (colSpan == 0) { x1 = base.rect.x; } else { x1 = (base.rect.x + this.table.spanBases[colSpan]) - (this.table.spanWidth[colSpan - 1] / 2); } if (colSpan == (this.table.ColCount - 1)) { x2 = base.rect.x + this.table.totalHorzFrameSpacing; } else { x2 = ((base.rect.x + this.table.spanBases[(colSpan + cell.columnSpan) - 1]) + this.table.spanHeight[(colSpan + cell.columnSpan) - 1]) + (this.table.spanWidth[(colSpan + cell.columnSpan) - 1] / 2); } y1 = (row.node.box.Y + this.table.rowspanWidth(i, cell.rowSpan)) + (this.table.spacingWidth[rspan] / 2); if (row.lines == TableLineStyle.SOLID) { base.painter_.DrawLine(x1, y1, x2, y1, color); } else if (row.lines == TableLineStyle.DASHED) { base.painter_.DrawDashLine(x1, y1, x2, y1, color); } } } } for (int i = 0; i < this.table.RowCount; i++) { MRow row = this.table.GetRow(i); for (int j = 0; j < row.Count; j++) { MCell cell = (MCell)row.cells[j]; int cspn = (cell.colSpan + cell.columnSpan) - 1; if (cspn < (this.table.ColCount - 1)) { int x1 = 0; int y1 = 0; int y2 = 0; int hh = 0; for (int k = 0; k < cell.rowSpan; k++) { MRow rrow = this.table.GetRow(i + k); hh += rrow.node.box.Height; if (k < (cell.rowSpan - 1)) { hh += this.table.spacingWidth[i + k]; } } x1 = ((base.rect.x + this.table.spanBases[cspn]) + this.table.spanHeight[cspn]) + (this.table.spanWidth[cspn] / 2); if (i == 0) { y1 = base.rect.y; } else { y1 = row.node.box.Y - (this.table.spacingWidth[i - 1] / 2); } if ((i + (cell.rowSpan - 1)) == (this.table.RowCount - 1)) { y2 = base.rect.y + base.rect.height; } else { y2 = (row.node.box.Y + hh) + (this.table.spacingWidth[i] / 2); } if (this.table.colLines[cspn] == TableLineStyle.SOLID) { base.painter_.DrawLine(x1, y1, x1, y2, color); } else if (this.table.colLines[cspn] == TableLineStyle.DASHED) { base.painter_.DrawDashLine(x1, y1, x1, y2, color); } } } } for (int i = 0; i < this.table.RowCount; i++) { MRow row = this.table.GetRow(i); if (row.isLabeled) { row.node.box.Width = this.table.totalWidth; } } } }
// Use this for initialization void Start() { lines = GetComponent <LineRenderer>(); maze = new Maze(); // instantiate new maze object maze.create(resolutionX, resolutionY, protos, protoBlock); // create it System.Random rnd = new System.Random(); MCell firstCell = maze.cells[rnd.Next() % maze.resx, rnd.Next() % maze.resy]; // pick the starting cell maze.generateDistanceField(firstCell); // generate solution path from the first cell to the one with the highest cost MCell currentCell = firstCell; MCell maxC = firstCell; foreach (MCell c in maze.cells) { if (c.cost > maxC.cost) { maxC = c; // if the cell cost is greater than the max cost, update max cost to cell cost } } double maxcost = maxC.cost; foreach (MCell c in maze.cells) { if (c.cost < 0.0) { c.setFloorColor(mooTwo); // if the cell is not accessible set it to a custom color } else { float ncost = (float)(c.cost / maxcost); c.setFloorColor(new Color(ncost, ncost, ncost, 1.0f)); // otherwise, set a gradient of grey } } MCell targetMoo = maxC; List <MCell> path = new List <MCell>(); for (int s = 0; s < 200; ++s) { path.Add(targetMoo); if (targetMoo == firstCell) { break; // if the first and last cell are the same then break } MCell nextCell = new MCell(); for (int b = 0; b < 4; ++b) { if (targetMoo.isOpen(b) && targetMoo.others[b].cost == targetMoo.cost - 1.0 ) // if the last cell is open in the direction of the neighboring cell and the cost of the neighboring cell is 1 less, then make it the next cell { nextCell = targetMoo.others[b]; } } if (nextCell.others.Length > 0.0) { for (int d = 0; d < nextCell.others.Length; ++d) { if (nextCell.isOpen(d) && nextCell.others[d].cost == targetMoo.cost - 2.0 ) // if the neighbors of the next cell have a cost of two less than the target cell, make it the next cell { targetMoo = nextCell; } else if (nextCell.cost == 0.0) { targetMoo = firstCell; // end of solution path } } } } lines.positionCount = path.Count; // draw the path for (int i = 0; i < path.Count; ++i) { Vector3 lp = path[i].p; lp.y += 1.0f; lines.SetPosition(i, lp); Material lineMaterial = new Material(Shader.Find("Sprites/Default")); lines.material = lineMaterial; } }
public void create(int rx, int ry, List <GameObject> m, List <int> y) { resx = rx; resy = ry; for (int i = 0; i < m.Count; ++i) { MCellType newtype = new MCellType(); newtype.geometry = m[i]; newtype.isOpen[0] = true; newtype.isOpen[1] = true; newtype.isOpen[2] = true; newtype.isOpen[3] = true; newtype.index = i; newtype.isOpen[y[i]] = false; //set a type to close cellTypes.Add(newtype); } cells = new MCell[rx, ry]; float dx = 1.0f; float dy = 1.0f; System.Random rnd = new System.Random(); //generate maze for (int j = 0; j < ry; ++j) { for (int i = 0; i < rx; ++i) { int cellindex = rnd.Next() % cellTypes.Count; // set cellindex to random [0, cellTypes.Count] MCell newcell = new MCell(); newcell.type = cellTypes[cellindex]; // generate cell with the random index above newcell.p = new Vector3(i * dx, 0.0f, j * dy); // get center point of each cell (for solution path) //draw cell GameObject clone = GameObject.Instantiate <GameObject>(newcell.type.geometry); clone.transform.position = new Vector3(i * dx, 0.0f, j * dy); newcell.geometry = clone; cells[i, j] = newcell; } } // determine neighboring cells and set restrictions for corner cells for (int j = 0; j < ry; ++j) { for (int i = 0; i < rx; ++i) { MCell c = cells[i, j]; if (i > 0) { c.others[left] = cells[i - 1, j]; } if (i < rx - 1) { c.others[right] = cells[i + 1, j]; } if (j > 0) { c.others[bottom] = cells[i, j - 1]; } if (j < ry - 1) { c.others[top] = cells[i, j + 1]; } } } }
public void rotateCell(MCell c) { c.type = cellTypes[(c.type.index + 1) % cellTypes.Count]; }
public List <Cell> ReturnCellsInRow(int rowNumber) { List <Cell> cols = new List <Cell>(); int colIndex = 0; foreach (List <string> l in _parsedFile) { MultipleCell multi = null; // there will be 5 items in each .APP file if (l.Count != 5) { break; } string label = l[0]; string type = l[1]; int digits; // not really necessary for this application, but leaving for reverse compatibility int.TryParse(l[2], out digits); int precision; int.TryParse(l[3], out precision); string connectionInfo = l[4]; switch (type) { // keyboard cell case "K": if (MultipleCell.IsMultiCell(label) && cols.OfType <MultipleCell>().ToList().Count > 0) { colIndex--; } KCell k = new KCell(label, digits, precision, connectionInfo, rowNumber, colIndex); if (MultipleCell.IsMultiCell(label)) { multi = BuildMultipleCell(k, cols); if (multi != null) { cols.Add(multi); } } else { cols.Add(k); } break; // weight cell case "W": if (MultipleCell.IsMultiCell(label) && cols.OfType <MultipleCell>().ToList().Count > 0) { colIndex--; } WCell w = new WCell(label, digits, precision, connectionInfo, rowNumber, colIndex); if (MultipleCell.IsMultiCell(label)) { multi = BuildMultipleCell(w, cols); if (multi != null) { cols.Add(multi); } } else { cols.Add(w); } break; // calculation cell case "C": List <string> names = connectionInfo.Split(new char[] { '(', ')', '+', '-', '*', '/', '^' }).ToList(); // need for TryParse double n; List <string> dependencyNamesPossibleDupes = (from name in names where name.Length > 0 && !double.TryParse(name, out n) // make sure the value isn't an integer select name).ToList(); List <string> dependencyNames = dependencyNamesPossibleDupes.Distinct().ToList(); List <Cell> dependencies = new List <Cell>(); foreach (string name in dependencyNames) { Cell dependency = cols.First(x => x.Label == name); if (dependency != null) { dependencies.Add(dependency); } } if (MultipleCell.IsMultiCell(label) && cols.OfType <MultipleCell>().ToList().Count > 0) { colIndex--; } CCell c = new CCell(label, digits, precision, connectionInfo, rowNumber, colIndex, dependencies); if (MultipleCell.IsMultiCell(label)) { multi = BuildMultipleCell(c, cols); if (multi != null) { cols.Add(multi); } } else { cols.Add(c); } break; // mirror cell case "M": // find cell to mirror var columnToMirror = cols.FirstOrDefault(x => x.Label == connectionInfo); if (MultipleCell.IsMultiCell(label) && cols.OfType <MultipleCell>().ToList().Count > 0) { colIndex--; } MCell m = new MCell(label, digits, precision, connectionInfo, rowNumber, colIndex, columnToMirror); if (MultipleCell.IsMultiCell(label)) { multi = BuildMultipleCell(m, cols); if (multi != null) { cols.Add(multi); } } else { cols.Add(m); } break; // newscreen, for backwards compatibility case "0": NewScreen newScreen = new NewScreen(label, digits, precision, connectionInfo, rowNumber, colIndex); cols.Add(newScreen); break; } colIndex++; } return(cols); }
// Finished Editing Cell Event Handler void NewBalanceDataGridView_CellEndEdit(object sender, System.Windows.Forms.DataGridViewCellEventArgs e) { _cellBeginEdit = NewBalanceDataGridView[e.ColumnIndex, e.RowIndex]; // arbitrary number bool changed; double?d = null; string s = String.Empty; // need to update logic layer string valueToCheck = (string)_cellBeginEdit.Value ?? ""; if (valueToCheck == oldCellValue) { return; } else { changed = true; } if (_cellBeginEdit.Value != null) { d = nullableDoubleTryParse(_cellBeginEdit.Value.ToString()); } if (_cellBeginEdit.Value != null && d == null) { s = _cellBeginEdit.Value.ToString(); } switch (ViewData.GetCellType(e.RowIndex, e.ColumnIndex)) { // don't update if value is not valid case CellType.C: CCell c = ViewData.GetCell(e.RowIndex, e.ColumnIndex) as CCell; if (c == null) { return; } if (changed == true && d != null) { c.OverrideValue((double)d); } else { c.Value = null; } break; case CellType.K: KCell k = ViewData.GetCell(e.RowIndex, e.ColumnIndex) as KCell; if (k == null) { return; } if (s.Length > 0) { k.KValue = s; } else if (d != null && changed == true) { k.KValue = d.ToString(); } else { k.KValue = null; } break; case CellType.M: MCell m = ViewData.GetCell(e.RowIndex, e.ColumnIndex) as MCell; if (m == null) { return; } if (changed == true && d != null) { m.OverrideValue((double)d); } else { m.Value = null; } break; case CellType.W: WCell w = ViewData.GetCell(e.RowIndex, e.ColumnIndex) as WCell; if (w == null) { return; } if (changed == true && d != null) { w.Value = d; } else { w.Value = null; } break; } RecentlySaved = false; }
// Logic Value Changed Event Handler void NewBalance_CellValueChanged(object sender, PropertyChangedEventArgs e) { Cell c = sender as Cell; if (e.PropertyName == "String") { if (sender is KCell) { KCell k = sender as KCell; if (k.KValue != String.Empty) { NewBalanceDataGridView.Rows[k.RowIndex].Cells[k.ColumnIndex].Value = k.KValue; } else { NewBalanceDataGridView.Rows[k.RowIndex].Cells[k.ColumnIndex].Value = k.Value.ToString(); } } else if (sender is MCell) { MCell m = sender as MCell; NewBalanceDataGridView.Rows[m.RowIndex].Cells[m.ColumnIndex].Value = m.MValue; } } else { if (c != null && c.Value == null) { if (c is KCell) { KCell kc = c as KCell; if (kc.KValue != String.Empty) { NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = kc.KValue; } else { NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = null; } } else if (c is MultipleCell) { MultipleCell mc = c as MultipleCell; if (mc.SelectedValue != null) { NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = mc.SelectedValue; } else { NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = null; } } else { NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = null; } } else { if (c != null) { // need to check if there is a calculation with sender as a dependency ViewData.CheckAndUpdateDependency(c); NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = c.Value.ToString(); if (ViewData.HasMultipleCells()) { MultipleCell mc = null; for (int i = 0; i < NewBalanceDataGridView.ColumnCount; i++) { if (ViewData.GetCellType(c.RowIndex, i) == CellType.Multiple) { mc = ViewData.GetCell(c.RowIndex, i) as MultipleCell; break; } } if (mc == null) { return; } // Update Value to the currently selected cell ViewData.CheckAndUpdateMultipleDependency(c, mc); if (mc.ColumnIndex == c.ColumnIndex && mc.RowIndex == c.RowIndex) { NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = mc.SelectedValue.ToString(); } } } } } }