示例#1
0
        public Robot(IArena arena)
        {
            _arena = arena
                     ?? throw new ArgumentException(nameof(arena));

            _handleMovement = new Dictionary <Direction, Action>
            {
                { Direction.North, () => { if (Longitude < _arena.Longitude)
                                           {
                                               Longitude++;
                                           }
                  } },
                { Direction.South, () => { if (Longitude > 0)
                                           {
                                               Longitude--;
                                           }
                  } },
                { Direction.East, () => { if (Latitude < _arena.Latitude)
                                          {
                                              Latitude++;
                                          }
                  } },
                { Direction.West, () => { if (Latitude > 0)
                                          {
                                              Latitude--;
                                          }
                  } }
            };
        }
示例#2
0
        public SuperHero Fight(SuperHero hero1, SuperHero hero2, IArena arena)
        {
            decimal hero1Attack = hero1.AttackStrength;
            decimal hero2Attack = hero2.AttackStrength;

            if (arena.IsDark)
            {
                hero1Attack = hero1Attack * hero1.NightModifier;
                hero2Attack = hero2Attack * hero2.NightModifier;
            }

            if (arena.IsUnderwater)
            {
                hero1Attack = hero1Attack * hero1.UnderwaterModifier;
                hero2Attack = hero2Attack * hero2.UnderwaterModifier;
            }

            if (arena.IsOuterSpace)
            {
                hero1Attack = hero1Attack * hero1.ZeroGravityModifier;
                hero2Attack = hero2Attack * hero2.ZeroGravityModifier;
            }

            var hero1Hit = hero1Attack - hero2.DefenseStrength;
            var hero2Hit = hero2Attack - hero1.DefenseStrength;

            return((hero1Hit > hero2Hit) ? hero1 : hero2);
        }
示例#3
0
 public void ResetGame()
 {
     _player = new Player();
     _robots = new List<IRobot>();
     _arena = new Arena(_player, _robots);
     _arena.DrawArena();
 }
        public TeamStanding DetermineStanding(IArena context)
        {
            // Why can't current standing do this?
            // TODO(greenstack): This is dirty and I dislike it.
            foreach (var ship in Members)
            {
                if (ship.Status == TeammateStatus.Active)
                {
                    CurrentStanding = TeamStanding.Competing;
                    return(CurrentStanding);
                }
            }
            var opponents = context.GetTeamsWithRelationship(this, TeamRelationship.Opposing);

            // This is, in particular, what I dislike. Maybe teams should
            // only _care_ about their own status, and the end of battle
            // phase should handle this? I'm not 100% sure. But part of the
            // reason I dislike this is that it relies on defeated teams being
            // updated first. Sure, I could loop over the enemy teams units as
            // well... but that opens another can of worms.
            foreach (var opponent in opponents)
            {
                if (opponent.CurrentStanding == TeamStanding.Defeated)
                {
                    CurrentStanding = TeamStanding.Victorious;
                    return(CurrentStanding);
                }
            }
            return(TeamStanding.Defeated);
        }
示例#5
0
        // faillet: Look for ways to get to these inputs, to get that result type
        public bool RecurseConversionAttempt(IArena arena, double salience, string reason, IContinuation skip, params object[] args)
        { // params: object value, IEnumerable<IAction> actions, IContinuation succ
            if (aborter.IsAborted)
            {
                return(true);   // abort!
            }
            // Can we go down another level?
            Aborter next = new Aborter(aborter);

            if (next.IsAborted)
            {
                return(true);
            }

            object value = args[0];
            IEnumerable <IAction> actions = (IEnumerable <IAction>)args[1];
            IContinuation         succ    = (IContinuation)args[2];

            foreach (IAction action in actions)
            {
                arena.Call(new ActionConversion(plugenv, action.Input, searched, next), salience * .9, value,
                           new CallableAsContinuation(action, succ), new NopCallable());
            }

            return(true);
        }
示例#6
0
        public override int Initialize(IArena arena, double salience)
        {
            int used = 0;
            if (callable is IAgent)
                used += ((IAgent)callable).Initialize(arena, salience);

            return base.Initialize(arena, salience) + used;
        }
 public PostRequestHandler(WabiSabiConfig config, Prison prison, IArena arena, IRPCClient rpc)
 {
     Config  = config;
     Prison  = prison;
     Arena   = arena;
     Rpc     = rpc;
     Network = rpc.Network;
 }
