Exemple #1
0
    public IEnumerator WaitForTurn(string lastTile, string onDeckPiece)
    {
        string[,] board = GameCoreController.Instance.GetBoard();
        string[]   newBoard = new string[board.Length];
        AI.Piece[] pieces   = new AI.Piece[GameCoreController.Instance.PieceNumberMap.Count];


        int newBoardCounter = 0;

        for (int i = 0; i < board.GetLength(0); i++)
        {
            for (int j = 0; j < board.GetLength(1); j++)
            {
                newBoard[newBoardCounter] = board[i, j] == EMPTYSLOT ? null : board[i, j];
                newBoardCounter++;
            }
        }
        intitializeAiPieceList(GameCoreController.Instance.GetPlayablePiecesList(), ref pieces, GameCoreController.Instance.PieceNumberMap);

        AI.moveData moveData = quartoAI.generateTree(2, newBoard, GameCoreController.Instance.PieceNumberMap[onDeckPiece], pieces);
        NextMove.OnDeckPiece = moveData.pieceToPlay;
        NextMove.Tile        = moveData.lastMoveOnBoard;

        return(null);
    }
Exemple #2
0
    public IEnumerator AIThreadProcedure()
    {
        Debug.Log("AI thread is running...");
        float startTime = Time.deltaTime;

        string[,] board = GameCoreController.Instance.GetBoard();
        string[]   newBoard = new string[board.Length];
        AI.Piece[] pieces   = new AI.Piece[GameCoreController.Instance.PieceNumberMap.Count];

        int newBoardCounter = 0;

        for (int i = 0; i < board.GetLength(0); i++)
        {
            for (int j = 0; j < board.GetLength(1); j++)
            {
                newBoard[newBoardCounter] = board[i, j] == EMPTYSLOT ? null : board[i, j];
                newBoardCounter++;
            }
        }

        intitializeAiPieceList(GameCoreController.Instance.GetPlayablePiecesList(), ref pieces, GameCoreController.Instance.PieceNumberMap);

        string onDeckPiece = GameCoreController.Instance.OnDeckPiece;
        int    pieceToFind = GameCoreController.Instance.PieceNumberMap[onDeckPiece];

        Task <AI.moveData> AITask = Task.Run(() => quartoAI.generateTree(newBoard, pieceToFind, pieces, difficulty));

        while (AITask.Status != TaskStatus.RanToCompletion)
        {
            yield return(null);
        }

        if (Time.deltaTime - startTime < 1.0f)
        {
            yield return(new WaitForSeconds(1));
        }

        AIMoveData = AITask.Result;
    }