private Bonus findBonus()
        {
            Vector dir = new Vector(path[0].DirOut.X, path[0].DirOut.Y);

            PCar pcar = new PCar(car, game);

            if (pcar.Speed.Length < 1)
            {
                return(null);
            }

            PCar zeroWheelTurnCar = pcar.GetZeroWheelTurnCar();

            Bonus priorityBonus = null;

            foreach (Bonus bonus in world.Bonuses)
            {
                double distance = car.GetDistanceTo(bonus);
                if (distance > game.TrackTileSize * 3.0)
                {
                    continue;
                }

                Vector bonusPos = new Vector(bonus.X, bonus.Y);

                if ((bonusPos - pcar.Pos).Dot(dir) < 0)//back
                {
                    continue;
                }

                if (!isNextTile(new TilePos(bonus.X, bonus.Y)))
                {
                    continue;
                }

                if (Constant.BonusPriority(bonus, car, false) < 0)
                {
                    continue;
                }

                double newBonusPriority = Constant.BonusPriority(bonus, car, true);

                if (null == priorityBonus || Constant.BonusPriority(priorityBonus, car, true) < newBonusPriority)
                {
                    priorityBonus = bonus;
                }
            }

            return(priorityBonus);
        }
Example #2
0
        private double cellPriority(Cell cell)
        {
            double priority = 0;

            if (!hasUnknown)
            {
                foreach (Bonus bonus in world.Bonuses)
                {
                    TilePos pos = new TilePos(bonus.X, bonus.Y);
                    if (pos.Equals(cell.Pos))
                    {
                        priority += Constant.BonusPriority(bonus, car, false) / 100.0;
                    }
                }

                int countAccidentCarInCell = 0;
                foreach (Car car in world.Cars)
                {
                    if (car.IsTeammate)
                    {
                        continue;
                    }

                    TilePos carPos = new TilePos(car.X, car.Y);
                    if (!carPos.Equals(cell.Pos))
                    {
                        continue;
                    }

                    if (car.Speed() < 1)
                    {
                        countAccidentCarInCell++;
                    }
                }

                priority -= 0.5 * countAccidentCarInCell;
            }

            return(priority);
        }