示例#8
0
 /// <summary>
 /// Determines if any team in the arena has the current standing.
 /// </summary>
 /// <param name="arena">The arena to check.</param>
 /// <param name="standing">The standing to check for.</param>
 /// <returns>True if any team has the given standing.</returns>
 public static bool AnyTeamHasStanding(this IArena arena, TeamStanding standing)
 {
     if (arena is null)
     {
         throw new ArgumentNullException(nameof(arena));
     }
     return(arena.Teams.Any((team) => team.CurrentStanding == standing));
 }
示例#9
0
        public override int Initialize(IArena arena, double salience)
        {
            int used = 0;
            if (continuation is IAgent)
                used += ((IAgent)continuation).Initialize(arena, salience);

            return base.Initialize(arena, salience) + used;
        }
示例#10
0
文件: Hero.cs 项目: gavin-zyi/Ains
        public async Task Step(IArena arena)
        {
            var pos = await arena.GetPlayerPosition(this);
            Console.WriteLine($"Position = Q:{pos.Q} R:{pos.R}");

            var path = FindPath(await arena.GetTerrain(), pos, new Hex());

            await arena.Move(this, new Hex(-1, -1));
        }
示例#11
0
 public AppService(ICommandParser parser, IArena arena, IEnumerable <IRobot> robots)
 {
     _parser = parser
               ?? throw new ArgumentException(nameof(parser));
     _arena = arena
              ?? throw new ArgumentException(nameof(arena));
     _robots = robots
               ?? throw new ArgumentException(nameof(robots));
 }
        public SetupArenaCommand(IArena arena)
        {
            if (arena == null)
            {
                throw new ArgumentNullException("arena");
            }

            this.arena = arena;
        }
示例#13
0
文件: Hero.cs 项目: gavin-zyi/Ains
        public async Task Step(IArena arena)
        {
            var pos = await arena.GetPlayerPosition(this);

            Console.WriteLine($"Position = Q:{pos.Q} R:{pos.R}");

            var path = FindPath(await arena.GetTerrain(), pos, new Hex());

            await arena.Move(this, new Hex(-1, -1));
        }
 bool FailToTryToRescue(IArena arena, double salience, string reason, IContinuation skip, params object[] args)
 {
     TryToRescueMatch tryToRescueMatch = (TryToRescueMatch) args[0];
     IParsedPhrase input = (IParsedPhrase) args[1];
     PatternTemplateSource patternTemplateSource = (PatternTemplateSource) args[2];
     IContinuation succ = (IContinuation) args[3];
     IFailure fail = (IFailure) args[4];
     Coderack coderack = (Coderack) args[5];
     return tryToRescueMatch.CallRescue(coderack, input, patternTemplateSource, reason, skip, succ, fail);
 }
示例#15
0
 /// <summary>
 /// Gets all the teams with the given standing.
 /// </summary>
 /// <param name="arena">The arena to check against.</param>
 /// <param name="standing">The standing to search for.</param>
 /// <returns>A sequence of teams that match the check.</returns>
 public static IEnumerable <T> GetTeamsWithStanding <T>(this IArena arena, TeamStanding standing) where T : ITeam
 {
     if (arena is null)
     {
         throw new ArgumentNullException(nameof(arena));
     }
     return(from team in arena.Teams
            where team.CurrentStanding == standing
            select(T) team);
 }
示例#16
0
 private MatchMaker(int dummy)
 {
     mutex             = new object();
     state             = State.NotQueued;
     match_player_decl = new MatchDecl();
     match_mode        = MatchMode.Skirmish; //Garbage
     aren_type         = Arena.None;         //Atleast an invalid value
     team_size         = TeamSize.One;       //Garbage
     arena             = null;
 }
        public override int Initialize(IArena arena, double salience)
        {
            int used = 0;

            if (continuation is IAgent)
            {
                used += ((IAgent)continuation).Initialize(arena, salience);
            }

            return(base.Initialize(arena, salience) + used);
        }
