Exemplo n.º 1
0
        private Vector2Int FindClosestOnSide(bool ally)
        {
            GameBoard  gb         = GameManager.Instance.MyGameBoard;
            Vector2Int myPosition = gb.GetTileEntityPosition(this);
            Tile       myTile     = gb.GetTile(this);

            TileEntity[] tileEntities = GameObject.FindObjectsOfType <TileEntity>();
            float        closest      = float.MaxValue;

            // Default to moving around where you are
            Vector2Int ret = myPosition;

            for (int i = 0; i < tileEntities.Length; ++i)
            {
                Vector2Int pos  = gb.GetTileEntityPosition(tileEntities[i]);
                float      dist = Vector2Int.Distance(myPosition, pos);

                if (tileEntities[i] == this)
                {
                    continue;
                }
                if (dist < closest)
                {
                    if (
                        (ally && myTile.GetSide() == gb.GetTile(tileEntities[i]).GetSide()) ||
                        (!ally && myTile.GetSide() != gb.GetTile(tileEntities[i]).GetSide())
                        )
                    {
                        ret = pos;
                    }
                }
            }

            return(ret);
        }
Exemplo n.º 2
0
        // returns the entity which was shot (null if nothing was shot)
        public bool DoShoot()
        {
            GameBoard  board          = GameManager.Instance.MyGameBoard;
            Vector2Int entityPosition = board.GetTileEntityPosition(this.parentEntity);
            Tile       entityTile     = board.GetTile(this.parentEntity);
            // If on left side, shoot right. Otherwise if on right side, shoot left
            Vector3 bulletDirection     = Tile.SIDE.LEFT.Equals(entityTile.GetSide()) ? new Vector3(1, 0, 0) : new Vector3(-1, 0, 0);
            Vector3 bulletSpawnPosition = this.parentEntity.transform.position + bulletDirection.normalized * 2;

            GameManager.Instance.SpawnStupidPhotonProjectile("BlasterBullet", bulletSpawnPosition, Quaternion.identity, bulletDirection, 50f, 1);
            //Vector2Int pos = entityPosition + direction;
            //for (int i = 0; i < this.shootRange && board.IsOnBoard(pos); ++i)
            //{
            //    Tile newTile = board.GetTile(pos);

            //    if (!newTile.GetSide().Equals(entityTile.GetSide()) &&
            //        newTile.GetEntities() != null && newTile.GetEntities().Count > 0)
            //    {
            //        // Tell GameBoard to damage everything in square
            //        foreach (TileEntity e in newTile.GetEntities())
            //        {
            //            board.DoDamageToTileEntity(e, this.baseDamage);
            //        }
            //        return true;
            //    }
            //    pos += direction;
            //}
            Debug.Log(this.parentEntity.GetName() + " did not shoot anything ");
            return(false);
        }
Exemplo n.º 3
0
        protected Tile GetTile()
        {
            Vector2Int pos        = gameBoard.GetTileEntityPosition(this);
            Tile       entityTile = gameBoard.GetTile(pos.x, pos.y);

            return(entityTile);
        }
Exemplo n.º 4
0
        /***
         * Make it more likely to move in a direction which is
         * close to an opposing enemy, and less likely to move
         * near an ally. This is a turret, so moving up and down
         * will always have the same probability for now.
         * */
        protected void ProbabilityUpdatePolicy()
        {
            GameBoard  gb         = GameManager.Instance.MyGameBoard;
            Vector2Int myPosition = gb.GetTileEntityPosition(this);
            Vector2Int target     = FindClosestFoe();
            Vector2Int ally       = FindClosestAlly();

            if (target.Equals(myPosition))
            {
                // no preference
                AssignRandomProbability();
                return;
            }


            double upPenalty    = sigmoid(Math.Abs((myPosition.x - target.x)) * (myPosition.x - target.x));
            double downPenalty  = 1 - upPenalty;
            double leftPenalty  = (upPenalty + downPenalty) / 2;; //sigmoid(Math.Abs((myPosition.y - target.y)) * (myPosition.y - target.y));
            double rightPenalty = (upPenalty + downPenalty) / 2;; //1 - leftPenalty;

            directionWeights[DIRS.UP]    = upPenalty;
            directionWeights[DIRS.DOWN]  = downPenalty;
            directionWeights[DIRS.LEFT]  = leftPenalty;
            directionWeights[DIRS.RIGHT] = rightPenalty;

            // Update weights based on ally distance
            double downAward  = sigmoid(Math.Abs((myPosition.x - ally.x)) * (myPosition.x - ally.x));
            double upAward    = 1 - downAward;
            double rightAward = (downAward + upAward) / 2; //sigmoid(Math.Abs((myPosition.y - ally.y)) * (myPosition.y - ally.y));
            double leftAward  = (downAward + upAward) / 2; //1 - rightAward;

            directionWeights[DIRS.UP]    += upAward;
            directionWeights[DIRS.DOWN]  += downAward;
            directionWeights[DIRS.LEFT]  += leftAward;
            directionWeights[DIRS.RIGHT] += rightAward;

            /*if (!gb.IsOnBoard(TileEntityConstants.DirectionVectors.UP + myPosition) )
             * {
             *  directionWeights[DIRS.UP] = 0;
             * }
             * if (!gb.IsOnBoard(TileEntityConstants.DirectionVectors.DOWN + myPosition))
             * {
             *  directionWeights[DIRS.DOWN] = 0;
             * }
             * if (!gb.IsOnBoard(TileEntityConstants.DirectionVectors.LEFT + myPosition))
             * {
             *  directionWeights[DIRS.LEFT] = 0;
             * }
             * if (!gb.IsOnBoard(TileEntityConstants.DirectionVectors.RIGHT + myPosition))
             * {
             *  directionWeights[DIRS.RIGHT] = 0;
             * }*/
            normWeights();
        }