Example #1
0
        public SimpleCircle(Coord center, int radius)
            : base(center, radius)
        {
            pts = new List<Coord>();

            int x0 = center.X;
            int y0 = center.Y;
            int x = radius;
            int y = 0;
            int decisionOver2 = 1 - x;   // Decision criterion divided by 2 evaluated at x=r, y=0

            while (y <= x)
            {
                pts.Add(new Coord(x + x0, y + y0)); // Octant 1
                pts.Add(new Coord(y + x0, x + y0)); // Octant 2
                pts.Add(new Coord(-x + x0, y + y0)); // Octant 4
                pts.Add(new Coord(-y + x0, x + y0)); // Octant 3
                pts.Add(new Coord(-x + x0, -y + y0)); // Octant 5
                pts.Add(new Coord(-y + x0, -x + y0)); // Octant 6
                pts.Add(new Coord(x + x0, -y + y0)); // Octant 7
                pts.Add(new Coord(y + x0, -x + y0)); // Octant 8
                y++;
                if (decisionOver2 <= 0)
                {
                    decisionOver2 += 2 * y + 1;   // Change in decision criterion for y -> y+1
                }
                else
                {
                    x--;
                    decisionOver2 += 2 * (y - x) + 1;   // Change for y -> y+1, x -> x-1
                }
            }
        }        
Example #2
0
        public User OnUserJoinedMessage(EMMServerMessage message)
        {
            // make sure user exists in database
            using (EMMDataContext db = Manager.GetContext)
            {
                User user = db.Users.SingleOrDefault(i => i.Username == message.Data["username"]);
                if (user == null)
                {
                    user = CreateDefaultUser(message.Data["username"]);
                }

                // parse their current location from the join message
                Coord position = new Coord(message);
                user.LocX = position.X;
                user.LocY = position.Y;
                user.LocZ = position.Z;
                user.LastSeen = DateTime.Now;
                db.SubmitChanges();

                // save the current location to the tracking table
                TrackUserPosition(user);

                return user;
            }
        }
Example #3
0
        public void StraightTrajectory()
        {
            this.board.RemovePinAt(1, 1);

            Coord from = new Coord(0, 1), to = new Coord(2, 1);
            this.AssertBestProbToArrive(from, to, 1);
        }
	// Generate a line from one coordinate to another
	// You can ask for it to be totaly walls or totally floor, based on the bool
	// False: Walls
	// True: Floor
	public static void makeLine(Tile[,] map, Coord begin, Coord end, bool applyFloor) {

		// Assert in range
		if( begin.isOOB (map.GetLength(0), map.GetLength (1), Direction.Stop) ||
		    end.isOOB (map.GetLength(0), map.GetLength (1), Direction.Stop) )
			return;
		
		int startX = begin.x;
		int endX = end.x;
		int startY = begin.y;
		int endY = end.y;


		// Find the linear spacing appropriate from point
		// including the endpoint
		int lengthX = Math.Abs( endX - startX );

		var linspace = new List<Double>();
			linspace = LinSpace (startY, endY, lengthX, true).ToList ();

		// Now it's time to actually put our money where our mouth is
		for(int i = startX; i < endX; i++) {
			int j = (int) linspace[i] ;
			map[i,j].property = applyFloor ? TileType.Floor1 : TileType.OuterWall1;
		}

		// Phew! Thought this one was so easy, didn't cha!?

		return;
	}
    public int Distance(Coord start, Coord end)
    {
        //		Debug.Log ("Chain Start: " + start.ToString());
        //		Debug.Log ("Chain End: " + end.ToString());

        return GetChain(start,end).Count;
    }
		public override void RenderOverlay(Scene scene)
		{
			// compute the current frame rate
			if (_stopwatch.IsRunning)
			{
				var fps = 1.0 / _stopwatch.Elapsed.TotalSeconds;
				_stopwatch.Reset();
				_fpsAverager.Add(fps);
			}
			else
			{
				_stopwatch.Start();
			}

			// get the last mouse position
			Coord pos;
			if (_lastMouseEvent != null)
				pos = _lastMouseEvent.Pos;
			else
				pos = new Coord();
					
			_label.Body = String.Format("{0:###.#} fps -- {1} ({2} x {3})", 
				_fpsAverager.Compute(), pos, Scene.Width, Scene.Height);
			OnSceneResized(Scene);

			base.RenderOverlay(scene);
		}
		public DemoCardContents() : base(Orientation.Vertical)
		{
			var label = new Label(Name);
			AddChild(label);
			
			UserSize = new Coord(320, 480);
		}
