Beispiel #1
0
        /// <summary>
        /// Publishes the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        private void Publish(
            Marble item,
            VisualRxChannelWrapper[] channels)
        {
            #region Validation

            if (channels == null || !channels.Any())
            {
                _setting.Log(LogLevel.Warning, $"{nameof(VisualRxPublishersSettings)}: No proxy found", null);
                return;
            }

            #endregion Validation

            item.IndexOrder = _indexOrder;

            foreach (VisualRxChannelWrapper channel in channels)
            {
                try
                {
                    // the channel wrapper apply parallelism and batching (VIA Rx Subject)
                    channel.Send(item);
                }
                #region Exception Handling

                catch (Exception ex)
                {
                    _setting.Log(LogLevel.Error, nameof(VisualRxPublishersSettings), ex);
                }

                #endregion Exception Handling
            }
        }
    public int MoveAMarble(State s, Tile fromTile, Tile toTile) //Flyttar pjäsen
    {
        Marble m = fromTile.Marble;

        List <Tile>[] legalMoves = GetValidMoves(fromTile, s);
        for (int i = 0; i < legalMoves.Length; i++)
        {
            foreach (Tile t in legalMoves[i])
            {
                if (t.xPos == toTile.xPos && t.yPos == toTile.yPos)
                {
                    toTile.Marble       = fromTile.Marble;
                    fromTile.isOccupied = false;
                    if (i == 0)
                    {
                        return(0); //Enkelflytt
                    }
                    else
                    {
                        s.visitedTiles.Add(fromTile);
                        return(1); //Hoppade över något
                    }
                }
            }
        }
        return(2); //Ogiltig flytt
    }
Beispiel #3
0
    //Creates a shop Object -> sets its name cost and sprite from the Marble List
    public void DisplayShopItems()
    {
        Generate3ShopItems();
        int counter = 0;

        foreach (var item in shopMarbles)
        {
            GameObject shop = Instantiate(shopObject);
            shop.transform.SetParent(transform);
            Marble marble = item.GetComponent <Marble>();
            string name   = marble.commonName;
            string cost   = marble.cost.ToString();
            Sprite sprite = marble.marbleSprite;

            ShopObject newShopObject = shop.GetComponent <ShopObject>();
            newShopObject.marbleName.text             = name;
            newShopObject.marbleCost.text             = "$" + cost;
            newShopObject.marbleSpriteRenderer.sprite = sprite;

            if (counter < shopObjectLocations.Length)
            {
                shop.transform.position = shopObjectLocations[counter].position;
            }
            counter++;
        }
    }
Beispiel #4
0
 public Tile(int x, int y, Marble m) //Ifall det finns en pjäs utplacerad på brickan
 {
     isOccupied = true;
     xPos       = x;
     yPos       = y;
     marble     = new Marble(m, this);
 }
Beispiel #5
0
        public static void Run()
        {
            var instructions = File.ReadAllText("input.txt");

            var parts = instructions.Split(new string[] { " players; last marble is worth " }, StringSplitOptions.RemoveEmptyEntries);

            numOfPlayers    = int.Parse(parts[0]);
            lastMarbleValue = int.Parse(parts[1].Replace(" points", ""));

            marbleBag = 1;
            players   = new List <Player>();

            for (int i = 0; i < numOfPlayers; i++)
            {
                players.Add(new Player());
            }

            current       = new Marble(0);
            current.Left  = current;
            current.Right = current;

            bool run = false;

            do
            {
                run = Round();
            } while (run);

            Console.WriteLine("Highest Points: " + players.Max(p => p.Score));
        }
