public static string Export(Replay replay)
 {
     Game game = new Game(replay);
     GameState oldState = null;
     List<GameAction> actions = new List<GameAction>();
     for (int i = 0; i < replay.Actions.Count; i++)
     {
         if (replay.Actions[i] is ReplayTimeAction)
             actions.Add(replay.Actions[i]);
         game.Seek(i);
         List<GameAction> newActions = StateDelta.Delta(oldState, game.State);
         actions.AddRange(newActions);
         if (game.State != null)
             oldState = game.State.Clone();
     }
     List<JObject> jActions = new List<JObject>();
     TimeSpan time = TimeSpan.Zero;
     foreach (var action in actions)
     {
         if (action is ReplayTimeAction)
             time = ((ReplayTimeAction)action).Time;
         else
             jActions.Add(SerializeAction(action, time));
     }
     JObject json = new JObject(new JProperty("changes", new JArray(jActions)));
     return json.ToString(Newtonsoft.Json.Formatting.None);
 }
Exemplo n.º 2
0
 private void CalculateEnemiesBehind(Car self, Game game)
 {
     foreach (var car in this.enemiesCars)
     {
         if (!car.IsFinishedTrack && car.Durability > 0.0)
         {
             var currentPosition = new PointF((float)car.X, (float)car.Y);
             var nextPosition = new PointF((float)car.X + (float)car.SpeedX, (float)car.Y + (float)car.SpeedY);
             var futurePosition = new PointF(
                 (float)car.X + PredictionCount * (float)car.SpeedX,
                 (float)car.Y + PredictionCount * (float)car.SpeedY);
             var xOffset =
                 (float)
                 (Math.Cos(self.Angle) * (game.CarHeight + game.OilSlickInitialRange + game.OilSlickRadius));
             var yOffset =
                 (float)
                 (Math.Sin(self.Angle) * (game.CarHeight + game.OilSlickInitialRange + game.OilSlickRadius));
             var oilPosition = new PointF((float)self.X + xOffset, (float)self.Y - yOffset);
             float distance = MathHelper.DistanceToLine(oilPosition, currentPosition, futurePosition);
             if (distance < game.OilSlickRadius + game.CarWidth / 2
                 && MathHelper.Distance(currentPosition, oilPosition)
                 < game.OilSlickRadius + PredictionCount * car.GetSpeed()
                 && MathHelper.Distance(currentPosition, oilPosition)
                 > MathHelper.Distance(nextPosition, oilPosition))
             {
                 this.enemyBehind = true;
                 break;
             }
         }
     }
 }
Exemplo n.º 3
0
 public void Move(Car self, World world, Game game, Move move)
 {
     if (IsActivated)
     {
         if (this.step1)
         {
             if (self.EnginePower <= -1.0f)
             {
                 this.hack++;
                 if (this.hack >= 5)
                 {
                     this.step1 = false;
                     this.step2 = true;
                     this.hack = 0;
                 }
             }
         }
         else if (this.step2)
         {
             if (self.EnginePower >= 0.2f)
             {
                 this.step2 = false;
                 IsActivated = false;
                 this.lastUsedTick = world.Tick;
             }
         }
     }
 }
Exemplo n.º 4
0
 public void PostMove(Car self, World world, Game game, Move move)
 {
     if (this.gameStarted)
     {
         move.IsThrowProjectile = this.enemyInFront;
         move.IsSpillOil = this.enemyBehind;
     }
 }
Exemplo n.º 5
0
 public void PreMove(Car self, World world, Game game, Move move)
 {
     this.gameStarted = world.Tick > game.InitialFreezeDurationTicks;
     this.enemiesCars.Clear();
     this.enemiesCars.AddRange(world.Cars.Where(car => !car.IsTeammate));
     this.enemyBehind = false;
     this.enemyInFront = false;
 }
Exemplo n.º 6
0
 public void Move(Car self, World world, Game game, Move move)
 {
     if (!BackMovingModule.IsActivated)
     {
         this.distance = MathHelper.Distance(new PointF((float)self.X, (float)self.Y), this.nextPoint);
         this.desiredAngle = self.GetAngleTo(this.nextPoint.X, this.nextPoint.Y);
     }
 }
Exemplo n.º 7
0
 public void PreMove(Car self, World world, Game game, Move move)
 {
     if (!IsActivated && self.GetSpeed() < 0.75f
         && (this.IsFaceObstacle(self, world, game)
             || (self.EnginePower >= 0.5f && world.Tick > 190 && world.Tick > this.lastUsedTick + 60)))
     {
         IsActivated = true;
         this.step1 = true;
     }
 }
