Ejemplo n.º 1
0
        // Start is called before the first frame update
        new void Start()
        {
            base.Start();

            int s1 = (int)HandType.Max, s2 = fingertips.Length;

            Vector3[,] fingerPosition = new Vector3[s1, s2];
            Vector3[] gripPosition = new Vector3[s1];
            FingerShape[,] fingerShape = new FingerShape[s1, s2];
            HandShape[] handShape = new HandShape[s1];
            Vector3[]   handVelocity = new Vector3[s1];
            Vector3[]   handAcceleration = new Vector3[s1];

            for (int i = 0; i < s1; ++i)
            {
                for (int j = 0; j < s2; ++j)
                {
                    fingerPosition[i, j] = new Vector3();
                    fingerShape[i, j]    = FingerShape.Max;
                }
                gripPosition[i]     = new Vector3();
                handShape[i]        = HandShape.Unknown;
                handVelocity[i]     = new Vector3();
                handAcceleration[i] = new Vector3();
            }

            cachedPoseData = new CircularBuffer <PoseDataFrame>(Globals.FRAME_BUFFER_SIZE,
                                                                new PoseDataFrame(fingerPosition, gripPosition, fingerShape, handShape, handVelocity, handAcceleration));
            _avatarHands[0] = HandRight; _avatarHands[1] = HandLeft;
        }
Ejemplo n.º 2
0
        public static Func <HandShape> ConsoleMoveStrategy(ILogger logger)
        {
            logger.Log("Rock, Paper, Scissors?");
            var handMove  = Console.ReadLine();
            var handShape = HandShape.From(handMove);

            logger.Log($"Human chose {handMove}");
            return(handShape);
        }
        public void HandShapeAdjuster_ShortensHandshape()
        {
            var testHandshape = new HandShape(0, 10000, 11999);

            testArrangement.Levels[0].HandShapes.Add(testHandshape);
            testArrangement.Levels[0].HandShapes.Add(new HandShape(0, 12000, 13000));

            new HandShapeAdjuster().Apply(testArrangement, nullLog);

            testHandshape.EndTime.Should().BeLessThan(11999);
        }
Ejemplo n.º 4
0
        internal void CheckHandshapes(Level level, List <ChordTemplate> chordTemplates)
        {
            var handShapes = level.HandShapes;
            var anchors    = level.Anchors;

            for (int i = 0; i < handShapes.Count; i++)
            {
                // Check anchor position relative to handshape fingering
                HandShape handShape = handShapes[i];
                HandShape?previous  = (i == 0) ? null : handShapes[i - 1];
                HandShape?next      = (i == handShapes.Count - 1) ? null : handShapes[i + 1];

                var activeAnchor  = anchors.Last(a => a.Time <= handShape.StartTime);
                var chordTemplate = chordTemplates[handShape.ChordId];

                // Check only handshapes that do not use the 1st finger
                if (!chordTemplate.Fingers.Any(f => f == 1))
                {
                    bool chordOK = true;

                    for (int j = 0; j < 6; j++)
                    {
                        if (chordTemplate.Frets[j] == activeAnchor.Fret && chordTemplate.Fingers[j] != -1)
                        {
                            chordOK = false;
                        }
                    }

                    if (!chordOK)
                    {
                        if (previous is not null && IsSameAnchorWith1stFinger(previous, activeAnchor))
                        {
                            continue;
                        }

                        if (next is not null && IsSameAnchorWith1stFinger(next, activeAnchor))
                        {
                            continue;
                        }

                        AddIssue($"Handshape fingering does not match anchor position at {handShape.StartTime.TimeToString()}.", handShape.StartTime);
                    }
                }
            }

            // Logic to weed out some false positives
            bool IsSameAnchorWith1stFinger(HandShape neighbour, Anchor activeAnchor)
            {
                var neighbourAnchor   = anchors.Last(a => a.Time <= neighbour.StartTime);
                var neighbourTemplate = chordTemplates[neighbour.ChordId];

                return(neighbourTemplate.Fingers.Any(f => f == 1) && neighbourAnchor == activeAnchor);
            }
        }