Example #8
0
 public static bool IsJumpableFrom(Game game, Coord src, Coord toJump)
 {
     Coord diff = new Coord() { Row = toJump.Row - src.Row, Col = toJump.Col - src.Col };
     Coord toLand = new Coord() { Row = src.Row + diff.Row * 2, Col = src.Col + diff.Col * 2 };
     // TODO add out of bounds checking
     return game.GetPieceAt(toLand) == BoardSpaceState.None && game.GetPieceAt(toJump) != BoardSpaceState.None;
 }
Example #9
0
 /// <summary>
 /// 拷贝源本到新元素
 /// </summary>
 /// <param name="desPos">目标坐标</param>
 public void CopyTo(Coord desPos)
 {
     if (SouVersion != null)
     {
         MotaWorld.GetInstance().MapManager.CopyNode(SouVersion, desPos);
     }
 }
Example #10
0
        public Line(Coord ptA, Coord ptB)
        {
            pts = new List<Coord>();

            int x0 = ptA.X;
            int y0 = ptA.Y;
            int x1 = ptB.X;
            int y1 = ptB.Y;

            bool steep = Math.Abs(y1 - y0) > Math.Abs(x1 - x0);
            if (steep) { Utilities.Swap<int>(ref x0, ref y0); Utilities.Swap<int>(ref x1, ref y1); }
            if (x0 > x1) { Utilities.Swap<int>(ref x0, ref x1); Utilities.Swap<int>(ref y0, ref y1); }
            int dX = (x1 - x0), dY = Math.Abs(y1 - y0), err = (dX / 2), ystep = (y0 < y1 ? 1 : -1), y = y0;

            for (int x = x0; x <= x1; ++x)
            {
                pts.Add(steep ? new Coord(y, x) : new Coord(x, y));
                err = err - dY;
                if (err < 0) { y += ystep; err += dX; }
            }

            if (pts.Count > 0 && pts[0] != ptA)
            {
                pts.Reverse();
            }
        }
Example #11
0
        public static BoardSpace.ArrowDirection ArrowDirectionOfCoords(Coord from, Coord to)
        {
            Coord diff = to - from;

            if (diff.Row < 0 && diff.Col == 0)
            {
                return BoardSpace.ArrowDirection.NORTH;
            }
            if (diff.Row < 0 && diff.Col < 0)
            {
                return BoardSpace.ArrowDirection.NORTHWEST;
            }
            if (diff.Row == 0 && diff.Col < 0)
            {
                return BoardSpace.ArrowDirection.WEST;
            }
            if (diff.Row > 0 && diff.Col < 0)
            {
                return BoardSpace.ArrowDirection.SOUTHWEST;
            }
            if (diff.Row > 0 && diff.Col == 0)
            {
                return BoardSpace.ArrowDirection.SOUTH;
            }
            if (diff.Row > 0 && diff.Col > 0)
            {
                return BoardSpace.ArrowDirection.SOUTHEAST;
            }
            if (diff.Row == 0 && diff.Col > 0)
            {
                return BoardSpace.ArrowDirection.EAST;
            }

            return BoardSpace.ArrowDirection.NORTHEAST;
        }