Beispiel #6
0
        public void Init()
        {
            Marble m0 = new Marble();

            m0.Value = 0;

            Marble m1 = new Marble();

            m1.Value = 1;

            Marble m2 = new Marble();

            m2.Value = 2;

            m0.Next = m2;
            m0.Prev = m1;

            m1.Next = m0;
            m1.Prev = m2;

            m2.Next = m1;
            m2.Prev = m0;

            Current = m2;
        }
        public void Test2()
        {
            //0 (2) 1
            var currentMarble = new Marble {
                Value = 0
            };

            currentMarble.Previous = currentMarble;
            currentMarble.Next     = currentMarble;

            Int64 result = 0;

            for (int i = 1; i <= 2; i++)
            {
                result = Functions.PlayRound(i, ref currentMarble);
            }

            Assert.AreEqual(0, result);
            CollectionAssert.AreEqual(new List <Int64> {
                2, 1, 0
            }, currentMarble.Walk(true));
            CollectionAssert.AreEqual(new List <Int64> {
                2, 0, 1
            }, currentMarble.Walk(false));
        }
Beispiel #8
0
    Ability dash;       // Dash ability.

    // Initialize - Sets up charm's attributes.
    public override void Initialize()
    {
        data = (CharmData)Resources.Load(dataPath + "DashCharm");

        marble = GameMaster.CreateGM().marble;
        dash   = new Ability("Power Dash", 1, 1, 1.5f, data.icon, Dash);
    }
Beispiel #9
0
        private static long PlayMarble(int numberOfPlayers, int numberOfMarbles)
        {
            var playerScores = Enumerable
                               .Range(0, numberOfPlayers)
                               .ToDictionary(i => i, _ => 0L);

            var currentMarble = new Marble(0);
            var currentPlayer = 0;

            foreach (var marbleValue in Enumerable.Range(1, numberOfMarbles))
            {
                var marble = new Marble(marbleValue);
                if (marbleValue % 23 == 0)
                {
                    playerScores[currentPlayer] += marbleValue;
                    var marbleToRemove = currentMarble.GetCounterclockwise(7);
                    playerScores[currentPlayer] += marbleToRemove.Value;
                    currentMarble = marbleToRemove.Remove();
                }
                else
                {
                    currentMarble = currentMarble.Clockwise.InsertClockwise(marble);
                }

                currentPlayer++;
                if (currentPlayer == numberOfPlayers)
                {
                    currentPlayer = 0;
                }
            }

            return(playerScores
                   .Values
                   .Max());
        }
Beispiel #10
0
        private int MiniMax(Marble player, Marble originalPlayer, bool maximize, int depth)
        {
            movesTried++;
            if (IsWinner(originalPlayer))
            {
                return(1);
            }
            if (IsWinner(Reverse(originalPlayer)))
            {
                return(-1);
            }
            if (count == 9)
            {
                return(0);
            }
            int bestValue = maximize ? -2 : 2;

            for (int i = 1; i <= 9; i++)
            {
                if (IsEmpty(i))
                {
                    DoMove(player, i);
                    int value = MiniMax(Reverse(player), originalPlayer, !maximize, depth + 1);
                    if (bestValue < value == maximize)
                    {
                        bestValue = value;
                    }
                    UndoMove();
                }
            }
            return(bestValue);
        }
Beispiel #11
0
        /***
         * methods to be implemented for finding the best move
         * */

        public bool FindAndDoBestComputerMove(Marble m)
        {
            movesTried = 0;
            int bestMoveValue = -2;
            int bestMove      = 0;

            for (int i = 1; i <= 9; i++)
            {
                if (IsEmpty(i))
                {
                    DoMove(m, i);
                    int value = MiniMax(Reverse(m), m, false, 0);
                    if (value > bestMoveValue)
                    {
                        bestMove      = i;
                        bestMoveValue = value;
                    }
                    UndoMove();
                }
            }
            if (bestMove == 0)
            {
                return(false);
            }

            DoMove(m, bestMove);
            Console.WriteLine(movesTried);
            return(true);
        }
Beispiel #12
0
        // TODO improve score calculation
        /// <summary>
        /// Evaluates the score of the current board by only checking for the win condition
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        public int eval(Marble player)
        {
            Marble other      = GetOppositePlayer(player);
            int    MyScore    = 0;
            int    OtherScore = 0;

            // First check on end-game states, those should heavily impact the score.
            if (IsWinner(player))
            {
                return(999);
            }
            if (IsWinner(other))
            {
                return(-999);
            }

            /*
             * for (int i = 1; i < board.Length; i++)
             * {
             *  if (B(player, i))
             *  {
             *
             *
             *  }
             *  else if (B(other, i))
             *  {
             *      OtherScore++;
             *  }
             * }*/
            return(MyScore - OtherScore);
        }