Exemplo n.º 8
0
        public async Task <int> AddGame(Model.Game game)
        {
            using (var context = ContextFactory.CreateDbContext(ConnectionString))
            {
                context.Games.Add(game);
                var gameCreator = context.Players.Single(p => p.Id == game.CreatorId);
                gameCreator.Game = game;
                await context.SaveChangesAsync();

                return(game.Id);
            }
        }
Exemplo n.º 9
0
 private void CalculateEnemiesInFront(Car self, Game game)
 {
     foreach (var car in this.enemiesCars)
     {
         if (car.Type == CarType.Buggy)
         {
             if (!car.IsFinishedTrack && car.Durability > 0.0)
             {
                 var currentEnemyPosition = new PointF((float)car.X, (float)car.Y);
                 var nextEnemyPosition = new PointF(
                     (float)car.X + (float)car.SpeedX,
                     (float)car.Y + (float)car.SpeedY);
                 var futureEnemyPosition = new PointF(
                     (float)car.X + PredictionCount * (float)car.SpeedX,
                     (float)car.Y + PredictionCount * (float)car.SpeedY);
                 var currentWasherPosition = new PointF((float)self.X, (float)self.Y);
                 var nextWasherPosition =
                     new PointF(
                         (float)self.X + (float)self.SpeedX / self.GetSpeed() * (float)game.WasherInitialSpeed,
                         (float)self.Y + (float)self.SpeedY / self.GetSpeed() * (float)game.WasherInitialSpeed);
                 var futureWasherPosition =
                     new PointF(
                         (float)self.X
                         + PredictionCount * (float)self.SpeedX / self.GetSpeed()
                         * (float)game.WasherInitialSpeed,
                         (float)self.Y
                         + PredictionCount * (float)self.SpeedY / self.GetSpeed()
                         * (float)game.WasherInitialSpeed);
                 PointF? intersectsPoint = MathHelper.PointOfIntersection(
                     currentWasherPosition,
                     futureWasherPosition,
                     currentEnemyPosition,
                     futureEnemyPosition);
                 if (intersectsPoint.HasValue
                     && MathHelper.Distance(intersectsPoint.Value, currentWasherPosition)
                     / (float)game.WasherInitialSpeed <= PredictionCount
                     && MathHelper.Distance(currentWasherPosition, currentEnemyPosition)
                     > MathHelper.Distance(nextWasherPosition, nextEnemyPosition)
                     && Math.Abs(
                         MathHelper.Distance(intersectsPoint.Value, currentWasherPosition)
                         / (float)game.WasherInitialSpeed
                         - MathHelper.Distance(intersectsPoint.Value, currentEnemyPosition) / car.GetSpeed())
                     < WasherPredictionError)
                 {
                     this.enemyInFront = true;
                     break;
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
 public override IEnumerable<GameAction> Click(Game game, int commandID, Position p)
 {
     StoneColor oldColor = game.State.Stones[p.X, p.Y];
     StoneColor newColor;
     if (commandID == 1)
         newColor = StoneColor.Black;
     else if (commandID == 2)
         newColor = StoneColor.White;
     else
         newColor = StoneColor.None;
     if (newColor == oldColor)
         newColor = StoneColor.None;
     yield return new SetStoneAction(p, newColor);
 }
Exemplo n.º 11
0
 public void PostMove(Car self, World world, Game game, Move move)
 {
     if (IsActivated)
     {
         move.WheelTurn = 0.0f;
         if (this.step1)
         {
             move.EnginePower = -1.0f;
         }
         else if (this.step2)
         {
             move.EnginePower = 1.0f;
         }
     }
 }
Exemplo n.º 12
0
        public override IEnumerable<GameAction> Click(Game game, int actionIndex, Position p)
        {
            string oldLabel = game.State.Labels[p.X, p.Y];
            string newLabel;

            HashSet<string> existingLabels = new HashSet<string>();
            foreach (string s in game.State.Labels)
            {
                existingLabels.Add(s);
            }

            newLabel = getLabel(game, actionIndex, existingLabels, oldLabel);
            if (newLabel == null)
                throw new InvalidOperationException();
            yield return new LabelAction(p, newLabel);
        }
Exemplo n.º 13
0
 protected override string getLabel(Game game, int commandID, HashSet<string> existingLabels, string oldLabel)
 {
     if (!String.IsNullOrEmpty(oldLabel))
         return "";
     string newLabel;
     if (commandID == 1)
         newLabel = Label1;
     else if (commandID == 2)
         newLabel = Label2;
     else if (commandID == 3)
         newLabel = Label3;
     else
         newLabel = "";
     if (newLabel == oldLabel)
         newLabel = "";
     return newLabel;
 }
Exemplo n.º 14
0
        private Point GetNextWaypoint(Car self, Game game, World world)
        {
            var nextWayPoint = new PointF(
                (self.NextWaypointX + 0.5f) * (float)game.TrackTileSize,
                (self.NextWaypointY + 0.5f) * (float)game.TrackTileSize);
            float cornerTileOffset = 0.225f * (float)game.TrackTileSize;
            switch (world.TilesXY[self.NextWaypointX][self.NextWaypointY])
            {
                case TileType.LeftBottomCorner:
                    nextWayPoint.X += cornerTileOffset;
                    nextWayPoint.Y -= cornerTileOffset;
                    break;
                case TileType.LeftTopCorner:
                    nextWayPoint.X += cornerTileOffset;
                    nextWayPoint.Y += cornerTileOffset;
                    break;
                case TileType.RightBottomCorner:
                    nextWayPoint.X -= cornerTileOffset;
                    nextWayPoint.Y -= cornerTileOffset;
                    break;
                case TileType.RightTopCorner:
                    nextWayPoint.X -= cornerTileOffset;
                    nextWayPoint.Y += cornerTileOffset;
                    break;
                case TileType.BottomHeadedT:
                    nextWayPoint.Y += cornerTileOffset;
                    break;
                case TileType.TopHeadedT:
                    nextWayPoint.Y -= cornerTileOffset;
                    break;
                case TileType.LeftHeadedT:
                    nextWayPoint.X -= cornerTileOffset;
                    break;
                case TileType.RightHeadedT:
                    nextWayPoint.X += cornerTileOffset;
                    break;
            }

            return new Point((int)nextWayPoint.X / MyTileSize, (int)nextWayPoint.Y / MyTileSize);
        }
Exemplo n.º 15
0
        private void FindPath(Car self, World world, Game game)
        {
            this.BuildMap(world, game);
            this.BuildIdealPath(self, game, world);
            int horLength = map.GetLength(0);
            int vertLength = map.GetLength(1);
            bool step34AreNecessary = false;
            for (int i = 0; i < horLength && !step34AreNecessary; i++)
            {
                for (int j = 0; j < vertLength; j++)
                {
                    if (this.mapWithIdealPath[i, j] == MyRoadType.IdealPath && map[i, j] == MyTileType.Red)
                    {
                        step34AreNecessary = true;
                        break;
                    }
                }
            }

            if (step34AreNecessary)
            {
                AvoidObstacles();
                BuildRealPath();
            }
            else
            {
                this.nextPoint = new PointF(
                    (self.NextWaypointX + 0.5f) * (float)game.TrackTileSize,
                    (self.NextWaypointY + 0.5f) * (float)game.TrackTileSize);
                bool nextPointFound = false;
                for (int i = 0; i < horLength && !nextPointFound; i++)
                {
                    for (int j = 0; j < vertLength; j++)
                    {
                        if (this.mapWithIdealPath[i, j] == MyRoadType.Destination)
                        {

                            this.nextPoint = new PointF((i + 0.5f) * MyTileSize, (j + 0.5f) * MyTileSize);
                            nextPointFound = true;
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        private bool IsFaceObstacle(Car self, World world, Game game)
        {
            List<PointF> checkPositions = new List<PointF>(3);
            double absOffset = game.CarWidth / 2 + 120;
            var xOffset = (float)(Math.Cos(self.Angle) * absOffset);
            var yOffset = (float)(Math.Sin(self.Angle) * absOffset);
            checkPositions.Add(new PointF((float)self.X + xOffset, (float)self.Y + yOffset));
            double absOffset1 = game.CarWidth / 2 + 10;
            var xOffset1 = (float)(Math.Cos(self.Angle) * absOffset1);
            var yOffset1 = (float)(Math.Sin(self.Angle) * absOffset1);
            checkPositions.Add(new PointF((float)self.X + xOffset1, (float)self.Y + yOffset1 + 65));
            double absOffset2 = game.CarWidth / 2 + 10;
            var xOffset2 = (float)(Math.Cos(self.Angle) * absOffset2);
            var yOffset2 = (float)(Math.Sin(self.Angle) * absOffset2);
            checkPositions.Add(new PointF((float)self.X + xOffset2, (float)self.Y + yOffset2 - 65));
            try
            {
                foreach (var checkPosition in checkPositions)
                {
                    int tileX = (int)checkPosition.X / (int)game.TrackTileSize;
                    int tileY = (int)checkPosition.Y / (int)game.TrackTileSize;
                    float checkX = checkPosition.X % (int)game.TrackTileSize;
                    float checkY = checkPosition.Y % (int)game.TrackTileSize;
                    var tileType = world.TilesXY[tileX][tileY];
                    switch (tileType)
                    {
                        case TileType.BottomHeadedT:
                            if (checkY < game.TrackTileMargin
                                || Math.Sqrt(
                                    checkX * checkX
                                    + ((int)game.TrackTileSize - checkY) * ((int)game.TrackTileSize - checkY))
                                < game.TrackTileMargin
                                || Math.Sqrt(
                                    ((int)game.TrackTileSize - checkX) * ((int)game.TrackTileSize - checkX)
                                    + ((int)game.TrackTileSize - checkY) * ((int)game.TrackTileSize - checkY))
                                < game.TrackTileMargin)
                            {
                                return true;
                            }

                            break;
                        case TileType.Empty:
                            return true;
                        case TileType.LeftHeadedT:
                            if (checkX > game.TrackTileSize - game.TrackTileMargin
                                || Math.Sqrt(checkX * checkX + checkY * checkY) < game.TrackTileMargin
                                || Math.Sqrt(
                                    checkX * checkX
                                    + ((int)game.TrackTileSize - checkY) * ((int)game.TrackTileSize - checkY))
                                < game.TrackTileMargin)
                            {
                                return true;
                            }

                            break;
                        case TileType.RightHeadedT:
                            if (checkX < game.TrackTileMargin
                                || Math.Sqrt(
                                    ((int)game.TrackTileSize - checkX) * ((int)game.TrackTileSize - checkX)
                                    + checkY * checkY) < game.TrackTileMargin
                                || Math.Sqrt(
                                    ((int)game.TrackTileSize - checkX) * ((int)game.TrackTileSize - checkX)
                                    + ((int)game.TrackTileSize - checkY) * ((int)game.TrackTileSize - checkY))
                                < game.TrackTileMargin)
                            {
                                return true;
                            }

                            break;
                        case TileType.TopHeadedT:
                            if (checkY > game.TrackTileSize - game.TrackTileMargin
                                || Math.Sqrt(checkX * checkX + checkY * checkY) < game.TrackTileMargin
                                || Math.Sqrt(
                                    ((int)game.TrackTileSize - checkX) * ((int)game.TrackTileSize - checkX)
                                    + checkY * checkY) < game.TrackTileMargin)
                            {
                                return true;
                            }

                            break;
                        case TileType.Crossroads:
                            if (Math.Sqrt(checkX * checkX + checkY * checkY) < game.TrackTileMargin
                                || Math.Sqrt(
                                    ((int)game.TrackTileSize - checkX) * ((int)game.TrackTileSize - checkX)
                                    + checkY * checkY) < game.TrackTileMargin
                                || Math.Sqrt(
                                    checkX * checkX
                                    + ((int)game.TrackTileSize - checkY) * ((int)game.TrackTileSize - checkY))
                                < game.TrackTileMargin
                                || Math.Sqrt(
                                    ((int)game.TrackTileSize - checkX) * ((int)game.TrackTileSize - checkX)
                                    + ((int)game.TrackTileSize - checkY) * ((int)game.TrackTileSize - checkY))
                                < game.TrackTileMargin)
                            {
                                return true;
                            }

                            break;
                        case TileType.Vertical:
                            if (checkX < game.TrackTileMargin || checkX > game.TrackTileSize - game.TrackTileMargin)
                            {
                                return true;
                            }

                            break;
                        case TileType.Horizontal:
                            if (checkY < game.TrackTileMargin || checkY > game.TrackTileSize - game.TrackTileMargin)
                            {
                                return true;
                            }

                            break;
                        case TileType.LeftBottomCorner:
                            if (
                                Math.Sqrt(
                                    ((int)game.TrackTileSize - checkX) * ((int)game.TrackTileSize - checkX)
                                    + checkY * checkY) < game.TrackTileMargin
                                || checkY > game.TrackTileSize - game.TrackTileMargin || checkX < game.TrackTileMargin)
                            {
                                return true;
                            }

                            break;
                        case TileType.RightBottomCorner:
                            if (Math.Sqrt(checkX * checkX + checkY * checkY) < game.TrackTileMargin
                                || checkY > game.TrackTileSize - game.TrackTileMargin
                                || checkX > game.TrackTileSize - game.TrackTileMargin)
                            {
                                return true;
                            }

                            break;
                        case TileType.RightTopCorner:
                            if (
                                Math.Sqrt(
                                    checkX * checkX
                                    + ((int)game.TrackTileSize - checkY) * ((int)game.TrackTileSize - checkY))
                                < game.TrackTileMargin || checkY < game.TrackTileMargin
                                || checkX > game.TrackTileSize - game.TrackTileMargin)
                            {
                                return true;
                            }

                            break;
                        case TileType.LeftTopCorner:
                            if (
                                Math.Sqrt(
                                    ((int)game.TrackTileSize - checkX) * ((int)game.TrackTileSize - checkX)
                                    + ((int)game.TrackTileSize - checkY) * ((int)game.TrackTileSize - checkY))
                                < game.TrackTileMargin || checkY < game.TrackTileMargin || checkX < game.TrackTileMargin)
                            {
                                return true;
                            }

                            break;
                        default:
                            throw new NotImplementedException(":(");
                    }
                }
            }
            catch
            {
            }

            return false;
        }
Exemplo n.º 17
0
 public void Move(Car self, World world, Game game, Move move)
 {
     this.modules.ForEach(module => module.PreMove(self, world, game, move));
     this.modules.ForEach(module => module.Move(self, world, game, move));
     this.modules.ForEach(module => module.PostMove(self, world, game, move));
 }
Exemplo n.º 18
0
 public override IEnumerable<GameAction> Click(Game game, int commandID, Position p)
 {
     if (commandID == 1)
     {
         if (game.State.Stones[p.X, p.Y] == StoneColor.None)
         {
             int? alreadyPlayed = game.Tree.MoveAlreadyPlayed(p);
             if (alreadyPlayed != null)
             {
                 yield return new SelectStateAction((int)alreadyPlayed);
             }
             else
             {
                 yield return new StoneMoveAction(p, game.State.PlayerToMove);
                 if (game.State.Labels.Any(s => s != null))
                     yield return LabelAction.ClearLabels;
             }
         }
     }
     if (commandID == 2)
     {
         int? moveIndex = game.Tree.FindMove(p);
         if (moveIndex != null)
         {
             yield return new SelectStateAction((int)moveIndex);
         }
     }
 }
Exemplo n.º 19
0
 protected override string getLabel(Game game, int commandID, HashSet<string> existingLabels, string oldLabel)
 {
     if (!String.IsNullOrEmpty(oldLabel))
         return "";
     int i = 1;
     string s;
     do
     {
         s = i.ToString();
         i++;
     } while (existingLabels.Contains(s));
     return s;
 }
Exemplo n.º 20
0
 public void Move(Car self, World world, Game game, Move move)
 {
     // TODO: Optimize - check my cooldown
     this.CalculateEnemiesBehind(self, game);
     this.CalculateEnemiesInFront(self, game);
 }
Exemplo n.º 21
0
 protected override string getLabel(Game game, int commandID, HashSet<String> existingLabels, string oldLabel)
 {
     if (!String.IsNullOrEmpty(oldLabel))
         return "";
     string s;
     //if (actionIndex == 1)
     {
         int i = 0;
         do
         {
             s = ((char)((int)'A' + i % 26)).ToString();
             if (i > 25)
                 s += (i / 26 + 1).ToString();
             i++;
         } while (existingLabels.Contains(s));
         return s;
     }
     /*else
     {
         throw new NotImplementedException();
     }*/
 }
Exemplo n.º 22
0
        private void BuildMap(World world, Game game)
        {
            int multiplier = (int)game.TrackTileSize / MyTileSize;
            map = new MyTileType[world.Width * multiplier, world.Height * multiplier];
            for (int i = 0; i < world.Width; i++)
            {
                for (int j = 0; j < world.Height; j++)
                {
                    switch (world.TilesXY[i][j])
                    {
                        case TileType.Empty:
                            for (int k = 0; k < multiplier; k++)
                            {
                                for (int l = 0; l < multiplier; l++)
                                {
                                    map[i * multiplier + k, j * multiplier + l] = MyTileType.Red;
                                }
                            }

                            break;
                        case TileType.Unknown:
                            break;
                        case TileType.Crossroads:
                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    if (k + 1 != (int)game.TrackTileMargin * 2 / MyTileSize
                                        || l + 1 != (int)game.TrackTileMargin * 2 / MyTileSize)
                                    {
                                        map[i * multiplier + k, j * multiplier + l] = MyTileType.Red;
                                        map[i * multiplier + k, (j + 1) * multiplier - l - 1] = MyTileType.Red;
                                        map[(i + 1) * multiplier - k - 1, j * multiplier + l] = MyTileType.Red;
                                        map[(i + 1) * multiplier - k - 1, (j + 1) * multiplier - l - 1] = MyTileType.Red;
                                    }
                                }
                            }

                            break;
                        case TileType.Horizontal:
                            for (int k = 0; k < multiplier; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    map[i * multiplier + k, j * multiplier + l] = MyTileType.Red;
                                    map[i * multiplier + k, (j + 1) * multiplier - l - 1] = MyTileType.Red;
                                }
                            }

                            break;
                        case TileType.Vertical:
                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < multiplier; l++)
                                {
                                    map[i * multiplier + k, j * multiplier + l] = MyTileType.Red;
                                    map[(i + 1) * multiplier - k - 1, j * multiplier + l] = MyTileType.Red;
                                }
                            }

                            break;
                        case TileType.BottomHeadedT:
                            for (int k = 0; k < multiplier; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    map[i * multiplier + k, j * multiplier + l] = MyTileType.Red;
                                }
                            }

                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    if (k + 1 != (int)game.TrackTileMargin * 2 / MyTileSize
                                        || l + 1 != (int)game.TrackTileMargin * 2 / MyTileSize)
                                    {
                                        map[i * multiplier + k, (j + 1) * multiplier - l - 1] = MyTileType.Red;
                                        map[(i + 1) * multiplier - k - 1, (j + 1) * multiplier - l - 1] = MyTileType.Red;
                                    }
                                }
                            }

                            break;
                        case TileType.TopHeadedT:
                            for (int k = 0; k < multiplier; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    map[i * multiplier + k, (j + 1) * multiplier - l - 1] = MyTileType.Red;
                                }
                            }

                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    if (k + 1 != (int)game.TrackTileMargin * 2 / MyTileSize
                                        || l + 1 != (int)game.TrackTileMargin * 2 / MyTileSize)
                                    {
                                        map[i * multiplier + k, j * multiplier + l] = MyTileType.Red;
                                        map[(i + 1) * multiplier - k - 1, j * multiplier + l] = MyTileType.Red;
                                    }
                                }
                            }

                            break;
                        case TileType.LeftHeadedT:
                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < multiplier; l++)
                                {
                                    map[(i + 1) * multiplier - k - 1, j * multiplier + l] = MyTileType.Red;
                                }
                            }

                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    if (k + 1 != (int)game.TrackTileMargin * 2 / MyTileSize
                                        || l + 1 != (int)game.TrackTileMargin * 2 / MyTileSize)
                                    {
                                        map[i * multiplier + k, j * multiplier + l] = MyTileType.Red;
                                        map[i * multiplier + k, (j + 1) * multiplier - l - 1] = MyTileType.Red;
                                    }
                                }
                            }

                            break;
                        case TileType.RightHeadedT:
                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < multiplier; l++)
                                {
                                    map[i * multiplier + k, j * multiplier + l] = MyTileType.Red;
                                }
                            }

                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    if (k + 1 != (int)game.TrackTileMargin * 2 / MyTileSize
                                        || l + 1 != (int)game.TrackTileMargin * 2 / MyTileSize)
                                    {
                                        map[(i + 1) * multiplier - k - 1, j * multiplier + l] = MyTileType.Red;
                                        map[(i + 1) * multiplier - k - 1, (j + 1) * multiplier - l - 1] = MyTileType.Red;
                                    }
                                }
                            }

                            break;
                        case TileType.LeftTopCorner:
                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    if (k + 1 != (int)game.TrackTileMargin * 2 / MyTileSize
                                        || l + 1 != (int)game.TrackTileMargin * 2 / MyTileSize)
                                    {
                                        map[(i + 1) * multiplier - k - 1, (j + 1) * multiplier - l - 1] = MyTileType.Red;
                                    }
                                }
                            }

                            for (int k = 0; k < (int)game.TrackTileMargin * 3 / MyTileSize; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 3 / MyTileSize; l++)
                                {
                                    map[i * multiplier + k, j * multiplier + l] = MyTileType.Red;
                                }
                            }

                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < multiplier; l++)
                                {
                                    map[i * multiplier + k, j * multiplier + l] = MyTileType.Red;
                                }
                            }

                            for (int k = 0; k < multiplier; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    map[i * multiplier + k, j * multiplier + l] = MyTileType.Red;
                                }
                            }

                            break;
                        case TileType.RightTopCorner:
                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    if (k + 1 != (int)game.TrackTileMargin * 2 / MyTileSize
                                        || l + 1 != (int)game.TrackTileMargin * 2 / MyTileSize)
                                    {
                                        map[i * multiplier + k, (j + 1) * multiplier - l - 1] = MyTileType.Red;
                                    }
                                }
                            }

                            for (int k = 0; k < (int)game.TrackTileMargin * 3 / MyTileSize; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 3 / MyTileSize; l++)
                                {
                                    map[(i + 1) * multiplier - k - 1, j * multiplier + l] = MyTileType.Red;
                                }
                            }

                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < multiplier; l++)
                                {
                                    map[(i + 1) * multiplier - k - 1, j * multiplier + l] = MyTileType.Red;
                                }
                            }

                            for (int k = 0; k < multiplier; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    map[i * multiplier + k, j * multiplier + l] = MyTileType.Red;
                                }
                            }

                            break;
                        case TileType.LeftBottomCorner:
                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    if (k + 1 != (int)game.TrackTileMargin * 2 / MyTileSize
                                        || l + 1 != (int)game.TrackTileMargin * 2 / MyTileSize)
                                    {
                                        map[(i + 1) * multiplier - k - 1, j * multiplier + l] = MyTileType.Red;
                                    }
                                }
                            }

                            for (int k = 0; k < (int)game.TrackTileMargin * 3 / MyTileSize; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 3 / MyTileSize; l++)
                                {
                                    map[i * multiplier + k, (j + 1) * multiplier - l - 1] = MyTileType.Red;
                                }
                            }

                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < multiplier; l++)
                                {
                                    map[i * multiplier + k, j * multiplier + l] = MyTileType.Red;
                                }
                            }

                            for (int k = 0; k < multiplier; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    map[i * multiplier + k, (j + 1) * multiplier - l - 1] = MyTileType.Red;
                                }
                            }

                            break;
                        case TileType.RightBottomCorner:
                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    if (k + 1 != (int)game.TrackTileMargin * 2 / MyTileSize
                                        || l + 1 != (int)game.TrackTileMargin * 2 / MyTileSize)
                                    {
                                        map[i * multiplier + k, j * multiplier + l] = MyTileType.Red;
                                    }
                                }
                            }

                            for (int k = 0; k < (int)game.TrackTileMargin * 3 / MyTileSize; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 3 / MyTileSize; l++)
                                {
                                    map[(i + 1) * multiplier - k - 1, (j + 1) * multiplier - l - 1] = MyTileType.Red;
                                }
                            }

                            for (int k = 0; k < (int)game.TrackTileMargin * 2 / MyTileSize; k++)
                            {
                                for (int l = 0; l < multiplier; l++)
                                {
                                    map[(i + 1) * multiplier - k - 1, j * multiplier + l] = MyTileType.Red;
                                }
                            }

                            for (int k = 0; k < multiplier; k++)
                            {
                                for (int l = 0; l < (int)game.TrackTileMargin * 2 / MyTileSize; l++)
                                {
                                    map[i * multiplier + k, (j + 1) * multiplier - l - 1] = MyTileType.Red;
                                }
                            }

                            break;
                        default:
                            throw new NotImplementedException("NOOOOOOOOO!!!");
                    }
                }
            }
        }
