private void ExecuteNextAction(BoardPress action, BoardPressStateInfo stateInfo)
        {
            switch (action)
            {
            case BoardPress.CLICK_HIGHLIGHT:
                NextActionHighlight(stateInfo.piece.Value);
                break;

            case BoardPress.MOVE_PIECE:
                NextActionMovePiece(stateInfo.piece.Value, stateInfo.tile.Value);
                break;

            case BoardPress.DROP:
                NextActionDropPiece(stateInfo.handPiece.Value, stateInfo.tile.Value);
                break;

            case BoardPress.SUBSTITUTION:
                NextActionSubstitution(stateInfo.piece.Value, stateInfo.tile.Value);
                break;

            case BoardPress.TIER_1_3_EXCHANGE:
                NextActionTierExchange(stateInfo.tile.Value);
                break;

            case BoardPress.NOTHING:
                break;

            default:
                throw new InvalidOperationException("Invalid or unsupported BoardPress state");
            }
        }
Beispiel #2
0
        public bool IsTierExchangePossible(BoardPressStateInfo stateInfo, TurnEV currentTurn, IEntitiesDB entitiesDB)
        {
            if (!stateInfo.tile.HasValue || currentTurn.InitialArrangement.IsInitialArrangementInEffect)
            {
                return(false);
            }

            List <PieceEV> towerPieces = pieceFindService.FindPiecesByLocation(stateInfo.tile.Value.Location.Location, entitiesDB);

            return(IsTier1ExchangePossible(towerPieces, currentTurn.TurnPlayer.PlayerColor) ||
                   IsTier3ExchangePossible(towerPieces, currentTurn.TurnPlayer.PlayerColor));
        }
Beispiel #3
0
        public bool IsTierExchangePossible(BoardPressStateInfo stateInfo, IEntitiesDB entitiesDB)
        {
            if (!stateInfo.tile.HasValue)
            {
                return(false);
            }

            TurnEV         currentTurn = turnService.GetCurrentTurnEV(entitiesDB);
            List <PieceEV> towerPieces = pieceFindService.FindPiecesByLocation(stateInfo.tile.Value.Location.Location, entitiesDB);

            return(IsTier1ExchangePossible(towerPieces, currentTurn.TurnPlayer.PlayerColor) ||
                   IsTier3ExchangePossible(towerPieces, currentTurn.TurnPlayer.PlayerColor));
        }