Beispiel #13
0
        public static Marble BuildCircle(int count)
        {
            var marble = new Marble {
                Value = 0
            };

            marble.Previous = marble;
            marble.Next     = marble;

            var prev = marble;

            for (int i = 0; i < count; i++)
            {
                var temp = new Marble
                {
                    Value    = i + 1,
                    Previous = prev,
                    Next     = marble
                };
                temp.Previous.Next = temp;
                prev = temp;
            }

            marble.Previous = prev;
            return(marble);
        }
Beispiel #14
0
        [InlineData(465, 7149800, 3148209772)] // Solution 2
        public void Solve(int numPlayers, int numMarbles, ulong answer)
        {
            var players          = new ulong[numPlayers];
            var getCurrentPlayer = Generators.Cycler(numPlayers);
            var currentMarble    = new Marble(0);

            for (var i = 1u; i <= numMarbles; i++)
            {
                var currentPlayer = getCurrentPlayer();
                if (i % 23 != 0)
                {
                    var marble = new Marble(i);
                    currentMarble.Insert(marble);
                    currentMarble = marble;
                }
                else
                {
                    var marble = currentMarble.RemoveAntiClockwise(7);
                    players[currentPlayer] += (i + marble.Value);
                    currentMarble           = marble.Clockwise;
                }
            }

            players.Max().Should().Be(answer);
        }
Beispiel #15
0
 public Tile(int x, int y) //Ifall det inte finns en pjäs utplacerad på brickan
 {
     isOccupied = false;
     xPos       = x;
     yPos       = y;
     marble     = null;
 }
Beispiel #16
0
            public Marble Remove()
            {
                this.next.previous = this.previous;
                this.previous.next = this.next;

                return(this);
            }
Beispiel #17
0
            public void AddAfter(Marble marble)
            {
                marble.next     = this.next;
                marble.previous = this;

                this.next.previous = marble;
                this.next          = marble;
            }
Beispiel #18
0
    public bool Matches(Marble m)
    {
        var T     = typeof(Marble);
        var prop  = T.GetProperty(PropertyName);
        var value = prop.GetValue(m);

        return(value.Equals(PropertyValue));
    }
Beispiel #19
0
        public IHttpActionResult Add(Marble marble)
        {
            var db = new MarbleContext();

            db.Marbles.Add(marble);
            db.SaveChanges();
            return(Ok(marble));
        }
Beispiel #20
0
        public long GetMaxScore(int playerCount, int lastMarble)
        {
            var players = new Dictionary <int, long>();

            for (int i = 1; i < playerCount + 1; i++)
            {
                players[i] = 0;
            }

            var currentPlayer = 1;
            var currentMarble = new Marble {
                Value = 0
            };

            currentMarble.Next     = currentMarble;
            currentMarble.Previous = currentMarble;

            for (int i = 1; i < lastMarble + 1; i++)
            {
                if (i % 23 == 0)
                {
                    players[currentPlayer] += i;

                    var ccw7 = currentMarble.Previous.Previous.Previous.Previous.Previous.Previous.Previous;                     // lol
                    players[currentPlayer] += ccw7.Value;

                    var ccw8 = ccw7.Previous;
                    var ccw6 = ccw7.Next;

                    ccw8.Next     = ccw6;
                    ccw6.Previous = ccw8;

                    currentMarble = ccw6;
                }
                else
                {
                    var cw1 = currentMarble.Next;
                    var cw2 = currentMarble.Next.Next;

                    currentMarble = new Marble
                    {
                        Value    = i,
                        Previous = cw1,
                        Next     = cw2
                    };
                    cw1.Next     = currentMarble;
                    cw2.Previous = currentMarble;
                }

                currentPlayer++;
                if (currentPlayer > playerCount)
                {
                    currentPlayer = 1;
                }
            }

            return(players.Max(p => p.Value));
        }
        public static void Send(
            Marble marble,
            JsonSerializerSettings setting = null)
        {
            setting = setting ?? Constants.JsonDefaultSetting;

            string json = JsonConvert.SerializeObject(marble, setting);
            _log.Send(json);
        }
