Exemplo n.º 1
0
Arquivo: Form1.cs Projeto: Xrumzik/-5
 private void button3_Click(object sender, EventArgs e)
 {
     if (Int32.TryParse(numFirstValue.Text, out int One) && Int32.TryParse(numSecondValue.Text, out int Two) &&
         Int32.TryParse(numThirdValue.Text, out int Three) && Int32.TryParse(number.Text, out int Chislo))
     {
         int         firstNumber  = Convert.ToInt32(numFirstValue.Text);
         int         secondNumber = Convert.ToInt32(numSecondValue.Text);
         int         thirdNumber  = Convert.ToInt32(numThirdValue.Text);
         int         chislo       = Convert.ToInt32(number.Text);
         Lib_5.Triad triadNumbers = new Triad(firstNumber, secondNumber, thirdNumber, chislo);
         //Произведение
         triadNumbers.Proverka();
         //Вывод
         if (triadNumbers.Proverka() == true)
         {
             proverka.Text = "Числа равны";
         }
         else
         {
             proverka.Text = "Числа не равны";
         }
     }
     else
     {
         MessageBox.Show("Введите правильное значение");
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Find "array" subscripts corresponding to a location
        /// </summary>
        /// <param name="physical">Physical coordinates of location</param>
        /// <returns>Game-based coordinates of location</returns>
        public Triad GameFromPhysical(Point physical)
        {
            var result = new Triad();

            // Calculate row and column in floating-point (interim data)
            var row    = (physical.Y - puzzleTopMargin - PuzzlePadding) / pixelsPerCell;
            var column = (physical.X - puzzleLeftMargin - PuzzlePadding) / pixelsPerCell;

            // Game Row and Column are truncated versions, excluding the last pixel
            // on the right and on the bottom and forcing non-negative
            result.Row    = (int)(Math.Max(Math.Min(row, gameBreadth - 1), 0));
            result.Column = (int)(Math.Max(Math.Min(column, gameBreadth - 1), 0));

            // Default value for HintZone is out-of-range, fixed later when applicable
            result.HintZone = HintZoneUnknown;

            // Inside Cell - find floating-point representation of hint zone
            var hintVertOffset  = (row - result.Row) * gridUnitsPerCell;
            var hintHorizOffset = (column - result.Column) * gridUnitsPerCell;

            // Nearest hint zone, integral representation. Subtract one due to offset within Cell
            var potentialVertHintZone  = Util.IntFromFP(hintVertOffset);
            var potentialHorizHintZone = Util.IntFromFP(hintHorizOffset);

            // Close enough to be within hint zone (while not at leading left/top edge)?
            if (OnGame(physical) &&
                Math.Abs(hintVertOffset - potentialVertHintZone) < hintZoneThreshold &&
                Math.Abs(hintHorizOffset - potentialHorizHintZone) < hintZoneThreshold &&
                potentialVertHintZone % gridUnitsPerCell != 0 && potentialHorizHintZone % gridUnitsPerCell != 0 &&
                potentialVertHintZone >= 1 && potentialHorizHintZone >= 1)
            {
                result.HintZone = (potentialVertHintZone - 1) * regionBreadth + (potentialHorizHintZone - 1);
            }
            return(result);
        }
Exemplo n.º 3
0
        private void ClassifyMinorTriadsZ12(Triad triad)
        {
            long firstNotePitchClass  = MusicHelper.ReduceToPitchClass(triad.FirstNote.EulerPoint.P.Numerator, 12);
            long secondNotePitchClass = MusicHelper.ReduceToPitchClass(triad.SecondNote.EulerPoint.P.Numerator, 12);
            long thirdNotePitchClass  = MusicHelper.ReduceToPitchClass(triad.ThirdNote.EulerPoint.P.Numerator, 12);

            if (triad.triadType == TriadType.NoTriad)              //Abbrechen wenn Dreiklangtyp gefunden wurde
            {
                long lowerInterval = secondNotePitchClass - firstNotePitchClass;
                lowerInterval = MusicHelper.ReduceToPitchClass(lowerInterval, 12);
                long upperInterval = thirdNotePitchClass - secondNotePitchClass;
                upperInterval = MusicHelper.ReduceToPitchClass(upperInterval, 12);

                CheckIfExpectedEqualsValueAndSetType(MusicHelper.MinorThird, lowerInterval, MusicHelper.MajorThird, upperInterval, TriadType.MinorTriad, TriadInversion.NoInversion, FundamentalTone.FirstNote, triad);
                CheckIfExpectedEqualsValueAndSetType(MusicHelper.MajorThird, lowerInterval, MusicHelper.Fourth, upperInterval, TriadType.MinorTriad, TriadInversion.FirstInversion, FundamentalTone.ThirdNote, triad);
                CheckIfExpectedEqualsValueAndSetType(MusicHelper.Fourth, lowerInterval, MusicHelper.MinorThird, upperInterval, TriadType.MinorTriad, TriadInversion.SecondInversion, FundamentalTone.SecondNote, triad);
                CheckIfExpectedEqualsValueAndSetType(MusicHelper.Fifth, lowerInterval, MusicHelper.MinorSixth, upperInterval, TriadType.MinorTriad, TriadInversion.StatisticalInversionFundamentalToneFirst, FundamentalTone.FirstNote, triad);
                CheckIfExpectedEqualsValueAndSetType(MusicHelper.MajorSixth, lowerInterval, MusicHelper.Fourth, upperInterval, TriadType.MinorTriad, TriadInversion.StatisticalInversionFundamentalToneSecond, FundamentalTone.SecondNote, triad);
                CheckIfExpectedEqualsValueAndSetType(MusicHelper.MinorSixth, lowerInterval, MusicHelper.MajorSixth, upperInterval, TriadType.MinorTriad, TriadInversion.StatisticalInversionFundamentalToneThird, FundamentalTone.ThirdNote, triad);
            }
            else
            {
                return;
            }
        }
Exemplo n.º 4
0
        private void StartInversion()
        {
            var scale       = ChosenScale;
            var progression = Triad.ChordGen(scale, ProgressionPattern, ColorPattern, Repeat);
            var chordInv    = Triad.Inversion(progression, OctavePattern, InversionPattern, ChosenKey);
            var counter     = 0;

            RemainingCount = chordInv.Chords.Count;

            ThreadPool.QueueUserWorkItem(
                o =>
            {
                foreach (var chord in chordInv.Chords)
                {
                    SetNotes(chord.Notes);

                    MidiLogic.PlayChord(_mOut, SelectedChannel, 127, chord.Notes.ToArray());
                    Thread.Sleep(LengthPattern[counter % LengthPattern.Count]);
                    MidiLogic.StopChord(_mOut, SelectedChannel, 127, chord.Notes.ToArray());
                    counter++;
                    RemainingCount -= 1;
                }
            }
                );
        }
Exemplo n.º 5
0
 private void VerifyTriadContains(Triad tri, int nbourTriad, int idA, int idB)
 {
     if (tri.ab == nbourTriad)
     {
         Debug.Assert(
             ((tri.a == idA) && (tri.b == idB)) ||
             ((tri.b == idA) && (tri.a == idB)));
     }
     else if (tri.ac == nbourTriad)
     {
         Debug.Assert(
             ((tri.a == idA) && (tri.c == idB)) ||
             ((tri.c == idA) && (tri.a == idB)));
     }
     else if (tri.bc == nbourTriad)
     {
         Debug.Assert(
             ((tri.c == idA) && (tri.b == idB)) ||
             ((tri.b == idA) && (tri.c == idB)));
     }
     else
     {
         Debug.Assert(false);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Respond to user-triggered puzzle actions
        /// </summary>
        /// <param name="sender">Object that triggered the event handler</param>
        /// <param name="e">Object encapsulating event properties and methods</param>
        private void pnlPuzzle_MouseClick(object sender, MouseEventArgs e)
        {
            // Identify game-based location of the mouse pointer
            var here = new Point(e.X, e.Y);

            // Save location, but only if mouse is over the true game area
            if (trans.OnGame(here))
            {
                mouseLocation = trans.GameFromPhysical(here);
            }

            lblFeedback.Text = "Clicked at " + mouseLocation.ToString(trans.HintZoneUnknown);
            string.Format("Clicked at Row: {0:d}, Col: {1:d}", mouseLocation.Row, mouseLocation.Column);

            // Click close enough to a hint zone?
            if (!(mouseLocation.HintZone == trans.HintZoneUnknown))
            {
                // Save a snapshot of the game as it currently stands
                gameHistory.Push(game.DeepClone);
                //TODO: Modify game

                RefreshPuzzle();
            }
            //TODO: Determine action, if any, when clicking outside a hint zone
        }
Exemplo n.º 7
0
        public static string Decode(string str)
        {
            string ret  = "";
            string buf  = "";
            Triad  symb = new Triad();

            for (int i = 0; i < str.Length; i++)
            {
                buf += str[i];
                symb = Table.FirstOrDefault(tri => tri.Code == buf);
                if (symb != null)
                {
                    ret += symb.Symbol;
                    buf  = "";
                }
            }
            if (symb == null)
            {
                return("Архив поврежден");
            }
            else
            {
                return(ret);
            }
        }
Exemplo n.º 8
0
 private static void ParseMessage(string str)
 {
     if (Table == null)
     {
         Table = new List <Triad>();
     }
     Table.Clear();
     for (int i = 0; i < str.Length; i++)
     {
         bool find = false;
         for (int j = 0; j < Table.Count; j++)
         {
             if (Table[j].Symbol == str[i])
             {
                 find = true;
                 Table[j].Probability++;
             }
         }
         if (!find)
         {
             Triad tr = new Triad();
             tr.Symbol = str[i];
             tr.Probability++;
             Table.Add(tr);
         }
     }
     for (int i = 0; i < Table.Count; i++)
     {
         Table[i].Probability /= (double)str.Length;
         Math.Round(Table[i].Probability, 2);
     }
     Table.Sort();
 }
Exemplo n.º 9
0
        private void ClassifyDiminishedTriadsZ12(Triad triad)
        {
            //Reduce note value to pitch class
            long firstNotePitchClass  = MusicHelper.ReduceToPitchClass(triad.FirstNote.EulerPoint.P.Numerator, 12);
            long secondNotePitchClass = MusicHelper.ReduceToPitchClass(triad.SecondNote.EulerPoint.P.Numerator, 12);
            long thirdNotePitchClass  = MusicHelper.ReduceToPitchClass(triad.ThirdNote.EulerPoint.P.Numerator, 12);

            if (triad.triadType == TriadType.NoTriad)              //Abbrechen wenn Dreiklangtyp gefunden wurde
            {
                //Calculate difference between notes
                long lowerInterval = secondNotePitchClass - firstNotePitchClass;
                lowerInterval = MusicHelper.ReduceToPitchClass(lowerInterval, 12);
                long upperInterval = thirdNotePitchClass - secondNotePitchClass;
                upperInterval = MusicHelper.ReduceToPitchClass(upperInterval, 12);

                //check if difference between notes (interval) equals the intervals for diminished triads
                //all options need to be tested

                CheckIfExpectedEqualsValueAndSetType(MusicHelper.MinorThird, lowerInterval, MusicHelper.MinorThird, upperInterval, TriadType.DiminishedTriad, TriadInversion.NoInversion, FundamentalTone.Default, triad);
                //CheckIfExpectedEqualsValueAndSetType( MusicHelper.MinorThird, lowerInterval, MusicHelper.MinorThird, upperInterval, TriadType.AugmentedTriad, TriadInversion.FirstInversion, triad );
                //CheckIfExpectedEqualsValueAndSetType( MusicHelper.MinorThird, lowerInterval, MusicHelper.MinorThird, upperInterval, TriadType.AugmentedTriad, TriadInversion.SecondInversion, triad );
                CheckIfExpectedEqualsValueAndSetType(MusicHelper.MajorSixth, lowerInterval, MusicHelper.Tritone, upperInterval, TriadType.DiminishedTriad, TriadInversion.NoInversion, FundamentalTone.Default, triad);
                CheckIfExpectedEqualsValueAndSetType(MusicHelper.Tritone, lowerInterval, MusicHelper.MajorSixth, upperInterval, TriadType.DiminishedTriad, TriadInversion.NoInversion, FundamentalTone.Default, triad);
            }
            else
            {
                return;
            }
        }
Exemplo n.º 10
0
        //##Analysing

        private void SearchForTriads()         //TODO Verbessern damit garantiert nichts geskippt wird
        {
            //Search for triads in all notes of instrument

            IEnumerable <Note> notesWithSameOnset;
            List <Note>        notesWithSameOnsetList;
            Note previousNote;

            if (Triads.Count > 0)              //Reset member list of triads
            {
                Triads.Clear();
            }

            for (int i = 0; i < Notes.Count; i++)
            {
                Note note = Notes[i];
                notesWithSameOnset = Notes.Where(comparedNote => comparedNote.Onset == note.Onset); //Filtere Noten mit gleicher Einsatzzeit
                if (notesWithSameOnset.Count() == 3)                                                //Wenn 3 Noten zwischenspeichern
                {
                    notesWithSameOnsetList = notesWithSameOnset.ToList();
                    Triad triad = new Triad(notesWithSameOnsetList[0], notesWithSameOnsetList[1], notesWithSameOnsetList[2]);
                    Triads.Add(triad);

                    if (i + 2 < Notes.Count)            //skip next two notes, cause they are part of the triad
                    {
                        i += 2;                         //skip two notes of triad
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 11
0
        public void Triad_Constructor_ParametersSet()
        {
            var t = new Triad(int.MinValue, int.MaxValue, default(int));

            Assert.AreEqual(t.Row, int.MinValue);
            Assert.AreEqual(t.Column, int.MaxValue);
            Assert.AreEqual(t.HintZone, default(int));
        }
Exemplo n.º 12
0
        public void Triad_DefaultConstructor_DefaultProperties()
        {
            var t = new Triad();

            Assert.AreEqual(t.Row, default(int));
            Assert.AreEqual(t.Column, default(int));
            Assert.AreEqual(t.HintZone, default(int));
        }
Exemplo n.º 13
0
        public void CantReturnAnEmptyTriad()
        {
            // Given
            Triad triad = new Triad();

            // When/Then
            Assert.Throws <NotValidStateException>(() => triad.GetCoordinates(), "Triad getter must raise an exception when list is empty");
        }
Exemplo n.º 14
0
        public void Transform_GameFromPhysical_CorrectCellAndHintZone()
        {
            // Aim for 3 1/3 of 4 across, 2 2/3 of 4 down
            var actual   = trans.GameFromPhysical(new Point(300 + 33, 200 + 66));
            var expected = new Triad(2, 3, 2);

            Assert.AreEqual(expected.Row, actual.Row);
            Assert.AreEqual(expected.Column, actual.Column);
            Assert.AreEqual(expected.HintZone, actual.HintZone);
        }
Exemplo n.º 15
0
        public void Transform_GameFromPhysical_CorrectCellNoHintZone()
        {
            // Aim for 3 1/2 of 4 across, 2 2/3 of 4 down
            // 1/2 across is in center between hint zones, so hint zone should be undefined
            var actual   = trans.GameFromPhysical(new Point(300 + 50, 200 + 66));
            var expected = new Triad(2, 3, trans.HintZoneUnknown);

            Assert.AreEqual(expected.Row, actual.Row);
            Assert.AreEqual(expected.Column, actual.Column);
            Assert.AreEqual(expected.HintZone, actual.HintZone);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Save current mouse position
        /// </summary>
        /// <param name="sender">Object that triggered the event handler</param>
        /// <param name="e">Object encapsulating event properties and methods</param>
        private void pnlPuzzle_MouseMove(object sender, MouseEventArgs e)
        {
            // Identify game-based location of the mouse pointer
            var here = new Point(e.X, e.Y);

            // Save location, but only if mouse is over the true game area
            if (trans.OnGame(here))
            {
                mouseLocation = trans.GameFromPhysical(here);
            }
        }
Exemplo n.º 17
0
        public void Write_1()
        {
            var psp = A.PasportRandom(1);
            var res = A.NewResource();


            Triad triad = new Triad(A.Connection, psp.Oper[0], psp.Zagot[0], res.Id);

            Signal.Write(triad);

            Assert.AreEqual(1, Signal.Find(triad).Count());
        }
Exemplo n.º 18
0
 /// <summary>
 /// Create clone method for Triad
 /// </summary>
 /// <param name="t">A Triad object t.</param>
 /// <returns>A copy of the Triad t</returns>
 public static Triad Clone(this Triad t)
 {
     return(new Triad(t.a, t.b, t.c)
     {
         ab = t.ab,
         bc = t.bc,
         ac = t.ac,
         circumcircleX = t.circumcircleX,
         circumcircleY = t.circumcircleY,
         circumcircleR2 = t.circumcircleR2
     });
 }
Exemplo n.º 19
0
 private bool CheckTriadSafity(Triad triad)
 {
     if (!CheckTriadOperandSafity(triad.LeftOperand))
     {
         return(false);
     }
     if (!CheckTriadOperandSafity(triad.RightOperand))
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 20
0
        public void Triad_ColumnParameter_Persists()
        {
            var t        = new Triad();
            var stimulus = rand.Next();

            t.Column = stimulus;

            var expected = stimulus;
            var actual   = t.Column;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 21
0
        public void Write_DateAsutp_1()
        {
            var psp = A.PasportRandom(1);
            var res = A.NewResource();


            Triad triad = new Triad(A.Connection, psp.Oper[0], psp.Zagot[0], res.Id);

            var signal = Signal.Write(triad);

            Assert.IsNotNull(signal.DateAsutp);
        }
Exemplo n.º 22
0
        public void Triad_HintZoneParameter_Persists()
        {
            var t        = new Triad();
            var stimulus = rand.Next();

            t.HintZone = stimulus;

            var expected = stimulus;
            var actual   = t.HintZone;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 23
0
        public void Triad_ToStringParam_ExcludingHint()
        {
            var row      = rand.Next();
            var column   = rand.Next();
            var hintZone = rand.Next();

            var t = new Triad(row, column, hintZone);

            var expected = "Row: " + row.ToString("d") + ", Col: " + column.ToString("d");
            var actual   = t.ToString(hintZone);        // Intentionally matches HintZone value

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 24
0
        private void AddOrUpdateTriadWithResult(Triad triad, bool result)
        {
            var triadWithResult = TriadResults.FirstOrDefault(t => t.TriadIndex == GetTriadIndex(triad));

            if (triadWithResult != null)
            {
                triadWithResult.Value = result.ToString();
            }
            else
            {
                TriadResults.Add(new TriadWithResult(GetTriadIndex(triad), result.ToString()));
            }
        }
Exemplo n.º 25
0
        private Polygon CreateTriangle(Triad triangle)
        {
            Polygon polygon = new Polygon();
            Vertex  a       = points[triangle.A];
            Vertex  b       = points[triangle.B];
            Vertex  c       = points[triangle.C];

            polygon.Points          = new PointCollection(new Point[] { new Point(a.X, a.Y), new Point(b.X, b.Y), new Point(c.X, c.Y) });
            polygon.StrokeThickness = TriangleTickness;
            polygon.Stroke          = new SolidColorBrush(triangleStrokeColor);
            Panel.SetZIndex(polygon, TriangleZIndex);
            return(polygon);
        }
Exemplo n.º 26
0
        public void Triad_ToString_Valid()
        {
            var row      = rand.Next();
            var column   = rand.Next();
            var hintZone = rand.Next();

            var t = new Triad(row, column, hintZone);

            var expected = "(" + row.ToString("d") + ", " + column.ToString("d") + ", " + hintZone.ToString("d") + ")";
            var actual   = t.ToString();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 27
0
        public void CoordinatesMustBeAllDistinct()
        {
            // Given
            Coordinate coord1 = new Coordinate(10, 20);
            Coordinate coord2 = new Coordinate(20, 30);
            Coordinate coord3 = new Coordinate(20, 30);

            // When
            Triad triad = new Triad();

            // Then
            Assert.Throws <NotValidValueException>(() => triad.SetCoordinates(coord1, coord2, coord3), "All coordinates must be distinct");
        }
Exemplo n.º 28
0
        public void Update(TaskDTO task, int employeeID, int ToChangeTaskId)
        {
            if (Get(ToChangeTaskId).State == TaskState.Resolved)
            {
                throw new ResolvedTask();
            }
            var     discriptionLog = $"Update : task.Name = {task.Name} task.ownerID = {task.OwnerID}, task.description = {task.Description}, task.state = {task.State}";
            var     log            = new Triad <DateTime, int, string> (DateTime.Now, employeeID, discriptionLog);
            TaskDAL DALTask        = _taskReposirory.GetAll().Find(t => t.ID.Equals(ToChangeTaskId));

            task.Logger.AddRange(DALTask.Logger);
            task.Logger.Add(log);
            _taskReposirory.Update(ToDALConverter(task), ToChangeTaskId);
        }
Exemplo n.º 29
0
        public void ATriadStoresOnly3CoordinatesHappyPath()
        {
            // Given
            Coordinate coord1 = new Coordinate(10, 20);
            Coordinate coord2 = new Coordinate(20, 30);
            Coordinate coord3 = new Coordinate(30, 40);

            // When
            Triad triad = new Triad(coord1, coord2, coord3);
            ICollection <Coordinate> resp = triad.GetCoordinates();

            // Then
            Assert.IsTrue(resp.Count == 3, "Triad getter must return exactly 3 coordinates");
        }
Exemplo n.º 30
0
        public void Write_0()
        {
            var psp = A.PasportRandom(1);
            var res = A.NewResource();


            Triad triad = new Triad(A.Connection, psp.Oper[0], psp.Zagot[0], res.Id);

            var cnt = Tables.RppSignal.Count(A.Connection);

            Signal.Write(triad);

            Assert.AreEqual(cnt + 1, Tables.RppSignal.Count(A.Connection));
        }