Beispiel #4
0
        public BoardPressStateInfo FindBoardPressStateInfo(IEntitiesDB entitiesDB, ref BoardPressStepState token)
        {
            BoardPressStateInfo returnValue = new BoardPressStateInfo
            {
                piece = pieceFindService.FindPieceEVById(token.PieceEntityId, entitiesDB),
                tile  = tileService.FindTileEVById(token.TileEntityId, entitiesDB),
                pieceAtDestination = null, // If movement-related information is later required
                handPiece          = handService.FindHighlightedHandPiece(entitiesDB)
            };

            if (!returnValue.piece.HasValue &&
                returnValue.tile.HasValue &&
                returnValue.tile.Value.Tile.PieceRefEntityId.HasValue &&
                returnValue.tile.Value.Tile.PieceRefEntityId != 0)    // Find by tile information
            {
                returnValue.piece = pieceFindService.FindPieceEVById(
                    returnValue.tile.Value.Tile.PieceRefEntityId.Value, entitiesDB);
            }

            if (!returnValue.tile.HasValue) // Find by piece information
            {
                returnValue.tile = tileService.FindTileEV(
                    returnValue.piece.Value.Location.Location, entitiesDB);
            }

            if (returnValue.tile.HasValue && !returnValue.piece.HasValue)
            {
                returnValue.piece = pieceFindService.FindTopPieceByLocation(
                    returnValue.tile.Value.Location.Location, entitiesDB);
            }

            if (returnValue.tile.HasValue)
            {
                returnValue.pieceAtDestination = pieceFindService.FindTopPieceByLocation(
                    returnValue.tile.Value.Location.Location, entitiesDB);
            }

            // Movement: Piece is clicked with intention to move a DIFFERENT piece to that tile location
            if (returnValue.tile.HasValue &&
                returnValue.tile.Value.Tile.PieceRefEntityId.HasValue &&
                returnValue.tile.Value.Tile.PieceRefEntityId.Value != 0 &&
                returnValue.piece.HasValue &&
                returnValue.piece.Value.Location.Location == returnValue.tile.Value.Location.Location)
            {
                returnValue.piece = pieceFindService.FindPieceEVById(
                    returnValue.tile.Value.Tile.PieceRefEntityId.Value, entitiesDB);
            }

            return(returnValue);
        }
        public void Step(ref BoardPressStepState token, int condition)
        {
            ConstraintCheck(ref token);

            BoardPressStateInfo stateInfo = pieceTileService.FindBoardPressStateInfo(entitiesDB, ref token);
            bool   substitutionPossible   = pieceTileService.IsSubstitutionPossible(stateInfo, entitiesDB);
            bool   tierExchangePossible   = pieceTileService.IsTierExchangePossible(stateInfo, entitiesDB);
            TurnEV currentTurn            = turnService.GetCurrentTurnEV(entitiesDB);

            BoardPress action = boardPressService.DecideAction(
                stateInfo,
                substitutionPossible,
                tierExchangePossible,
                currentTurn);

            ExecuteNextAction(action, stateInfo);
        }
        public BoardPress DecideAction(
            BoardPressStateInfo stateInfo,
            bool substitutionPossible,
            bool tierExchangePossible,
            TurnEV currentTurn)
        {
            BoardPress returnValue = BoardPress.NOTHING;
            TileEV     tileEV      = stateInfo.tile.Value;
            int        tilePieceId = tileEV.Tile.PieceRefEntityId.GetValueOrDefault();

            // TODO Scenario: Clicked highlighted tile containing opponent piece to initiate mobile capture

            // If hand piece highlighted, it's an attempted drop
            if (stateInfo.handPiece.HasValue)
            {
                returnValue = BoardPress.DROP;
            }
            else if (currentTurn.InitialArrangement.IsInitialArrangementInEffect)
            {   // User is not dropping during Initial Arrangement, so deny
                returnValue = BoardPress.NOTHING;
            }
            else if (substitutionPossible)
            {
                returnValue = BoardPress.SUBSTITUTION;
            }
            else if (tierExchangePossible)
            {
                returnValue = BoardPress.TIER_1_3_EXCHANGE;
            }
            // Tile is clicked, tile highlighted, piece reference exists; move vs mobile capture determined in later engine
            else if (tileEV.Highlight.IsHighlighted &&
                     stateInfo.piece.HasValue &&
                     tilePieceId != 0 &&
                     stateInfo.piece.Value.PlayerOwner.PlayerColor == currentTurn.TurnPlayer.PlayerColor)
            {
                returnValue = BoardPress.MOVE_PIECE;
            }
            // NOT move scenario, Piece/Tile clicked, both piece and tile exist, piece reference does not exist
            else if (stateInfo.piece.HasValue && tilePieceId == 0)
            {
                returnValue = BoardPress.CLICK_HIGHLIGHT;
            }

            return(returnValue);
        }
Beispiel #7
0
 public bool IsSubstitutionPossible(BoardPressStateInfo stateInfo, IEntitiesDB entitiesDB)
 {
     return(checkService.IsSubstitutionPossible(stateInfo.piece, stateInfo.tile, entitiesDB));
 }
Beispiel #8
0
 public bool IsSubstitutionPossible(BoardPressStateInfo stateInfo, TurnEV currentTurn, IEntitiesDB entitiesDB)
 {
     return(!currentTurn.InitialArrangement.IsInitialArrangementInEffect &&
            checkService.IsSubstitutionPossible(stateInfo.piece, stateInfo.tile, entitiesDB));
 }