public void PointIndex_DefaultConstruction_XIsZeroAndYIsZero() { PointIndex actual = new PointIndex(); Assert.That(actual.X, Is.EqualTo(0)); Assert.That(actual.Y, Is.EqualTo(0)); }
public void PointIndex_ConstructionWithPArameters_XIsFiveAndYIsThree() { PointIndex actual = new PointIndex(5, 3); Assert.That(actual.X, Is.EqualTo(5)); Assert.That(actual.Y, Is.EqualTo(3)); }
public void GetAiHardPointIndex_MiniMaxToPointIndex_() { Mock <IMatrixAlgorithm> algorithm = new Mock <IMatrixAlgorithm>(); PlayerType[,] board = new PlayerType[3, 3] { { PlayerType.O, PlayerType.X, PlayerType.O }, { PlayerType.X, PlayerType.X, PlayerType.Unassigned }, { PlayerType.X, PlayerType.O, PlayerType.O } }; algorithm .Setup(x => x.Board) .Returns(board); algorithm .Setup(x => x.CurrentTurn) .Returns(PlayerType.O); algorithm .Setup(x => x.BoardSize) .Returns(3); AiMove localInstance = this.CreateInstance(); PointIndex actual = localInstance.GetAiHardPointIndex(algorithm.Object); PointIndex expected = localInstance.BestPointMove; Assert.That(() => actual, Is.EqualTo(expected)); }
public void GetAiMediumPointIndex_BestMoveIsPointIndex_ReturnTrue() { Mock <IMatrixAlgorithm> algorithm = new Mock <IMatrixAlgorithm>(); PlayerType[,] board = new PlayerType[3, 3] { { PlayerType.X, PlayerType.X, PlayerType.O }, { PlayerType.O, PlayerType.X, PlayerType.Unassigned }, { PlayerType.X, PlayerType.O, PlayerType.O } }; algorithm .Setup(x => x.Board) .Returns(board); algorithm .Setup(x => x.CurrentTurn) .Returns(PlayerType.O); algorithm .Setup(x => x.BoardSize) .Returns(3); PointIndex expected = this.CreateInstance().GetAiMediumPointIndex(algorithm.Object); Move bestMove = this.CreateInstance().GetBestAiMoveMedium(algorithm.Object); PointIndex actual = new PointIndex { X = bestMove.Row, Y = bestMove.Col }; Assert.That(() => actual, Is.EqualTo(expected)); }
private void PlayAiMiddleMode() { if (this.matrixAlgorithm.CurrentTurn != PlayerType.X) { return; } PointIndex aiHardPoint = this.aiMove.GetAiHardPointIndex(this.matrixAlgorithm); foreach (Button button in this.gamePanel.ButtonList) { if (aiHardPoint.Equals(button.Tag)) { this.matrixAlgorithm.Board[aiHardPoint.X, aiHardPoint.Y] = this.matrixAlgorithm.CurrentTurn; button.Text = this.matrixAlgorithm.CurrentTurn.ToString(); this.matrixAlgorithm.CheckWinner(aiHardPoint, this.matrixAlgorithm.CurrentTurn); if (this.matrixAlgorithm.WinnerState) { this.RestartGame(); } break; } } }
//C++ TO C# CONVERTER WARNING: The original C++ declaration of the following method implementation was not found: public void DeleteFace(int fi) { nff--; for (int i = 1; i <= faces.Get(fi).Face().GetNP(); i++) { PointIndex pi = faces.Get(fi).Face().PNum(i); points[pi].RemoveFace(); if (!points[pi].Valid()) { delpointl.Append(pi); } } MiniElement2d face = faces.Get(fi).Face(); Point3d p1 = points[face.PNum(1)].P(); Point3d p2 = points[face.PNum(2)].P(); Point3d p3 = points[face.PNum(3)].P(); vol -= 1.0 / 6.0 * (p1.X() + p2.X() + p3.X()) * ((p2.Y() - p1.Y()) * (p3.Z() - p1.Z()) - (p2.Z() - p1.Z()) * (p3.Y() - p1.Y())); if (face.GetNP() == 4) { Point3d p4 = points[face.PNum(4)].P(); vol -= 1.0 / 6.0 * (p1.X() + p3.X() + p4.X()) * ((p3.Y() - p1.Y()) * (p4.Z() - p1.Z()) - (p3.Z() - p1.Z()) * (p4.Y() - p1.Y())); nff4--; } faces.Elem(fi).Invalidate(); }
public void Equals_ParameterIsNotTypeOfPointIndex_ResultIsFalse() { PointIndex actual = new PointIndex(); String s = "foo"; Boolean test = actual.Equals(s); Assert.That(test, Is.False); }
public void GetHashCode_VerifyHashCodeIsEqually_ResultIsTrue(Int32 x, Int32 y) { PointIndex actual = new PointIndex(x, y); Int32 expected = (x.ToString() + y.ToString()).GetHashCode(); Assert.That(actual.GetHashCode(), Is.EqualTo(expected)); }
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#: //ORIGINAL LINE: virtual double FuncDeriv(const Vector & x, const Vector & dir, double & deriv) const public override double FuncDeriv(Vector x, Vector dir, ref double deriv) { // from 2d: int j; int k; int lpi; int gpi; Vec <3> n, vgrad; Point <3> pp1; Vec2d g1 = new Vec2d(); Vec2d vdir = new Vec2d(); double badness; double hbad; double hderiv; vgrad = 0; badness = 0; ld.meshthis.GetNormalVector(ld.surfi, ld.sp1, ld.gi1, n); // pp1 = sp1; // pp1.Add2 (x.Get(1), t1, x.Get(2), t2); pp1 = ld.sp1 + x(0) * ld.t1.functorMethod + x(1) * ld.t2.functorMethod; //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static Array<Point2d> pts2d; FuncDeriv_pts2d.SetSize(mesh.GetNP()); deriv = 0; for (j = 1; j <= ld.locelements.Size(); j++) { lpi = ld.locrots.Get(j); Element2d bel = mesh[ld.locelements.Get(j)]; gpi = bel.PNum(lpi); for (k = 1; k <= bel.GetNP(); k++) { PointIndex pi = bel.PNum(k); FuncDeriv_pts2d.Elem(pi) = new Point2d(ld.t1.functorMethod * (new mesh.Point(pi) - ld.sp1), ld.t2.functorMethod * (new mesh.Point(pi) - ld.sp1)); } FuncDeriv_pts2d.Elem(gpi) = new Point2d(x(0), x(1)); vdir = new Vec2d(dir(0), dir(1)); hbad = bel.CalcJacobianBadnessDirDeriv(FuncDeriv_pts2d, lpi, vdir, ref hderiv); deriv += hderiv; badness += hbad; } return(badness); }
/// <summary> /// Initializes a new instance of the <see cref="SpatialIndex"/> class /// with nothing in it. /// </summary> public SpatialIndex() { Extent all = new Extent(); m_Points = new PointIndex(); m_Lines = new RectangleIndex(all); m_Text = new RectangleIndex(all); m_Polygons = new RectangleIndex(all); }
public void Equals_OtherXIsNotFiveOrOtherYIsNotThree_ResultIsFalse(Int32 x, Int32 y) { // arrange PointIndex testee = new PointIndex(5, 3); PointIndex other = new PointIndex(x, y); // act Boolean actual = testee.Equals(other); //assert Assert.That(actual, Is.False); }
public PointIndex GetAiMediumPointIndex(IMatrixAlgorithm ticTacToeMatrix) { Move bestMove = this.GetBestAiMoveMedium(ticTacToeMatrix); PointIndex point = new PointIndex { X = bestMove.Row, Y = bestMove.Col }; return(point); }
private void PlayAiEasyMode() { if (this.gamePanel.ButtonList.Count > 0) { Int32 index = this.aiMove.GetAiEasyPointIndex(this.gamePanel.ButtonList); PointIndex point = (PointIndex)this.gamePanel.ButtonList[index].Tag; this.matrixAlgorithm.Board[point.X, point.Y] = this.matrixAlgorithm.CurrentTurn; this.gamePanel.ButtonList[index].Text = this.matrixAlgorithm.CurrentTurn.ToString(); this.gamePanel.ButtonList.RemoveAt(index); this.matrixAlgorithm.CheckWinner(point, this.matrixAlgorithm.CurrentTurn); } if (this.matrixAlgorithm.WinnerState) { this.RestartGame(); } }
private void ClickAiMiddle() { Random random = new Random(); Int32 row = random.Next(0, this.matrixAlgorithm.BoardSize); Int32 col = random.Next(0, this.matrixAlgorithm.BoardSize); PointIndex point = new PointIndex(col, row); foreach (Button btn in this.gamePanel.ButtonList) { if (btn.Tag.Equals(point)) { btn.PerformClick(); return; } } }
public void CheckWinner_NoWinner_ReturnFalse() { PointIndex test = new PointIndex { X = 0, Y = 0 }; MatrixAlgorithm matrixAlgorithm = this.CreateInstance(); matrixAlgorithm.Board = new PlayerType[3, 3] { { PlayerType.X, PlayerType.O, PlayerType.X }, { PlayerType.X, PlayerType.O, PlayerType.X }, { PlayerType.O, PlayerType.X, PlayerType.O } }; Assert.That(() => matrixAlgorithm.CheckWinner(test, PlayerType.Unassigned), Is.False); }
private void PlayerButtonOnClick(Object sender, EventArgs e) { if (!(sender is Button btn)) { return; } if (!String.IsNullOrWhiteSpace(btn.Text)) { return; } PointIndex point = (PointIndex)btn.Tag; this.matrixAlgorithm.Board[point.X, point.Y] = this.matrixAlgorithm.CurrentTurn; btn.Text = this.matrixAlgorithm.CurrentTurn.ToString(); this.gamePanel.ButtonList.Remove(btn); this.matrixAlgorithm.CheckWinner(point, this.matrixAlgorithm.CurrentTurn); if (this.matrixAlgorithm.WinnerState) { this.RestartGame(); return; } switch (this.gamePanel.Difficulty) { case Difficulty.FaceToFace: return; case Difficulty.Easy: this.PlayAiEasyMode(); break; case Difficulty.Hard: this.PlayAiHardMode(); break; case Difficulty.Middle: this.PlayAiMiddleMode(); break; } }
public void CheckWinner_PlayerWinsWithDiagonalsFromLeftToRight_ReturnTrue() { PointIndex test = new PointIndex { X = 0, Y = 0 }; MatrixAlgorithm matrixAlgorithm = this.CreateInstance(); matrixAlgorithm.Board = new PlayerType[3, 3] { { PlayerType.X, PlayerType.Unassigned, PlayerType.Unassigned }, { PlayerType.Unassigned, PlayerType.X, PlayerType.Unassigned }, { PlayerType.Unassigned, PlayerType.Unassigned, PlayerType.X } }; Assert.That(() => matrixAlgorithm.CheckWinner(test, PlayerType.X), Is.True); }
public void Equals_BothXAndYAreEqually_ResultIsTrue() { // 1) Parameter ist kein Typ PointIndex! // => Ist ein PointIndex ein BitConverter??? => Nein // 2) Parameter ist vom Type PointIndex! // 2a) beide sind gleich wenn x und y gleich sind // 2b) beide sind ungleich wenn entweder x oder y ungleich ist. // Bsp 2a. // arrange PointIndex other = new PointIndex(5, 3); PointIndex testee = new PointIndex(5, 3); // act Boolean actual = testee.Equals(other); //assert Assert.That(actual, Is.True); }
public void CheckWinner_GameEndsWithDraw_ReturnTrue() { PointIndex test = new PointIndex { X = 0, Y = 0 }; MatrixAlgorithm matrixAlgorithm = this.CreateInstance(); matrixAlgorithm.Board = new PlayerType[3, 3] { { PlayerType.X, PlayerType.X, PlayerType.O }, { PlayerType.O, PlayerType.O, PlayerType.X }, { PlayerType.X, PlayerType.O, PlayerType.X } }; matrixAlgorithm.CurrentTurnCount = 8; Assert.That(() => matrixAlgorithm.CheckWinner(test, PlayerType.X), Is.True); }
private void PlayAiHardMode() { PointIndex aiMediumPoint = this.aiMove.GetAiMediumPointIndex(this.matrixAlgorithm); foreach (Button button in this.gamePanel.ButtonList) { if (!button.Tag.Equals(aiMediumPoint)) { continue; } button.Text = this.matrixAlgorithm.CurrentTurn.ToString(); this.matrixAlgorithm.Board[aiMediumPoint.X, aiMediumPoint.Y] = this.matrixAlgorithm.CurrentTurn; this.matrixAlgorithm.CheckWinner(aiMediumPoint, this.matrixAlgorithm.CurrentTurn); if (this.matrixAlgorithm.WinnerState) { this.RestartGame(); } break; } }
public static List <PointIndex> CullClosestPoints(List <Point3d> points, List <RFNode> existingNodes, ref int lastNodeIndex, double tol) { var outPoints = new List <PointIndex>(); BoundingBox empty = BoundingBox.Empty; // Create PointIndexes var existingPointIndices = new List <PointIndex>(points.Count); for (int i = 0; i < existingNodes.Count; i++) { PointIndex pointIndex = new PointIndex(); pointIndex.Index = existingNodes[i].No; pointIndex.Point = existingNodes[i].Location; existingPointIndices.Add(pointIndex); empty.Union(pointIndex.Point); } var list2 = new List <PointIndex>(points.Count); for (int i = 0; i < points.Count; i++) { PointIndex pointIndex = new PointIndex(); pointIndex.Index = -1; pointIndex.Point = points[i]; list2.Add(pointIndex); empty.Union(pointIndex.Point); } empty.Inflate(tol); Node3d <PointIndex> val = new Node3d <PointIndex>((Coordinates3d <PointIndex>)PointIndexCoordinates, empty, 30); int firstItem = 0; if (existingNodes.Count > 0) { val.AddRange(existingPointIndices); // list to compare points to } else { var node = list2[0]; node.Index = 1; firstItem = 1; lastNodeIndex = 1; val.Add(node); // list to compare points to outPoints.Add(node); } for (int j = firstItem; j <= list2.Count - 1; j++) { PointIndex pointIndex2 = list2[j]; while (true) { Index3d <PointIndex> val2 = val.NearestItem(pointIndex2); if (val2 == null) { lastNodeIndex++; pointIndex2.Index = lastNodeIndex; val.Add(pointIndex2); outPoints.Add(pointIndex2); break; } PointIndex item = val2.Item; double num4 = pointIndex2.Point.DistanceTo(item.Point); if (num4 > tol || double.IsNaN(num4)) { lastNodeIndex++; pointIndex2.Index = lastNodeIndex; val.Add(pointIndex2); outPoints.Add(pointIndex2); break; } pointIndex2.Point = Point3d.Unset; pointIndex2.Index = val2.Item.Index; outPoints.Add(pointIndex2); break; } List <PointIndex> itemsGlobal = val.ItemsGlobal; } return(outPoints); }
public static void PointIndexCoordinates(PointIndex pi, out double x, out double y, out double z) { x = pi.Point.X; y = pi.Point.Y; z = pi.Point.Z; }
public void UpdateCoarseGrid() { // cout << "UpdateCoarseGrid" << endl; // if (is_updated) return; NgMPI_Comm comm = mesh.GetCommunicator(); int id = comm.Rank(); int ntasks = comm.Size(); if (ntasks == 1) { return; } Reset(); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timer = NgProfiler::CreateTimer("UpdateCoarseGrid"); NgProfiler.RegionTimer reg = new NgProfiler.RegionTimer(UpdateCoarseGrid_timer); (*testout) << "UPDATE COARSE GRID PARALLEL TOPOLOGY " << "\n"; if (id == 0) { PrintMessage(1, "update parallel topology"); } // UpdateCoarseGridGlobal(); // MPI_Barrier (MPI_COMM_WORLD); MPI_Group MPI_GROUP_comm = new MPI_Group(); MPI_Group MPI_LocalGroup = new MPI_Group(); MPI_Comm MPI_LocalComm = new MPI_Comm(); int[] process_ranks = { 0 }; MPI_Comm_group(comm, MPI_GROUP_comm); MPI_Group_excl(MPI_GROUP_comm, 1, process_ranks, MPI_LocalGroup); MPI_Comm_create(comm, MPI_LocalGroup, MPI_LocalComm); if (id == 0) { return; } MeshTopology topology = mesh.GetTopology(); Array <int> cnt_send = new Array <int>(ntasks - 1); // update new vertices after mesh-refinement if (mesh.mlbetweennodes.Size() > 0) { // cout << "UpdateCoarseGrid - vertices" << endl; int newnv = mesh.mlbetweennodes.Size(); loc2distvert.ChangeSize(mesh.mlbetweennodes.Size()); /* * for (PointIndex pi = PointIndex::BASE; pi < newnv+PointIndex::BASE; pi++) * { * PointIndex v1 = mesh.mlbetweennodes[pi][0]; * PointIndex v2 = mesh.mlbetweennodes[pi][1]; * if (mesh.mlbetweennodes[pi][0] != PointIndex::BASE-1) * for (int dest = 1; dest < ntasks; dest++) * if (IsExchangeVert (dest, v1) && IsExchangeVert (dest, v2)) * SetDistantPNum(dest, pi); * } */ bool changed = true; while (changed) { changed = false; // build exchange vertices cnt_send = 0; foreach (PointIndex pi in mesh.Points().Range()) { foreach (int dist in GetDistantPNums(pi - PointIndex.BASE)) { cnt_send[dist - 1]++; } } TABLE <int> dest2vert = new TABLE <int>(cnt_send); foreach (PointIndex pi in mesh.Points().Range()) { foreach (int dist in GetDistantPNums(pi - PointIndex.BASE)) { dest2vert.Add(dist - 1, pi); } } for (PointIndex pi = PointIndex.BASE; pi < newnv + PointIndex.BASE; pi++) { PointIndex v1 = mesh.mlbetweennodes[pi][0]; PointIndex v2 = mesh.mlbetweennodes[pi][1]; if (mesh.mlbetweennodes[pi][0] != PointIndex.BASE - 1) { // for (int dest = 1; dest < ntasks; dest++) foreach (int dest in GetDistantPNums(v1 - PointIndex.BASE)) { if (IsExchangeVert(dest, new netgen.PointIndex(v1)) && IsExchangeVert(dest, new netgen.PointIndex(v2))) { cnt_send[dest - 1]++; } } } } TABLE <int> dest2pair = new TABLE <int>(cnt_send); // for (int dest = 1; dest < ntasks; dest++) for (PointIndex pi = PointIndex.BASE; pi < newnv + PointIndex.BASE; pi++) { PointIndex v1 = mesh.mlbetweennodes[pi][0]; PointIndex v2 = mesh.mlbetweennodes[pi][1]; if (mesh.mlbetweennodes[pi][0] != PointIndex.BASE - 1) { foreach (int dest in GetDistantPNums(v1 - PointIndex.BASE)) { if (IsExchangeVert(dest, new netgen.PointIndex(v1)) && IsExchangeVert(dest, new netgen.PointIndex(v2))) { dest2pair.Add(dest - 1, pi); } } } } cnt_send = 0; int v1; int v2; for (PointIndex pi = PointIndex.BASE; pi < newnv + PointIndex.BASE; pi++) { PointIndex v1 = mesh.mlbetweennodes[pi][0]; PointIndex v2 = mesh.mlbetweennodes[pi][1]; if (mesh.mlbetweennodes[pi][0] != PointIndex.BASE - 1) { foreach (int dest in GetDistantPNums(v1 - PointIndex.BASE)) { if (IsExchangeVert(dest, new netgen.PointIndex(v2))) { cnt_send[dest - 1] += 2; } } } } TABLE <int> send_verts = new TABLE <int>(cnt_send); Array <int, PointIndex.BASE> loc2exchange = new Array <int, PointIndex.BASE>(mesh.GetNV()); for (int dest = 1; dest < ntasks; dest++) { if (dest != id) { loc2exchange = -1; int cnt = 0; /* * for (PointIndex pi : mesh.Points().Range()) * if (IsExchangeVert(dest, pi)) * loc2exchange[pi] = cnt++; */ foreach (PointIndex pi in dest2vert[dest - 1]) { loc2exchange[pi] = cnt++; } // for (PointIndex pi = PointIndex::BASE; pi < newnv+PointIndex::BASE; pi++) foreach (PointIndex pi in dest2pair[dest - 1]) { PointIndex v1 = mesh.mlbetweennodes[pi][0]; PointIndex v2 = mesh.mlbetweennodes[pi][1]; if (mesh.mlbetweennodes[pi][0] != PointIndex.BASE - 1) { if (IsExchangeVert(dest, new netgen.PointIndex(v1)) && IsExchangeVert(dest, new netgen.PointIndex(v2))) { send_verts.Add(dest - 1, loc2exchange[v1]); send_verts.Add(dest - 1, loc2exchange[v2]); } } } } } TABLE <int> recv_verts = new TABLE <int>(ntasks - 1); netgen.GlobalMembers.MyMPI_ExchangeTable(send_verts, recv_verts, MPI_TAG_MESH + 9, MPI_LocalComm); for (int dest = 1; dest < ntasks; dest++) { if (dest != id) { loc2exchange = -1; int cnt = 0; /* * for (PointIndex pi : mesh.Points().Range()) * if (IsExchangeVert(dest, pi)) * loc2exchange[pi] = cnt++; */ foreach (PointIndex pi in dest2vert[dest - 1]) { loc2exchange[pi] = cnt++; } FlatArray <int> recvarray = recv_verts[dest - 1]; for (int ii = 0; ii < recvarray.Size(); ii += 2) { foreach (PointIndex pi in dest2pair[dest - 1]) { // for (PointIndex pi = PointIndex::BASE; pi < newnv+PointIndex::BASE; pi++) PointIndex v1 = mesh.mlbetweennodes[pi][0]; PointIndex v2 = mesh.mlbetweennodes[pi][1]; if (mesh.mlbetweennodes[pi][0] != PointIndex.BASE - 1) { INDEX_2 re = new INDEX_2(recvarray[ii], recvarray[ii + 1]); INDEX_2 es = new INDEX_2(loc2exchange[v1], loc2exchange[v2]); if (es == re && !IsExchangeVert(dest, new netgen.PointIndex(pi))) { SetDistantPNum(dest, new netgen.PointIndex(pi)); changed = true; } } } } } } } } Array <int> sendarray = new Array <int>(); Array <int> recvarray = new Array <int>(); // cout << "UpdateCoarseGrid - edges" << endl; // static int timerv = NgProfiler::CreateTimer ("UpdateCoarseGrid - ex vertices"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timere = NgProfiler::CreateTimer("UpdateCoarseGrid - ex edges"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timerf = NgProfiler::CreateTimer("UpdateCoarseGrid - ex faces"); NgProfiler.StartTimer(UpdateCoarseGrid_timere); int nfa = topology.GetNFaces(); int ned = topology.GetNEdges(); // build exchange vertices cnt_send = 0; foreach (PointIndex pi in mesh.Points().Range()) { foreach (int dist in GetDistantPNums(pi - PointIndex.BASE)) { cnt_send[dist - 1]++; } } TABLE <int> dest2vert = new TABLE <int>(cnt_send); foreach (PointIndex pi in mesh.Points().Range()) { foreach (int dist in GetDistantPNums(pi - PointIndex.BASE)) { dest2vert.Add(dist - 1, pi); } } // exchange edges cnt_send = 0; int v1; int v2; for (int edge = 1; edge <= ned; edge++) { topology.GetEdgeVertices(edge, ref v1, ref v2); for (int dest = 1; dest < ntasks; dest++) { if (IsExchangeVert(dest, v1) && IsExchangeVert(dest, v2)) { cnt_send[dest - 1] += 1; } } } TABLE <int> dest2edge = new TABLE <int>(cnt_send); foreach (int v in cnt_send) { v *= 2; } TABLE <int> send_edges = new TABLE <int>(cnt_send); for (int edge = 1; edge <= ned; edge++) { topology.GetEdgeVertices(edge, ref v1, ref v2); for (int dest = 1; dest < ntasks; dest++) { if (IsExchangeVert(dest, v1) && IsExchangeVert(dest, v2)) { dest2edge.Add(dest - 1, edge); } } } Array <int, PointIndex.BASE> loc2exchange = new Array <int, PointIndex.BASE>(mesh.GetNV()); for (int dest = 1; dest < ntasks; dest++) { loc2exchange = -1; int cnt = 0; foreach (PointIndex pi in dest2vert[dest - 1]) { loc2exchange[pi] = cnt++; } foreach (int edge in dest2edge[dest - 1]) { topology.GetEdgeVertices(edge, ref v1, ref v2); if (IsExchangeVert(dest, v1) && IsExchangeVert(dest, v2)) { send_edges.Add(dest - 1, loc2exchange[v1]); send_edges.Add(dest - 1, loc2exchange[v2]); } } } // cout << "UpdateCoarseGrid - edges mpi-exchange" << endl; TABLE <int> recv_edges = new TABLE <int>(ntasks - 1); netgen.GlobalMembers.MyMPI_ExchangeTable(send_edges, recv_edges, MPI_TAG_MESH + 9, MPI_LocalComm); // cout << "UpdateCoarseGrid - edges mpi-exchange done" << endl; /* * for (int dest = 1; dest < ntasks; dest++) * { * auto ex2loc = dest2vert[dest-1]; * FlatArray<int> recvarray = recv_edges[dest-1]; * for (int ii = 0; ii < recvarray.Size(); ii+=2) * for (int edge : dest2edge[dest-1]) * { * topology.GetEdgeVertices (edge, v1, v2); * INDEX_2 re(ex2loc[recvarray[ii]], * ex2loc[recvarray[ii+1]]); * INDEX_2 es(v1, v2); * if (es == re) * SetDistantEdgeNum(dest, edge); * } * } */ for (int dest = 1; dest < ntasks; dest++) { var ex2loc = dest2vert[dest - 1]; if (ex2loc.Size() == 0) { continue; } INDEX_2_CLOSED_HASHTABLE <int> vert2edge = new INDEX_2_CLOSED_HASHTABLE <int>((uint)(2 * dest2edge[dest - 1].Size() + 10)); foreach (int edge in dest2edge[dest - 1]) { topology.GetEdgeVertices(edge, ref v1, ref v2); vert2edge.Set(new INDEX_2(v1, v2), edge); } FlatArray <int> recvarray = recv_edges[dest - 1]; for (int ii = 0; ii < recvarray.Size(); ii += 2) { INDEX_2 re = new INDEX_2(ex2loc[recvarray[ii]], ex2loc[recvarray[ii + 1]]); if (vert2edge.Used(re)) { SetDistantEdgeNum(dest, vert2edge.Get(re)); } } } NgProfiler.StopTimer(UpdateCoarseGrid_timere); // MPI_Barrier (MPI_LocalComm); // cout << "UpdateCoarseGrid - faces" << endl; if (mesh.GetDimension() == 3) { NgProfiler.StartTimer(UpdateCoarseGrid_timerf); Array <int> verts = new Array <int>(); // exchange faces cnt_send = 0; for (int face = 1; face <= nfa; face++) { topology.GetFaceVertices(face, verts); for (int dest = 1; dest < ntasks; dest++) { if (dest != id) { if (IsExchangeVert(dest, verts[0]) && IsExchangeVert(dest, verts[1]) && IsExchangeVert(dest, verts[2])) { cnt_send[dest - 1]++; } } } } TABLE <int> dest2face = new TABLE <int>(cnt_send); for (int face = 1; face <= nfa; face++) { topology.GetFaceVertices(face, verts); for (int dest = 1; dest < ntasks; dest++) { if (dest != id) { if (IsExchangeVert(dest, verts[0]) && IsExchangeVert(dest, verts[1]) && IsExchangeVert(dest, verts[2])) { dest2face.Add(dest - 1, face); } } } } foreach (int c in cnt_send) { c *= 3; } TABLE <int> send_faces = new TABLE <int>(cnt_send); Array <int, PointIndex.BASE> loc2exchange = new Array <int, PointIndex.BASE>(mesh.GetNV()); for (int dest = 1; dest < ntasks; dest++) { if (dest != id) { /* * loc2exchange = -1; * int cnt = 0; * for (PointIndex pi : mesh.Points().Range()) * if (IsExchangeVert(dest, pi)) * loc2exchange[pi] = cnt++; */ if (dest2vert[dest - 1].Size() == 0) { continue; } loc2exchange = -1; int cnt = 0; foreach (PointIndex pi in dest2vert[dest - 1]) { loc2exchange[pi] = cnt++; } foreach (int face in dest2face[dest - 1]) { topology.GetFaceVertices(face, verts); if (IsExchangeVert(dest, verts[0]) && IsExchangeVert(dest, verts[1]) && IsExchangeVert(dest, verts[2])) { send_faces.Add(dest - 1, loc2exchange[verts[0]]); send_faces.Add(dest - 1, loc2exchange[verts[1]]); send_faces.Add(dest - 1, loc2exchange[verts[2]]); } } } } // cout << "UpdateCoarseGrid - faces mpi-exchange" << endl; TABLE <int> recv_faces = new TABLE <int>(ntasks - 1); netgen.GlobalMembers.MyMPI_ExchangeTable(send_faces, recv_faces, MPI_TAG_MESH + 9, MPI_LocalComm); // cout << "UpdateCoarseGrid - faces mpi-exchange done" << endl; /* * for (int dest = 1; dest < ntasks; dest++) * if (dest != id) * { * loc2exchange = -1; * int cnt = 0; * for (PointIndex pi : dest2vert[dest-1]) * loc2exchange[pi] = cnt++; * * FlatArray<int> recvarray = recv_faces[dest-1]; * for (int ii = 0; ii < recvarray.Size(); ii+=3) * for (int face : dest2face[dest-1]) * { * topology.GetFaceVertices (face, verts); * INDEX_3 re(recvarray[ii], recvarray[ii+1], recvarray[ii+2]); * INDEX_3 es(loc2exchange[verts[0]], loc2exchange[verts[1]], loc2exchange[verts[2]]); * if (es == re) * SetDistantFaceNum(dest, face); * } * } */ for (int dest = 1; dest < ntasks; dest++) { var ex2loc = dest2vert[dest - 1]; if (ex2loc.Size() == 0) { continue; } INDEX_3_CLOSED_HASHTABLE <int> vert2face = new INDEX_3_CLOSED_HASHTABLE <int>(2 * dest2face[dest - 1].Size() + 10); foreach (int face in dest2face[dest - 1]) { topology.GetFaceVertices(face, verts); vert2face.Set(new INDEX_3(verts[0], verts[1], verts[2]), face); } FlatArray <int> recvarray = recv_faces[dest - 1]; for (int ii = 0; ii < recvarray.Size(); ii += 3) { INDEX_3 re = new INDEX_3(ex2loc[recvarray[ii]], ex2loc[recvarray[ii + 1]], ex2loc[recvarray[ii + 2]]); if (vert2face.Used(re)) { SetDistantFaceNum(dest, vert2face.Get(re)); } } } /* * Array<int,1> glob2loc; * * int maxface = 0; * for (int face = 1; face <= nfa; face++) * maxface = max (maxface, GetGlobalFaceNum (face)); * * // glob2loc.SetSize (nfaglob); * glob2loc.SetSize (maxface); * glob2loc = -1; * * for (int loc = 1; loc <= nfa; loc++) * glob2loc[GetGlobalFaceNum(loc)] = loc; * * cnt_send = 0; * Array<int> verts; * for (int face = 1; face <= nfa; face++) * { * topology.GetFaceVertices (face, verts); * for (int dest = 1; dest < ntasks; dest++) * if (IsExchangeVert (dest, verts[0]) && * IsExchangeVert (dest, verts[1]) && * IsExchangeVert (dest, verts[2])) * { * cnt_send[dest-1]+=2; * } * } * * TABLE<int> send_faces(cnt_send); * for (int face = 1; face <= nfa; face++) * { * topology.GetFaceVertices (face, verts); * for (int dest = 1; dest < ntasks; dest++) * { * if (IsExchangeVert (dest, verts[0]) && * IsExchangeVert (dest, verts[1]) && * IsExchangeVert (dest, verts[2])) * { * send_faces.Add (dest-1, GetGlobalFaceNum(face)); * send_faces.Add (dest-1, face); * } * } * } * TABLE<int> recv_faces(ntasks-1); * MyMPI_ExchangeTable (send_faces, recv_faces, MPI_TAG_MESH+8, MPI_LocalComm); * * for (int sender = 1; sender < ntasks; sender ++) * if (id != sender) * { * FlatArray<int> recvarray = recv_faces[sender-1]; * * for (int ii = 0; ii < recvarray.Size(); ) * { * int globf = recvarray[ii++]; * int distf = recvarray[ii++]; * * if (globf <= maxface) * { * int locf = glob2loc[globf]; * if (locf != -1) * SetDistantFaceNum (sender, locf); * } * } * } */ NgProfiler.StopTimer(UpdateCoarseGrid_timerf); } // cout << "UpdateCoarseGrid - done" << endl; is_updated = true; }
//C++ TO C# CONVERTER WARNING: The original C++ declaration of the following method implementation was not found: public void Delaunay(Mesh mesh, int domainnr, MeshingParameters mp) { //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timer = NgProfiler::CreateTimer("Meshing2::Delaunay - total"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timerstart = NgProfiler::CreateTimer("Meshing2::Delaunay - start"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timerfinish = NgProfiler::CreateTimer("Meshing2::Delaunay - finish"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timer1 = NgProfiler::CreateTimer("Meshing2::Delaunay - incremental"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timer1a = NgProfiler::CreateTimer("Meshing2::Delaunay - incremental a"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timer1b = NgProfiler::CreateTimer("Meshing2::Delaunay - incremental b"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timer1c = NgProfiler::CreateTimer("Meshing2::Delaunay - incremental c"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timer1d = NgProfiler::CreateTimer("Meshing2::Delaunay - incremental d"); NgProfiler.RegionTimer reg = new NgProfiler.RegionTimer(Delaunay_timer); Console.Write("2D Delaunay meshing (in progress)"); Console.Write("\n"); BlockFillLocalH(mesh, mp); NgProfiler.StartTimer(Delaunay_timerstart); // do the delaunay // face bounding box: Box <3> bbox(Box <3> .EMPTY_BOX); for (int i = 0; i < adfront.GetNFL(); i++) { FrontLine line = adfront.GetLine(i); bbox.Add(Point <3> (adfront.GetPoint(line.L [0]))); bbox.Add(Point <3> (adfront.GetPoint(line.L [1]))); } for (int i = 0; i < mesh.LockedPoints().Size(); i++) { bbox.Add(new mesh.Point(mesh.LockedPoints [i])); } Console.Write("bbox = "); Console.Write(bbox); Console.Write("\n"); // external point Vec <3> vdiag = bbox.PMax() - bbox.PMin(); var old_points = mesh.Points().Range(); DelaunayTrig startel = new DelaunayTrig(); startel[0] = mesh.AddPoint(bbox.PMin() + Vec <3> (-8 * vdiag(0), -8 * vdiag(1), 0)); startel[1] = mesh.AddPoint(bbox.PMin() + Vec <3> (+8 * vdiag(0), -8 * vdiag(1), 0)); startel[2] = mesh.AddPoint(bbox.PMin() + Vec <3> (0, 8 * vdiag(1), 0)); Box <3> hbox; hbox.Set(mesh[startel[0]]); hbox.Add(mesh[startel[1]]); hbox.Add(mesh[startel[2]]); Point <3> hp = mesh[startel[0]]; hp(2) = 1; hbox.Add(hp); hp(2) = -1; hbox.Add(hp); BoxTree <3> searchtree(hbox); Array <DelaunayTrig> tempels = new Array <DelaunayTrig>(); startel.CalcCenter(mesh); tempels.Append(startel); searchtree.Insert(startel.BoundingBox(), 0); Array <int> closeels = new Array <int>(); Array <int> intersecting = new Array <int>(); Array <INDEX_2> edges = new Array <INDEX_2>(); // reorder points Array <PointIndex, PointIndex.BASE, PointIndex> mixed = new Array <PointIndex, PointIndex.BASE, PointIndex>(old_points.Size()); int[] prims = { 11, 13, 17, 19, 23, 29, 31, 37 }; int prim; { int i = 0; while (old_points.Size() % prims[i] == 0) { i++; } prim = prims[i]; } foreach (PointIndex pi in old_points) { mixed[pi] = new PointIndex((prim * pi) % old_points.Size() + PointIndex.BASE); } NgProfiler.StopTimer(Delaunay_timerstart); NgProfiler.StartTimer(Delaunay_timer1); foreach (PointIndex i1 in old_points) { PointIndex i = mixed[i1]; NgProfiler.StartTimer(Delaunay_timer1a); Point <3> newp = mesh[i]; intersecting.SetSize(0); edges.SetSize(0); searchtree.GetIntersecting(newp, newp, closeels); // for (int jj = 0; jj < closeels.Size(); jj++) // for (int j = 0; j < tempels.Size(); j++) foreach (int j in closeels) { if (tempels[j][0] < 0) { continue; } Point <3> c = tempels[j].Center(); double r2 = tempels[j].Radius2(); bool inside = Dist2(mesh[i], c) < r2; if (inside) { intersecting.Append(j); } } NgProfiler.StopTimer(Delaunay_timer1a); NgProfiler.StartTimer(Delaunay_timer1b); // find outer edges foreach (var j in intersecting) { DelaunayTrig trig = tempels[j]; for (int k = 0; k < 3; k++) { int p1 = trig[k]; int p2 = trig[(k + 1) % 3]; INDEX_2 edge = new INDEX_2(p1, p2); edge.Sort(); bool found = false; for (int l = 0; l < edges.Size(); l++) { if (edges[l] == edge) { edges.Delete(l); found = true; break; } } if (!found) { edges.Append(edge); } } } NgProfiler.StopTimer(Delaunay_timer1b); NgProfiler.StartTimer(Delaunay_timer1c); /* * for (int j = intersecting.Size()-1; j >= 0; j--) * tempels.Delete (intersecting[j]); */ foreach (int j in intersecting) { searchtree.DeleteElement(j); tempels[j][0] = -1; tempels[j][1] = -1; tempels[j][2] = -1; } NgProfiler.StopTimer(Delaunay_timer1c); NgProfiler.StartTimer(Delaunay_timer1d); foreach (var edge in edges) { DelaunayTrig trig = new DelaunayTrig(edge[0], edge[1], i); trig.CalcCenter(mesh); tempels.Append(trig); searchtree.Insert(trig.BoundingBox(), tempels.Size() - 1); } NgProfiler.StopTimer(Delaunay_timer1d); } NgProfiler.StopTimer(Delaunay_timer1); NgProfiler.StartTimer(Delaunay_timerfinish); foreach (DelaunayTrig trig in tempels) { if (trig[0] < 0) { continue; } Point <3> c = Center(mesh[trig[0]], mesh[trig[1]], mesh[trig[2]]); if (!adfront.Inside(Point <2> (c(0), c(1)))) { continue; } Vec <3> n = Cross(mesh[trig[1]] - mesh[trig[0]], mesh[trig[2]] - mesh[trig[0]]); if (n(2) < 0) { Swap(ref trig[1], ref trig[2]); } Element2d el = new Element2d(trig[0], trig[1], trig[2]); el.SetIndex(domainnr); mesh.AddSurfaceElement(el); } foreach (PointIndex pi in mesh.Points().Range()) { *testout << pi << ": " << mesh[pi].Type() << "\n"; } NgProfiler.StopTimer(Delaunay_timerfinish); }
//C++ TO C# CONVERTER WARNING: The original C++ declaration of the following method implementation was not found: public void BlockFillLocalH(Mesh mesh, MeshingParameters mp) { //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timer = NgProfiler::CreateTimer("Meshing2::BlockFill"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timer1 = NgProfiler::CreateTimer("Meshing2::BlockFill 1"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timer2 = NgProfiler::CreateTimer("Meshing2::BlockFill 2"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timer3 = NgProfiler::CreateTimer("Meshing2::BlockFill 3"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timer4 = NgProfiler::CreateTimer("Meshing2::BlockFill 4"); NgProfiler.RegionTimer reg = new NgProfiler.RegionTimer(BlockFillLocalH_timer); NgProfiler.StartTimer(BlockFillLocalH_timer1); double filldist = mp.filldist; Console.Write("blockfill local h"); Console.Write("\n"); Console.Write("rel filldist = "); Console.Write(filldist); Console.Write("\n"); PrintMessage(3, "blockfill local h"); Array <Point <3> > npoints = new Array <Point <3> >(); // adfront -> CreateTrees(); Box <3> bbox(Box <3> .EMPTY_BOX); double maxh = 0; for (int i = 0; i < adfront.GetNFL(); i++) { FrontLine line = adfront.GetLine(i); const Point <3>& p1 = adfront.GetPoint(line.L().I1()); const Point <3>& p2 = adfront.GetPoint(line.L().I2()); maxh = Math.Max(maxh, Dist(p1, p2)); bbox.Add(p1); bbox.Add(p2); } Console.Write("bbox = "); Console.Write(bbox); Console.Write("\n"); // Point<3> mpc = bbox.Center(); bbox.Increase(bbox.Diam() / 2); Box <3> meshbox = bbox; NgProfiler.StopTimer(BlockFillLocalH_timer1); NgProfiler.StartTimer(BlockFillLocalH_timer2); LocalH loch2 = new LocalH(bbox, 1, 2); if (mp.maxh < maxh) { maxh = mp.maxh; } bool changed; do { mesh.LocalHFunction().ClearFlags(); for (int i = 0; i < adfront.GetNFL(); i++) { FrontLine line = adfront.GetLine(i); Box <3> bbox(adfront.GetPoint(line.L().I1())); bbox.Add(adfront.GetPoint(line.L().I2())); double filld = filldist * bbox.Diam(); bbox.Increase(filld); mesh.LocalHFunction().CutBoundary(bbox); } mesh.LocalHFunction().FindInnerBoxes(adfront, null); npoints.SetSize(0); mesh.LocalHFunction().GetInnerPoints(npoints); changed = false; for (int i = 0; i < npoints.Size(); i++) { if (mesh.LocalHFunction().GetH(npoints[i]) > 1.2 * maxh) { mesh.LocalHFunction().SetH(npoints[i], maxh); changed = true; } } } while (changed); NgProfiler.StopTimer(BlockFillLocalH_timer2); NgProfiler.StartTimer(BlockFillLocalH_timer3); if (debugparam.slowchecks) { (*testout) << "Blockfill with points: " << "\n"; } *testout << "loch = " << mesh.LocalHFunction() << "\n"; *testout << "npoints = " << "\n" << npoints << "\n"; for (int i = 1; i <= npoints.Size(); i++) { if (meshbox.IsIn(npoints.Get(i))) { PointIndex gpnum = mesh.AddPoint(npoints.Get(i)); adfront.AddPoint(npoints.Get(i), gpnum); if (debugparam.slowchecks) { (*testout) << npoints.Get(i) << "\n"; Point <2> p2d(npoints.Get(i)(0), npoints.Get(i)(1)); if (!adfront.Inside(p2d)) { Console.Write("add outside point"); Console.Write("\n"); (*testout) << "outside" << "\n"; } } } } NgProfiler.StopTimer(BlockFillLocalH_timer3); NgProfiler.StartTimer(BlockFillLocalH_timer4); // find outer points loch2.ClearFlags(); for (int i = 0; i < adfront.GetNFL(); i++) { FrontLine line = adfront.GetLine(i); Box <3> bbox(adfront.GetPoint(line.L().I1())); bbox.Add(adfront.GetPoint(line.L().I2())); loch2.SetH(bbox.Center(), bbox.Diam()); } for (int i = 0; i < adfront.GetNFL(); i++) { FrontLine line = adfront.GetLine(i); Box <3> bbox(adfront.GetPoint(line.L().I1())); bbox.Add(adfront.GetPoint(line.L().I2())); bbox.Increase(filldist * bbox.Diam()); loch2.CutBoundary(bbox); } loch2.FindInnerBoxes(adfront, null); // outer points : smooth mesh-grading npoints.SetSize(0); loch2.GetOuterPoints(npoints); for (int i = 1; i <= npoints.Size(); i++) { if (meshbox.IsIn(npoints.Get(i))) { PointIndex gpnum = mesh.AddPoint(npoints.Get(i)); adfront.AddPoint(npoints.Get(i), gpnum); } } NgProfiler.StopTimer(BlockFillLocalH_timer4); }
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#: //ORIGINAL LINE: virtual double FuncGrad(const Vector & x, Vector & grad) const public override double FuncGrad(Vector x, ref Vector grad) { // from 2d: int lpi; int gpi; Vec <3> n, vgrad; Point <3> pp1; Vec2d g1 = new Vec2d(); Vec2d vdir = new Vec2d(); double badness; double hbad; double hderiv; vgrad = 0; badness = 0; ld.meshthis.GetNormalVector(ld.surfi, ld.sp1, ld.gi1, n); pp1 = ld.sp1 + x(0) * ld.t1.functorMethod + x(1) * ld.t2.functorMethod; // meshthis -> ProjectPoint (surfi, pp1); // meshthis -> GetNormalVector (surfi, pp1, n); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static Array<Point2d> pts2d; FuncGrad_pts2d.SetSize(mesh.GetNP()); grad = 0; for (int j = 1; j <= ld.locelements.Size(); j++) { lpi = ld.locrots.Get(j); Element2d bel = mesh[ld.locelements.Get(j)]; gpi = bel.PNum(lpi); for (int k = 1; k <= bel.GetNP(); k++) { PointIndex pi = bel.PNum(k); FuncGrad_pts2d.Elem(pi) = new Point2d(ld.t1.functorMethod * (new mesh.Point(pi) - ld.sp1), ld.t2.functorMethod * (new mesh.Point(pi) - ld.sp1)); } FuncGrad_pts2d.Elem(gpi) = new Point2d(x(0), x(1)); for (int k = 1; k <= 2; k++) { if (k == 1) { vdir = new Vec2d(1, 0); } else { vdir = new Vec2d(0, 1); } hbad = bel.CalcJacobianBadnessDirDeriv(FuncGrad_pts2d, lpi, vdir, ref hderiv); grad(k - 1) += hderiv; if (k == 1) { badness += hbad; } } } /* * vgrad.Add (-(vgrad * n), n); * * grad.Elem(1) = vgrad * t1; * grad.Elem(2) = vgrad * t2; */ return(badness); }
private static void AddTriangle(StringBuilder sb, PointIndex tri) { sb.AppendFormat(CultureInfo.InvariantCulture, "f {0:F0}/{0:F0}/{0:F0} {1:F0}/{1:F0}/{1:F0} {2:F0}/{2:F0}/{2:F0}\n", tri.Point1, tri.Point2, tri.Point3); }
public Boolean CheckWinner(PointIndex point, PlayerType state) { if (point == null) { throw new ArgumentNullException(nameof(point)); } for (Int32 x = 0; x < this.BoardSize; x++) { if (this.Board[x, point.Y] != state) { break; } if (x == this.BoardSize - 1) { this.GetWinnerMessage(state); this.WinnerState = true; return(true); } } for (Int32 y = 0; y < this.BoardSize; y++) { if (this.Board[point.X, y] != state) { break; } if (y == this.BoardSize - 1) { this.GetWinnerMessage(state); this.WinnerState = true; return(true); } } for (Int32 x = 0, y = 0; x < this.BoardSize && y < this.BoardSize; x++, y++) { if (this.Board[x, y] != state) { break; } if (x == this.BoardSize - 1 || y == this.BoardSize - 1) { this.GetWinnerMessage(state); this.WinnerState = true; return(true); } } for (Int32 x = this.BoardSize - 1, y = 0; x >= 0 && y < this.BoardSize; x--, y++) { if (this.Board[x, y] != state) { break; } if (x == 0 || y == this.BoardSize - 1) { this.GetWinnerMessage(state); this.WinnerState = true; return(true); } } this.CurrentTurnCount++; if (this.CurrentTurnCount == this.BoardSize * this.BoardSize) { this.GetWinnerMessage(state); this.WinnerState = true; return(true); } this.CurrentTurn = this.CurrentTurn == PlayerType.X ? PlayerType.O : PlayerType.X; return(false); }
/** * Look for groups of vertices that are separated by at most merge_distance() * and merge them into a single vertex. */ private void MergeVertices() { // The overall strategy is to start from each vertex and grow a maximal // cluster of mergable vertices. In graph theoretic terms, we find the // connected components of the undirected graph whose edges connect pairs of // vertices that are separated by at most merge_distance. // // We then choose a single representative vertex for each cluster, and // update all the edges appropriately. We choose an arbitrary existing // vertex rather than computing the centroid of all the vertices to avoid // creating new vertex pairs that need to be merged. (We guarantee that all // vertex pairs are separated by at least merge_distance in the output.) var index = new PointIndex(_options.MergeDistance.Radians); foreach (var edge in _edges) { index.Add(edge.Key); var vset = edge.Value; foreach (var v in vset) { index.Add(v); } } // Next, we loop through all the vertices and attempt to grow a maximial // mergeable group starting from each vertex. var mergeMap = new Dictionary <S2Point, S2Point>(); var frontier = new Stack <S2Point>(); var mergeable = new List <S2Point>(); foreach (var entry in index) { var point = entry.Value; if (point.IsMarked) { continue; // Already processed. } point.Mark(); // Grow a maximal mergeable component starting from "vstart", the // canonical representative of the mergeable group. var vstart = point.Point; frontier.Push(vstart); while (frontier.Any()) { var v0 = frontier.Pop(); index.Query(v0, mergeable); foreach (var v1 in mergeable) { frontier.Push(v1); mergeMap.Add(v1, vstart); } } } // Finally, we need to replace vertices according to the merge_map. MoveVertices(mergeMap); }
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#: //ORIGINAL LINE: auto PNums() const //C++ TO C# CONVERTER TODO TASK: The return type of the following function could not be determined: public auto PNums() { return(new FlatArray <const PointIndex> (np, pnum[0]));