Esempio n. 1
0
        protected PathCheckResult checkSnakeWithOffset(int offset = 0)
        {
            if (3 + offset >= path.Count)
            {
                return(PathCheckResult.Unknown);
            }

            TilePos posIn  = path[1 + offset].Pos;
            TilePos posOut = path[2 + offset].Pos;

            TileDir dirIn  = path[1 + offset].DirIn;
            TileDir dirOut = path[2 + offset].DirOut;

            if (null == dirOut || dirOut == TileDir.Zero)
            {
                return(PathCheckResult.Unknown);
            }

            TileDir dir = new TileDir(posOut.X - posIn.X, posOut.Y - posIn.Y);

            if (dirIn == dirOut && (dir == dirIn.PerpendicularLeft() || dir == dirIn.PerpendicularRight()))
            {
                return(PathCheckResult.Yes);
            }
            else
            {
                return(PathCheckResult.No);
            }
        }
        public override void execute(Move move)
        {
            TileDir dirMove = path[offset].DirOut;
            TileDir dirEnd  = path[1 + offset].DirOut;
            TilePos endTile = path[1 + offset].Pos;

            MovingCalculator calculator = new MovingCalculator();

            calculator.setupEnvironment(car, game, world);
            calculator.setupMapInfo(dirMove, path[0].Pos, path[1 + offset].Pos);

            calculator.setupDefaultAction(GetWayEnd(path[1 + offset].Pos, dirEnd.Negative() + dirMove.Negative() * 2));

            Vector endDir = new Vector(dirEnd.X - dirMove.X, dirEnd.Y - dirMove.Y).Normalize();

            calculator.setupAngleReach(endDir);
            calculator.setupPassageLine(GetWayEnd(endTile, dirEnd, 1.0), new Vector(dirEnd.X + dirMove.X, dirEnd.Y + dirMove.Y).Normalize(), 0.75);

            if (0 != offset)
            {
                calculator.setupAdditionalPoints(additionalPoints);
            }

            Dictionary <TilePos, TileDir[]> selfMap = new Dictionary <TilePos, TileDir[]>();

            for (int i = 0; i <= offset; i++)
            {
                if (path[i].DirIn == path[i].DirOut)
                {
                    selfMap.Add(path[i].Pos, new TileDir[2] {
                        dirMove.PerpendicularLeft(), dirMove.PerpendicularRight()
                    });
                }
                else
                {
                    selfMap.Add(path[i].Pos, new TileDir[3] {
                        path[i].DirIn, path[i].DirOut.Negative(), path[i].DirIn.Negative() + path[i].DirOut
                    });
                }
            }
            selfMap.Add(endTile, new TileDir[2] {
                dirEnd.Negative(), dirEnd + dirMove.Negative()
            });

            calculator.setupSelfMapCrash(selfMap);

            Move needMove = calculator.calculateTurn(endDir);

            move.IsBrake     = needMove.IsBrake;
            move.EnginePower = needMove.EnginePower;
            move.WheelTurn   = needMove.WheelTurn;
        }
Esempio n. 3
0
        public override void execute(Move move)
        {
            TileDir dirMove = path[0].DirOut;

            Physic.MovingCalculator calculator = new Physic.MovingCalculator();
            calculator.setupEnvironment(car, game, world);
            calculator.setupMapInfo(dirMove, path[0].Pos, null);

            calculator.setupAngleReach(new Vector(dirMove.X, dirMove.Y));
            calculator.setupDefaultAction(EndSidePos());

            Dictionary <TilePos, TileDir[]> selfMap = new Dictionary <TilePos, TileDir[]>();

            for (int i = 0; i <= 2; i++)
            {
                if (path[i].DirIn == path[i].DirOut)
                {
                    selfMap.Add(path[i].Pos, new TileDir[2] {
                        dirMove.PerpendicularLeft(), dirMove.PerpendicularRight()
                    });
                }
                else if (0 == i)
                {
                    selfMap.Add(path[i].Pos, new TileDir[1] {
                        path[0].DirIn
                    });
                }
                else
                {
                    break;
                }
            }
            calculator.setupSelfMapCrash(selfMap);
            calculator.setupAdditionalPoints(this.additionalPoints);

            Move needMove = calculator.calculateMove();

            move.IsBrake     = needMove.IsBrake;
            move.EnginePower = needMove.EnginePower;
            move.WheelTurn   = needMove.WheelTurn;
        }
        public override void execute(Move move)
        {
            TileDir dirMove = path[0].DirOut;
            TileDir dirEnd  = path[2].DirOut;

            MovingCalculator calculator = new MovingCalculator();

            calculator.setupEnvironment(car, game, world);
            calculator.setupMapInfo(dirMove, path[0].Pos, path[2].Pos);
            calculator.setupDefaultAction(GetWayEnd(path[2].Pos, dirEnd.Negative()));

            Vector endDir = new Vector(dirEnd.X + dirMove.X, dirEnd.Y + dirMove.Y).Normalize();

            calculator.setupAngleReach(endDir);
            calculator.setupPassageLine(GetWayEnd(path[2].Pos, TileDir.Zero), new Vector(dirMove.X, dirMove.Y), 0.5);

            Dictionary <TilePos, TileDir[]> selfMap = new Dictionary <TilePos, TileDir[]>();

            for (int i = 0; i < 2; i++)
            {
                selfMap.Add(path[i].Pos, new TileDir[2] {
                    dirMove.PerpendicularLeft(), dirMove.PerpendicularRight()
                });
            }
            selfMap.Add(path[2].Pos, new TileDir[2] {
                dirEnd + dirMove.Negative(), dirEnd
            });

            calculator.setupSelfMapCrash(selfMap);
            calculator.setupAdditionalPoints(this.additionalPoints);

            Move needMove = calculator.calculateTurn(endDir);

            move.IsBrake     = needMove.IsBrake;
            move.EnginePower = needMove.EnginePower;
            move.WheelTurn   = needMove.WheelTurn;
        }
Esempio n. 5
0
        protected PathCheckResult checkTurn(int offset = 0)
        {
            if (1 + offset >= path.Count)
            {
                return(PathCheckResult.Unknown);
            }

            TileDir dirIn  = path[offset + 1].DirIn;
            TileDir dirOut = path[offset + 1].DirOut;

            if (null == dirOut || dirOut == TileDir.Zero)
            {
                return(PathCheckResult.Unknown);
            }

            if (dirIn == dirOut.PerpendicularLeft() || dirIn == dirOut.PerpendicularRight())
            {
                return(PathCheckResult.Yes);
            }
            else
            {
                return(PathCheckResult.No);
            }
        }