예제 #1
0
파일: TankLogic.cs 프로젝트: bjowes/cwg
        //Called every time player is supposed to calculate a new move.
        //The player has 1 second to calculate the move and call setJoystick.
        public void MakeMove(Consoden.TankGame.GameState gameState)
        {
            //TODO: implement your own tank logic and call setJoystick

            //-------------------------------------------------------
            //Example of a stupid tank logic:
            //Remove it and write your own brilliant version!
            //-------------------------------------------------------
            GameMap gm = new GameMap (tankId, gameState); //helpler object
            Bfs bfs=new Bfs(gameState, gm.OwnPosition); //breadth first search
            Consoden.TankGame.Direction.Enumeration moveDirection = Consoden.TankGame.Direction.Enumeration.Neutral;

            if (bfs.CanReachSquare (gm.EnemyPosition)) { //if we can reach the enemy, get him
                moveDirection = bfs.BacktrackFromSquare (gm.EnemyPosition);
            }
            else { //find any empty square
                if (!gm.IsWall (gm.Move (gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Left)) &&
                    !gm.IsMine (gm.Move (gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Left))) {
                    moveDirection = Consoden.TankGame.Direction.Enumeration.Left;
                } else if (!gm.IsWall (gm.Move (gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Right)) &&
                    !gm.IsMine (gm.Move (gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Right))) {
                    moveDirection = Consoden.TankGame.Direction.Enumeration.Right;
                } else if (!gm.IsWall (gm.Move (gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Up)) &&
                    !gm.IsMine (gm.Move (gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Up))) {
                    moveDirection = Consoden.TankGame.Direction.Enumeration.Up;
                } else if (!gm.IsWall (gm.Move (gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Down)) &&
                    !gm.IsMine (gm.Move (gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Down))) {
                    moveDirection = Consoden.TankGame.Direction.Enumeration.Down;
                }
            }

            //Advanced tower aim stategy
            Consoden.TankGame.Direction.Enumeration towerDirection =
                (Consoden.TankGame.Direction.Enumeration)((1 + gm.OwnPosition.X + gm.OwnPosition.Y) % 4);

            //Of course we always want to fire
            bool fire = true;

            //Sometimes we also drop a mine
            bool dropMine=((int)(gameState.ElapsedTime.Val) % 3)==0;

            bool fireLaser = false;
            if(gm.getLaserCount > 0 ){
                fireLaser = true;
            }

            bool deploySmoke = false;
            if(gm.HasSmoke){
                deploySmoke = true;
            }

            bool fireRedeemer = false;
            int redeemerTimer = 0;
            if(gm.HasRedeemer){
                fireRedeemer = true;
                redeemerTimer = 3;
            }

            //Move our joystick.
            setJoystick (moveDirection, towerDirection, fire,dropMine,fireLaser,deploySmoke, fireRedeemer, redeemerTimer);
        }
예제 #2
0
        //Called every time player is supposed to calculate a new move.
        //The player has 1 second to calculate the move and call setJoystick.
        public void MakeMove(Consoden.TankGame.GameState gameState)
        {
            //TODO: implement your own tank logic and call setJoystick

            //-------------------------------------------------------
            //Example of a stupid tank logic:
            //Remove it and write your own brilliant version!
            //-------------------------------------------------------
            GameMap gm  = new GameMap(tankId, gameState);           //helpler object
            Bfs     bfs = new Bfs(gameState, gm.OwnPosition);       //breadth first search

            Consoden.TankGame.Direction.Enumeration moveDirection = Consoden.TankGame.Direction.Enumeration.Neutral;

            if (bfs.CanReachSquare(gm.EnemyPosition))                //if we can reach the enemy, get him
            {
                moveDirection = bfs.BacktrackFromSquare(gm.EnemyPosition);
            }
            else               //find any empty square
            {
                if (!gm.IsWall(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Left)) &&
                    !gm.IsMine(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Left)))
                {
                    moveDirection = Consoden.TankGame.Direction.Enumeration.Left;
                }
                else if (!gm.IsWall(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Right)) &&
                         !gm.IsMine(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Right)))
                {
                    moveDirection = Consoden.TankGame.Direction.Enumeration.Right;
                }
                else if (!gm.IsWall(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Up)) &&
                         !gm.IsMine(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Up)))
                {
                    moveDirection = Consoden.TankGame.Direction.Enumeration.Up;
                }
                else if (!gm.IsWall(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Down)) &&
                         !gm.IsMine(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Down)))
                {
                    moveDirection = Consoden.TankGame.Direction.Enumeration.Down;
                }
            }

            //Advanced tower aim stategy
            Consoden.TankGame.Direction.Enumeration towerDirection =
                (Consoden.TankGame.Direction.Enumeration)((1 + gm.OwnPosition.X + gm.OwnPosition.Y) % 4);

            //Of course we always want to fire
            bool fire = true;

            //Sometimes we also drop a mine
            bool dropMine = ((int)(gameState.ElapsedTime.Val) % 3) == 0;

            bool fireLaser = false;

            if (gm.getLaserCount > 0)
            {
                fireLaser = true;
            }

            bool deploySmoke = false;

            if (gm.HasSmoke)
            {
                deploySmoke = true;
            }

            bool fireRedeemer  = false;
            int  redeemerTimer = 0;

            if (gm.HasRedeemer)
            {
                fireRedeemer  = true;
                redeemerTimer = 3;
            }

            //Move our joystick.
            setJoystick(moveDirection, towerDirection, fire, dropMine, fireLaser, deploySmoke, fireRedeemer, redeemerTimer);
        }