Example #1
0
        public void TestApplyTurn(Turn turn, Cardinal a, Cardinal b)
        {
            var expected = new Position(0, 0, b);
            var actual   = (new EasterNavigation()).ApplyTurn(new Position(0, 0, a), turn);

            Assert.Equal(expected, actual);
        }
Example #2
0
        private void Process(Chunk fromChunk, Cardinal direction)
        {
            if (fromChunk == null)
            {
                return;
            }

            Vector3i chunkIndexAdd;
            Vector3i chunkIndexRemove;

            SignedVector3i addDelta    = Cardinals.VectorFrom(direction) * (World.VIEW_DISTANCE_NEAR_X);
            SignedVector3i removeDelta = Cardinals.OppositeVectorFrom(direction) * (World.VIEW_DISTANCE_NEAR_X);

            chunkIndexAdd = fromChunk.Index.add(addDelta);

            if (world.viewableChunks[chunkIndexAdd.X, chunkIndexAdd.Z] != null)
            {
                return;
            }

            chunkIndexRemove = fromChunk.Index.add(removeDelta);
            Debug.WriteLine("Process  {0} Add at {1}, remove at {2}", direction, chunkIndexAdd, chunkIndexRemove);

            //Chunk toRemove = world.viewableChunks[chunkIndexRemove.X, chunkIndexRemove.Z];
            //world.viewableChunks.Remove(toRemove.Index.X, toRemove.Index.Z);
            world.viewableChunks.Remove(chunkIndexRemove.X, chunkIndexRemove.Z);//null safe

            // Instead of removing, Re assign new chunk to opposite chunk
            //toRegen.Assign(chunkIndexAdd);

            // Generate & Build new chunk
            Chunk addedChunk = DoGenerate(chunkIndexAdd);

            DoBuild(addedChunk);
        }
    public static Slider Slide(this Rect r, Cardinal direction)
    {
        Slider s = new Slider(r);

        s.Slide(direction);
        return(s);
    }
Example #4
0
        public void TestApplyMagnitude(Cardinal direction, int magnitude, int x, int y)
        {
            var expected = new Position(x, y, direction);
            var actual   = (new EasterNavigation()).ApplyMagnitude(new Position(0, 0, direction), magnitude);

            Assert.Equal(expected, actual);
        }
Example #5
0
    public List <MapPoint> GetRange(bool forceRebuild = false)
    {
        if (m_cachedRange == null || forceRebuild)
        {
            m_cachedRange = new List <MapPoint>();
            m_cachedRange.Add(GetMapPos());

            for (Cardinal dir = Cardinal.North; dir <= Cardinal.West; dir++)
            {
                for (int range = 1; range <= m_range; range++)
                {
                    var point = (GameController.CardinalToDelta(dir) * range) + GetMapPos();
                    // stop when hitting a wall
                    if (!Map.IsValid(point))
                    {
                        break;
                    }
                    var tile = Map.GetAt(point);
                    if (tile == MapTile.Wall)
                    {
                        break;
                    }
                    // spawn explosion manager
                    m_cachedRange.Add(point);
                    // if we're going through a crate, stop here instead (after the explosion was placed)
                    if (tile == MapTile.Crate)
                    {
                        break;
                    }
                }
            }
        }

        return(m_cachedRange);
    }
Example #6
0
        public void Run()
        {
            int            j = 1;
            const int      startingLocation  = 1;
            const Cardinal startingDirection = Cardinal.South;
            var            rover             = new Rover(startingLocation, startingDirection);

            for (int i = 0; i < j; i++)
            {
                Console.WriteLine("Please enter the comma separated list of directions for the rover");
                string argList = Console.ReadLine();

                argList = RemoveWhitespace(argList);

                IEnumerable <string> commands = argList.Split(',').AsEnumerable();
                var roverCalc = new RoverCoordinateCalculate(commands);

                var(Location, Compass)  = roverCalc.AddressCommands(rover.Location, rover.CardinalDirection);
                rover.Location          = Location;
                rover.CardinalDirection = Compass;

                Console.WriteLine($"Rover is now at {rover.Location}, facing {rover.CardinalDirection}");
                Console.WriteLine("Any further commands? Y/N");
                string response = Console.ReadLine();

                if (RepeatProcess(response))
                {
                    j++;
                }
                else
                {
                    return;
                }
            }
        }