Beispiel #22
0
    public override bool[,] PossibleMove()
    {
        int    i, j;
        Marble c = null;

        bool[,] r = new bool[(BoardManager.GridSize), (BoardManager.GridSize)];
        i         = CurrentX - 1;
        j         = CurrentY + 1;

        if (CurrentY != 0)
        {
            if (BoardManager.Instance.Marbles[CurrentX, CurrentY - 1] != null)
            {
                c = BoardManager.Instance.Marbles[CurrentX, CurrentY - 1];
            }
            else
            {
                r[CurrentX, CurrentY - 1] = true;
            }
        }
        if (CurrentY != (BoardManager.GridSize - 1))
        {
            if (BoardManager.Instance.Marbles[CurrentX, CurrentY + 1] != null)
            {
                c = BoardManager.Instance.Marbles[CurrentX, CurrentY + 1];
            }
            else
            {
                r[CurrentX, CurrentY + 1] = true;
            }
        }
        if (CurrentX != 0)
        {
            if (BoardManager.Instance.Marbles[CurrentX - 1, CurrentY] != null)
            {
                c = BoardManager.Instance.Marbles[CurrentX - 1, CurrentY];
            }
            else
            {
                r[CurrentX - 1, CurrentY] = true;
            }
        }
        if (CurrentX != (BoardManager.GridSize - 1))
        {
            if (BoardManager.Instance.Marbles[CurrentX + 1, CurrentY] != null)
            {
                c = BoardManager.Instance.Marbles[CurrentX + 1, CurrentY];
            }
            else
            {
                r[CurrentX + 1, CurrentY] = true;
            }
        }


        return(r);
    }
Beispiel #23
0
        private static Marble RotateAntiClockwise(Marble marble, int pos)
        {
            for (int i = 0; i < 7; i++)
            {
                marble = marble.Left;
            }

            return(marble);
        }
Beispiel #24
0
 public Marble(ulong value)
 {
     Value = value;
     if (value == 0)
     {
         Clockwise     = this;
         AntiClockwise = this;
     }
 }
Beispiel #25
0
            public void Insert(Marble marble)
            {
                var clock1 = Clockwise;
                var clock2 = clock1.Clockwise;

                marble.AntiClockwise = clock1;
                marble.Clockwise     = clock2;
                clock1.Clockwise     = marble;
                clock2.AntiClockwise = marble;
            }
Beispiel #26
0
        //Marble fell in its hole
        private void FillTheHoleIfMarbleIsIn(Marble marble)
        {
            Hole marbleHole = Holes.First(h => h.Number == marble.Number);

            if (marbleHole.Position.Row == marble.Position.Row && marbleHole.Position.Column == marble.Position.Column)
            {
                marbleHole.IsFilled = true;
                marble.IsInHole     = true;
            }
        }
Beispiel #27
0
            public Marble InsertClockwise(Marble marble)
            {
                marble.Counterclockwise = this;
                marble.Clockwise        = Clockwise;

                Clockwise.Counterclockwise = marble;
                Clockwise = marble;

                return(marble);
            }
Beispiel #28
0
        public static void Send(
            Marble marble,
            JsonSerializerSettings setting = null)
        {
            setting = setting ?? Constants.JsonDefaultSetting;

            string json = JsonConvert.SerializeObject(marble, setting);

            _log.Send(json);
        }