Ejemplo n.º 5
0
        public void AwardWin_VariousConditions_ProducesAppropriateResult(HandShape shape1, HandShape shape2, HandShape?expectedResult)
        {
            // Arrange
            var referee = new Referee();

            // Act
            var result = referee.AwardWin(shape1, shape2);

            // Assert
            Assert.AreEqual(expectedResult, result);
        }
Ejemplo n.º 6
0
 public void Beats()
 {
     Assert.True(HandShape.Rock().Beats(HandShape.Scissors()));
     Assert.False(HandShape.Rock().Beats(HandShape.Paper()));
     Assert.False(HandShape.Rock().Beats(HandShape.Rock()));
     Assert.True(HandShape.Scissors().Beats(HandShape.Paper()));
     Assert.False(HandShape.Scissors().Beats(HandShape.Rock()));
     Assert.False(HandShape.Scissors().Beats(HandShape.Scissors()));
     Assert.True(HandShape.Paper().Beats(HandShape.Rock()));
     Assert.False(HandShape.Paper().Beats(HandShape.Scissors()));
     Assert.False(HandShape.Paper().Beats(HandShape.Paper()));
 }
Ejemplo n.º 7
0
    void ModifyShape()
    {
        float morphSpeed = 10.0f * Time.deltaTime;

        upLength   += grabPinchActive ? morphSpeed : -morphSpeed;
        downLength += grabGripActive  ? morphSpeed : -morphSpeed;

        upLength   = Mathf.Clamp(upLength, 0.0f, maxLength);
        downLength = Mathf.Clamp(downLength, 0.0f, maxLength);

        HandShape lhs = handShape;

        if (upLength > 0.3f)
        {
            if (downLength > 0.3f)
            {
                handShape = HandShape.SwordStaff;
            }
            else
            {
                handShape = HandShape.Sword;
            }
        }
        else
        {
            if (downLength > 0.3f)
            {
                handShape = HandShape.Staff;
            }
            else
            {
                handShape = HandShape.Fist;
            }
        }

        if (lhs != handShape)
        {
            // hand shape has changed:
            fistCollider.enabled  = handShape == HandShape.Fist;
            swordCollider.enabled = handShape == HandShape.Sword || handShape == HandShape.SwordStaff;
            staffCollider.enabled = handShape == HandShape.Staff || handShape == HandShape.SwordStaff;
        }

        SetDimension();
    }
Ejemplo n.º 8
0
        /// <summary>
        /// Adds a round to the game
        /// </summary>
        /// <param name="player">A player</param>
        /// <param name="handshape">A hand shape</param>
        public void RecordRound(IPlayer player, HandShape handshape)
        {
            if (player == null)
            {
                throw new ArgumentNullException();
            }

            if (handshape == HandShape.Invalid)
            {
                throw new InvalidEnumArgumentException();
            }

            // add to rounds collection
            Rounds.Add(new Tuple <IPlayer, HandShape>(player, handshape));

            // if all players have had their round
            if (Rounds?.Count == Constants.PLAYERS_COUNT)
            {
                var handler = Complete;
                handler?.Invoke(this, new GameCompleteEventArgs {
                    GameId = Id
                });
            }
        }
