private int GetWeightForBridge(Map map, Edge claimEdge, Punter punter, HashSet <int> reachableNodeIds)
        {
            claimEdge.Punter = new Punter {
                Id = -1
            };

            var leftComponent = graphVisitor.GetReachableNodesForPunter(claimEdge.Source, map, punter, true)
                                .Where(x => reachableNodeIds.Contains(x.Id))
                                .ToArray();
            var rightComponent = graphVisitor.GetReachableNodesForPunter(claimEdge.Target, map, punter, true)
                                 .Where(x => reachableNodeIds.Contains(x.Id))
                                 .ToArray();

            claimEdge.Punter = null;

            var left       = leftComponent.Length;
            var leftMines  = leftComponent.Count(x => x.IsMine);
            var right      = rightComponent.Length;
            var rightMines = rightComponent.Count(x => x.IsMine);

            if (left == 0 || right == 0)
            {
                return(0);
            }

            var scalingFactor = Math.Max(10, bridgeMaxScore / 10);
            var scoreDelta    = ((left - leftMines) * rightMines + (right - rightMines) * leftMines - 1 + scalingFactor) /
                                scalingFactor;

            return(scoreDelta);
        }
Ejemplo n.º 2
0
 public void Init(Map map, int puntersCount, Punter punter)
 {
     scorer.Init(map);
     movesCount = (map.Edges.Length - punter.Id + puntersCount - 1) / puntersCount;
     componentManager.InitComponents(map, punter);
     desire = componentManager.FindGreedyFullComponent(movesCount + 1);
 }
