Exemple #1
0
    public static int Main()
    {
        MiscMethods m = new MiscMethods(10, 20);

        if (!m.InstanceCalls(m))
        {
            return(Fail);
        }

        int[] a = new int[5] {
            1, 2, 3, 4, 5
        };
        int x = InstanceCalls(m, a);

        float[] b = new float[5] {
            1f, 2f, 3f, 4f, 5f
        };
        int y = InstanceCalls(m, b);

        double[] c = new double[5] {
            1d, 2d, 3d, 4d, 5d
        };
        int z = InstanceCalls(m, c, 1d, 2d, 3d, 4d, 5d);

        if (x == Pass && y == Pass && z == Pass)
        {
            return(Pass);
        }
        return(Fail);
    }
Exemple #2
0
        private async void InitialAnimation()
        {
            await MiscMethods.TaskDelay(1500);

            Animate("overlaySlideRight", OverlayPanel1);
            Animate("overlaySlideLeft", OverlayPanel2);

            await MiscMethods.TaskDelay(1990);

            Overlay.Visibility = Visibility.Collapsed;

            foreach (CharacterImage image in playerImages)
            {
                await MiscMethods.TaskDelay(50);

                image.InitialAnimation();
            }

            foreach (CharacterImage image in enemyImages)
            {
                await MiscMethods.TaskDelay(50);

                image.InitialAnimation();
            }
        }
Exemple #3
0
        public void DigitTest()
        {
            //arrange
            int num = 1234567890;

            //act

            //assert
            Assert.IsTrue(MiscMethods.IsOnlyDigits(num.ToString()));
        }
        /// <summary>
        /// Sets the image output corresponding to the selected RadioButton
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        public void SetOutputFromCapturedFrame()
        {
            if (RadioButtonSelected == CameraViewRadioButtons.OriginalImage || RadioButtonSelected == CameraViewRadioButtons.ImageWithDetectedFeaturess)
            {
                CurrentFrame = MiscMethods.MatToBitmapSource(cm.CameraViewMat);
            }
            else
            {
                CurrentFrame = MiscMethods.MatToBitmapSource(cm.CameraViewGrayScaleMat);
            }

            cm.Output.UpdateOutputValues(eyeAngle, (int)timer.ElapsedMilliseconds);
        }
Exemple #5
0
        private void InventoryCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;
            int    index  = Array.IndexOf(SlotsContainer.Children.OfType <Button>().ToArray(), button);

            if (SelectedItem == null && button.Content != null)
            {
                SelectedPlayer.Unequipt(index);
            }
            else if (SelectedItem == null) //Nothing selected and button.Content is null
            {
                MessageBox.Show("To equipt a piece of equiptment, click on an equiptment in the Equiptment tab and click on the appropriate slot.");
                return;
            }
            else if (SelectedItem.GetType() != typeof(Equiptment))
            {
                return;
            }
            else if (!((Equiptment)SelectedItem).EquiptableSlots.Contains((Equiptment.SlotMode)(index + 1)))
            {
                //Equiptment does not fit on specified slots. Generate error message.

                string selectedItemSlotsList = "";

                for (int i = 0; i < ((Equiptment)SelectedItem).EquiptableSlots.Count; i++)
                {
                    Equiptment.SlotMode slot = ((Equiptment)SelectedItem).EquiptableSlots[i];

                    selectedItemSlotsList = $"{selectedItemSlotsList}" +
                                            $"{MiscMethods.GetSeperator(i, ((Equiptment)SelectedItem).EquiptableSlots.Count)} " +
                                            $"{slot.GetDescription()}".Trim();
                }

                MessageBox.Show($"The {SelectedItem.Name} only fits on slots {selectedItemSlotsList}.");
                return;
            }
            else
            {
                //All test successful. Equipt equiptment.

                SelectedPlayer.Equipt((Equiptment)SelectedItem, (Equiptment.SlotMode)(index + 1));
                SelectedItem = null;
            }

            foreach (Button btn in SlotsContainer.Children.OfType <Button>().ToArray())
            {
                btn.GetBindingExpression(Button.ContentProperty).UpdateTarget();
            }

            ForceItemsControlUpdate(equiptmentsList);
        }