Example #7
0
    public static Cardinal AddCardinal(Cardinal c1, Cardinal c2)
    {
        int cardinalIntResult = (int)c1 + (int)c2;

        cardinalIntResult = cardinalIntResult % 4;
        return((Cardinal)cardinalIntResult);
    }
Example #8
0
        public override void Update(GameTime gameTime)
        {
            Chunk currentChunk = world.ChunkAt(camera.Position);

            if (currentChunk == null)
            {
                return;                       // should not happen when this code will be finished
            }
            //  if (currentChunk.Index != previousChunkIndex )
            // {
            Cardinal direction = camera.FacingCardinal();

            previousChunkIndex = currentChunk.Index;
            previousDirection  = direction;

            Process(currentChunk, direction);

            Cardinal[] adjacents = Cardinals.Adjacents(direction);

            Chunk adjacentChunk;

            //process the adjacent chunks, for example when going north, first process west chunks and then east chunks
            foreach (Cardinal adj in adjacents)
            {
                adjacentChunk = currentChunk;

                while (adjacentChunk.GetNeighbour(adj) != null)
                {
                    adjacentChunk = adjacentChunk.GetNeighbour(adj);
                    //Debug.WriteLine("current[ {0}],adj {1} : {2}",currentChunk, adj, adjacentChunk);
                    Process(adjacentChunk, direction);
                }
            }
            //}
        }
Example #9
0
 public NewRoverCommand(INasa nasa, IPlateau plateau, Location position, Cardinal cardinal)
 {
     _nasa         = nasa;
     _plateau      = plateau;
     this.position = position;
     this.cardinal = cardinal;
 }
        public Chunk GetNeighbour(Cardinal c)
        {
            switch (c)
            {
            case Cardinal.N:
                return(N);

            case Cardinal.S:
                return(S);

            case Cardinal.E:
                return(E);

            case Cardinal.W:
                return(W);

            case Cardinal.SE:
                return(SE);

            case Cardinal.SW:
                return(SW);

            case Cardinal.NE:
                return(NE);

            case Cardinal.NW:
                return(NW);
            }
            throw new NotImplementedException();
        }
Example #11
0
        /// <summary>
        /// Recursive function which visits a specified cell and goes to another cell adjacent until
        /// all the cells around it are either connected to the cell, or visited by another path.
        /// </summary>
        /// <param name="x">x Coordinate of the cell.</param>
        /// <param name="y">y Coordinate of the cell.</param>
        /// <param name="direction">Direction the cell is being visited from.</param>
        /// <param name="rand">Passes a random number generator through, to allow the use of a seed throughout the code without a global variable.</param>
        private void Generate(int x, int y, Cardinal cardinal, Random rand)
        {
            Cells[x][y].Visit(cardinal);
            cardinal = GetCardinal(rand, x, y);
            while (cardinal != Cardinal.NONE)//will visit each direction not currently visited around the current cell.
            {
                switch (cardinal)
                {
                case Cardinal.NORTH:
                    Generate(x, y - 1, Cardinal.SOUTH, rand);
                    break;

                case Cardinal.EAST:
                    Generate(x + 1, y, Cardinal.WEST, rand);
                    break;

                case Cardinal.SOUTH:
                    Generate(x, y + 1, Cardinal.NORTH, rand);
                    break;

                case Cardinal.WEST:
                    Generate(x - 1, y, Cardinal.EAST, rand);
                    break;
                }
                Cells[x][y].Visit(cardinal);
                cardinal = GetCardinal(rand, x, y);
            }
        }
