Beispiel #1
0
        public void Step(ref TurnStartStepState token, int condition)
        {
            TurnEV turn    = turnService.GetCurrentTurnEV(entitiesDB);
            bool   inCheck = checkService.IsCommanderInCheck(turn.TurnPlayer.PlayerColor, entitiesDB);

            turnService.SetCheckStatus(turn, inCheck, entitiesDB);

            Debug.Log("Turn Player: " + turn.TurnPlayer.PlayerColor.ToString());
            if (inCheck)
            {
                Debug.Log("CHECK: " + turn.TurnPlayer.PlayerColor.ToString());
            }
        }
        private bool DropCheckmateNotViolated(
            PieceEV pieceToDrop,
            Vector2 location,
            PlayerColor playerColor,
            PieceSide side,
            HandPieceEV handPiece,
            DropCheckmateLevel recursionLevel,
            IEntitiesDB entitiesDB)
        {
            bool        returnValue      = true;
            PlayerColor enemyPlayerColor = TurnService.CalcOtherTurnPlayer(playerColor);

            if (recursionLevel != DropCheckmateLevel.FINAL_TURN_PLAYER_CHECK && // Prevent infinite recursion
                AbilityToPiece.HasAbility(DropAbility.CANNOT_DROP_CHECKMATE, pieceToDrop.Piece.PieceType) &&
                checkService.IsCommanderInCheck(enemyPlayerColor, entitiesDB))
            {
                recursionLevel = recursionLevel == DropCheckmateLevel.FIRST_TURN_PLAYER_CHECK
                    ? DropCheckmateLevel.SECOND_ENEMY_PLAYER_CHECK : DropCheckmateLevel.FINAL_TURN_PLAYER_CHECK;
                returnValue = AnyValidMoves(enemyPlayerColor, entitiesDB, recursionLevel);
            }

            return(returnValue);
        }
Beispiel #3
0
        // Will need to be careful of betrayal effect when doing temp move
        private bool IsMobileMoveValid(PieceEV pieceToCalc, Vector2 destination, bool shouldStackEnemyPiece, IEntitiesDB entitiesDB)
        {
            List <PieceEV> allPieces = pieceFindService.FindAllBoardPieces(entitiesDB).ToList();
            // Make temp move while saving old info
            PreviousMoveState  previousMoveState             = destinationTileService.SaveCurrentMove(pieceToCalc, destination, allPieces);
            PreviousTowerState?previousDestinationTowerState = previousMoveState.pieceCaptured.HasValue &&
                                                               destinationTileService.BetrayalInEffect(previousMoveState.pieceToMove.Piece)
                ? destinationTileService.SaveDestinationTowerState(previousMoveState, allPieces) : null;

            destinationTileService.MakeTemporaryMove(pieceToCalc, destination, allPieces, shouldStackEnemyPiece);

            bool returnValue = !checkService.IsCommanderInCheck(pieceToCalc.PlayerOwner.PlayerColor, entitiesDB);

            if (returnValue)
            {
                returnValue = !checkService.CannotCaptureCommanderViolated(destination, pieceToCalc.PlayerOwner.PlayerColor, entitiesDB);
            }

            destinationTileService.RestorePreviousState(previousMoveState, previousDestinationTowerState);

            return(returnValue);
        }
        private bool DoesImmobileCaptureResolveOrPreventCheck(List <PieceEV> towerPieces, int tierIndex, IEntitiesDB entitiesDB)
        {
            bool returnValue = false;
            PreviousTowerState previousState = CreatePreviousState(towerPieces);
            TurnEV             currentTurn   = turnService.GetCurrentTurnEV(entitiesDB);
            PieceEV            commander     = pieceFindService.FindCommander(currentTurn.TurnPlayer.PlayerColor, entitiesDB);

            PieceEV?capturedPiece = TempImmobileCapture(
                towerPieces, tierIndex, currentTurn.TurnPlayer.PlayerColor, entitiesDB);

            // Betrayal did not cause two file move violation
            if (capturedPiece.HasValue)
            {
                returnValue = !checkService.IsCommanderInCheck(currentTurn.TurnPlayer.PlayerColor, entitiesDB);

                if (!returnValue && checkService.IsForcedRearrangementPossible(capturedPiece.Value))
                {
                    returnValue = DoesForcedRearrangementResolveOrPreventCheck(capturedPiece.Value, commander, towerPieces, entitiesDB);
                }
            }

            RestorePreviousState(previousState, entitiesDB);
            return(returnValue);
        }