Exemple #6
0
    public static int InstanceCalls(MiscMethods m, double[] a, double v1, double v2, double v3, double v4, double v5)
    {
        int result = Pass;

        double s1 = m.Sum(a);
        double s2 = m.Sum(v1, v2, v3, v4, v5);

        if (!doubleEqual(s1, s2))
        {
            result = Fail;
        }

        return(result);
    }
Exemple #7
0
        /// <summary>
        /// Uses machiene learning website http://poeprices.info to price magic/rare items
        /// </summary>
        /// <param name="rawItemData">Ctrl+C'd raw item data</param>
        /// <returns>Suggested price as double, 0 if unsuccessful</returns>
        public Entry SearchPoePrices(string rawItemData)
        {
            Entry returnEntry = new Entry()
            {
                count = 20
            };

            try {
                // Make request to http://poeprices.info
                string jsonString = MainWindow.webClient.DownloadString("https://www.poeprices.info/api?l=" + Settings.league +
                                                                        "&i=" + MiscMethods.Base64Encode(rawItemData));

                // Deserialize JSON-encoded reply string
                PoePricesReply reply = new JavaScriptSerializer().Deserialize <PoePricesReply>(jsonString);

                // Some protection
                if (reply == null || reply.error != "0")
                {
                    return(null);
                }

                // If the price was in exalts, convert it to chaos
                if (reply.currency == "exalt")
                {
                    Entry exaltedEntry;
                    prices.TryGetValue("Exalted Orb|5", out exaltedEntry);
                    if (exaltedEntry == null)
                    {
                        return(null);
                    }
                    returnEntry.value = (reply.max * exaltedEntry.value + reply.min * exaltedEntry.value) / 2.0;
                }
                else
                {
                    returnEntry.value = (reply.max + reply.min) / 2.0;
                }

                // Return the constructed entry
                return(returnEntry);
            } catch (Exception ex) {
                MainWindow.Log(ex.ToString(), 2);
                return(null);
            }
        }
Exemple #8
0
    public static int InstanceCalls(MiscMethods m, float[] a)
    {
        int result = Pass;

        float s = m.Sum(a);

        if (!floatEqual(s, 15f))
        {
            result = Fail;
        }

        s = m.Sum(1f, 2f, 3f, 4f, 5f);
        if (!floatEqual(s, 15f))
        {
            result = Fail;
        }

        return(result);
    }
Exemple #9
0
    public static int InstanceCalls(MiscMethods m, int[] a)
    {
        int result = Pass;

        int s = m.Sum(a);

        if (s != 15)
        {
            result = Fail;
        }

        s = m.Sum(1, 2, 3, 4, 5);
        if (s != 15)
        {
            result = Fail;
        }

        return(result);
    }
Exemple #10
0
        /// <summary>
        /// Returns a pair of points that are farthest in distance from each other
        /// </summary>
        /// <param name="points"></param>
        /// <returns></returns>
        public static Point[] MaxDistanceNaive(Point[] points)
        {
            Point[] selectedPoints = { points[0], points[1] };
            double  minDistance    = MiscMethods.DistanceFormula(points[0], points[1]);

            for (int i = 0; i < points.Length; i++)
            {
                for (int j = i + 1; j < points.Length; j++)
                {
                    if (MiscMethods.DistanceFormula(points[i], points[j]) < minDistance)
                    {
                        minDistance       = MiscMethods.DistanceFormula(points[i], points[j]);
                        selectedPoints[0] = points[i];
                        selectedPoints[1] = points[j];
                    }
                }
            }

            return(selectedPoints);
        }