示例#18
0
        bool FailToTryToRescue(IArena arena, double salience, string reason, IContinuation skip, params object[] args)
        {
            TryToRescueMatch      tryToRescueMatch      = (TryToRescueMatch)args[0];
            IParsedPhrase         input                 = (IParsedPhrase)args[1];
            PatternTemplateSource patternTemplateSource = (PatternTemplateSource)args[2];
            IContinuation         succ = (IContinuation)args[3];
            IFailure fail     = (IFailure)args[4];
            Coderack coderack = (Coderack)args[5];

            return(tryToRescueMatch.CallRescue(coderack, input, patternTemplateSource, reason, skip, succ, fail));
        }
示例#19
0
        public override int Initialize(IArena arena, double salience)
        {
            int used = 0;

            if (callable is IAgent)
            {
                used += ((IAgent)callable).Initialize(arena, salience);
            }

            return(base.Initialize(arena, salience) + used);
        }
示例#20
0
        public virtual void Setup()
        {
            this.arenaStub = MockRepository.GenerateStub <IArena>();
            this.arenaStub.Stub(c => c.Width).Return(coordinate);
            this.arenaStub.Stub(c => c.Height).Return(coordinate);

            this.robotStub = MockRepository.GenerateStub <IRobotWars>();
            this.robotStub.Stub(c => c.Direction).Return(Direction.South);

            this.contextStub = MockRepository.GenerateStub <IContext>();
            this.robot       = new RobotWars();
        }
示例#21
0
 /// <summary>
 /// Gets a single opposing team from the arena.
 /// </summary>
 /// <typeparam name="TTeam">The type of team to cast to.</typeparam>
 /// <param name="arena">The arena to search in.</param>
 /// <param name="team">The team whose opponent you want to get.</param>
 /// <returns>The team that rivals the given team.</returns>
 /// <exception cref="ArgumentNullException">If either arena or team are null.</exception>
 /// <exception cref="InvalidOperationException">If there are multiple opposing teams.</exception>
 public static TTeam GetOpposingTeam <TTeam>(this IArena arena, TTeam team) where TTeam : ITeam
 {
     if (arena == null)
     {
         throw new ArgumentNullException(nameof(arena));
     }
     if (team == null)
     {
         throw new ArgumentNullException(nameof(team));
     }
     return((TTeam)arena.Teams.Single(t => !((TTeam)t).Equals(team)));
 }
示例#22
0
        public virtual void Setup()
        {
            this.arenaStub = MockRepository.GenerateStub<IArena>();
            this.arenaStub.Stub(c => c.Width).Return(coordinate);
            this.arenaStub.Stub(c => c.Height).Return(coordinate);

            this.robotStub = MockRepository.GenerateStub<IRobotWars>();
            this.robotStub.Stub(c => c.Direction).Return(Direction.South);

            this.contextStub = MockRepository.GenerateStub<IContext>();
            this.robot = new RobotWars();
        }
示例#23
0
 /// <summary>
 /// This should be called on all players when <see cref="AnswerPendingResult.player_state"/> == <see cref="State.AwaitingOtherPlayers"/> and <see cref="AnswerPendingResult.all_is_ready"/> == true.
 /// </summary>
 /// <returns></returns>
 public State InArena(IArena arena)
 {
     lock (mutex)
     {
         if (state != State.AwaitingOtherPlayers)
         {
             return(state);
         }
         state      = State.InArena;
         this.arena = arena;
         return(state);
     }
 }
示例#24
0
        private static bool SolveSudoku(IArena arena, int row, int col)
        {
            //Thread.Sleep(10);
            while (true)
            {
                // avoid backtracking
                if (row == arena.GridSize - 1 && col == arena.GridSize)
                {
                    return(true);
                }

                // set new row if end of line
                if (col == arena.GridSize)
                {
                    row++;
                    col = 0;
                }

                // move next if value founded
                if (arena.GetValue(row, col) != Constants.ORIG_SUDOKU_EMPTY_VALUE)
                {
                    col += 1;
                    continue;
                }


                var values = Enumerable.Range(Constants.ORIG_SUDOKU_MIN_VALUE, Constants.ORIG_SUDOKU_MAX_VALUE).ToList();
                while (values.Any())
                {
                    var num = values[_rand.Next(values.Count)];

                    // check value possibility
                    if (CheckModel(arena, row, col, num))
                    {
                        arena.SetValue(row, col, num);

                        // Check next positions
                        if (SolveSudoku(arena, row, col + 1))
                        {
                            return(true);
                        }
                    }

                    // remove the assigned num
                    values.Remove(num);
                    arena.SetValue(row, col);
                }

                return(false);
            }
        }
