Exemplo n.º 1
0
    // sets up the board with the given puzzle
    private void SetupChessPuzzle()
    {
        activePieces = new List <GameObject>();
        chessPieces  = new ChessPiece[8, 8];

        // Retrieve new puzzle
        HttpClient hc           = new HttpClient();
        Puzzle     ActivePuzzle = hc.retrieveRandomPuzzle();

        if (ActivePuzzle == null)
        {
            // TODO: Show error
            Debug.Log("Error: Geen verbinding met API");
            return;
        }

        FenParser.FenParser parser = new FenParser.FenParser(ActivePuzzle.FenBefore);
        isPlayerWhite = parser.BoardStateData.ActivePlayerColor.ToLower() == "white" ? false : true; // First turn is computer
        isWhiteTurn   = parser.BoardStateData.ActivePlayerColor.ToLower() == "white" ? true : false;
        currentMoves  = ActivePuzzle.ForcedLine;
        currentMoves.Insert(0, ActivePuzzle.BlunderMove);
        Debug.Log(String.Join(", ", currentMoves.ToArray()));


        moveColor      = GameObject.Find("MoveColor").GetComponent <Text>();
        moveColor.text = isPlayerWhite ? "White to move" : "Black to move";

        for (int i = 0; i < 8; i++)
        {
            string[] currentRank = parser.BoardStateData.Ranks[7 - i];
            for (int j = 0; j < 8; j++)
            {
                switch (currentRank[j].ToString())
                {
                case "P":
                    // white pawn
                    SpawnChessPiece(5, j, i);
                    break;

                case "N":
                    // white knight
                    SpawnChessPiece(4, j, i);
                    break;

                case "B":
                    // white bishop
                    SpawnChessPiece(3, j, i);
                    break;

                case "R":
                    // white rook
                    SpawnChessPiece(2, j, i);
                    break;

                case "Q":
                    // white queen
                    SpawnChessPiece(1, j, i);
                    break;

                case "K":
                    // white king
                    SpawnChessPiece(0, j, i);
                    break;

                // BLACK PIECES
                case "p":
                    // black pawn
                    SpawnChessPiece(11, j, i);
                    break;

                case "n":
                    // black knight
                    SpawnChessPiece(10, j, i);
                    break;

                case "b":
                    // black bishop
                    SpawnChessPiece(9, j, i);
                    break;

                case "r":
                    // black rook
                    SpawnChessPiece(8, j, i);
                    break;

                case "q":
                    // black queen
                    SpawnChessPiece(7, j, i);
                    break;

                case "k":
                    // black king
                    SpawnChessPiece(6, j, i);
                    break;
                }
            }
        }
    }
Exemplo n.º 2
0
    void updatePositions()
    {
        int indBPawn  = 0;
        int indWPawn  = 0;
        int indBTower = 0;
        int indWTower = 0;
        int indBHorse = 0;
        int indWHorse = 0;
        int indBBshop = 0;
        int indWBshop = 0;
        int indWKing  = 0;
        int indBKing  = 0;
        int indWQueen = 0;
        int indBQueen = 0;

        FenParser.FenParser parser = new FenParser.FenParser(fen);
        string[][]          test   = parser.BoardStateData.Ranks;
        for (int i = 0; i < test.Length; i++)
        {
            for (int j = 0; j < test.Length; j++)
            {
                switch (test[i][j])
                {
                case "P":
                {
                    WPawns[indWPawn++].transform.position = getPosition(i, j);
                    break;
                }

                case "p":
                {
                    BPawns[indBPawn++].transform.position = getPosition(i, j);
                    break;
                }

                case "R":
                {
                    WTower[indWTower++].transform.position = getPosition(i, j);
                    break;
                }

                case "r":
                {
                    BTower[indBTower++].transform.position = getPosition(i, j);
                    break;
                }

                case "n":
                {
                    BHorse[indBHorse++].transform.position = getPosition(i, j);
                    break;
                }

                case "N":
                {
                    WHorse[indWHorse++].transform.position = getPosition(i, j);
                    break;
                }

                case "b":
                {
                    BBishop[indBBshop++].transform.position = getPosition(i, j);
                    break;
                }

                case "B":
                {
                    WBishop[indWBshop++].transform.position = getPosition(i, j);
                    break;
                }

                case "k":
                {
                    BKing[indBKing++].transform.position = getPosition(i, j);
                    break;
                }

                case "K":
                {
                    WKing[indWKing++].transform.position = getPosition(i, j);
                    break;
                }

                case "q":
                {
                    BQueen[indBQueen++].transform.position = getPosition(i, j);
                    break;
                }

                case "Q":
                {
                    WQueen[indWQueen++].transform.position = getPosition(i, j);
                    break;
                }
                }
            }
        }
        for (int i = indWPawn; i < WPawns.Length; i++)
        {
            Destroy(WPawns[i]);
        }
        for (int i = indBPawn; i < BPawns.Length; i++)
        {
            Destroy(BPawns[i]);
        }
        for (int i = indWTower; i < WTower.Length; i++)
        {
            Destroy(WTower[i]);
        }
        for (int i = indBTower; i < BTower.Length; i++)
        {
            Destroy(BTower[i]);
        }
        for (int i = indWHorse; i < WHorse.Length; i++)
        {
            Destroy(WHorse[i]);
        }
        for (int i = indBHorse; i < BHorse.Length; i++)
        {
            Destroy(BHorse[i]);
        }
        for (int i = indWBshop; i < WBishop.Length; i++)
        {
            Destroy(WBishop[i]);
        }
        for (int i = indBBshop; i < BBishop.Length; i++)
        {
            Destroy(BBishop[i]);
        }
        for (int i = indWKing; i < WKing.Length; i++)
        {
            Destroy(WKing[i]);
        }
        for (int i = indBKing; i < BKing.Length; i++)
        {
            Destroy(BKing[i]);
        }
        for (int i = indBQueen; i < BQueen.Length; i++)
        {
            Destroy(BQueen[i]);
        }
        for (int i = indWQueen; i < WQueen.Length; i++)
        {
            Destroy(WQueen[i]);
        }
        parsing = true;
        fen     = "";
    }