Ejemplo n.º 3
0
        private void FindBridges(int nodeId, List <Edge> bridges, Map map, Punter punter, HashSet <int> visited, Dictionary <int, int> tin, Dictionary <int, int> fup, int?parent = null)
        {
            visited.Add(nodeId);
            tin[nodeId] = fup[nodeId] = timer++;

            foreach (var(to, edge) in map.GetAvaliableEdges(nodeId, punter))
            {
                if (to.Id == parent)
                {
                    continue;
                }

                if (visited.Contains(to.Id))
                {
                    fup[nodeId] = Math.Min(fup[nodeId], tin[to.Id]);
                }
                else
                {
                    FindBridges(to.Id, bridges, map, punter, visited, tin, fup, nodeId);
                    fup[nodeId] = Math.Min(fup[nodeId], fup[to.Id]);
                    if (fup[to.Id] > tin[nodeId])
                    {
                        bridges.Add(edge);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void TestMethod1()
        {
            Punter punter = Factory.GetPunterInstance("Ava");
            bool   result = punter is Ava;

            Assert.AreEqual(result, true);
        }
Ejemplo n.º 5
0
        public void TestFactory()
        {
            Punter punter = Factory.GetAPunter("AI");
            bool   result = punter is AI;

            Assert.AreEqual(result, true);
        }
Ejemplo n.º 6
0
        public void TestGetReachableNodesForPunter(Node from, Map map, Punter punter, Node[] expected)
        {
            var graphVisitor = new GraphVisitor();
            var actual       = graphVisitor.GetReachableNodesForPunter(@from, map, punter);

            actual.ShouldAllBeEquivalentTo(expected);
        }
Ejemplo n.º 7
0
        public void TestFactory()
        {
            Punter punter = Factory.GetPunter("George");
            bool   result = punter is George;

            Assert.AreEqual(result, true);
        }
Ejemplo n.º 8
0
 private void SetupPunter()
 {
     for (int index = 0; index < punters.Length; index++)
     {
         Punter punter  = punters[index];
         string message = "";
         if (punter.Busted)
         {
             message = "Player BUSTED. Lose All Amount in Game";
         }
         else
         {
             if (punter.PunterBet == null)
             {
                 message = string.Format("{0} hasn't placed a Bet", punter.Name);
             }
             else
             {
                 message = string.Format("{0} placed Bet Amount ${1} on {2}", punter.Name, punter.PunterBet.Amount, punter.PunterBet.Fox.Name);
             }
             if (punter.PunterRadioButton.Checked)
             {
                 lblMax.Text         = string.Format("{0} Max Bet Amount Limit is ${1}", punter.Name, punter.Amount);
                 btnOperation.Text   = string.Format("Place BET For Player {0}", punter.Name);
                 lblBet.Text         = string.Format("Bet Amount of {0} is $", punter.Name);
                 lblFox.Text         = string.Format("{0} Place Bet on Fox No", punter.Name);
                 npBetAmount.Minimum = 1;
                 npBetAmount.Maximum = punter.Amount;
                 npBetAmount.Value   = 1;
             }
         }
         punter.PunterTextBox.Text = message;
     }
 }
Ejemplo n.º 9
0
        public void TestFactory()
        {
            Punter punter = Factory.GetPunter("Olivia");
            bool   result = punter is Olivia;

            Assert.AreEqual(result, true);
        }
Ejemplo n.º 10
0
        private void Allrb_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton fakerb = new RadioButton();

            fakerb = (RadioButton)sender;
            if (fakerb.Checked == true)
            {
                switch (fakerb.Text)
                {
                case "Matt":
                    singlePunter = Factory.GetAPunter(0);


                    break;

                case "Clark":
                    singlePunter = Factory.GetAPunter(1);

                    break;

                case "Zoe":
                    singlePunter = Factory.GetAPunter(2);

                    break;
                }
            }
        }
Ejemplo n.º 11
0
        //TODO Refactor whole region into the portable project.

        private void CheckForBust(Punter punter)
        {
            if (punter.Money <= 0)
            {
                punter.isBust = true;
            }
        }
Ejemplo n.º 12
0
        public void TestFactory()
        {
            Punter punter = Factory.GetPunter("Vicky");
            bool   result = punter is Vicky;

            Assert.AreEqual(result, true);
        }
Ejemplo n.º 13
0
 public void SetUp()
 {
     node0 = new Node {
         Id = 0
     };
     node1 = new Node {
         Id = 1, IsMine = true
     };
     node2 = new Node {
         Id = 2
     };
     node3 = new Node {
         Id = 3
     };
     node4 = new Node {
         Id = 4
     };
     node5 = new Node {
         Id = 5
     };
     node6 = new Node {
         Id = 6, IsMine = true
     };
     node7 = new Node {
         Id = 7
     };
     yellowPunter = new Punter {
         Id = 0
     };
     redPunter = new Punter {
         Id = 1
     };
 }
        private static bool HasNeighborPunterEdge(Map map, Edge edge, Punter punter)
        {
            var from = edge.Source.Id;
            var to   = edge.Target.Id;

            return(map.GetPunterEdges(@from, punter).Count > 0 ||
                   map.GetPunterEdges(to, punter).Count > 0);
        }
Ejemplo n.º 15
0
        private void BtnReset_Click(object sender, EventArgs e)
        {
            //resets swimmers' location when "reset" is clicked
            for (int i = 0; i < 4; i++)
            {
                Swimmer[i].myPB.Left = 10;
            }

            Punter[0].Cash = 50;
            Punter[1].Cash = 50;
            Punter[2].Cash = 50;
            Punter[3].Cash = 50;

            switch (CurrentPunter.PunterName)
            {
            case "Zeph":
                CurrentPunter     = Punter[0];
                lblZephCash.Text  = " has $" + Punter[0].Cash;
                lblSarahCash.Text = "";
                lblMaeCash.Text   = "";
                lblFeyCash.Text   = "";
                break;

            case "Sarah":
                CurrentPunter     = Punter[1];
                lblSarahCash.Text = " has $" + Punter[1].Cash;
                lblZephCash.Text  = "";
                lblMaeCash.Text   = "";
                lblFeyCash.Text   = "";
                break;

            case "Mae":
                CurrentPunter     = Punter[2];
                lblMaeCash.Text   = " has $" + Punter[2].Cash;
                lblZephCash.Text  = "";
                lblSarahCash.Text = "";
                lblFeyCash.Text   = "";
                break;

            case "Fey":
                CurrentPunter     = Punter[3];
                lblFeyCash.Text   = " has $" + Punter[3].Cash;
                lblZephCash.Text  = "";
                lblSarahCash.Text = "";
                lblMaeCash.Text   = "";
                break;
            }

            //clears all items in the list box
            lbxBets.Items.Clear();
            lblWinner.Text = "Results: ";

            //enables all disabled radio buttons upon game reset
            rbZeph.Enabled  = true;
            rbSarah.Enabled = true;
            rbMae.Enabled   = true;
            rbFey.Enabled   = true;
        }
Ejemplo n.º 16
0
 public void Should_Return_True_When_Getting_Punters()
 {
     Punter[] myPunters = new Punter[3];
     for (int i = 0; i < 3; i++)
     {
         myPunters[i] = Factory.GetAPunter(i);
     }
     Assert.IsTrue(myPunters[0].Name == "Jack" && myPunters[1].Name == "Vaughn" && myPunters[2].Name == "Jeremy");
 }
Ejemplo n.º 17
0
 public void RunningFactoryToCreatePunters()
 {
     Punter[] myPunters = new Punter[3];
     for (int i = 0; i < 3; i++)
     {
         myPunters[i] = Factory.GetAPunter(i);
     }
     Assert.IsTrue(myPunters[0].name == "Jack" && myPunters[1].name == "Jeremy" && myPunters[2].name == "Vaughn");
 }
        public Edge Claim(GameState gameState)
        {
            var map    = gameState.Map;
            var punter = gameState.CurrentPunter;

            var connectedComponents = graphVisitor.GetConnectedComponents(map);
            var punters             = connectedComponents.GetPunters;
            var scoreByPunter       = punters
                                      .ToDictionary(x => x,
                                                    x => scorer.Score(new GameState {
                Map = map, CurrentPunter = new Punter {
                    Id = x
                }
            }));

            var reachableNodeIds = GetReachableNodesFromMines(map, punter);

            var bestIncreasingPathEdge = map
                                         .Edges
                                         .Where(x => x.Punter == null)
                                         .Where(x => reachableNodeIds.Contains(x.Source.Id) ||
                                                reachableNodeIds.Contains(x.Target.Id) ||
                                                x.Source.IsMine ||
                                                x.Target.IsMine)
                                         .OrderByDescending(x => GetWeight(x, punter, connectedComponents))
                                         .ThenByDescending(x => CountFreeNeighborEdges(gameState, x))
                                         .FirstOrDefault();

            if (bestIncreasingPathEdge != null)
            {
                return(bestIncreasingPathEdge);
            }

            var bestPunter = new Punter
            {
                Id = scoreByPunter.OrderByDescending(x => x.Value).First().Key
            };

            if (bestPunter.Id != punter.Id)
            {
                return(map
                       .Edges
                       .Where(x => x.Punter == null)
                       .OrderByDescending(x => !connectedComponents.IsInSameComponent(x.Source.Id, x.Target.Id, punter.Id))
                       .ThenByDescending(x => HasNeighborPunterEdge(map, x, bestPunter))
                       .ThenBy(x => Guid.NewGuid())
                       .FirstOrDefault(x => x.Punter == null));
            }

            return(map
                   .Edges
                   .Where(x => x.Punter == null)
                   .OrderByDescending(x => CountFreeNeighborEdges(gameState, x))
                   .ThenBy(x => Guid.NewGuid())
                   .FirstOrDefault(x => x.Punter == null));
        }
Ejemplo n.º 19
0
 public void InitComponents(Map map, Punter punter)
 {
     this.state.map    = map;
     this.state.punter = punter;
     state.mines       = map.Nodes.Where(n => n.IsMine).ToArray();
     state.components  = map.Nodes.Select(n => new Component(n, state.mines, scorer)).ToList();
     nodeToComponent   = state.components
                         .SelectMany(c => c.Nodes.Select(n => new { Key = n, Value = c }))
                         .ToDictionary(x => x.Key.Id, x => x.Value);
 }
Ejemplo n.º 20
0
        public void TestValuesFromInstantiation()
        {
            Punter[] myPunter = new Punter[3];
            int      Id       = 1;
            string   name     = "Farmer Brown";

            myPunter[1] = Factory.GetAPunter(Id);

            Assert.AreEqual(name, myPunter[1].PunterName);
        }
Ejemplo n.º 21
0
        public void Test2() // Tests to check how many punters are there
        {
            Punter newPunter = Factory.GetAPunter(0);
            Punter secPunter = Factory.GetAPunter(1);


            int num = Factory.count;

            Assert.AreEqual(num, 2);
        }
Ejemplo n.º 22
0
        public void TestMethod1()
        {
            Punter[] myPunter = new Punter[2];
            int      Id       = 1;
            string   name     = "Clark";

            myPunter[1] = Factory.GetAPunter(Id);

            Assert.AreEqual(name, myPunter[1].PunterName);
        }
Ejemplo n.º 23
0
        public void BetWonTest()
        {
            Runner r1 = new Runner("1", 1000, new System.Windows.Forms.PictureBox());

            Punter p = Factory.GetApunter("Joe", new System.Windows.Forms.RadioButton(), 50, new System.Windows.Forms.TextBox());

            p.PlaceBet(r1, 10);
            p.BetWon();
            Assert.AreEqual(60, p.GetCash(), 0, "Validate failed expected return value 60 got " + p.GetCash());
        }
        public void Init(Map map, int puntersCount, Punter punter)
        {
            movesCount = (map.Edges.Length - punter.Id + puntersCount - 1) / puntersCount;
            scorer.Init(map);
            componentManager.InitComponents(map, punter);
            var mineCount = componentManager.GetMineComponents().Length;

            lambdasCount = Math.Max(Math.Min(movesCount / 20, 2 * mineCount), mineCount);
            desire       = new DesireComponent();
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Get the name of the selected punter so the selected punter can be instantiated
        /// </summary>
        private void cbxPunter_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selection = cbxPunter.SelectedItem.ToString();

            // set ID manually because indexes change once punters are removed from the combobox
            Id = SetComboBoxValue(selection);
            // set up the selected punter as the correct punter
            selectedPunter = myPunter[Id];

            SetMaxUDValues();
        }
Ejemplo n.º 26
0
        public void GetApunterTest()
        {
            //to check if correct punter object is returned
            Punter p = Factory.GetApunter("Joe", new System.Windows.Forms.RadioButton(), 50, new System.Windows.Forms.TextBox());

            Assert.AreEqual("Joe", p.getName(), "Validate failed expected return value 'Joe' got '" + p.getName() + "'");
            p = Factory.GetApunter("al", new System.Windows.Forms.RadioButton(), 50, new System.Windows.Forms.TextBox());
            Assert.AreEqual("Al", p.getName(), "Validate failed expected return value 'Al' got '" + p.getName() + "'");

            p = Factory.GetApunter("bob", new System.Windows.Forms.RadioButton(), 50, new System.Windows.Forms.TextBox());
            Assert.AreEqual("Bob", p.getName(), "Validate failed expected return value 'Bob' got '" + p.getName() + "'");
        }
Ejemplo n.º 27
0
        public void AiPunterPopulateTest()
        {
            Punter[] punters = new Punter[3];

            var factory = new PunterFactory();

            for (int i = 0; i < punters.Length; i++)
            {
                punters[i] = factory.GetNewAiPunter(i);
            }

            Assert.IsNotNull(punters[1].Money);
        }
Ejemplo n.º 28
0
        private void PunterRb_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton PunterRB = new RadioButton();

            PunterRB = (RadioButton)sender;

            if (PunterRB.Checked == true)
            {
                this.Text = PunterRB.Text;

                //look for the punter name
                switch (PunterRB.Text)
                {
                //instatiate that punter

                case "Zeph":
                    CurrentPunter     = Punter[0];
                    lblZephCash.Text  = " has $" + CurrentPunter.Cash;
                    lblSarahCash.Text = "";
                    lblMaeCash.Text   = "";
                    lblFeyCash.Text   = "";
                    break;

                case "Sarah":
                    CurrentPunter     = Punter[1];
                    lblSarahCash.Text = " has $" + CurrentPunter.Cash;
                    lblZephCash.Text  = "";
                    lblMaeCash.Text   = "";
                    lblFeyCash.Text   = "";
                    break;

                case "Mae":
                    CurrentPunter     = Punter[2];
                    lblMaeCash.Text   = " has $" + CurrentPunter.Cash;
                    lblZephCash.Text  = "";
                    lblSarahCash.Text = "";
                    lblFeyCash.Text   = "";
                    break;

                case "Fey":
                    CurrentPunter     = Punter[3];
                    lblFeyCash.Text   = " has $" + CurrentPunter.Cash;
                    lblZephCash.Text  = "";
                    lblSarahCash.Text = "";
                    lblMaeCash.Text   = "";
                    break;
                }

                udBets.Maximum = (decimal)CurrentPunter.Cash;
            }
        }
Ejemplo n.º 29
0
        public Node[] GetReachableNodesFromMinesForPunter(Map map, Punter punter)
        {
            var result         = new List <Node>();
            var queue          = new Queue <Node>();
            var visitedNodeIds = new HashSet <int>();

            foreach (var node in map.Nodes.Where(x => x.IsMine))
            {
                result.Add(AddNode(queue, visitedNodeIds, node));
            }
            Bfs(map, punter, queue, visitedNodeIds, result);

            return(result.ToArray());
        }
Ejemplo n.º 30
0
        public async Task OnGetAsync(int id)
        {
            var o = 4;

            Punter = await _db.Punter.FromSql($"ReadPunterByID {id}").FirstOrDefaultAsync();

            Punts = Punter;
            try
            {
                Market = await _db.Market.AsNoTracking().ToListAsync();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }