Ejemplo n.º 1
0
        public SolutionKey[] CheckRevelation(ClientRevelation revelation)
        {
            if (revelation == null)
            {
                throw new ArgumentNullException($"{nameof(revelation)}");
            }
            if (revelation.FakeIndexes.Length != Parameters.FakePuzzleCount ||
                revelation.Solutions.Length != Parameters.FakePuzzleCount)
            {
                throw new ArgumentException("Expecting " + Parameters.FakePuzzleCount + " puzzle solutions");
            }
            AssertState(SolverServerStates.WaitingRevelation);


            List <SolvedPuzzle> fakePuzzles = new List <SolvedPuzzle>();

            for (int i = 0; i < Parameters.FakePuzzleCount; i++)
            {
                var index        = revelation.FakeIndexes[i];
                var solvedPuzzle = InternalState.SolvedPuzzles[index];
                if (solvedPuzzle.Solution != revelation.Solutions[i])
                {
                    throw new PuzzleException("Incorrect puzzle solution");
                }

                fakePuzzles.Add(solvedPuzzle);
            }

            List <SolvedPuzzle> realPuzzles = new List <SolvedPuzzle>();

            for (int i = 0; i < Parameters.GetTotalCount(); i++)
            {
                if (Array.IndexOf(revelation.FakeIndexes, i) == -1)
                {
                    realPuzzles.Add(InternalState.SolvedPuzzles[i]);
                }
            }

            InternalState.SolvedPuzzles = realPuzzles.ToArray();
            InternalState.Status        = SolverServerStates.WaitingBlindFactor;
            return(fakePuzzles.Select(f => f.SolutionKey).ToArray());
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public async Task <SolutionKey[]> CheckRevelationAsync(int cycleId, string channelId, PuzzleSolver.ClientRevelation revelation)
        {
            SolutionKey[] result = await this.serverAddress.AppendPathSegment($"api/v1/tumblers/0/clientschannels/{cycleId}/{channelId}/checkrevelation").PostJsonAsync(revelation).ReceiveJson <SolutionKey[]>();

            return(result);
        }