Esempio n. 1
0
    private Movement SortCandidate()
    {
        Control.UpdateValues();
        IAPiece    candidate    = Control.iAPieces[UnityEngine.Random.Range(0, Control.iAPieces.Length)];
        Directions dirCandidate = Directions.NULL;

        foreach (Directions direction in allDirections)
        {
            if (candidate.IsThereAPossibleMove(direction).isPossible)
            {
                dirCandidate = direction;
                break;
            }
        }

        if (dirCandidate == Directions.NULL)
        {
            return(SortCandidate());
        }

        Movement move = new Movement
        {
            direction = dirCandidate,
            piece     = candidate
        };

        return(move);
    }
Esempio n. 2
0
    private Movement KillerPiece()
    {
        Control.UpdateValues();
        Directions _direction = Directions.NULL;
        IAPiece    killer     = null;//inDangerPiece();

        foreach (IAPiece piece in Control.iAPieces)
        {
            foreach (Directions direction in allDirections)
            {
                if (piece.IsThereSomeoneToKill(direction))
                {
                    killer     = piece;
                    _direction = direction;
                    break;
                }
            }
            if (killer)
            {
                break;
            }
        }
        Movement move = new Movement
        {
            direction = _direction,
            piece     = killer
        };

        return(move);
    }
Esempio n. 3
0
    void myCallBack(bool validmove)
    {
        Control.UpdateValues();
        sorted = null;

        if (!validmove)
        {
            wait = false;
        }
        else
        {
            Move();
        }
    }
Esempio n. 4
0
    void Move()
    {
        if (Control.Token == Turn.Player)
        {
            wait = false;
        }

        if (!wait && Control.Token == Turn.IA)
        {
            wait = true;
            Vector3 intense = Vector3.zero;
            Control.UpdateValues();
            if (Control.iAPieces.Length <= 0)
            {
                Control.UpdateValues();
                return;
            }

            if (sorted == null)
            {
                Movement killer = KillerPiece();
                dir    = killer.direction;
                sorted = killer.piece;
            }

            if (sorted == null)
            {
                Movement notKiller = SortCandidate();
                sorted = notKiller.piece;
                dir    = notKiller.direction;
            }

            StartCoroutine(MovePart(sorted, dir, intense));
            sorted = null;
        }
    }
Esempio n. 5
0
    IEnumerator MovePart(IAPiece piece, Directions direction, Vector3 intense)
    {
        yield return(new WaitForSeconds(0.5f));

        piece.EnableIA(iaCall, updateCallBack, direction, intense);
    }