示例#25
0
        public bool EnterArena(IArena arena, uint x, uint y, Direction direction)
        {
            if (arena == null || x > arena.Width || y > arena.Height)
            {
                return false;
            }

            this.Arena = arena;
            this.XAxis = x;
            this.YAxis = y;
            this.Direction = direction;

            return true;
        }
示例#26
0
        public bool EnterArena(IArena arena, uint x, uint y, Direction direction)
        {
            if (arena == null || x > arena.Width || y > arena.Height)
            {
                return(false);
            }

            this.Arena     = arena;
            this.XAxis     = x;
            this.YAxis     = y;
            this.Direction = direction;

            return(true);
        }
示例#27
0
        private static bool SolveSudoku(IArena arena, int row, int col)
        {
            //Thread.Sleep(10);
            while (true)
            {
                // avoid backtracking
                if (row == arena.GridSize - 1 && col == arena.GridSize)
                {
                    return(true);
                }

                // set new row if end of line
                if (col == arena.GridSize)
                {
                    row++;
                    col = 0;
                }

                // move next if value founded
                if (arena.GetValue(row, col) != CellValue.None)
                {
                    col += 1;
                    continue;
                }

                var values = Enum.GetValues(typeof(CellValue)).Cast <CellValue>().Where(e => e > CellValue.None).ToList();
                while (values.Any())
                {
                    var num = values[_rand.Next(values.Count)];

                    // check value possibility
                    if (CheckModel(arena, row, col, num))
                    {
                        arena.SetValue(row, col, num);

                        // Check next positions
                        if (SolveSudoku(arena, row, col + 1))
                        {
                            return(true);
                        }
                    }

                    // remove the assigned num
                    values.Remove(num);
                    arena.SetValue(row, col);
                }

                return(false);
            }
        }
示例#28
0
        /// <summary>
        /// Enter an arena and go to a specified location 
        /// </summary>
        /// <param name="arena">Arena to enter</param>
        /// <param name="x">X coordinate (latitude)</param>
        /// <param name="y">Y coordinate (longitude)</param>
        /// <param name="direction"></param>
        /// <returns>True if arena entered successfully, otherwise false</returns>
        public bool EnterArena(IArena arena, uint x, uint y, RobotDirection direction)
        {
            if (arena == null || x > arena.UpperLatitude || y > arena.UpperLongitude)
            {
                return false;
            }

            this.Arena = arena;
            this.Latitude = x;
            this.Longitude = y;
            this.Direction = direction;

            return true;
        }
示例#29
0
        public bool EnterArena(IArena arena, uint x, uint y, RobotDirection direction)
        {
            if (arena == null || x > arena.UpperLatitude || y > arena.UpperLongitude)
            {
                return(false);
            }

            this.Arena     = arena;
            this.Latitude  = x;
            this.Longitude = y;
            this.Direction = direction;

            return(true);
        }
示例#30
0
 /// <summary>
 /// Returns the new state.
 /// If the state is <see cref="State.InArena"/> then state is set to <see cref="State.NotQueued"/>.
 /// In all other cases the state is unmodified and that state is returned instead.
 /// </summary>
 /// <returns></returns>
 public State LeaveArena(Player player)
 {
     lock (mutex)
     {
         if (state != State.InArena)
         {
             return(state);
         }
         arena.RemoveLeftPlayer(player);
         arena.RemoveRightPlayer(player);
         arena = null;
         state = State.NotQueued;
         return(State.NotQueued);
     }
 }
