bool IsBorder(PositionVector pos) { if (pos.x == 0 || pos.x == size.x - 1 || pos.y == 0 || pos.y == size.y - 1) { return(true); } return(false); }
public void AddRange(PositionVector values) { bwapiPINVOKE.PositionVector_AddRange(swigCPtr, PositionVector.getCPtr(values)); if (bwapiPINVOKE.SWIGPendingException.Pending) { throw bwapiPINVOKE.SWIGPendingException.Retrieve(); } }
void Can_store_direction() { PositionVector positionVector = new PositionVector() { Direction = Direction.East }; positionVector.Direction.Should().Be(Direction.East); }
public PGCMap(PositionVector size) { // Simulation parameters tileDeathLimit = TILE_DEATH_LIMIT; tileBirthLimit = TILE_BIRTH_LIMIT; maxIterations = MAX_SIMULATIONS_OF_TILEGEN; barrierFrequency = BARRIER_PERCENTAGE; OnInit(size); }
public PositionVector GetRange(int index, int count) { global::System.IntPtr cPtr = bwapiPINVOKE.PositionVector_GetRange(swigCPtr, index, count); PositionVector ret = (cPtr == global::System.IntPtr.Zero) ? null : new PositionVector(cPtr, true); if (bwapiPINVOKE.SWIGPendingException.Pending) { throw bwapiPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public static PositionVector Repeat(Position value, int count) { global::System.IntPtr cPtr = bwapiPINVOKE.PositionVector_Repeat(Position.getCPtr(value), count); PositionVector ret = (cPtr == global::System.IntPtr.Zero) ? null : new PositionVector(cPtr, true); if (bwapiPINVOKE.SWIGPendingException.Pending) { throw bwapiPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public override bool IsElement(Point2D point) { if (DirectionVector.Equals(Vector2D.NullVector)) { return(PositionVector.Equals(point)); } Vector2D vec = point - PositionVector / DirectionVector; return(vec.X == vec.Y); }
public void DotProduct(double leftInitialX, double leftInitialY, double leftTerminalX, double leftTerminalY, double rightInitialX, double rightInitialY, double rightTerminalX, double rightTerminalY, double expectedDotProduct) { var lhs = new PositionVector(leftInitialX, leftInitialY, leftTerminalX, leftTerminalY); var rhs = new PositionVector(rightInitialX, rightInitialY, rightTerminalX, rightTerminalY); var result = lhs.DotProduct(rhs); Assert.AreEqual(expectedDotProduct, result); }
public void Rove(char c) { if (c == 'L' || c == 'R') { currentPositionVector = doAction.Rotate(currentPositionVector, c); } else if (c == 'F') { currentPositionVector = doAction.StepForward(currentPositionVector, MaxCoordinateToRove); } }
public PositionVector StepForward(PositionVector currentPositionVector, Coordinate maxCoordinateToRove) { PositionVector updatedPositionVector = currentPositionVector; updatedPositionVector.Coordinate.Y = currentPositionVector.Coordinate.Y - 1; if (updatedPositionVector.Coordinate.CheckBounds(maxCoordinateToRove) == false) { return(updatedPositionVector); } return(currentPositionVector); }
public override bool IsElement(Point3D point) { if (DirectionVector.Equals(Vector3D.NullVector)) { return(PositionVector.Equals((Vector3D)point)); } Vector3D vec = point - PositionVector; vec = vec / DirectionVector; return(vec.EqualsXY() || vec.EqualsXZ() || vec.EqualsYZ()); }
void Can_store_coordinate() { Coordinate coordinate = new Coordinate() { X = 2, Y = 3 }; PositionVector positionVector = new PositionVector() { Coordinate = coordinate }; positionVector.Coordinate.X.Should().Be(2); positionVector.Coordinate.Y.Should().Be(3); }
public void Impermissible_Command_Sequence_Causes_Fall_Off_Plateau() { //Arrange Rover r = new Rover(new Plateau { Height = 30, Width = 40 }); string commands = "R31"; PositionVector expectedResultantPosition = null; //Act r.Move(commands); //Assert Assert.True(r.CurrentPosition == expectedResultantPosition); }
public void InitialTerminalPositions(double initialX, double initialY, double terminalX, double terminalY) { var vector = new PositionVector(initialX, initialY, terminalX, terminalY); var initialPosition = new Position(initialX, initialY); var terminalPosition = new Position(terminalX, terminalY); Assert.AreEqual(initialPosition, vector.InitialPosition, nameof(vector.InitialPosition)); Assert.AreEqual(terminalPosition, vector.TerminalPosition, nameof(vector.TerminalPosition)); var vectorType = initialPosition == Position.Zero ? VectorType.Standard : VectorType.Component; Assert.AreEqual(vectorType, vector.Type, nameof(vector.Type)); }
public void DefaultCtor() { var vector = new PositionVector(); Assert.Zero(vector.Magnitude, nameof(vector.Magnitude)); Assert.Zero(vector.MagnitudeSquared, nameof(vector.MagnitudeSquared)); Assert.AreEqual(Position.Zero, vector.InitialPosition, nameof(vector.InitialPosition)); Assert.AreEqual(Position.Zero, vector.TerminalPosition, nameof(vector.TerminalPosition)); Assert.AreEqual(Position.Zero, vector.AxisProjection, nameof(vector.AxisProjection)); Assert.AreEqual(PositionVector.Zero, vector.Normalized, nameof(vector.Normalized)); Assert.AreEqual(VectorType.Standard, vector.Type, nameof(vector.Type)); }
public PositionVector Rotate(PositionVector currentPositionVector) { PositionVector updatedLocationVector = currentPositionVector; if ((int)updatedLocationVector.Direction == 7) { updatedLocationVector.Direction = (Direction)0; } else { updatedLocationVector.Direction = (Direction)updatedLocationVector.Direction + 1; } return(updatedLocationVector); }
public void Normalized(double initialX, double initialY, double terminalX, double terminalY) { var vector = new PositionVector(initialX, initialY, terminalX, terminalY); var normalizedVector = vector.Normalized; if (vector.Magnitude > Constants.SmallDouble) { Assert.IsTrue(1 - normalizedVector.Magnitude < Constants.SmallDouble, nameof(normalizedVector.Magnitude)); Assert.IsTrue(1 - vector.Cos(normalizedVector) < Constants.SmallDouble, nameof(vector.Cos)); } else { Assert.IsTrue(normalizedVector.Magnitude < Constants.SmallDouble, nameof(normalizedVector.Magnitude)); } }
public void Valid_Command_Sequence_Movement_Is_Successful() { //Arrange Rover r = new Rover(new Plateau { Height = 30, Width = 40 }); string commands = "R1R3L2L1"; PositionVector expectedResultantPosition = new PositionVector { FacingDirection = Direction.North, XCoordinate = 13, YCoordinate = 8 }; //Act r.Move(commands); //Assert Assert.True(r.CurrentPosition.Equals(expectedResultantPosition)); }
protected override void ProcessRecord() { if (m_init == null) { m_posv = new PositionVector(); } else if (m_init.Length == 9) { m_posv = new PositionVector(m_init[0], m_init[1], m_init[2], m_init[3], m_init[4], m_init[5], m_init[6], m_init[7], m_init[8]); } else { ThrowTerminatingError(new ErrorRecord(new Exception("Invalid number of arguments, -init parameter requires an array of 9 arguments"), "", ErrorCategory.InvalidArgument, m_init)); } WriteObject(m_posv); }
void OnInit(PositionVector size) { // Initialize containers, static values Reset(); tilemap = BuildEmptyPGCMap(size); // Populate PGCMap int[,] randomTiles = MakeRandomTilemapFromPositions(positions); int[,] initialTilemapState = RunSimulation(randomTiles, maxIterations); tilemapState = initialTilemapState; // Save state PlaceEnumTilesFromTilemapState(initialTilemapState); // Adds doors to border positions // AddWalls(tilemap); // AddDoors(tilemap); // Build Graphs of TileTypes graphsByTileType = BuildAllGraphs(); }
// TODO: generalize rules based on position better? void FillAtPosition(PositionVector pos, List <List <ETile> > tilemap) { // Count neighbors if (IsBorder(pos)) { MSet(pos.x, pos.y, ETile.Wall, tilemap); } else if (IsRandomBarrier(pos)) { MSet(pos.x, pos.y, ETile.Barrier, tilemap); } else { // TODO: put this somewhere else validEntityPositions.Add(new Vector2Int(pos.x, pos.y)); MSet(pos.x, pos.y, ETile.Space, tilemap); } }
public void Rover_can_store_current_location_vector_test() { Coordinate coordinate = new Coordinate() { X = 1, Y = 3 }; PositionVector positiontionVector = new PositionVector() { Coordinate = coordinate, Direction = Direction.North }; Rover rover = new Rover() { currentPositionVector = positiontionVector }; rover.currentPositionVector.Direction.Should().Be(Direction.North); rover.currentPositionVector.Coordinate.X.Should().Be(1); rover.currentPositionVector.Coordinate.Y.Should().Be(3); }
bool IsRandomBarrier(PositionVector pos) { // TODO: enable a safe mode? // // Avoids edges to make levels not impossible. // TODO: make this unnecessary // if (pos.x == 1 || pos.x == size.x - 2 || pos.y == 1 || pos.y == size.y - 2) // { // return false; // } int rInt = GetRandInt(0, 101); if (rInt <= barrierFrequency) { return(true); } else { return(false); } }
public string ReadSpecialKey(IEnumerable <MatchLineModel> matchLineModels, PositionVector positionVector) { var specialKey = Literals.Nil; var hasVerticalMatch = false; var hasHorizontalMatch = false; var hasSquareMatch = false; var maxMagnitude = 0; foreach (var matchLineModel in matchLineModels) { hasVerticalMatch = hasVerticalMatch || matchLineModel.type == MatchLineType.V; hasHorizontalMatch = hasHorizontalMatch || matchLineModel.type == MatchLineType.H; hasSquareMatch = hasSquareMatch || matchLineModel.type == MatchLineType.S; maxMagnitude = Math.Max(matchLineModel.magnitude, maxMagnitude); } if (maxMagnitude == 5) { specialKey = Literals.SP; } else if (hasVerticalMatch && hasHorizontalMatch) { specialKey = Literals.C; } else if (maxMagnitude == 4) { specialKey = positionVector.colOffset != 0 ? Literals.H: Literals.V; } else if (hasSquareMatch) { specialKey = Literals.SQ; } return(specialKey); }
/// <summary>Calculates next coordinate moving forward from selected position.</summary> /// <param name="currentPosition">The selected position.</param> /// <returns>New position.</returns> public PositionVector Move(PositionVector currentPosition) { int x = 0; int y = 0; switch (currentPosition.Direction) { case Direction.Notrh: y = 1; break; case Direction.East: x = 1; break; case Direction.South: y = -1; break; case Direction.West: x = -1; break; default: throw new Exception("This direction is not recognised."); } var newPosition = new PositionVector(currentPosition.X + x, currentPosition.Y + y, currentPosition.Direction); if (this.CanMove(newPosition)) { return(newPosition); } return(currentPosition); }
static void Main(string[] args) { Console.WriteLine("---------------------------"); Console.WriteLine("-- Map Generator: v0.0.1 --"); Console.WriteLine("---------------------------"); PositionVector size = new PositionVector(64, 32); PGCMap.MAX_SIMULATIONS_OF_TILEGEN = 1; PGCMap.TILE_DEATH_LIMIT = 3; PGCMap.TILE_BIRTH_LIMIT = 2; PGCMap.BARRIER_PERCENTAGE = 10; PGCMap m = new PGCMap(size); m.PrintPGCMap(); // // Auto // while (true) // { // Console.Clear(); // m.RebuildFromState(m.tilemapState); // m.PrintPGCMap(); // Thread.Sleep(100); // } ConsoleKeyInfo cki = Program.Prompt(); while (cki.Key == ConsoleKey.Enter) { Console.Clear(); m.RebuildFromState(m.tilemapState); m.PrintPGCMap(); // m.PrintGraphs(); cki = Program.Prompt(); } }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PositionVector obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public PositionVector(PositionVector other) : this(bwapiPINVOKE.new_PositionVector__SWIG_1(PositionVector.getCPtr(other)), true) { if (bwapiPINVOKE.SWIGPendingException.Pending) { throw bwapiPINVOKE.SWIGPendingException.Retrieve(); } }
public AttachPoint(string name, PositionVector position) { this.name = name; this.position = position; }
public AttachPoint(PositionVector position) { this.position = position; }