Exemple #1
0
    private void OnTrackingFound()
    {
        Renderer[] rendererComponents = GetComponentsInChildren <Renderer>(true);
        Collider[] colliderComponents = GetComponentsInChildren <Collider>(true);

        // Enable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = true;
        }

        // Enable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = true;
        }

        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");

        MarkerBehaviour markerBehaviour = GetComponent <MarkerBehaviour>();

        if (markerBehaviour)
        {
            MonAgent.SetLastFoundMonID(markerBehaviour.Marker.MarkerID);
            StateAgent.ChangeState(StateAgent.State.Playing);
        }
    }
    void Awake()
    {
        if( mInstance != null )
        {
            Debug.LogError( string.Format( "Only one instance of StateAgent allowed! Destroying:" + gameObject.name +", Other:" + mInstance.gameObject.name ) );
            Destroy( gameObject );
            return;
        }

        mInstance = this;
    }
Exemple #3
0
    void Awake()
    {
        if (mInstance != null)
        {
            Debug.LogError(string.Format("Only one instance of StateAgent allowed! Destroying:" + gameObject.name + ", Other:" + mInstance.gameObject.name));
            Destroy(gameObject);
            return;
        }

        mInstance = this;
    }
Exemple #4
0
    private void OnTriggerEnter(Collider other)
    {
        SearchAgent searchAgent = other.GetComponent <SearchAgent>();

        if (searchAgent && (searchAgent.waypoint == this || searchAgent.waypoint == null))
        {
            searchAgent.waypoint = m_nextWaypoint;
        }
        StateAgent stateAgent = other.GetComponent <StateAgent>();

        if (stateAgent && (stateAgent.waypoint == this || stateAgent.waypoint == null))
        {
            stateAgent.waypoint = m_nextWaypoint;
        }
    }
Exemple #5
0
    void Awake()
    {
        if (mInstance != null)
        {
            Debug.LogError(string.Format("Only one instance of StateAgent allowed! Destroying:" + gameObject.name + ", Other:" + mInstance.gameObject.name));
            Destroy(gameObject);
            return;
        }

        mInstance = this;

        startTask   = new Task(TaskType.Start, KeyCode.T, startClips, startImage, Mathf.Infinity);
        successTask = new Task(TaskType.Success, KeyCode.None, successClips, successImage, 1f);
        endLoseTask = new Task(TaskType.EndLose, KeyCode.T, endLoseClips, endLoseImage, Mathf.Infinity);
        endWinTask  = new Task(TaskType.EndWin, KeyCode.T, endWinClips, endWinImage, Mathf.Infinity);

        possibleTasks = new List <Task>();

        possibleTasks.Add(new Task(TaskType.CPR, KeyCode.C, cprClips, cprImage, failTime));
        possibleTasks.Add(new Task(TaskType.PrecordialThump, KeyCode.T, precordialThumpClips, precordialThumpImage, failTime));
        possibleTasks.Add(new Task(TaskType.Pulse, KeyCode.P, pulseClips, pulseImage, failTime));
    }
Exemple #6
0
    private IEnumerator DoBattle()
    {
        yield return(new WaitForSeconds(3f));

        if (currentMon.currentTypeType == MonAgent.TypeType.Invalid)
        {
            currentMon = new MonAgent.Mon(newMon.currentTypeType, newMon.currentAttack1Type, newMon.currentAttack2Type);
        }
        else
        {
            int randomValue = Mathf.FloorToInt(Random.value * 3f);

            switch (randomValue)
            {
            case 0: currentMon = new MonAgent.Mon(MonAgent.GetComboTypeType(newMon.currentTypeType, currentMon.currentTypeType), currentMon.currentAttack1Type, currentMon.currentAttack2Type); break;

            case 1: currentMon = new MonAgent.Mon(currentMon.currentTypeType, newMon.currentAttack1Type, currentMon.currentAttack2Type); break;

            case 2: currentMon = new MonAgent.Mon(currentMon.currentTypeType, currentMon.currentAttack1Type, newMon.currentAttack2Type); break;
            }
        }

        currentMonString = currentMon.ToString();

        MonAgent.SetCurrentMonID(MonAgent.IDFromMon(currentMon));
        MonAgent.SetLastFoundMonID(-1);

        yield return(new WaitForSeconds(1f));

        newMonString = "";
        vsString     = "";

        yield return(new WaitForSeconds(3f));

        StateAgent.ChangeState(StateAgent.State.Showing);
    }
