示例#1
0
文件: Player.cs 项目: bjowes/cwg
        public void OnNewEntity(Safir.Dob.EntityProxy entityProxy)
        {
            Consoden.TankGame.GameState gameState = entityProxy.Entity as Consoden.TankGame.GameState;
            if (gameState == null)
            {
                return;
            }

            for (int i = 0; i < gameState.Tanks.Count; i++)
            {
                if (!gameState.Tanks [i].IsNull())
                {
                    Consoden.TankGame.Tank tank = gameState.Tanks [i].Obj;
                    if (tank.PlayerId.Val == myPlayerId)
                    {
                        currentGameId = entityProxy.InstanceId;
                        myTankId      = tank.TankId.Val;
                        myJoystickId  = InstanceId.GenerateRandom();

                        Consoden.TankGame.Joystick joystick = new Consoden.TankGame.Joystick();
                        joystickCounter       = 0;
                        joystick.PlayerId.Val = myPlayerId;
                        joystick.GameId.Val   = currentGameId;
                        joystick.TankId.Val   = myTankId;
                        joystick.Counter.Val  = joystickCounter++;
                        connection.SetAll(joystick, myJoystickId, myHandlerId);
                        logic = new TankLogic(myTankId, UpdateJoystick);
                        break;
                    }
                }
            }
        }
示例#2
0
文件: Bfs.cs 项目: 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);
        }
示例#3
0
        //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);
        }
示例#4
0
文件: Player.cs 项目: bjowes/cwg
 public void OnUpdatedEntity(Safir.Dob.EntityProxy entityProxy)
 {
     if (entityProxy.TypeId == Consoden.TankGame.GameState.ClassTypeId &&
         entityProxy.InstanceId == currentGameId && logic != null)
     {
         Consoden.TankGame.GameState gs = (Consoden.TankGame.GameState)entityProxy.Entity;
         if (gs.Winner.Val == Consoden.TankGame.Winner.Enumeration.Unknown)
         {
             try
             {
                 logic.MakeMove((Consoden.TankGame.GameState)entityProxy.Entity);
             }
             catch
             {
                 Console.WriteLine("Caught unhandled exception in TankLogic!");
             }
         }
     }
 }
示例#5
0
文件: GameMap.cs 项目: bjowes/cwg
 //Constructor, creates a new GameMap from a GameState.
 public GameMap(int tankId, Consoden.TankGame.GameState gameState)
 {
     this.tankId=tankId;
     this.gameState=gameState;
 }
示例#6
0
文件: GameMap.cs 项目: bjowes/cwg
 //Constructor, creates a new GameMap from a GameState.
 public GameMap(int tankId, Consoden.TankGame.GameState gameState)
 {
     this.tankId    = tankId;
     this.gameState = gameState;
 }
示例#7
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);
        }