Exemplo n.º 1
0
        private void MakeBotsRank(IBot firstBot, IBot secondBot, bool isDraw, int cycle)
        {
            float firstScore = 0;

            if (isDraw)
            {
                firstScore = 0;
            }
            else
            {
                switch (cycle)
                {
                case 3:
                    firstScore = 1;
                    break;

                case 4:
                    firstScore = 0.75f;
                    break;

                case 5:
                    firstScore = 0.5f;
                    break;
                }
            }

            var firstRank  = new BotRank(firstBot, firstScore);
            var secondRank = new BotRank(secondBot, 0);

            m_botsRanking = new BotRank[] { firstRank, secondRank };
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the round.
        /// </summary>
        /// <param name="context">The world context.</param>
        public override void InitializeRound(IWorldContext context)
        {
            MarkAllCellsUnknown();
            MarkBornAndTargetCells();

            m_environmentContext = new MazeEnvironmentContext(m_map);
            m_environmentContext.SetCellState(m_bornCell.Y, m_bornCell.X, CellState.Visited);
            m_environmentContext.MyCell = m_bornCell;

            m_roundBot        = context.GetBotsWithKindOfAbility <IMazeBotAbility>()[0];
            m_roundBotAbility = (IMazeBotAbility)context.GetBotAbility <IMazeBotAbility>(m_roundBot);
            m_roundBotAbility.Initialize(m_environmentContext);

            m_botRank = null;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates the environment (run a cycle).
        /// </summary>
        /// <param name="context">The world context.</param>
        public override void Update(IWorldContext context)
        {
            if (State == EnvironmentState.Running)
            {
                var ctx = m_environmentContext;

                var botWalkDirection = m_roundBotAbility.Walk(ctx);

                if (ctx.CanWalkTo(botWalkDirection))
                {
                    var botWishCell = GetBotWishCell(ctx, botWalkDirection);
                    var mainMapCell = m_map[botWishCell.Y, botWishCell.X];

                    switch (mainMapCell.State)
                    {
                    case CellState.Occupied:
                        ctx.SetCellState(botWishCell.Y, botWishCell.X, mainMapCell.State);
                        break;

                    case CellState.Target:
                        m_botRank = new BotRank(m_roundBot, ((MaxUpdateCycles - context.Cycle) / (float)MaxUpdateCycles));
                        State     = EnvironmentState.Finished;
                        break;

                    default:
                        mainMapCell.State         = CellState.Occupied;
                        mainMapCell.OccupiedByBot = m_roundBot;

                        mainMapCell       = m_map[ctx.MyCell.Y, ctx.MyCell.X];
                        mainMapCell.State = CellState.Visited;

                        ctx.SetCellState(ctx.MyCell.Y, ctx.MyCell.X, CellState.Visited);
                        ctx.SetCellState(botWishCell.Y, botWishCell.X, CellState.Occupied);

                        ctx.MyCell = botWishCell;
                        break;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public override void Update(IWorldContext context)
        {
            var result = m_ability.SwapItems();

            if (!ValidateIndex(result.FirstItemIndex) || !ValidateIndex(result.SecondItemIndex))
            {
                throw new EnvironmentException(
                          "Some swap index invalid (FirstItemIndex:{0}, SecondItemIndex:{1})."
                          .With(result.FirstItemIndex, result.SecondItemIndex));
            }

            int tmp = m_context.Items [result.FirstItemIndex];

            m_context.Items [result.FirstItemIndex]  = m_context.Items [result.SecondItemIndex];
            m_context.Items [result.SecondItemIndex] = tmp;

            if (m_context.Items.SequenceEqual(m_sortedItems))
            {
                m_rank = new BotRank(m_roundBot, MaxUpdateCycles - context.Cycle);
                State  = EnvironmentState.Finished;
            }
        }
Exemplo n.º 5
0
        public override void Update(IWorldContext context)
        {
            m_leftPaddleContext.Cycle           = context.Cycle;
            m_leftPaddleContext.MyPaddleX       = LeftPaddle.CenterX;
            m_leftPaddleContext.MyPaddleY       = LeftPaddle.CenterY;
            m_leftPaddleContext.OpponentPaddleX = RightPaddle.CenterX;
            m_leftPaddleContext.OpponentPaddleY = RightPaddle.CenterY;
            m_leftPaddleContext.BallX           = Ball.CenterX;
            m_leftPaddleContext.BallY           = Ball.CenterY;
            m_leftPaddleContext.BallSpeedX      = Ball.SpeedX;
            m_leftPaddleContext.BallSpeedY      = Ball.SpeedY;
            m_leftPaddleContext.BallWidth       = Ball.Width;
            m_leftPaddleContext.BallHeight      = Ball.Height;

            m_rightPaddleContext.Cycle           = context.Cycle;
            m_rightPaddleContext.MyPaddleX       = RightPaddle.CenterX;
            m_rightPaddleContext.MyPaddleY       = RightPaddle.CenterY;
            m_rightPaddleContext.OpponentPaddleX = LeftPaddle.CenterX;
            m_rightPaddleContext.OpponentPaddleY = LeftPaddle.CenterY;
            m_rightPaddleContext.BallX           = Ball.CenterX;
            m_rightPaddleContext.BallY           = Ball.CenterY;
            m_rightPaddleContext.BallSpeedX      = Ball.SpeedX;
            m_rightPaddleContext.BallSpeedY      = Ball.SpeedY;
            m_rightPaddleContext.BallWidth       = Ball.Width;
            m_rightPaddleContext.BallHeight      = Ball.Height;

            PeformsPaddleMove(LeftPaddle, m_leftPaddleBotAbility, m_leftPaddleContext);
            PeformsPaddleMove(RightPaddle, m_rightPaddleBotAbility, m_rightPaddleContext);

            PerformsBallMove();

            if (LeftPaddle.Points == 3 || RightPaddle.Points == 3)
            {
                m_botsRanks[0] = new BotRank(LeftPaddle.Controller, CalculateRank(LeftPaddle, context));
                m_botsRanks[1] = new BotRank(RightPaddle.Controller, CalculateRank(RightPaddle, context));
                State          = EnvironmentState.Finished;
            }
        }