Beispiel #1
0
        public QuantumPiece GetQuantumPiece(Position pos)
        {
            Piece?piece = null;
            ulong filled = 0, empty = 0;

            foreach (QuantumHarmonic harmonic in Harmonics_)
            {
                Piece?classical = harmonic.Board[pos];
                if (classical.HasValue)
                {
                    AssertionException.Assert(piece == null || piece == classical,
                                              $"The square {pos} appears in a superposition of two pieces");
                    piece   = classical;
                    filled += harmonic.Degeneracy;
                }
                else
                {
                    empty += harmonic.Degeneracy;
                }
            }
            if (piece.HasValue)
            {
                return(new QuantumPiece(piece, MeasurementUtils.Probability(filled, filled + empty)));
            }
            else
            {
                return(new QuantumPiece(null, 1.0));
            }
        }
Beispiel #2
0
        private void UpdateGameState()
        {
            if (GameState_ != GameState.GameStillGoing)
            {
                return;
            }

            if (Harmonics_.All((h) => h.Board.GameState != GameState.GameStillGoing))
            {
                ulong white_victory_degeneracy = Harmonics_
                                                 .Where((h) => h.Board.GameState == GameState.WhiteVictory)
                                                 .Select((h) => h.Degeneracy)
                                                 .Aggregate(0ul, (a, b) => a + b);

                ulong black_victory_degeneracy = Harmonics_
                                                 .Where((h) => h.Board.GameState == GameState.BlackVictory)
                                                 .Select((h) => h.Degeneracy)
                                                 .Aggregate(0ul, (a, b) => a + b);

                ulong tie_degeneracy = Harmonics_
                                       .Where((h) => h.Board.GameState == GameState.Tie)
                                       .Select((h) => h.Degeneracy)
                                       .Aggregate(0ul, (a, b) => a + b);

                ulong total_degeneracy = white_victory_degeneracy + black_victory_degeneracy + tie_degeneracy;
                if (!MeasurementUtils.Decide(tie_degeneracy, total_degeneracy))
                {
                    total_degeneracy -= tie_degeneracy;
                    if (MeasurementUtils.Decide(white_victory_degeneracy, total_degeneracy))
                    {
                        GameState_ = GameState.WhiteVictory;
                    }
                    else
                    {
                        GameState_ = GameState.BlackVictory;
                    }
                }
                else
                {
                    GameState_ = GameState.Tie;
                }
            }
        }
Beispiel #3
0
        private void PerformMeasurement(Position pos)
        {
            var   piece_degeneracies = new Dictionary <Piece, ulong>();
            ulong overall_degeneracy = 0;

            foreach (QuantumHarmonic harmonic in Harmonics_)
            {
                Piece?square = harmonic.Board[pos];
                if (square.HasValue)
                {
                    if (!piece_degeneracies.ContainsKey(square.Value))
                    {
                        piece_degeneracies[square.Value] = 0;
                    }
                    piece_degeneracies[square.Value] += harmonic.Degeneracy;
                    overall_degeneracy += harmonic.Degeneracy;
                }
            }

            if (piece_degeneracies.Count <= 1)
            {
                // No measurement is needed
                return;
            }

            foreach (Piece piece in piece_degeneracies.Keys)
            {
                ulong degeneracy = piece_degeneracies[piece];
                if (MeasurementUtils.Decide(degeneracy, overall_degeneracy))
                {
                    // Removing all the harmonics with another piece
                    FilterBy((h) => h.Board[pos] == null || h.Board[pos] == piece);
                    return;
                }
                else
                {
                    overall_degeneracy -= degeneracy;
                }
            }
            AssertionException.Assert(false, "One of the pieces has to be chosen");
        }
Beispiel #4
0
        private void PerformSpontaneousMeasurement()
        {
            ulong total_degeneracy = 0;

            foreach (QuantumHarmonic harmonic in Harmonics_)
            {
                total_degeneracy += harmonic.Degeneracy;
            }

            foreach (QuantumHarmonic harmonic in Harmonics_)
            {
                if (MeasurementUtils.Decide(harmonic.Degeneracy, total_degeneracy))
                {
                    var new_harmonics = new List <QuantumHarmonic>();
                    new_harmonics.Add(harmonic);
                    Harmonics_ = new_harmonics;
                    return;
                }
                total_degeneracy -= harmonic.Degeneracy;
            }
        }