Ejemplo n.º 9
0
 public void GenerateShape()
 {
     Assert.AreEqual(HandShape.Rock(), new Player("connor", PlayerTestStrategies.Rock).GenerateShape());
     Assert.AreEqual(HandShape.Scissors(), new Player("bob", PlayerTestStrategies.Scissors).GenerateShape());
     Assert.AreEqual(HandShape.Paper(), new Player("harry", PlayerTestStrategies.Paper).GenerateShape());
 }
        public void SlideOutEvent_CreatesHandshape()
        {
            const int chordTime   = 20222;
            const int sustainTime = 3000;

            var phrase = new Phrase("test", (byte)(testArrangement.Levels.Count - 1), PhraseMask.None);

            testArrangement.Phrases.Add(phrase);

            var phraseIter = new PhraseIteration(chordTime, testArrangement.Phrases.Count - 1);

            testArrangement.PhraseIterations.Add(phraseIter);

            var template = new ChordTemplate();

            template.SetFingering(1, 3, 3, -1, -1, -1);
            template.SetFrets(1, 3, 4, -1, -1, -1);

            testArrangement.ChordTemplates.Add(template);
            short chordId = (short)(testArrangement.ChordTemplates.Count - 1);

            var chord = new Chord
            {
                ChordId    = chordId,
                Time       = chordTime,
                ChordNotes = new List <Note>
                {
                    new Note
                    {
                        String         = 0,
                        Fret           = 1,
                        SlideUnpitchTo = 5,
                        Sustain        = sustainTime
                    },
                    new Note
                    {
                        String         = 1,
                        Fret           = 3,
                        SlideUnpitchTo = 7,
                        Sustain        = sustainTime
                    },
                    new Note
                    {
                        String         = 2,
                        Fret           = 3,
                        SlideUnpitchTo = 7,
                        Sustain        = sustainTime
                    }
                }
            };

            var hardestLevel = testArrangement.Levels.Last();

            var handshape = new HandShape(chordId, chordTime, chordTime + sustainTime);

            hardestLevel.Chords.Add(chord);
            hardestLevel.HandShapes.Add(handshape);
            testArrangement.Events.Add(new Event("so", chordTime));

            int handShapeCount     = hardestLevel.HandShapes.Count;
            int chordTemplateCount = testArrangement.ChordTemplates.Count;

            new CustomEventPostProcessor(new List <ImproverMessage>()).Apply(testArrangement, nullLog);

            testArrangement.Events.Should().NotContain(ev => ev.Code == "so");
            hardestLevel.HandShapes.Should().HaveCount(handShapeCount + 1);
            testArrangement.ChordTemplates.Should().HaveCount(chordTemplateCount + 1);
            handshape.EndTime.Should().BeLessThan(chordTime + sustainTime);
        }
Ejemplo n.º 11
0
        /// <inheritdoc cref="IReferee"/>
        public HandShape?AwardWin(HandShape shape1, HandShape shape2)
        {
            // Validate parameter #1
            if (shape1 == HandShape.Invalid)
            {
                throw new InvalidOperationException("Handshape shape1 cannot be invalid");
            }

            // Validate parameter #2
            if (shape2 == HandShape.Invalid)
            {
                throw new InvalidOperationException("Handshape shape2 cannot be invalid");
            }

            // Determine winner
            HandShape?rtn = null;

            switch (shape1)
            {
            case HandShape.Rock:
                switch (shape2)
                {
                case HandShape.Rock:
                    // rtn = null; (rtn is already null)
                    break;

                case HandShape.Paper:
                    rtn = HandShape.Paper;
                    break;

                case HandShape.Scissors:
                    rtn = HandShape.Rock;
                    break;
                }

                break;

            case HandShape.Paper:
                switch (shape2)
                {
                case HandShape.Rock:
                    rtn = HandShape.Paper;
                    break;

                case HandShape.Paper:
                    // rtn = null; (rtn is already null)
                    break;

                case HandShape.Scissors:
                    rtn = HandShape.Scissors;
                    break;
                }

                break;

            case HandShape.Scissors:
                switch (shape2)
                {
                case HandShape.Rock:
                    rtn = HandShape.Rock;
                    break;

                case HandShape.Paper:
                    rtn = HandShape.Scissors;
                    break;

                case HandShape.Scissors:
                    // rtn = null; (rtn is already null)
                    break;
                }

                break;
            }

            // Return result
            return(rtn);
        }
Ejemplo n.º 12
0
 static bool FlagTurnedOff(HandShape Old, HandShape New, HandShape flag) =>
 !New.HasFlag(flag) && Old.HasFlag(flag);
Ejemplo n.º 13
0
 static bool FlagTurnedOn(HandShape Old, HandShape New, HandShape flag) =>
 New.HasFlag(flag) && !Old.HasFlag(flag);