예제 #1
0
        private async Task<RoundPartialHistory> PerformMove(AntModel movableObject, int roundNumber)
        {
            var move = await movableObject.NextMoveAsync(null);
            var actionDescription = move.Action.ToString() + " ";

            if (move.ActionDirection != null)
            {
                actionDescription += move.ActionDirection.Value.ToString() + ". ";
            }

            switch (move.Action)
            {
                case AvailableActions.Move:
                    {
                        switch (move.ActionDirection)
                        {
                            case ActionDirections.Down:
                                {
                                    if (IsMoveValid(movableObject.X, movableObject.Y + 1))
                                    {
                                        movableObject.Down();
                                    }
                                    else
                                    {
                                        actionDescription += "Lost his move.";
                                    }
                                    break;
                                }
                            case ActionDirections.Up:
                                {
                                    if (IsMoveValid(movableObject.X, movableObject.Y - 1))
                                    {
                                        movableObject.Up();
                                    }
                                    else
                                    {
                                        actionDescription += "Lost his move.";
                                    }
                                    break;
                                }
                            case ActionDirections.Left:
                                {
                                    if (IsMoveValid(movableObject.X - 1, movableObject.Y))
                                    {
                                        movableObject.Left();
                                    }
                                    else
                                    {
                                        actionDescription += "Lost his move.";
                                    }
                                    break;
                                }
                            case ActionDirections.Right:
                                {
                                    if (IsMoveValid(movableObject.X + 1, movableObject.Y))
                                    {
                                        movableObject.Right();
                                    }
                                    else
                                    {
                                        actionDescription += "Lost his move.";
                                    }
                                    break;
                                }
                        }
                        break;
                    }
                case AvailableActions.Watch:
                    {
                        // movableObject.Watch();
                        break;
                    }
                case AvailableActions.FireMissile:
                    {

                        switch (move.ActionDirection)
                        {
                            case ActionDirections.Down:
                                {
                                    if (IsMoveValid(movableObject.X, movableObject.Y + 1))
                                    {
                                        _listOfMissilesToFire.Add(movableObject.FireMissile(move.ActionDirection.Value));
                                    }
                                    else
                                    {
                                        actionDescription += "Lost his move.";
                                    }
                                    break;
                                }
                            case ActionDirections.Up:
                                {
                                    if (IsMoveValid(movableObject.X, movableObject.Y - 1))
                                    {
                                        _listOfMissilesToFire.Add(movableObject.FireMissile(move.ActionDirection.Value));
                                    }
                                    else
                                    {
                                        actionDescription += "Lost his move.";
                                    }
                                    break;
                                }
                            case ActionDirections.Left:
                                {
                                    if (IsMoveValid(movableObject.X - 1, movableObject.Y))
                                    {
                                        _listOfMissilesToFire.Add(movableObject.FireMissile(move.ActionDirection.Value));
                                    }
                                    else
                                    {
                                        actionDescription += "Lost his move.";
                                    }
                                    break;
                                }
                            case ActionDirections.Right:
                                {
                                    if (IsMoveValid(movableObject.X + 1, movableObject.Y))
                                    {
                                        _listOfMissilesToFire.Add(movableObject.FireMissile(move.ActionDirection.Value));
                                    }
                                    else
                                    {
                                        actionDescription += "Lost his move.";
                                    }
                                    break;
                                }
                        }
                        break;
                    }
            }

            return new RoundPartialHistory
            {
                Caption = string.Format("Round {0} {1}: {2}", roundNumber, movableObject.Competitor.Name, actionDescription),
            };
        }
예제 #2
0
        private async Task <RoundPartialHistory> PerformMove(AntModel movableObject, int roundNumber)
        {
            var move = await movableObject.NextMoveAsync(null);

            var actionDescription = move.Action.ToString() + " ";

            if (move.ActionDirection != null)
            {
                actionDescription += move.ActionDirection.Value.ToString() + ". ";
            }

            switch (move.Action)
            {
            case AvailableActions.Move:
            {
                switch (move.ActionDirection)
                {
                case ActionDirections.Down:
                {
                    if (IsMoveValid(movableObject.X, movableObject.Y + 1))
                    {
                        movableObject.Down();
                    }
                    else
                    {
                        actionDescription += "Lost his move.";
                    }
                    break;
                }

                case ActionDirections.Up:
                {
                    if (IsMoveValid(movableObject.X, movableObject.Y - 1))
                    {
                        movableObject.Up();
                    }
                    else
                    {
                        actionDescription += "Lost his move.";
                    }
                    break;
                }

                case ActionDirections.Left:
                {
                    if (IsMoveValid(movableObject.X - 1, movableObject.Y))
                    {
                        movableObject.Left();
                    }
                    else
                    {
                        actionDescription += "Lost his move.";
                    }
                    break;
                }

                case ActionDirections.Right:
                {
                    if (IsMoveValid(movableObject.X + 1, movableObject.Y))
                    {
                        movableObject.Right();
                    }
                    else
                    {
                        actionDescription += "Lost his move.";
                    }
                    break;
                }
                }
                break;
            }

            case AvailableActions.Watch:
            {
                // movableObject.Watch();
                break;
            }

            case AvailableActions.FireMissile:
            {
                switch (move.ActionDirection)
                {
                case ActionDirections.Down:
                {
                    if (IsMoveValid(movableObject.X, movableObject.Y + 1))
                    {
                        _listOfMissilesToFire.Add(movableObject.FireMissile(move.ActionDirection.Value));
                    }
                    else
                    {
                        actionDescription += "Lost his move.";
                    }
                    break;
                }

                case ActionDirections.Up:
                {
                    if (IsMoveValid(movableObject.X, movableObject.Y - 1))
                    {
                        _listOfMissilesToFire.Add(movableObject.FireMissile(move.ActionDirection.Value));
                    }
                    else
                    {
                        actionDescription += "Lost his move.";
                    }
                    break;
                }

                case ActionDirections.Left:
                {
                    if (IsMoveValid(movableObject.X - 1, movableObject.Y))
                    {
                        _listOfMissilesToFire.Add(movableObject.FireMissile(move.ActionDirection.Value));
                    }
                    else
                    {
                        actionDescription += "Lost his move.";
                    }
                    break;
                }

                case ActionDirections.Right:
                {
                    if (IsMoveValid(movableObject.X + 1, movableObject.Y))
                    {
                        _listOfMissilesToFire.Add(movableObject.FireMissile(move.ActionDirection.Value));
                    }
                    else
                    {
                        actionDescription += "Lost his move.";
                    }
                    break;
                }
                }
                break;
            }
            }

            return(new RoundPartialHistory
            {
                Caption = string.Format("Round {0} {1}: {2}", roundNumber, movableObject.Competitor.Name, actionDescription),
            });
        }