public void ApplyQuantumMove(QuantumMove move) { bool applied = false; var new_harmonics = new List <QuantumHarmonic>(); foreach (QuantumHarmonic harmonic in Harmonics_) { if (harmonic.Board.CheckQuantumMoveApplicable(move)) { // Passing to the superposition of the original and new harmonics QuantumHarmonic new_harmonic = harmonic.Clone(); new_harmonic.Board.ApplyQuantumMove(move); new_harmonics.Add(harmonic); new_harmonics.Add(new_harmonic); applied = true; } else { // Keeping the original harmonic with degeneracy doubled harmonic.Degeneracy *= 2; new_harmonics.Add(harmonic); } } Harmonics_ = new_harmonics; UpdateQuantumCheckboard(); AssertionException.Assert(applied, "Quantum move couldn't be applied on any harmonic"); }
public void ApplyQuantumMove(QuantumMove move) { AssertionException.Assert(CheckQuantumMoveApplicable(move), $"Attempted applying inapplicable quantum move"); this[move.Target] = this[move.Source]; this[move.Source] = null; if (move.ActorPiece.PieceType == PieceType.Pawn && (move.Target.Y == 0 || move.Target.Y == 7)) { // Pawn entered its final destination, promoting it to a queen AssertionException.Assert(this[move.Target].HasValue && this[move.Target].Value.PieceType == PieceType.Pawn, "We just applied the pawn move, but somehow no pawn present at the target square"); this[move.Target] = new Piece(this[move.Target].Value.Player, PieceType.Queen); } }
public bool CheckQuantumMoveApplicable(QuantumMove move) { if (move.Source == move.Target) { // Dummy moves aren't allowed by the rules of the game return(false); } Piece?source = this[move.Source]; if (source != move.ActorPiece) { // The chessboard doesn't have an actor piece at the source position // Therefore the move is inapplicable return(false); } Piece?target = this[move.Target]; if (target != null) { // You can't quantum-capture! return(false); } if (move.Middle.HasValue) { Piece?middle = this[move.Middle.Value]; if (middle != null) { // Move is inapplicable return(false); } return(CheckIntermediateSquares(move.ActorPiece, move.Source, move.Middle.Value, false) && CheckIntermediateSquares(move.ActorPiece, move.Middle.Value, move.Target, false)); } else { return(CheckIntermediateSquares(move.ActorPiece, move.Source, move.Target, false)); } }
public bool CheckQuantumMoveApplicable(QuantumMove move) { return(Harmonics_.Any((h) => h.Board.GameState == GameState.GameStillGoing && h.Board.CheckQuantumMoveApplicable(move))); }