Example #12
0
        static void Main(string[] args)
        {
            string delim = new string('-', 50);

            string st1 = "Niki";
            string st2 = "Niki";
            string st3 = st2;
            st3 = "Gosho";
            Console.WriteLine(Object.ReferenceEquals(st3, st2));  // returns false, because for strings assigning new value doesn`t change the value in heap, but creates  new instance, writes the new value there and changes the address of the string to point to the new address with the new value. st2 value is unchanged

            //st3 = Console.ReadLine();

            Console.WriteLine(st3.Equals(st2)); // if we entered "Niki" at the console this will return true, because Equals is overriden for string types to compare by value
            Console.WriteLine(Object.ReferenceEquals(st3, st2)); // this will return false because st3 has different address than st2, although its value is the same it was dynamically (at runtime) assigned, so it was stored in a new address in heap. If it was compile time aassigned, it was going to be at the same address as st2, so this would have returned true

            Console.WriteLine(delim);
            int i1 = 1;
            //int i2 = int.Parse(Console.ReadLine());
            int i2 = 1;
            Console.WriteLine(ReferenceEquals(i1, i2));
            Console.WriteLine(Equals(i1, i2));
            Console.WriteLine(i1 == i2);

            Console.WriteLine(delim);
            Coord c1 = new Coord(1, 2);
            Coord c2 = new Coord(1, 2);

            Console.WriteLine(ReferenceEquals(c1, c2)); // always gives false for value types
            Console.WriteLine(Equals(c1, c2)); // actually compares them
            //Console.WriteLine(c1 == c2); // must be overriden first
        }
Example #13
0
        public void Play(Player p, Coord start, Coord end)
        {
            if (CanSelectToPlay(p, start.x, start.y) && board.IsEmpty(end.x, end.y))
            {
                var distance = end - start;
                int travelLength = Math.Abs(distance.x) + Math.Abs(distance.y);

                //Move -> Remove original
                if (travelLength == 2)
                {
                    board[start.x, start.y] = null;
                }

                //Copy (or Move) -> Put token
                PutToken(p, end.x, end.y);
                var offsetCalc = new OffsetCalculator(end.x, end.y);
                for (int i = 0; i < 9; i++)
                {
                    offsetCalc.setDirection(i);
                    offsetCalc.MakeOffset(1);

                    if (board.CanOvertakeToken(p, offsetCalc.ResultX, offsetCalc.ResultY))
                    {
                        PutToken(p, offsetCalc.ResultX, offsetCalc.ResultY);
                    }
                }

                HandlePlayerChange();

                if (SnapshotContainer != null)
                {
                    SnapshotContainer.TakeSnapShot(new TwoPartTurn() { Start = start, End = end, PlayerThatPlayed = p, PlayerToPlay = CurrentPlayer, Board = board.Clone() });
                }
            }
        }
Example #14
0
 public void DeviceRect(Coord x0, Coord y0, Coord x1, Coord y1)
 {
     int x = (int) Math.Round(Math.Min((double) x0.Value, (double) x1.Value));
     int y = (int) Math.Round(Math.Min((double) x0.Value, (double) x1.Value));
     int w = (int) Math.Round(Math.Min((double) x0.Value, (double) x1.Value));
     int h = (int) Math.Round(Math.Min((double) x0.Value, (double) x1.Value));
 }
Example #15
0
        /// <summary>
        /// 以一定的移动速度创建可移动元素对象
        /// </summary>
        /// <param name="faceIndex">移动对象的图像索引</param>
        /// <param name="pos">可移动对象的初始位置</param>
        /// <param name="name">移动对象名称</param>
        public MoveElement(MotaElement faceIndex, Coord pos, string name)
            : base(faceIndex, pos, TouchMethod.ImmediatelyTouch, true, name)
        {
            this.Speed = GameIni.IniHeroSpeed;

            MoveDirection = Direction.No;
        }