Exemple #11
0
        private void ConsumableStackPanel_MouseUp(object sender, MouseButtonEventArgs e)
        {
            EquiptmentStackPanel_MouseUp(sender, e);

            string message = $"You will gain the following buffs from eating the {SelectedItem.Name}: \r\n";

            for (int i = 0; i < ((Consumable)SelectedItem).Buffs.Count; i++)
            {
                message = $"{message}{MiscMethods.GetSeperator(i, ((Consumable)SelectedItem).Buffs.Count)} " +
                          $"{((Consumable)SelectedItem).Buffs[i].DisplayName}";
            }

            MessageBoxResult result = MessageBox.Show(message, "", MessageBoxButton.OKCancel);

            if (result == MessageBoxResult.Cancel)
            {
                return;
            }

            SelectedPlayer.Consume((Consumable)SelectedItem);
            ForceItemsControlUpdate(consumablesList);
        }
        public static void AIStyle_Timid(Enemy attacker, Player[] activePlayers)
        {
            double[] percentStats = attacker.PercentStats;

            List <Player> playersWithinRange = CharactersWithinRange(attacker, attacker.AllAttacks, activePlayers);

            //Step 1: Find closest player and select that as target
            Player target      = activePlayers[0];
            double minDistance = int.MaxValue;

            foreach (Player player in playersWithinRange)
            {
                if (player == null)
                {
                    continue;
                }

                double distance = target.DirectDistanceFrom(player);
                if (minDistance < distance)
                {
                    target      = player;
                    minDistance = distance;
                }
            }

            //Step 2: Find longest ranged attack.
            Attack longestRangeAttack = attacker.AllAttacks.FindMax(t => t.Range);

            //Start logic for AI Style

            if (attacker.IsWellOff(statPercentages_Timid1))
            {
                if (playersWithinRange.Count < 1)
                {
                    //No players within range.
                    //Path find towards players

                    Pathfinding.PathFind_Direct(attacker, target, longestRangeAttack.Range, false);
                    return;
                }
                else
                {
                    //Attack weakest player
                    target = playersWithinRange.FindMin(t => t.CurrentStats[0]);
                    Attack selectedAttack = attacker.FindStrongestAttack(target, GameBase.Stats.HP);
                    attacker.DoAttack(selectedAttack, target);
                    return;
                }
            }
            else if (attacker.IsWellOff(statPercentages_Timid2))
            {
                RandomEventChooser chooser = new RandomEventChooser
                                             (
                    new List <RandomEvent>
                {
                    new RandomEvent("Attack", percentStats[0]),
                    new RandomEvent("Heal", 0.5)
                }
                                             );

                string selectedEvent = chooser.GetSelected().ToString();

                if (selectedEvent.Equals("Attack") && target != null)
                {
                    Attack selectedAttack = attacker.FindStrongestAttack(target, GameBase.Stats.HP);

                    //Find distance between attacker and target
                    double targetDistance = MiscMethods.DistanceFormula(target.BattleFieldLocation, attacker.BattleFieldLocation);

                    //If distance between targetDistance and range of selected attack is negligible, attack
                    if (selectedAttack.Range - targetDistance < 2)
                    {
                        //Attack weakest player
                        target = playersWithinRange.FindMin(t => t.CurrentStats[0]);

                        if (target != null)
                        {
                            attacker.DoAttack(selectedAttack, target);
                            return;
                        }
                        else if (AutoConsume(attacker, statPercentages_Timid1))
                        {
                            return;
                        }
                        else
                        {
                            //Change to something else?
                            attacker.RecoverMana();
                        }
                    }
                    //Else, move away
                    else
                    {
                        try
                        {
                            Pathfinding.PathFind_Direct(attacker, target, selectedAttack.Range, true);
                        }
                        catch (DidNotMoveException)
                        {
                            //Attack weakest player
                            target = playersWithinRange.FindMin(t => t.CurrentStats[0]);

                            if (target != null)
                            {
                                attacker.DoAttack(selectedAttack, target);
                                return;
                            }
                            else if (AutoConsume(attacker, statPercentages_Timid1))
                            {
                                return;
                            }
                            else
                            {
                                //Change to something else?
                                attacker.RecoverMana();
                            }
                        }

                        return;
                    }
                }
                else
                {
                    HealWithItemsOrAttacks(attacker, statPercentages_Timid1);
                    return;
                }
            }
            else
            {
                RandomEventChooser chooser = new RandomEventChooser
                                             (
                    new List <RandomEvent>
                {
                    new RandomEvent("Heal", 0.75),
                    new RandomEvent("RunFromPlayer", 0.25),
                    new RandomEvent("RunFromBattleField", 0.25)
                }
                                             );

                string eventSelector = chooser.GetSelected().ToString();

                switch (eventSelector)
                {
                case "Heal":
                    HealWithItemsOrAttacks(attacker, statPercentages_Timid1);
                    return;

                case "RunFromPlayer":
                    Pathfinding.PathFind_RunFromPlayers(attacker, activePlayers.ToList());
                    return;

                case "RunFromBattleField":
                    attacker.Run(GameBase.CurrentGame.CurrentBattleField);
                    return;
                }
            }
        }
