Пример #1
0
        private void init(byte[] variantBytes, int startPosition, int len)
        {
            sortOrder                 = Serializable.SortOrder.None;
            preferredVariantIndex     = -1;
            preferredUserVariantIndex = -1;
            trackBytes                = null;

            variants.Clear();

            if (len > 0)
            {
                //copy track bytes adding a 0 add the beginning and another at the end
                trackBytes = new byte[len + 2];
                Array.Copy(variantBytes, startPosition, trackBytes, 1, len);

                // calculate for two directions
                variants.Add(new Variant(trackBytes, bpc, add)
                {
                    track = trackId, direction = 0
                });
                variants.Add(new Variant(BitSolution.Reverse(trackBytes), bpc, add)
                {
                    track = trackId, direction = 1
                });
                variants.Sort(new VariantComparer(SortOrder.Descending));

                preferredUserVariantIndex = 0;
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            var timer = new Stopwatch();

            timer.Start();
            BitMaps.GenerateMoves();
            BitMaps.GenerateBombs();
            timer.Stop();

            char[,] map = new char[13, 11];
            List <Robot> bots  = new List <Robot>();
            List <Bomb>  bombs = new List <Bomb>();
            var          bomb  = new Bomb();

            bomb.position  = 2;
            bomb.owner     = 0;
            bomb.range     = 3;
            bomb.countDown = 7;
            bombs.Add(bomb);

            bomb           = new Bomb();
            bomb.position  = 13;
            bomb.owner     = 0;
            bomb.range     = 3;
            bomb.countDown = 4;
            bombs.Add(bomb);

            for (int i = 0; i < 11; i++)
            {
                for (int j = 0; j < 13; j++)
                {
                    map[j, i] = '.';
                }
            }

            var r = new Robot();

            r.owner = 0;
            var x = 0;
            var y = 0;

            r.position = BitState.GetBitIndex(x, y);
            r.param1   = 1;
            r.param2   = 3;

            bots.Add(r);

            var bgs = new BitState(map, bots, bombs, 0);

            var best = BitSolution.generateBestRandomSolution(bgs, 0, 20, 90);
            //var move = new Move(MoveType.Move, MoveDirection.Stay);
            var move = best.moves[0];

            bgs.getBot(0).getCommand(move);

            bgs.play(best, 0);
            bgs.score(0);

            Console.Error.WriteLine(timer.ElapsedMilliseconds);
        }