Example #1
0
        public Material GetMaterial(PieceScript.Type pieceType, PieceScript.Team team)
        {
            switch (pieceType)
            {
            case PieceScript.Type.Pawn:
                return(team == PieceScript.Team.White ? white_pawn : black_pawn);

            case PieceScript.Type.Rook:
                return(team == PieceScript.Team.White ? white_rook : black_rook);

            case PieceScript.Type.Bishop:
                return(team == PieceScript.Team.White ? white_bishop : black_bishop);

            case PieceScript.Type.Knight:
                return(team == PieceScript.Team.White ? white_knight : black_knight);

            case PieceScript.Type.Queen:
                return(team == PieceScript.Team.White ? white_queen : black_queen);

            case PieceScript.Type.King:
                return(team == PieceScript.Team.White ? white_king : black_king);

            case PieceScript.Type.BLOCK:
                return(BLOCK);

            default:
                return(null);
            }
        }
    /// <summary>
    /// Spawn a piece and put it on the square
    /// </summary>
    /// <param name="type"> which type of piece should be spawned </param>
    /// <param name="team"> which team the spawned piece should be on </param>
    public void SpawnPiece(PieceScript.Type type, PieceScript.Team team)
    {
        GameObject startingPiece = GameObject.Instantiate(GameManager.Instance.basePiecePrefab, new Vector3(position.x, position.y, -1), Quaternion.Euler(0, 0, 180));

        linkedPiece = startingPiece.GetComponent <PieceScript>();
        linkedPiece.SetSquare(this);
        linkedPiece.name = (team + " " + type);
        linkedPiece.type = type;
        linkedPiece.team = team;
        linkedPiece.SetMaterial(type, team);
        BoardManager.Instance.RegisterPiece(linkedPiece);
    }
Example #3
0
    /// <summary>
    /// Moves a piece to another place on the board
    /// </summary>
    /// <param name="oldBoard"> the board before the piece is moved </param>
    /// <param name="pieceToMove"> the piece to be moved on the board </param>
    /// <param name="squareToMoveTo"> yhe square to move the piece to </param>
    public Move(char[] oldBoard, int pieceToMove, int squareToMoveTo)
    {
        from = pieceToMove;
        to   = squareToMoveTo;

        newBoard = new char[oldBoard.Length];


        for (int i = 0; i < newBoard.Length; i++)
        {
            if (i == squareToMoveTo)
            {
                //moves piece to new place
                newBoard[i] = oldBoard[pieceToMove];
            }
            else
            {
                //Just copy it over
                newBoard[i] = oldBoard[i];
            }
        }

        //Enpassant check
        if (to == BoardManager.Instance.enPassentIndex && char.ToUpper(oldBoard[from]) == 'P')
        {
            if (from > to && to + 8 < newBoard.Length)
            {
                //Moving downward
                newBoard[to + 8] = '\0';
                enpassentIndex   = to + 8;
            }
            else if (to - 8 >= 0)
            {
                //Moving upward
                newBoard[to - 8] = '\0';
                enpassentIndex   = to - 8;
            }
        }

        //Promotion Check
        if ((char.ToUpper(movedPiece) == 'P') && (to > 55 || to < 8))
        {
            //Promoted
            if (TurnManager.Instance.IsPlayerTurn())
            {
                //Prompt player for which piece they want
            }
            else
            {
                //Choose queen, as statistcally it is the best choice
                newBoard[to]  = (GameManager.Instance.playerTeam == PieceScript.Team.White) ? 'q' : 'Q';
                promotionType = PieceScript.Type.Queen;
            }
        }

        //Remove old piece
        newBoard[pieceToMove] = '\0';


        //Set Self Fitness
        self_fitness = FitnessEvaluator.Evaluate(newBoard);

        pathFitness = self_fitness;
    }