Example #12
0
    private void SetMoveDir()
    {
        int xDiff = CurrentTile.X - NextTile.X;

        if (xDiff != 0)
        {
            if (xDiff < 0)
            {
                moveDir = Cardinal.East;
            }
            else
            {
                moveDir = Cardinal.West;
            }
        }
        else
        {
            int yDiff = CurrentTile.Y - NextTile.Y;
            if (yDiff < 0)
            {
                moveDir = Cardinal.North;
            }
            else
            {
                moveDir = Cardinal.South;
            }
        }
    }
    private bool MakeInteraction()
    {
        // Returns true if interacted, false if not an interactable
        Vector2 center    = _collider.bounds.center;
        Vector2 direction = Cardinal.vectorForDirection(_lookPosition);
        float   size      = _collider.size.x;

        // Disables own collider to prevent colliding on itself
        _collider.enabled = false;
        RaycastHit2D hit = Physics2D.Raycast(center, direction, size);

        _collider.enabled = true;

        if (hit.collider != null)
        {
            // Interactable interactable = hit.transform.GetComponent<Interactable>();
            Interactable[] interactables = hit.transform.GetComponents <Interactable>();
            if (interactables.Length < 1)
            {
                // Can't interact with this.
                return(false);
            }
            else
            {
                // Interaction successful.
                foreach (Interactable interactable in interactables)
                {
                    interactable.Interact(this.gameObject);
                }
                return(true);
            };
        }
        return(false);
    }
Example #14
0
        private int SetLocationAdjustment(Cardinal compass, int locationDiff)
        {
            var newLocation = 0;

            switch (compass)
            {
            case Cardinal.South:
                newLocation += (locationDiff * _yScalar);     // Add 100 with every meter
                break;

            case Cardinal.West:
                newLocation -= locationDiff;     // subtract 1 with every meter
                break;

            case Cardinal.North:
                newLocation -= (locationDiff * _yScalar);     // Subtract 100 with every meter
                break;

            case Cardinal.East:
                newLocation += locationDiff;     // Add 1 with every meter
                break;
            }

            return(newLocation);
        }
Example #15
0
 public CombinedAxis(Stick stick1, Stick stick2, Stick stick3, Cardinal dimension)
 {
     _stick1    = stick1;
     _stick2    = stick2;
     _stick3    = stick3;
     _dimension = dimension;
 }
        public Position ApplyTurn(Position position, Turn turn)
        {
            Cardinal facing = Cardinal.North;

            switch (position.facing)
            {
            case Cardinal.North:
                facing = ApplyTurn(turn, Cardinal.West, Cardinal.East);
                break;

            case Cardinal.South:
                facing = ApplyTurn(turn, Cardinal.East, Cardinal.West);
                break;

            case Cardinal.East:
                facing = ApplyTurn(turn, Cardinal.North, Cardinal.South);
                break;

            case Cardinal.West:
                facing = ApplyTurn(turn, Cardinal.South, Cardinal.North);
                break;

            default:
                facing = Cardinal.North;
                break;
            }

            return(new Position(position.x, position.y, facing));
        }
Example #17
0
    public static void CardinalToDelta(Cardinal dir, out int dx, out int dy)
    {
        switch (dir)
        {
        case Cardinal.North:
            dx = 0;
            dy = 1;
            break;

        case Cardinal.South:
            dx = 0;
            dy = -1;
            break;

        case Cardinal.East:
            dx = 1;
            dy = 0;
            break;

        case Cardinal.West:
            dx = -1;
            dy = 0;
            break;

        default:
            throw new ArgumentException(nameof(dir));
        }
    }
Example #18
0
    public static MapPoint CardinalToDelta(Cardinal dir)
    {
        int dx, dy;

        CardinalToDelta(dir, out dx, out dy);
        return(new MapPoint(dx, dy));
    }
Example #19
0
        public static SignedVector3i OppositeVectorFrom(Cardinal c)
        {
            switch (c)
            {
            case Cardinal.N: return(S);

            case Cardinal.NE: return(SW);

            case Cardinal.E: return(W);

            case Cardinal.SE: return(NW);

            case Cardinal.S: return(N);

            case Cardinal.SW: return(NE);

            case Cardinal.W: return(E);

            case Cardinal.NW: return(SE);

            default:
                break;
            }
            throw new NotImplementedException("unknown cardinal direction " + c);
        }
Example #20
0
        public static Cardinal[] Adjacents(Cardinal from)
        {
            switch (from)
            {
            case Cardinal.N: return(new Cardinal[] { Cardinal.E, Cardinal.W });

            case Cardinal.NE: return(new Cardinal[] { Cardinal.S, Cardinal.W, Cardinal.E, Cardinal.N });

            case Cardinal.E: return(new Cardinal[] { Cardinal.N, Cardinal.S });

            case Cardinal.SE: return(new Cardinal[] { Cardinal.N, Cardinal.W, Cardinal.E, Cardinal.S });

            case Cardinal.S: return(new Cardinal[] { Cardinal.E, Cardinal.W });

            case Cardinal.SW: return(new Cardinal[] { Cardinal.N, Cardinal.E, Cardinal.W, Cardinal.S });

            case Cardinal.W: return(new Cardinal[] { Cardinal.N, Cardinal.S });

            case Cardinal.NW: return(new Cardinal[] { Cardinal.S, Cardinal.E, Cardinal.N, Cardinal.W });

            default:
                break;
            }
            throw new NotImplementedException("unknown cardinal direction " + from);
        }