Exemple #13
0
    public static int InstanceCalls(MiscMethods m, int[] a)
    {
        int result = Pass;

        int s = m.Sum(a);
        if (s != 15) result = Fail;

        s = m.Sum(1, 2, 3, 4, 5);
        if (s != 15) result = Fail;

        return result;
    }
Exemple #14
0
 public bool InstanceCalls(MiscMethods m)    
 {
    return x == m.x && y == m.y;
 }
Exemple #15
0
    public static int Main()
    {
        MiscMethods m = new MiscMethods(10,20);
        if (!m.InstanceCalls(m)) return Fail;

        int[] a = new int[5] { 1, 2, 3, 4, 5 };
        int x = InstanceCalls(m,a);

        float[] b = new float[5] { 1f, 2f, 3f, 4f, 5f };
        int y = InstanceCalls(m,b);

        double[] c = new double[5] { 1d, 2d, 3d, 4d, 5d };
        int z = InstanceCalls(m,c, 1d, 2d, 3d, 4d, 5d);

        if (x == Pass && y == Pass && z == Pass)
           return Pass;
        return Fail;        
    }
Exemple #16
0
    public static int InstanceCalls(MiscMethods m, double[] a, double v1, double v2, double v3, double v4, double v5)
    {
        int result = Pass;

        double s1 = m.Sum(a);
        double s2 = m.Sum(v1, v2, v3, v4, v5);
        if (!doubleEqual(s1, s2)) result = Fail;

        return result;
    }
Exemple #17
0
    public static int InstanceCalls(MiscMethods m, float[] a)
    {
        int result = Pass;

        float s = m.Sum(a);
        if (!floatEqual(s, 15f)) result = Fail;

        s = m.Sum(1f, 2f, 3f, 4f, 5f);
        if (!floatEqual(s, 15f)) result = Fail;

        return result;
    }
Exemple #18
0
 public bool InstanceCalls(MiscMethods m)
 {
     return(x == m.x && y == m.y);
 }