Example #16
0
        /// <summary>
        /// 以待编辑的元素坐标创建窗口
        /// </summary>
        public FrmEdit(Coord editPos)
        {
            InitializeComponent();

            this.CurPosation = editPos;
            this.content.Text = MotaWorld.GetInstance().MapManager.GetNodeString(editPos);
        }
		public void AddCoordToAppropriateSequence(Coord coord)
		{
			bool flag = false;
			foreach (Sequence current in this.Sequences)
			{
				if (current.LastCoord.I + 1 == coord.I && current.LastCoord.J + 1 == coord.J)
				{
					current.LastCoord = coord;
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				this.Sequences.Add(new Sequence
				{
					FirstCoord = new Coord
					{
						I = coord.I - coord.Size + 1,
						J = coord.J - coord.Size + 1,
						Size = 1
					},
					LastCoord = coord
				});
			}
		}
Example #18
0
        public Node(NodeMapping mapping, Coord c)
        {
            m_coord = c;
            m_mapping = mapping;

            if (mapping.hasCPU(c.ID))
            {
                m_cpu = new CPU(this);
            }
            if (mapping.hasMem(c.ID))
            {
				Console.WriteLine("Proc/Node.cs : MC locations:{0}", c.ID);
                m_mem = new MemCtlr(this);
            }

            m_inj_pool = Simulator.controller.newPrioPktPool(m_coord.ID);
            Simulator.controller.setInjPool(m_coord.ID, m_inj_pool);
            m_injQueue_flit = new Queue<Flit>();
            m_injQueue_evict = new Queue<Flit>();
            m_local = new Queue<Packet>();

            m_rxbuf_naive = new RxBufNaive(this,
                    delegate(Flit f) { m_injQueue_evict.Enqueue(f); },
                    delegate(Packet p) { receivePacket(p); });
        }
Example #19
0
 public Apple(Renderer renderer, PlayField playField)
 {
     _renderer = renderer;
     AppleCoordinate = new Coord();
     _playFieldHeight = playField.Height;
     _playFieldWidth = playField.Width;
 }
Example #20
0
 public void ShouldConvertToVector3()
 {
     Coord coord = new Coord(2, 2);
     Vector2 vector = coord.ToVector2();
     Assert.AreEqual(2f, vector.x, 0.001f);
     Assert.AreEqual(2f, vector.y, 0.001f);
 }
Example #21
0
 public Router_Flit(Coord myCoord)
     : base(myCoord)
 {
     m_injectSlot  = null;
     m_injectSlot2 = null;
     rBuf = new ResubBuffer();
 }
Example #22
0
        /// <summary>
        /// 根据自定义的图像设置事件元素实例
        /// </summary>
        /// <param name="fileName">图像文件名</param>
        /// <param name="showPosation">事件在地图上的坐标</param>
        /// <param name="method">触发方式</param
        /// <param name="repeated">是否是触发触发的事件</param>>
        /// <param name="eventName">事件名</param>
        /// <param name="unitSize">图像分隔的单位尺寸</param>
        protected MapEvent(string fileName, Coord showPosation, TouchMethod method, bool repeated, string eventName, Size unitSize)
            : base(fileName, showPosation, unitSize)
        {
            SetAttr(method, repeated, eventName);

            this.FaceUnit = unitSize;
        }
 public Tree(Coord root)
 {
     this.rootNode = new TreeNode();
     this.rootNode.SetRoot(root,new List<Coord>());
     this.nodes = new List<TreeNode>();
     this.nodes.Add(rootNode);
 }
	public override void boardSetup() {
		
		boardHolder = new GameObject ("Board").transform;
		
		// Generate a map from Cellular Automata.
		// CellularAutomata foo = new CellularAutomata(rows, columns);
		//PureRandom foo = new PureRandom(rows, columns);
		GameObject playerChar = GameObject.FindGameObjectWithTag("Player");
		selectedRule.initializeMap ();
		selectedRule.generateMap ();
		Tile[,] mapConvert = selectedRule.map;

		MapValidationFunctions mvf = new MapValidationFunctions();

		Coord startPoint = new Coord(floodStartX,floodStartY); 
		Coord endPoint = new Coord(floodGoalX, floodGoalY);
		
		mvf.FloodFillCheck(selectedRule.map, startPoint, endPoint);

		// This is the autotiler phase.
		//
		// Let's try this method of instantiating the prefab of our choice...
		GameObject tileInstance = Instantiate(tilesetToUse, new Vector3(0,0,0), Quaternion.identity) as GameObject;
		
		selectedTileset = tileInstance.GetComponent<Tileset>();
		selectedTileset.autoTiler( mapConvert ); 

		if(MapValidationFunctions.clearable) Debug.Log ("The goal has been found!");
		else Debug.Log ("I can't find the goal.");
		
		//convertTiles( mapConvert );
		
	}
Example #25
0
        private Question travelRange()
        {
            Coord start, destination;
            int distance;

            Question travel = new Question("Where do you go?:", new string[] { });

            foreach (KeyValuePair<string, Coord> pair in Reference.Directory.Instance.Catalog) {

                start = Reference.Directory.Instance.Catalog[this.alias];

                destination = new Coord(pair.Value.coordX, pair.Value.coordY);

                distance = Utility.MathHelper.distance(start, destination);

                if (distance <= 10 && distance != 0) {

                    travel.addAnswer(pair.Key);

                }

            }

            travel.addAnswer("Exit");

            return travel;
        }
Example #26
0
 public void DeviceRect(Coord x0, Coord y0, Coord x1, Coord y1)
 {
     Coord left = Math.Min(x0.Value, x1.Value);
     Coord right = Math.Max(x0.Value, x1.Value);
     Coord botom = Math.Min(y0.Value, y1.Value);
     Coord top = Math.Max(y0.Value, y1.Value);
 }
Example #27
0
        public void ImpossibleTrajectory()
        {
            this.walker = new Walker(new Board(5, 9));

            Coord from = new Coord(0, 7), to = new Coord(4, 1);
            this.AssertBestProbToArrive(from, to, 0);
        }
Example #28
0
        /// <summary>
        /// 以一定的移动速度创建可移动元素对象
        /// </summary>
        /// <param name="fileName">移动对象的图像文件</param>
        /// <param name="pos">可移动对象的初始位置</param>
        /// <param name="name">移动对象名称</param>
        /// <param name="unitSize">图像分割的单位尺寸</param>
        public MoveElement(string fileName, Coord pos, string name, Size unitSize)
            :base(fileName, pos, TouchMethod.ImmediatelyTouch, true, name, unitSize)
        {
            this.Speed = GameIni.IniHeroSpeed;

            MoveDirection = Direction.No;
        }
Example #29
0
        public void TwoHopTrajectory()
        {
            this.walker = new Walker(new Board(5, 5));

            Coord from = new Coord(0, 3), to = new Coord(2, 1);
            this.AssertBestProbToArrive(from, to, 0.25f);
        }
	// Use this for initialization
	void Start () {

		supportive = GetComponent<AudioSource>();

		// This is some instantiation.
		// We want it so that if the player is within a + direction from the particle, they will get hurt.
		GameObject player = GameObject.FindGameObjectWithTag("Player");
		int playerX = (int)player.transform.position.x;
		int playerY = (int)player.transform.position.y;

		Coord myPlace = new Coord((int)this.transform.position.x, (int)this.transform.position.y);
		Coord playerCoord = new Coord(playerX, playerY);
		Coord n, w, s, e;
		n = playerCoord.nextCoord (Direction.North);
		w = playerCoord.nextCoord (Direction.West);
		s = playerCoord.nextCoord (Direction.South);
		e = playerCoord.nextCoord (Direction.East);

		if( myPlace.isEqual (playerCoord) ||
		    myPlace.isEqual (n) ||
		    myPlace.isEqual (w) ||
		    myPlace.isEqual (s) ||
		    myPlace.isEqual (e) ) {
			PlayerMovement hitPlayer = player.GetComponent<PlayerMovement>();
			supportive.PlayOneShot(haha,1f);
			hitPlayer.LoseHealth(750); }

		Destroy (this.gameObject, 3);

	}