Example #21
0
    bool CheckParallel(Cardinal direction, Vector2 startPos, RoomSize roomSize)
    {
        Vector2 dir = new Vector2(0, 0);
        Tile    tile;

        for (int i = 0; i < (int)roomSize; i++)
        {
            if (direction == Cardinal.up)
            {
                dir = Vector2.up;
            }
            else if (direction == Cardinal.down)
            {
                dir = Vector2.down;
            }
            else if (direction == Cardinal.left)
            {
                dir = Vector2.left;
            }
            else if (direction == Cardinal.right)
            {
                dir = Vector2.right;
            }

            if (tiles.TryGetValue(dir * i + startPos, out tile))
            {
                return(false);
            }
        }
        return(true);
    }
Example #22
0
 private bool GetPerimeterValidation(Cardinal compass, int location, int boundaryLimit)
 {
     if (compass == Cardinal.North || compass == Cardinal.West)
     {
         return(location < boundaryLimit);       // Lower boundary
     }
     return(Math.Abs(location) > boundaryLimit); // Upper boundary
 }
        public void CardinalMigrateReturnsTrueTest()
        {
            // Act
            Cardinal cardinal = new Cardinal();

            // Assert
            Assert.True(cardinal.Migrate());
        }
        public void CardinalColorReturnsRedTest()
        {
            // Act
            Cardinal cardinal = new Cardinal();

            // Assert
            Assert.Equal("red", cardinal.Color);
        }
Example #25
0
        private void ParseCommand(string command, out int x, out int y, out Cardinal cardinal)
        {
            var splitCommand = command.Split(' ');

            x        = int.Parse(splitCommand[0]);
            y        = int.Parse(splitCommand[1]);
            cardinal = Enum.Parse <Cardinal>(splitCommand[2]);
        }
Example #26
0
        private static Command ParsePlaceCommand(string[] arguments)
        {
            Cardinal cardinal = GetCardinal(arguments[3]);

            return(new PlaceCommand(new PointsTo(cardinal),
                                    int.Parse(arguments[1]),
                                    int.Parse(arguments[2])));
        }
Example #27
0
        public Map(Vector2 pivot, int num)
        {
            this.pivot = pivot;
            this.num   = num;

            parentCardinal = Cardinal.none;
            root           = new Dictionary <Cardinal, Map>();
        }
Example #28
0
        public List <PathNode> FindPath(BlockPos start, BlockPos end, int maxFallHeight, float stepHeight, Cuboidf entityCollBox, int searchDepth = 9999, bool allowReachAlmost = false)
        {
            blockAccess.Begin();

            centerOffsetX = 0.35 + api.World.Rand.NextDouble() * 0.35;
            centerOffsetZ = 0.35 + api.World.Rand.NextDouble() * 0.35;

            NodesChecked = 0;

            PathNode startNode  = new PathNode(start);
            PathNode targetNode = new PathNode(end);

            openSet.Clear();
            closedSet.Clear();

            openSet.Add(startNode);

            while (openSet.Count > 0)
            {
                if (NodesChecked++ > searchDepth)
                {
                    return(null);
                }

                PathNode nearestNode = openSet.First();
                foreach (var node in openSet)
                {
                    if (node.fCost <= nearestNode.fCost && node.hCost < nearestNode.hCost)
                    {
                        nearestNode = node;
                    }
                }

                openSet.Remove(nearestNode);
                closedSet.Add(nearestNode);


                if (nearestNode == targetNode || (allowReachAlmost && Math.Abs(nearestNode.X - targetNode.X) <= 1 && Math.Abs(nearestNode.Z - targetNode.Z) <= 1 && nearestNode.Y == targetNode.Y))
                {
                    return(retracePath(startNode, nearestNode));
                }

                for (int i = 0; i < Cardinal.ALL.Length; i++)
                {
                    Cardinal card = Cardinal.ALL[i];

                    PathNode neighbourNode = new PathNode(nearestNode, card);

                    float extraCost = 0;
                    if (traversable(neighbourNode, stepHeight, maxFallHeight, entityCollBox, card.IsDiagnoal, ref extraCost) && !closedSet.Contains(neighbourNode))
                    {
                        addIfNearer(nearestNode, neighbourNode, targetNode, openSet, extraCost);
                    }
                }
            }

            return(null);
        }