Exemple #19
0
        //public static void PathFind_AvoidPlayers(Enemy attacker, Character target, List<Player> players, int range)
        //{
        //    int spacesLeft = attacker.CurrentStats[4];
        //    Point attackerPoint = attacker.BattleFieldLocation;
        //    Point oldLocation = attackerPoint;
        //    Point targetPoint = target.BattleFieldLocation;

        //    //Divide BattleField into two parts based on number of players in either side of the field.
        //    //The attacker would want to move in the direction with the least amount of players while still being within range of attack
        //    List<Player> playersOnLeft = new List<Player>(), playersOnRight = new List<Player>();

        //    foreach (Player player in players)
        //    {
        //        if (targetPoint.X > player.BattleFieldLocation.X)
        //        {
        //            playersOnLeft.Add(player);
        //        }
        //        else if (targetPoint.X < player.BattleFieldLocation.X)
        //        {
        //            playersOnRight.Add(player);
        //        }
        //    }

        //    Gets in range the first time
        //    while (MiscMethods.DistanceFormula(attackerPoint, targetPoint) > range && spacesLeft > 1)
        //    {
        //        if (attackerPoint.X > targetPoint.X)
        //        {
        //            Attacker is right of target.Move left.
        //            attackerPoint.X--;
        //        }
        //        else if (attackerPoint.X < targetPoint.X)
        //        {
        //            Attacker is left of target.Move right.
        //            attackerPoint.X++;
        //        }
        //        else if (attackerPoint.Y > targetPoint.Y)
        //        {
        //            Attacker is above of target.Move down.
        //            attackerPoint.Y--;
        //        }
        //        else
        //        {
        //            Attacker is below of target.Move up.
        //            attackerPoint.Y++;
        //        }
        //        spacesLeft--;
        //    }

        //    Back up until the attacker is just out of range from the target
        //    while (MiscMethods.DistanceFormula(attackerPoint, targetPoint) < range && spacesLeft > 1)
        //    {
        //        if (attackerPoint.X > targetPoint.X)
        //        {
        //            Attacker is right of target.Move right.
        //            attackerPoint.X++;
        //        }
        //        else if (attackerPoint.X < targetPoint.X)
        //        {
        //            Attacker is left of target.Move left.
        //            attackerPoint.X--;
        //        }
        //        else if (attackerPoint.Y > targetPoint.Y)
        //        {
        //            Attacker is above of target.Move up.
        //            attackerPoint.Y++;
        //        }
        //        else
        //        {
        //            Attacker is below of target.Move down.
        //            attackerPoint.Y--;
        //        }
        //        spacesLeft--;
        //    }

        //    Get in range again
        //    while (MiscMethods.DistanceFormula(attackerPoint, targetPoint) > range && spacesLeft > 0)
        //    {
        //        if (attackerPoint.X > targetPoint.X)
        //        {
        //            Attacker is right of target.Move left.
        //            attackerPoint.X--;
        //        }
        //        else if (attackerPoint.X < targetPoint.X)
        //        {
        //            Attacker is left of target.Move right.
        //            attackerPoint.X++;
        //        }
        //        else if (attackerPoint.Y > targetPoint.Y)
        //        {
        //            Attacker is above of target.Move down.
        //            attackerPoint.Y--;
        //        }
        //        else
        //        {
        //            Attacker is below of target.Move up.
        //            attackerPoint.Y++;
        //        }
        //        spacesLeft--;
        //    }

        //    if (oldLocation == attackerPoint)
        //    {
        //        throw new DidNotMoveException($"Enemy {attacker.Name} did not move. Try to attack?");
        //    }
        //    else
        //    {
        //        attacker.BattleFieldLocation = attackerPoint;
        //        GameBase.CurrentGame.CurrentBattleField.FinalizeMovement(attacker, oldLocation);
        //    }
        //}

        public static void PathFind_RunFromPlayers(Enemy attacker, List <Player> players, int spacesLeft)
        {
            Point attackerPoint = attacker.BattleFieldLocation;
            Point oldLocation   = attackerPoint;

            //Divide BattleField into two parts based on number of players in either side of the field.
            //The attacker would want to move in the direction with the least amount of players while still being within range of attack
            List <Player> playersOnLeft = new List <Player>(), playersOnRight = new List <Player>();

            foreach (Player player in players)
            {
                if (attacker.BattleFieldLocation.X > player.BattleFieldLocation.X)
                {
                    playersOnLeft.Add(player);
                }
                else if (attacker.BattleFieldLocation.X < player.BattleFieldLocation.X)
                {
                    playersOnRight.Add(player);
                }
            }

            if (playersOnLeft.Count > playersOnRight.Count)
            {
                attackerPoint.X = Math.Max(0, attackerPoint.X - spacesLeft);
            }
            else
            {
                attackerPoint.X = Math.Min(BattleField.BattleFieldWidth, attackerPoint.X + spacesLeft);
            }

            spacesLeft -= Math.Abs(oldLocation.X - attackerPoint.X);

            if (spacesLeft > 0)
            {
                Player closestPlayer = players[0];
                double minDistance   = double.PositiveInfinity;

                foreach (Player player in players)
                {
                    if (player == null)
                    {
                        continue;
                    }

                    double distance = MiscMethods.DistanceFormula(attackerPoint, player.BattleFieldLocation);

                    if (minDistance < distance)
                    {
                        closestPlayer = player;
                        minDistance   = distance;
                    }
                }

                Point playerPoint = closestPlayer.BattleFieldLocation;

                while (spacesLeft > 0)
                {
                    if (attackerPoint.Y > playerPoint.Y)
                    {
                        //Attacker is above of target. Move up.
                        attackerPoint.Y++;

                        if (attackerPoint.Y == BattleField.BattleFieldHeight - 1)
                        {
                            break;
                        }
                    }
                    else
                    {
                        //Attacker is below of target. Move down.
                        attackerPoint.Y--;
                    }
                    spacesLeft--;
                }
            }

            if (oldLocation == attackerPoint)
            {
                throw new DidNotMoveException($"Enemy {attacker.Name} did not move. Try to attack?");
            }
            else
            {
                attacker.BattleFieldLocation = attackerPoint;
                GameBase.CurrentGame.CurrentBattleField.FinalizeMovement(attacker, oldLocation);
            }
        }
