public static List <Cell> GetCrossNormalCells(ModelGrid grid, Cell cell) { Cell neighbour; List <Cell> crossNormalCells = new List <Cell> (); if (!cell) { return(crossNormalCells); } crossNormalCells.Add(cell); //left neighbour = grid.GetCellFromModel(cell.x - 1, cell.y); if (neighbour) { crossNormalCells.Add(neighbour); } //right neighbour = grid.GetCellFromModel(cell.x + 1, cell.y); if (neighbour) { crossNormalCells.Add(neighbour); } //up neighbour = grid.GetCellFromModel(cell.x, cell.y + 2); if (neighbour) { crossNormalCells.Add(neighbour); } //down neighbour = grid.GetCellFromModel(cell.x, cell.y - 2); if (neighbour) { crossNormalCells.Add(neighbour); } return(crossNormalCells); }
public static void SetModelLoc(Model m, Model mList, ModelGrid mg, int x2, int y2) { //{ Move the model M to location X2,Y2, adjusting the contents of} //{ the modelgrid accordingly.} //{ Range check. If X2,Y2 lie out of bounds, bring them back into} //{ bounds.} if (x2 < 1) { x2 = 1; } else if (x2 > XMax) { x2 = XMax; } if (y2 < 1) { y2 = 1; } else if (y2 > YMax) { y2 = YMax; } //{ Save the initial position of the model.} int x1 = m.x; int y1 = m.y; //{Change the position of the model.} m.x = x2; m.y = y2; if (FindModelXY(mList, x1, y1) == null) { mg.Set(x1, y1, false); } mg.Set(x2, y2, true); }
private void button3_Click(object sender, EventArgs e) { AnalysisResults result = new AnalysisResults(tasks); var resultAnalyze = result.analyze(); this.Height = 661; dataGridView1.Rows.Clear(); dataGridView2.Rows.Clear(); dataGridView1.Rows.Add(resultAnalyze.countSuccessQueries, resultAnalyze.countErrorQueries, resultAnalyze.countSuccessTimeStart, resultAnalyze.countWrongTimeStart, resultAnalyze.countNotStart, resultAnalyze.avgDuration, resultAnalyze.avgWaiting); int i = 1; var listForGrid = new List <ModelGrid>(); foreach (var item in tasks) { var resultRow = item.GetResult(); var objList = new ModelGrid() { nomRow = i, timePlanningStart = resultRow.timePlanningStart.ToString("hh':'mm':'ss'.'fff"), timeFactStart = resultRow.timeFactStart.ToString("hh':'mm':'ss'.'fff"), durationConnection = resultRow.durationConnection, waitingTime = resultRow.waitingTime, errorText = (resultRow.errorText != null) ? resultRow.errorText.ToString() : "" }; listForGrid.Add(objList); i++; } foreach (var item in listForGrid.OrderByDescending(s => s.durationConnection)) { dataGridView2.Rows.Add(item.nomRow, item.timePlanningStart, item.timeFactStart, item.waitingTime, item.durationConnection, item.errorText); } }
//poruszanie obiektem private void Window_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Up) { ModelGrid.RotateX(-moveit); e.Handled = true; } else if (e.Key == Key.Down) { ModelGrid.RotateX(moveit); e.Handled = true; } else if (e.Key == Key.Right) { ModelGrid.RotateY(moveit); e.Handled = true; } else if (e.Key == Key.Left) { ModelGrid.RotateY(-moveit); e.Handled = true; } }
public static List <Cell> GetVerticalCells(ModelGrid grid, Cell cell) { Cell neighbour; List <Cell> verticalCells = new List <Cell> (); if (cell.y % 2 == 1) { return(verticalCells); } for (int i = 0; i < nBallToAlignVertically; i++) { neighbour = grid.GetCellFromModel(cell.x, i * 2); if (!neighbour) { continue; } verticalCells.Add(neighbour); } return(verticalCells); }
private void NewSolid(object sender, RoutedEventArgs e) { // Instantiate the dialog box NewModelWindow dlg = new NewModelWindow(); // Configure the dialog box dlg.Owner = this; dlg.NewHeight = defaultModelSize.ToString(); dlg.NewLength = defaultModelSize.ToString(); dlg.NewWidth = defaultModelSize.ToString(); // Open the dialog box modally dlg.ShowDialog(); if (dlg.DialogResult == true) { //tworzenie nowej bryly int width = (int)(double.Parse(dlg.NewWidth) * 2); int height = (int)(double.Parse(dlg.NewHeight) * 2); int length = (int)(double.Parse(dlg.NewLength) * 2); ModelGrid.SetParams(width, height, length); } }
private void CreateGrid() { modelGrid = new ModelGrid(5, 9, FindObjectsOfType <Cell>().ToList()); optiGrid = new OptimizedGrid(5, 9); optiGrid.SetPatternData(aiEvaluationData); }
private static bool CheckWinVertical(ModelGrid grid, Cell cell, bool mustHighlight = true) { Cell neighbour; BallColor color; if (!cell.ball) { color = BallColor.White; } else { color = cell.ball.Color; } int count = 1; List <Cell> patternCells = new List <Cell> (); patternCells.Add(cell); // down for (int i = 1; i < nBallToAlignVertically; i++) { neighbour = grid.GetCellFromModel(cell.x, cell.y - i * 2); if (!neighbour) { break; } if (neighbour.HasBall(color)) { count++; patternCells.Add(neighbour); } else { break; } } //up for (int i = 1; i < nBallToAlignVertically; i++) { neighbour = grid.GetCellFromModel(cell.x, cell.y + i * 2); if (!neighbour) { break; } if (neighbour.HasBall(color)) { count++; patternCells.Add(neighbour); } else { break; } } /*if(count >= nBallToAlignVertically && mustHighlight) * HighlighCells (patternCells, Color.red);*/ return(count >= nBallToAlignVertically); }
private static bool CheckWinDiagonalBottomRightToTopLeftIA(ModelGrid grid, Cell cell) { Cell neighbour; BallColor color; if (!cell.ball) { color = BallColor.Black; } else { color = cell.ball.Color; } int count = 1; List <Cell> patternCells = new List <Cell> (); patternCells.Add(cell); int offset = cell.y % 2; if (offset == 0) { //top for (int i = 1; i < nBallToAlignVertically; i++) { neighbour = grid.GetCellFromModel(cell.x - Mathf.CeilToInt(i / 2f), cell.y + i); if (!neighbour) { break; } if (neighbour.HasBall(color)) { patternCells.Add(neighbour); count++; } else { break; } } //bottom for (int i = 1; i < nBallToAlignVertically; i++) { neighbour = grid.GetCellFromModel(cell.x + i / 2, cell.y - i); if (!neighbour) { break; } if (neighbour.HasBall(color)) { patternCells.Add(neighbour); count++; } else { break; } } } else { //top for (int i = 1; i < nBallToAlignVertically; i++) { neighbour = grid.GetCellFromModel(cell.x - i / 2, cell.y + i); if (!neighbour) { break; } if (neighbour.HasBall(color)) { patternCells.Add(neighbour); count++; } else { break; } } //bottom for (int i = 1; i < nBallToAlignVertically; i++) { neighbour = grid.GetCellFromModel(cell.x + Mathf.CeilToInt(i / 2f), cell.y - i); if (!neighbour) { break; } if (neighbour.HasBall(color)) { patternCells.Add(neighbour); count++; } else { break; } } } /*if(count >= nBallToAlignHorizontally) * HighlighCells (patternCells, Color.red);*/ return(count >= nBallToAlignHorizontally); }
public static List <Cell> GetDiagonalBottomLeftToTopRightCells(ModelGrid grid, Cell cell) { Cell neighbour; List <Cell> diagonalCells = new List <Cell> (); int offset = cell.y % 2; diagonalCells.Add(cell); if (offset == 0) { //top for (int i = 1; i < nBallToAlignVertically; i++) { neighbour = grid.GetCellFromModel(cell.x + i / 2, cell.y + i); if (!neighbour) { continue; } diagonalCells.Add(neighbour); } //bottom for (int i = 1; i < nBallToAlignVertically; i++) { neighbour = grid.GetCellFromModel(cell.x - Mathf.CeilToInt(i / 2f), cell.y - i); if (!neighbour) { continue; } diagonalCells.Add(neighbour); } } else { //top for (int i = 1; i < nBallToAlignVertically; i++) { neighbour = grid.GetCellFromModel(cell.x + Mathf.CeilToInt(i / 2f), cell.y + i); if (!neighbour) { continue; } diagonalCells.Add(neighbour); } //bottom for (int i = 1; i < nBallToAlignVertically; i++) { neighbour = grid.GetCellFromModel(cell.x - i / 2, cell.y - i); if (!neighbour) { continue; } diagonalCells.Add(neighbour); } } return(diagonalCells); }
private static bool CheckCrossDiagonalIA(ModelGrid grid, Cell cell) { if (!cell) { return(false); } { if (!cell.HasBall()) { return(false); } } Cell neighbour; BallColor color; if (!cell.ball) { color = BallColor.White; } else { color = cell.ball.Color; } int offset = cell.y % 2; List <Cell> patternCells = new List <Cell> (); patternCells.Add(cell); //top left neighbour = grid.GetCellFromModel(cell.x - 1 + offset, cell.y + 1); if (!neighbour) { return(false); } if (!neighbour.HasBall(color)) { return(false); } patternCells.Add(neighbour); //top right neighbour = grid.GetCellFromModel(cell.x + offset, cell.y + 1); if (!neighbour) { return(false); } if (!neighbour.HasBall(color)) { return(false); } patternCells.Add(neighbour); //bottom left neighbour = grid.GetCellFromModel(cell.x - 1 + offset, cell.y - 1); if (!neighbour) { return(false); } if (!neighbour.HasBall(color)) { return(false); } patternCells.Add(neighbour); //bottom right neighbour = grid.GetCellFromModel(cell.x + offset, cell.y - 1); if (!neighbour) { return(false); } if (!neighbour.HasBall(color)) { return(false); } patternCells.Add(neighbour); //HighlighCells (patternCells, Color.red); return(true); }
private static bool CheckCrossNormalIA(ModelGrid grid, Cell cell) { if (!cell) { return(false); } if (!cell.HasBall()) { return(false); } Cell neighbour; BallColor color; if (!cell.ball) { color = BallColor.White; } else { color = cell.ball.Color; } List <Cell> patternCells = new List <Cell> (); patternCells.Add(cell); //left neighbour = grid.GetCellFromModel(cell.x - 1, cell.y); if (!neighbour) { return(false); } if (!neighbour.HasBall(color)) { return(false); } patternCells.Add(neighbour); //right neighbour = grid.GetCellFromModel(cell.x + 1, cell.y); if (!neighbour) { return(false); } if (!neighbour.HasBall(color)) { return(false); } patternCells.Add(neighbour); //up neighbour = grid.GetCellFromModel(cell.x, cell.y + 2); if (!neighbour) { return(false); } if (!neighbour.HasBall(color)) { return(false); } patternCells.Add(neighbour); //down neighbour = grid.GetCellFromModel(cell.x, cell.y - 2); if (!neighbour) { return(false); } if (!neighbour.HasBall(color)) { return(false); } patternCells.Add(neighbour); //HighlighCells (patternCells, Color.red); return(true); }
public static bool ModelPresent(ModelGrid mg, int x, int y) { return(mg.IsSet(x, y)); }
public static void CopyCrossCellProcessTrackerData( CrossCellProcessTracker c, IList <Madingley.Common.GridCellDispersal> dispersalData, uint timeStep, ModelGrid madingleyModelGrid) { var l0 = (int)madingleyModelGrid.NumLatCells; var l1 = (int)madingleyModelGrid.NumLonCells; var copyInboundCohorts = new uint[l0, l1, 8]; for (var ii = 0; ii < l0; ii++) { for (var jj = 0; jj < l1; jj++) { var cs = dispersalData[ii * l0 + jj].InboundCohorts; CopyDictionaryValue <Madingley.Common.CohortsEnterDirection>(copyInboundCohorts, ii, jj, 0, cs, Madingley.Common.CohortsEnterDirection.North); CopyDictionaryValue <Madingley.Common.CohortsEnterDirection>(copyInboundCohorts, ii, jj, 1, cs, Madingley.Common.CohortsEnterDirection.NorthEast); CopyDictionaryValue <Madingley.Common.CohortsEnterDirection>(copyInboundCohorts, ii, jj, 2, cs, Madingley.Common.CohortsEnterDirection.East); CopyDictionaryValue <Madingley.Common.CohortsEnterDirection>(copyInboundCohorts, ii, jj, 3, cs, Madingley.Common.CohortsEnterDirection.SouthEast); CopyDictionaryValue <Madingley.Common.CohortsEnterDirection>(copyInboundCohorts, ii, jj, 4, cs, Madingley.Common.CohortsEnterDirection.South); CopyDictionaryValue <Madingley.Common.CohortsEnterDirection>(copyInboundCohorts, ii, jj, 5, cs, Madingley.Common.CohortsEnterDirection.SouthWest); CopyDictionaryValue <Madingley.Common.CohortsEnterDirection>(copyInboundCohorts, ii, jj, 6, cs, Madingley.Common.CohortsEnterDirection.West); CopyDictionaryValue <Madingley.Common.CohortsEnterDirection>(copyInboundCohorts, ii, jj, 7, cs, Madingley.Common.CohortsEnterDirection.NorthWest); } } var copyOutboundCohorts = new uint[l0, l1, 8]; for (var ii = 0; ii < l0; ii++) { for (var jj = 0; jj < l1; jj++) { var cs = dispersalData[ii * l0 + jj].OutboundCohorts; CopyDictionaryValue <Madingley.Common.CohortsExitDirection>(copyOutboundCohorts, ii, jj, 0, cs, Madingley.Common.CohortsExitDirection.North); CopyDictionaryValue <Madingley.Common.CohortsExitDirection>(copyOutboundCohorts, ii, jj, 1, cs, Madingley.Common.CohortsExitDirection.NorthEast); CopyDictionaryValue <Madingley.Common.CohortsExitDirection>(copyOutboundCohorts, ii, jj, 2, cs, Madingley.Common.CohortsExitDirection.East); CopyDictionaryValue <Madingley.Common.CohortsExitDirection>(copyOutboundCohorts, ii, jj, 3, cs, Madingley.Common.CohortsExitDirection.SouthEast); CopyDictionaryValue <Madingley.Common.CohortsExitDirection>(copyOutboundCohorts, ii, jj, 4, cs, Madingley.Common.CohortsExitDirection.South); CopyDictionaryValue <Madingley.Common.CohortsExitDirection>(copyOutboundCohorts, ii, jj, 5, cs, Madingley.Common.CohortsExitDirection.SouthWest); CopyDictionaryValue <Madingley.Common.CohortsExitDirection>(copyOutboundCohorts, ii, jj, 6, cs, Madingley.Common.CohortsExitDirection.West); CopyDictionaryValue <Madingley.Common.CohortsExitDirection>(copyOutboundCohorts, ii, jj, 7, cs, Madingley.Common.CohortsExitDirection.NorthWest); } } var copyOutboundCohortWeights = new List <double> [l0, l1]; for (var ii = 0; ii < l0; ii++) { for (var jj = 0; jj < l1; jj++) { var index = ii * l0 + jj; var cs = dispersalData[index].OutboundCohortWeights; copyOutboundCohortWeights[ii, jj] = cs.ToList(); } } c.RecordDispersalForACell( copyInboundCohorts, copyOutboundCohorts, copyOutboundCohortWeights, timeStep, madingleyModelGrid); }
private void viewport_MouseDown(object sender, MouseButtonEventArgs e) { ModelGrid.BeginSculpturing(); ModelGrid.Sculpt(e.GetPosition(viewport), viewport.ActualWidth, viewport.ActualHeight); }