Example #29
0
 public override void AddPieceTypes()
 {
     base.AddPieceTypes();
     AddPieceType(Wizard   = new Wizard("Wizard", "W", 460, 460));
     AddPieceType(Champion = new Champion("Champion", "C", 475, 475));
     //	Set the name for the Archbishop (called a Cardinal in Grand Chess)
     Cardinal.Name = "Archbishop";
     Cardinal.SetNotation("A");
 }
Example #30
0
        private int GetLimitForLatitudinalTravel(Cardinal compass, int location)
        {
            int column     = location == 0 ? 1 : location % 100,
                cellRow    = (location / 100) + 1,
                upperLimit = cellRow * 100,
                lowerLimit = upperLimit - 99;

            return(compass == Cardinal.East? upperLimit : lowerLimit);
        }
	public static GUISliderMessage Factory(Rect a, float power, string m, Cardinal direction) {
		GameObject g = new GameObject("GUISliderMessage");
		GUISliderMessage sm = g.AddComponent<GUISliderMessage>();
		sm.slidePower = power;
		sm.area = a;
		sm.message = m;
		sm.direction = direction;
		sm.skin = Resources.Load("message", typeof(GUISkin)) as GUISkin;
		return sm;
	}
 public MMCardinal(Cardinal direction)
 {
     switch (direction)
     {
         case Cardinal.Down:
             dir = VecUtil.GetNormDown();
             break;
         case Cardinal.Up:
             dir = VecUtil.GetNormUP();
             break;
         case Cardinal.Left:
             dir = VecUtil.GetNormLeft();
             break;
         case Cardinal.Right:
             dir = VecUtil.GetNormRight();
             break;
     }
 }
    public void ShootWhithCanon(Cardinal cardinal)
    {
        List<int> m_ListOfCanonToShoot = new List<int>();
        switch (cardinal)
        {
            case Cardinal.North:
                m_ListOfCanonToShoot.Add(0);
                m_ListOfCanonToShoot.Add(1);
                m_ListOfCanonToShoot.Add(16);
                break;
            case Cardinal.East:
                m_ListOfCanonToShoot.Add(1);
                m_ListOfCanonToShoot.Add(2);
                m_ListOfCanonToShoot.Add(3);
                m_ListOfCanonToShoot.Add(4);
                m_ListOfCanonToShoot.Add(5);
                break;
            case Cardinal.South:
                m_ListOfCanonToShoot.Add(6);
                m_ListOfCanonToShoot.Add(7);
                m_ListOfCanonToShoot.Add(8);
                m_ListOfCanonToShoot.Add(9);
                m_ListOfCanonToShoot.Add(10);
                m_ListOfCanonToShoot.Add(11);
                break;
            case Cardinal.West:
                m_ListOfCanonToShoot.Add(12);
                m_ListOfCanonToShoot.Add(13);
                m_ListOfCanonToShoot.Add(14);
                m_ListOfCanonToShoot.Add(15);
                m_ListOfCanonToShoot.Add(16);
                break;
        }

        Action(m_ListOfCanonToShoot);
    }
	public static Slider Slide(this Rect r, Cardinal direction) {
		Slider s = new Slider(r);
		s.Slide(direction);
		return s;
	}
	public static GUISliderMessage Factory(Rect a, string m, Cardinal direction) { return Factory(a, 1, m, direction); }
	public void Slide(Cardinal direction, float power) {
		if (direction == Cardinal.Up) { SlideUp(power); }
		else if (direction == Cardinal.Down) { SlideDown(power); }
		else if (direction == Cardinal.Left) { SlideLeft(power); }
		else if (direction == Cardinal.Right) { SlideRight(power); }
	}
	public void Slide(Cardinal direction) { Slide(direction, 1); }