Exemplo n.º 23
0
        public void PostMove(Car self, World world, Game game, Move move)
        {
            if (!BackMovingModule.IsActivated)
            {
                float speed = self.GetSpeed();
                float angleDerivation = (float)Math.Abs(this.desiredAngle);
                SetCorrectAngles(self, move);
                if (self.RemainingNitroTicks > 0 && this.distance <= 2400)
                {
                    move.IsBrake = true;
                }

                else if (this.distance <= 1200)
                {
                    if (speed <= 10)
                    {
                        move.EnginePower = 0.5;
                    }
                    else if (speed <= 24 || self.EnginePower < 0.15)
                    {
                        move.EnginePower = -0.5;
                    }
                    else
                    {
                        move.IsBrake = true;
                    }
                }
                else
                {
                    if (angleDerivation <= 0.1f)
                    {
                        move.EnginePower = 1.0;
                        if (this.distance > 4000 && world.Tick > 180)
                        {
                            move.IsUseNitro = true;
                        }
                    }
                    else if (angleDerivation <= 0.5f)
                    {
                        move.EnginePower = 1.0;
                    }
                    else
                    {
                        if (speed <= 12)
                        {
                            move.EnginePower = 1.0;
                        }
                        else if (speed <= 22)
                        {
                            move.EnginePower = -0.15;
                        }
                        else
                        {
                            move.IsBrake = true;
                        }
                    }
                }

                if (self.EnginePower < 0.15)
                {
                    move.EnginePower = 0.25;
                }
            }
        }
