Example #1
0
File: Bfs.cs Project: bjowes/cwg
        //Create a bfs graph based on startPos.
        public Bfs(Consoden.TankGame.GameState gameState, Position startPos)
        {
            this.gameState=gameState;
            this.startPos = startPos;

            gamePaths = new int[SizeX, SizeY];
            for (int x=0; x<SizeX; x++) {
                for (int y=0; y<SizeY; y++) {
                    gamePaths [x, y] = int.MaxValue;
                }
            }

            gamePaths [startPos.X, startPos.Y] = 0;
            EvaluateShortestPaths (startPos, 1);
        }
Example #2
0
 //Constructor, creates a new GameMap from a GameState.
 public GameMap(int tankId, Consoden.TankGame.GameState gameState)
 {
     this.tankId=tankId;
     this.gameState=gameState;
 }
Example #3
0
 //Move p one step in specified direction and returns the new position.
 public Position Move(Position p, Consoden.TankGame.Direction.Enumeration d)
 {
     switch (d) {
     case Consoden.TankGame.Direction.Enumeration.Left:
         return new Position ((p.X - 1 + SizeX) % SizeX, p.Y);
     case Consoden.TankGame.Direction.Enumeration.Right:
         return new Position ((p.X + 1) % SizeX, p.Y);
     case Consoden.TankGame.Direction.Enumeration.Up:
         return new Position (p.X, (p.Y - 1 + SizeY) % SizeY);
     case Consoden.TankGame.Direction.Enumeration.Down:
         return new Position (p.X, (p.Y + 1) % SizeY);
     default:
         return p;
     }
 }
Example #4
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);
        }
Example #5
0
File: Player.cs Project: bjowes/cwg
        private void UpdateJoystick(Consoden.TankGame.Direction.Enumeration moveDirection,
		                            Consoden.TankGame.Direction.Enumeration towerDirection,
		                            bool fire, bool dropMine, bool fireLaser, bool deployLaser,
		                            bool fireRedeemer, int redeemerTimer)
        {
            if (myJoystickId == null) {
                return; //we are not active in a game
            }

            Consoden.TankGame.Joystick joystick = new Consoden.TankGame.Joystick ();
            joystick.PlayerId.Val = myPlayerId;
            joystick.GameId.Val = currentGameId;
            joystick.TankId.Val = myTankId;
            joystick.Counter.Val = joystickCounter++;
            joystick.MoveDirection.Val = moveDirection;
            joystick.TowerDirection.Val = towerDirection;
            joystick.Fire.Val = fire;
            joystick.FireLaser.Val = fireLaser;
            joystick.MineDrop.Val = dropMine;
            joystick.DeploySmoke.Val = deployLaser;
            joystick.FireRedeemer.Val = fireRedeemer;
            joystick.RedeemerTimer.Val = redeemerTimer;
            connection.SetAll (joystick, myJoystickId, myHandlerId);
        }