Exemple #20
0
        /// <summary>
        /// Simple path finding algorithm.
        /// </summary>
        /// <param name="attacker">The enemy doing the attack</param>
        /// <param name="target">The character the enemy is navigating to</param>
        /// <param name="range">The range of the attack the enemy is going to use</param>
        /// <param name="keepDistance">If true, then attacker will move away from target until it can barely hit the target.</param>
        /// <exception cref="DidNotMoveException"></exception>
        public static void PathFind_Direct(Enemy attacker, Character target, int range, bool keepDistance = false)
        {
            int   spacesLeft    = attacker.CurrentStats[4];
            Point attackerPoint = attacker.BattleFieldLocation;
            Point oldLocation   = attackerPoint;
            Point targetPoint   = target.BattleFieldLocation;

            //Gets in range
            while (MiscMethods.DistanceFormula(attackerPoint, targetPoint) > range && spacesLeft > 0)
            {
                if (attackerPoint.X > targetPoint.X)
                {
                    //Attacker is right of target. Move left.
                    attackerPoint.X--;
                }
                else if (attackerPoint.X < targetPoint.X)
                {
                    //Attacker is left of target. Move right.
                    attackerPoint.X++;
                }
                else if (attackerPoint.Y > targetPoint.Y)
                {
                    //Attacker is above target. Move down.
                    attackerPoint.Y--;
                }
                else
                {
                    //Attacker is below target. Move up.
                    attackerPoint.Y++;
                }
                spacesLeft--;
            }

            //Backs off
            if (keepDistance)
            {
                while (MiscMethods.DistanceFormula(attackerPoint, targetPoint) < range - 1 && spacesLeft > 0)
                {
                    if (attackerPoint.X > targetPoint.X)
                    {
                        //Attacker is right of target. Move right.
                        attackerPoint.X++;
                    }
                    else if (attackerPoint.X < targetPoint.X)
                    {
                        //Attacker is left of target. Move left.
                        attackerPoint.X--;
                    }
                    else if (attackerPoint.Y > targetPoint.Y)
                    {
                        //Attacker is above of target. Move up.
                        attackerPoint.Y++;
                    }
                    else
                    {
                        //Attacker is below of target. Move down.
                        attackerPoint.Y--;
                    }
                    spacesLeft--;
                }
            }

            if (oldLocation == attackerPoint)
            {
                throw new DidNotMoveException($"Enemy {attacker.Name} did not move. Try to attack?");
            }
            else
            {
                attacker.BattleFieldLocation = attackerPoint;
                GameBase.CurrentGame.CurrentBattleField.FinalizeMovement(attacker, oldLocation);
            }
        }