public void CanPromotePieceTypeYes()
    {
        ChessRuleEvaluator.currentRuleSet = new ChessRuleSet("Default Rule Set");
        ChessPiece piece1 = new Pawn(ChessPiece.PieceColor.WHITE);
        ChessPiece piece2 = new Queen(ChessPiece.PieceColor.WHITE);

        Assert.That(ChessRuleEvaluator.CanPromotePiece(piece1, piece2.pieceType));
    }
    public void CanPromotePieceTypeNoPromotionDisabled()
    {
        ChessRuleEvaluator.currentRuleSet = new ChessRuleSet("Default Rule Set");
        ChessRuleEvaluator.currentRuleSet.promotionEnabled = false;
        ChessPiece piece1 = new Pawn(ChessPiece.PieceColor.WHITE);
        ChessPiece piece2 = new Queen(ChessPiece.PieceColor.WHITE);

        Assert.That(!ChessRuleEvaluator.CanPromotePiece(piece1, piece2.pieceType));
    }
Esempio n. 3
0
    void Update()
    {
        GameController gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>();

        // Update tile highlights
        if (selectedChessPiece != lastSelectedPiece)
        {
            // Clear current highlights
            selectedTileHighlights.ForEach((GameObject h) =>
            {
                GameObject.Destroy(h);
            }
                                           );
            selectedTileHighlights.Clear();
            selectedTileHighlights.ForEach((GameObject h) =>
            {
                GameObject.Destroy(h);
            }
                                           );
            // Add new highlights (if any)
            if (selectedChessPiece != null)
            {
                MovementSet moves = selectedChessPiece.GetMovementSet(board);
                // Standard & capture move highlights
                for (int x = 0; x < board.width; x++)
                {
                    for (int y = 0; y < board.height; y++)
                    {
                        if (moves.movementBitboard[x, y])
                        {
                            GameObject newHighlight = null;
                            if (board.GetChessPieceAt(x, y) == null)
                            {
                                newHighlight = Instantiate(selectedPieceBasicMoveHighlight, boardTilesOrigin.parent, false) as GameObject;
                            }
                            else
                            {
                                newHighlight = Instantiate(selectedPieceCaptureHighlight, boardTilesOrigin.parent, false) as GameObject;
                            }
                            selectedTileHighlights.Add(newHighlight);
                            Vector3 newPos = newHighlight.transform.localPosition;
                            newPos.x += (boardTilesExtent.transform.localPosition - boardTilesOrigin.transform.localPosition).x / 8.0f * x;
                            newPos.z += (boardTilesExtent.transform.localPosition - boardTilesOrigin.transform.localPosition).z / 8.0f * y;
                            newHighlight.transform.localPosition = newPos;
                        }
                    }
                }
                // Special move highlights
                foreach (SpecialMovement special in moves.specialMovements)
                {
                    GameObject newHighlight = Instantiate(selectedPieceSpecialMoveHighlight, boardTilesOrigin.parent, false) as GameObject;
                    selectedTileHighlights.Add(newHighlight);
                    // move over the correct tile
                    Vector3 newPos = newHighlight.transform.localPosition;
                    newPos.x += (boardTilesExtent.transform.localPosition - boardTilesOrigin.transform.localPosition).x / 8.0f * special.targetTile.x;
                    newPos.z += (boardTilesExtent.transform.localPosition - boardTilesOrigin.transform.localPosition).z / 8.0f * special.targetTile.y;
                    newHighlight.transform.localPosition = newPos;
                    if (special.additionalPieceMoved != null)
                    {
                        IntVector2 start = board.GetTileCoordinates(special.additionalPieceMoved);
                        IntVector2 end   = special.additionalPieceMovedTarget;
                        newHighlight = Instantiate(additionalPieceSpecialMoveLine, boardTilesOrigin.parent, false) as GameObject;
                        selectedTileHighlights.Add(newHighlight);
                        additionalPieceSpecialMoveLine.GetComponent <LineRenderer>().SetPositions(new Vector3[] {
                            new Vector3(start.x, 0.0f, start.y),
                            new Vector3(end.x, 0.0f, end.y)
                        });
                    }
                    // TODO highlight eliminated piece
                    // TODO highlight additional moved piece
                }
            }
            lastSelectedPiece = selectedChessPiece;
        }
        // Selection, movement, turn advancement
        if (!(gameController.GetComponent <MainMenuController>().inMainMenu || gameController.GetComponent <PauseMenuController>().isOpen))
        {
            if (Input.GetMouseButtonUp(0))
            {
                GameObject highlighted = gameController.mouse3D.highlighted;
                if (selectedChessPiece == null)
                {
                    if (highlighted != null && highlighted.GetComponent <ChessPieceGUI>() != null)
                    {
                        ChessPiece highlightedPiece = highlighted.GetComponent <ChessPieceGUI>().chessPiece;
                        if (highlightedPiece.pieceColor == gameController.currentTurn && board.IsPieceInPlay(highlightedPiece))
                        {
                            selectedChessPiece = highlightedPiece;
                        }
                    }
                }
                else
                {
                    IntVector2 targetCoords = -IntVector2.one;
                    if (highlighted != null)
                    {
                        if (highlighted.GetComponent <ChessPieceGUI>() != null)
                        {
                            ChessPiece highlightedPiece = highlighted.GetComponent <ChessPieceGUI>().chessPiece;
                            if (highlightedPiece != selectedChessPiece)
                            {
                                if (highlightedPiece.pieceColor == selectedChessPiece.pieceColor)
                                {
                                    selectedChessPiece = highlightedPiece;
                                }
                                else
                                {
                                    targetCoords = board.GetTileCoordinates(highlightedPiece);
                                }
                            }
                        }
                        else if (Object.ReferenceEquals(highlighted.GetComponent <ChessBoardGUI>(), this))
                        {
                            targetCoords = GetBoardTileCoordinates(gameController.mouse3D.transform.position);
                        }
                        if (ChessRuleEvaluator.CanMovePiece(selectedChessPiece, targetCoords, board))
                        {
                            board.MovePiece(selectedChessPiece, targetCoords);
                            selectedChessPiece = null;
                            gameController.StartNextTurn();
                        }
                    }
                    else
                    {
                        selectedChessPiece = null;
                    }
                }
            }
        }
    }