示例#31
0
        // faillet: called each time we need to try the next option
        public bool ContinueNext(IArena arena, double salience, string reason, IContinuation skip, params object[] args)
        { // params: IContinuation succ, IFailure fail
            IContinuation succ = (IContinuation)args[0];
            IFailure      fail = (IFailure)args[1];

            // Try the next value!
            if (enumerator.MoveNext())
            {
                return(arena.Continue(succ, salience, enumerator.Current, new FailletWrapper(ContinueNext, succ, fail)));
            }
            else
            {
                // nothing more to try!
                return(arena.Fail(fail, salience, reason, succ));
            }
        }
示例#32
0
        // check all model
        private static bool CheckModel(IArena arena)
        {
            for (var row = 0; row < arena.GridSize; row++)
            {
                for (var col = 0; col < arena.GridSize; col++)
                {
                    var num = arena.GetValue(row, col);

                    if (num > 0 && !CheckModel(arena, row, col, num))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#33
0
        public Robot(IArena arena)
        {
            if (arena == null)
            {
                throw new ArgumentNullException("arena");
            }

            _arena = arena;

            // Setup Commands...
            _moveCommands = new Action<bool>[]
            {
                NorthCommand,
                EastCommand,
                SouthCommand,
                WestCommand
            };
        }
示例#34
0
        // check cell
        private static bool CheckModel(IArena arena, int row, int col, int num)
        {
            // check row for same value
            for (var x = 0; x < arena.GridSize; x++)
            {
                if (x != col && arena.GetValue(row, x) == num)
                {
                    return(false);
                }
            }

            // check column for same value
            for (var x = 0; x < arena.GridSize; x++)
            {
                if (x != row && arena.GetValue(x, col) == num)
                {
                    return(false);
                }
            }

            // check matrix for same value
            int startRow = row - row % arena.RegionSize, startCol = col - col % arena.RegionSize;

            for (var i = 0; i < arena.RegionSize; i++)
            {
                for (var j = 0; j < arena.RegionSize; j++)
                {
                    int cRow = i + startRow, cCol = j + startCol;
                    if (arena.GetValue(cRow, cCol) == num)
                    {
                        if (cCol == col && cRow == row)
                        {
                            continue;
                        }

                        return(false);
                    }
                }
            }

            return(true);
        }
        public int CheckAction(IArena arena, double salience, object value, IFailure fail, params object[] args)
        {
            // params: object oldval, IContinuation succ
            if (aborter.IsAborted)
                return 1;   // abort!

            ArgumentTree argtree = new ArgumentTree(args[0]);
            IContinuation succ = (IContinuation)args[1];
            IAction action = (IAction)value;

            ArgumentTree result = action.Input.IsValid(argtree);
            if (result == null)
            {
                // abort the search-- we found an appropriate action!
                aborter.Abort();

                return arena.Call(action, salience, args[0], succ, fail);
            }
            else
                return arena.Fail(fail, salience, "input type doesn't match", succ);
        }
示例#36
0
        public bool CheckAction(IArena arena, double salience, object value, IFailure fail, params object[] args)
        { // params: object oldval, IContinuation succ
            if (aborter.IsAborted)
            {
                return(true);   // abort!
            }
            ArgumentTree  argtree = new ArgumentTree(args[0]);
            IContinuation succ    = (IContinuation)args[1];
            IAction       action  = (IAction)value;

            ArgumentTree result = action.Input.IsValid(argtree);

            if (result == null)
            {
                // abort the search-- we found an appropriate action!
                aborter.Abort();

                return(arena.Call(action, salience, args[0], succ, fail));
            }
            else
            {
                return(arena.Fail(fail, salience, "input type doesn't match", succ));
            }
        }
示例#37
0
 public GameViewModel(IArena arena = null)
 {
     this._arena = arena ?? new SudokuArena();
 }
示例#38
0
 public AgentBase()
 {
     arena = new ImmediateArena();
     salience = 1.0;
 }
 private void CheckArenaIsNotNull (IArena arena)
 {
     if (arena == null)
     {
         throw new ArgumentNullException();
     }
 }
        private ICommand SetupArenaCommand()
        {
            arena = new RectangleArena();

            return new SetupArenaCommand(arena);
        }
 public BattleAnalyzer(IFightAlgorithm fightAlgorithm, IArena arena, IHeroFactory heroFactory)
 {
     FightAlgorithm = fightAlgorithm;
     Arena          = arena;
     Factory        = heroFactory;
 }
        public GameSupervisor (IArena arena)
        {
            CheckArenaIsNotNull(arena);

            this.Arena = arena;
        }
示例#43
0
 void IInitCSRobot.DeInit()
 {
     mArena = null;
 }
示例#44
0
 public virtual int Initialize(IArena arena, double salience)
 {
     this.arena = arena;
     this.salience = salience;
     return 1;
 }
示例#45
0
 public virtual void Deserialize(SerializationReader reader)
 {
     arena = (IArena)reader.ReadPointer();
     salience = reader.ReadDouble();
 }
        private OwnedArena <T> CreateAndAddArena <T>()
        {
            var arena = Create();

            _ownedArenas.Add(typeof(T), arena);
            _lastArena = arena;
            return(arena);

            OwnedArena <T> Create()
            {
                Allocator <T> allocator = null;
                bool          addBySize = false;

                try
                {
                    if (PerTypeHelpers <T> .IsBlittable && Unsafe.SizeOf <T>() > 0) // we can do fun things for blittable types
                    {
                        // can we use a padded approach? (more complex/slower allocations due to padding, but better memory usage)
                        if (Options.HasFlag(ArenaFlags.BlittablePaddedSharing) && // if the caller wants
                            Unsafe.SizeOf <T>() <= 256)    // don't use too-large T because of excessive padding
                        {
                            if (typeof(T) == typeof(byte)) // for blittable scenarios, byte is the underlying type, so don't thunk it
                            {
                                // however, we still need to let the factory suggest a (hopefully pinned) blittable allocator
                                allocator = (Allocator <T>)(object) Factory.SuggestBlittableAllocator <byte>(Options);
                            }
                            else
                            {
                                return((OwnedArena <T>)Activator.CreateInstance(
                                           typeof(PaddedBlittableOwnedArena <int>).GetGenericTypeDefinition()
                                           .MakeGenericType(typeof(T)),
                                           args: new object[] { this }));
                            }
                        }

                        // if we aren't using padded blittables; can we use a non-padded approach instead?
                        if (!Options.HasFlag(ArenaFlags.BlittablePaddedSharing) && Options.HasFlag(ArenaFlags.BlittableNonPaddedSharing))
                        {
                            if (_blittableBySize.TryGetValue(Unsafe.SizeOf <T>(), out var existing))
                            {
                                // one already exists for that size, yay!
                                return((OwnedArena <T>)Activator.CreateInstance(
                                           typeof(NonPaddedBlittableOwnedArena <int, uint>).GetGenericTypeDefinition()
                                           .MakeGenericType(existing.ElementType, typeof(T)),
                                           args: new object[] { this }));
                            }

                            // and even if one doesn't already exist; we will want to create one, which
                            // means we need a blittable allocator
                            allocator = (Allocator <T>) typeof(AllocatorFactory).GetMethod(nameof(AllocatorFactory.SuggestBlittableAllocator),
                                                                                           BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                                        .MakeGenericMethod(typeof(T)).Invoke(Factory, parameters: new object[] { Options });
                            addBySize = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    // if bad things happen; give up
                    Debug.WriteLine(ex.Message);
                }
                var newArena = new SimpleOwnedArena <T>(this, allocator);

                if (addBySize)
                {
                    _blittableBySize.Add(Unsafe.SizeOf <T>(), newArena);
                }
                return(newArena);
            }
        }
        // faillet: Look for ways to get to these inputs, to get that result type
        public int RecurseConversionAttempt(IArena arena, double salience, string reason, IContinuation skip, params object[] args)
        {
            // params: object value, IEnumerable<IAction> actions, IContinuation succ
            if (aborter.IsAborted)
                return 1;   // abort!

            // Can we go down another level?
            Aborter next = new Aborter(aborter);
            if (next.IsAborted)
                return 1;

            object value = args[0];
            IEnumerable<IAction> actions = (IEnumerable<IAction>)args[1];
            IContinuation succ = (IContinuation)args[2];

            int used = 1;
            foreach (IAction action in actions)
                used += arena.Call(new ActionConversion(plugenv, action.Input, searched, next), salience * .9, value,
                    new CallableAsContinuation(action, succ), new NopCallable());

            return used;
        }