Exemple #7
0
    public void UpdateAI()
    {
        if (grid == null)
        {
            grid = GameObject.FindObjectOfType <Grid>();
        }

        if (myTurn && !didTurn)
        {
            didTurn = true;

            State boardState = GetBoardState();

            Debug.Log("State visited counter: " + boardState.TimesVisited);

            if (brain == null)
            {
                brain = new StateAgent(boardState);
            }
            else
            {
                brain.SetState(boardState);
            }

            //get action from brain, execute.

            StateAction action = brain.GetChosenActionForCurrentState();

            string[] moves = Regex.Split(action.ActionString, "to");
            string[] from  = Regex.Split(moves[0], "-");
            string[] to    = Regex.Split(moves[1], "-");

            Debug.Log(action.ActionString + ", Quality: " + action.GetDeepEvaluation() + " (" + action.ActionEvaluation + ") --- " + brain.LearnedStates + "///" + brain.EvaluatedActions);

            if (action.GetDeepEvaluation() != action.ActionEvaluation)
            {
                Debug.Log("///////////////////////////////////////////////////////////////");
            }

            foreach (Node n in grid.grid)
            {
                n.UnhighlightEat();
                n.UnhighlightMove();
            }

            Node fromNode = grid.GetNodeAt(int.Parse(from[1]), int.Parse(from[0]));
            Node toNode   = grid.GetNodeAt(int.Parse(to[1]), int.Parse(to[0]));

            fromNode.HighlightMove();
            toNode.HighlightEat();

            piece = fromNode.Piece;
            piece.Pickup();
            GameManager.Instance.GameState.Grab();
            int reward = 0;

            Piece tPiece = toNode.Piece;
            if (tPiece == null)
            {
                if (piece.IsPossibleMove(toNode))
                {
                    if (Rules.IsCheckMove(this, piece, toNode, true))
                    {
                        Debug.Log("Move checked, not allowed"); // do nothing

                        brain.EvaluateLastAction(-10000);
                        GameManager.Instance.GameState.Checkmate();
                        GameManager.Instance.GameOver(GameManager.Instance.PlayerOponent, GameOverType.CHECKMATE);
                    }
                    else
                    {
                        piece.MoveToXZ(toNode, Drop);
                        GameManager.Instance.GameState.Place();
                    }
                }
            }
            else
            {
                if (piece.IsPossibleEat(toNode))
                {
                    if (Rules.IsCheckEat(this, piece, toNode, true))
                    {
                        Debug.Log("Eat checked"); // do nothing

                        brain.EvaluateLastAction(-10000);
                        GameManager.Instance.GameState.Checkmate();
                        GameManager.Instance.GameOver(GameManager.Instance.PlayerOponent, GameOverType.CHECKMATE);
                    }
                    else
                    {
                        GCPlayer oppPlayer = GameManager.Instance.Opponent(this);

                        oppPlayer.brain.EvaluateLastAction(-tPiece.GetPieceValue());
                        reward = tPiece.GetPieceValue();

                        oppPlayer.RemovePiece(tPiece);
                        AddEatenPieces(tPiece);
                        tPiece.ScaleOut(0.2f, 1.5f);
                        piece.MoveToXZ(toNode, Drop);
                        GameManager.Instance.GameState.Place();
                    }
                }
            }

            State newState = GetBoardState();

            brain.PerformStateAction(action, newState);
            brain.EvaluateLastAction(reward);
        }
    }