Exemplo n.º 24
0
 public abstract IEnumerable<GameAction> Click(Game game, int commandID, Position p);
Exemplo n.º 25
0
        private void BuildIdealPath(Car self, Game game, World world)
        {
            int horLength = map.GetLength(0);
            int vertLength = map.GetLength(1);
            this.mapWithIdealPath = new MyRoadType[horLength, vertLength];
            int currentPositionX = (int)self.X / MyTileSize;
            int currentPositionY = (int)self.Y / MyTileSize;
            this.mapWithIdealPath[currentPositionX, currentPositionY] = MyRoadType.CurrentPosition;
            var nextWaypoint = this.GetNextWaypoint(self, game, world);
            this.mapWithIdealPath[nextWaypoint.X, nextWaypoint.Y] = MyRoadType.Destination;
            if (Math.Abs(currentPositionX - nextWaypoint.X) == Math.Abs(currentPositionY - nextWaypoint.Y))
            {
                int cursorX = currentPositionX;
                int cursorY = currentPositionY;
                int deltaX = nextWaypoint.X > currentPositionX ? 1 : -1;
                int deltaY = nextWaypoint.Y > currentPositionY ? 1 : -1;
                cursorX += deltaX;
                cursorY += deltaY;
                int counter = 500;
                while (this.mapWithIdealPath[cursorX,cursorY] != MyRoadType.Destination)
                {
                    counter--;
                    if (counter <= 0)
                    {
                        throw new InvalidOperationException("I'm IDIOT!");
                    }

                    this.mapWithIdealPath[cursorX,cursorY] = MyRoadType.IdealPath;
                    cursorX += deltaX;
                    cursorY += deltaY;
                }
            }
            else if (Math.Abs(currentPositionX - nextWaypoint.X) > Math.Abs(currentPositionY - nextWaypoint.Y))
            {
                int cursorX = currentPositionX;
                int deltaX = nextWaypoint.X > currentPositionX ? 1 : -1;
                float cursorY = currentPositionY + 0.5f;
                float deltaY = nextWaypoint.Y > currentPositionY
                                   ? Math.Abs(currentPositionY - nextWaypoint.Y)
                                     / (float)Math.Abs(currentPositionX - nextWaypoint.X)
                                   : -Math.Abs(currentPositionY - nextWaypoint.Y)
                                     / (float)Math.Abs(currentPositionX - nextWaypoint.X);
                cursorX += deltaX;
                cursorY += deltaY;
                int counter = 500;
                while (this.mapWithIdealPath[cursorX, (int)cursorY] != MyRoadType.Destination)
                {
                    counter--;
                    if (counter <= 0)
                    {
                        throw new InvalidOperationException("I'm IDIOT. I am!");
                    }

                    this.mapWithIdealPath[cursorX, (int)cursorY] = MyRoadType.IdealPath;
                    cursorX += deltaX;
                    cursorY += deltaY;
                }
            }
            else
            {
                float cursorX = currentPositionX + 0.5f;
                float deltaX = nextWaypoint.X > currentPositionX
                                   ? (float)Math.Abs(currentPositionX - nextWaypoint.X)
                                     / Math.Abs(currentPositionY - nextWaypoint.Y)
                                   : -(float)Math.Abs(currentPositionX - nextWaypoint.X)
                                     / Math.Abs(currentPositionY - nextWaypoint.Y);
                int cursorY = currentPositionY;
                int deltaY = nextWaypoint.Y > currentPositionY ? 1 : -1;
                cursorX += deltaX;
                cursorY += deltaY;
                int counter = 500;
                while (this.mapWithIdealPath[(int)cursorX, cursorY] != MyRoadType.Destination)
                {
                    counter--;
                    if (counter <= 0)
                    {
                        throw new InvalidOperationException("I'm IDIOT! Really");
                    }

                    this.mapWithIdealPath[(int)cursorX, cursorY] = MyRoadType.IdealPath;
                    cursorX += deltaX;
                    cursorY += deltaY;
                }
            }
        }
Exemplo n.º 26
0
 protected abstract string getLabel(Game game, int commandID, HashSet<String> existingLabels, string oldLabel);
Exemplo n.º 27
0
 public void PreMove(Car self, World world, Game game, Move move)
 {
     if (!BackMovingModule.IsActivated)
     {
         this.FindPath(self, world, game);
     }
 }
 public GoVideoToReplay(Game game)
 {
     Game = game;
 }