Beispiel #29
0
    void addMarble()
    {
        GameObject marbleObj = new GameObject();

        marbleObj.transform.parent = marbleFolder.transform;
        marbleObj.name             = "Marble Container";
        Marble marble = marbleObj.AddComponent <Marble>();

        marbles.Add(marble);
    }
 public static void ToTree(this SimpleObservableCollection<MarbleDiagramTree> tree, Marble item)
 {
     var path = $"{item.StreamKey}.{item.MachineName}".Split('.');
     var mi = GetItem(tree, path[0]);
     for (int i = 1; i < path.Length; i++)
     {
         mi = GetItem(mi.Categories, path[i]);
     }
     var diagram = GetDiagram(mi, item.StreamKey);
     diagram.Items.Add(item);
 }
Beispiel #31
0
    // GiveBuff - Gives a specific buff to the specified marble.
    protected virtual void GiveBuff(Marble marble)
    {
        // Adds icon to holding GUI box.
        Messenger <Sprite, Color> .Broadcast("SetHeldSprite", icon, iconTint);

        // Passes information about the buff to the marble.
        buffSlot = new BuffSlot(buffType, intensity, duration, particles, TakeBuff, BuffFunction);
        //marble.buffs[1] = buffSlot;
        marble.buffs.Add(buffSlot);
        AudioSource.PlayClipAtPoint(buffCollect, Vector3.zero, settings.FXScaler);
    }
Beispiel #32
0
        public bool DoMove(Marble marble, int position)
        {
            if (count < 6)
            {
                board[position] = marble;
                count++;
                return(true);
            }

            return(false);
        }
Beispiel #33
0
	// Use this for initialization
	public void init(Marble parent) {
		this.marble = parent;
		transform.parent = parent.transform;
		transform.localPosition = new Vector3(0, 0, 0);
		Renderer renderer = GetComponent<Renderer>();
		renderer.material = (Material)Resources.Load("Textures/TrainMaterial", typeof(Material));
		name = "Marble Model";
		tag = "Player";
		DestroyImmediate(gameObject.GetComponent<Collider>());
		CircleCollider2D coll = gameObject.AddComponent<CircleCollider2D>();
		coll.isTrigger = true;
		coll.radius = 0.35f;
		Rigidbody2D rigidBody = gameObject.AddComponent<Rigidbody2D>();
		rigidBody.isKinematic = true;
		rigidBody.gravityScale = 0;
	}
Beispiel #34
0
	public void init(float x, float y, Marble owner, GameObject modelObject) {
		this.owner = owner;
		this.x = x;
		this.y = y;

		hit = 0;

		transform.parent = owner.transform;					
		transform.localPosition = new Vector3(0,0,-2);		
		name = "Marble Model";									

		rend = GetComponent<Renderer> ();
		rend.material = Resources.Load<Material> ("Material/Marble");

		sc = modelObject.GetComponent<SphereCollider> ();


		/*mat = GetComponent<Renderer>().material;
		mat.renderQueue = 4000;
		mat.mainTexture = Resources.Load<Texture2D>("Textures/marble");	
		mat.color = new Color(1,1,1);											
		mat.shader = Shader.Find ("Transparent/Diffuse");*/
	}
Beispiel #35
0
 public Marble(Marble m)
 {
     this.marble_location = new Point(m.marble_location);
     this.velocity = new Vector (m.velocity);
 }
Beispiel #36
0
	public void destroyMarble(Marble m) {
		Destroy(m.gameObject);
		marbles.Remove(m);
	}
Beispiel #37
0
 // Verifies if this marble has collided with another marble.
 // Uses the information of another marble to do so.
 // If marble has collided with another, it automatically bounces both.
 public bool CollidesWith(Marble other)
 {
     if (this.CollidesWithMarble (other)) {
         this.BounceFromMarble (other);
         Console.WriteLine ("Collision between marbles " + this.marble_location.ToString ()
             + " and " + other.marble_location.ToString () + ".");
         return (true);
     } else {
         return (false);
     }
 }
Beispiel #38
0
 private void BounceFromMarble(Marble other)
 {
     Vector temp = new Vector (this.velocity);
     this.velocity = new Vector (other.velocity);
     other.velocity = new Vector (temp);
 }
Beispiel #39
0
 private bool CollidesWithMarble(Marble other)
 {
     return (this.marble_location.Distance(other.marble_location) <= (this.radius + other.radius));
 }