Ejemplo n.º 1
0
 public static IMatch CreateMatch(MatchInput input)
 {
     using (var watch = new LogWatch())
     {
         return(CreateMatchCore(input, watch));
     }
 }
Ejemplo n.º 2
0
        public void Deserialize(Deserializer deserializer)
        {
            InputCount = deserializer.ReadUInt32();
            if (InputCount <= 0)
            {
                return;
            }
            ValidMask      = deserializer.ReadByte();
            StartTimestamp = deserializer.ReadUInt32();
            byte playerCount = GetPlayerCount(ValidMask);

            Inputs = ArrayPool <MatchInput> .Shared.Rent((int)InputCount);

            for (int i = 0; i < InputCount; i++)
            {
                Inputs[i] = new MatchInput(playerCount);
            }
            for (var i = 0; i < playerCount; i++)
            {
                if ((ValidMask & (1 << i)) == 0)
                {
                    continue;
                }
                PlayerInput?lastInput = null;
                for (int j = 0; j < InputCount; j++)
                {
                    var currentInput = PlayerInput.Deserialize(deserializer, lastInput);
                    Inputs[j][i] = currentInput;
                    lastInput    = currentInput;
                }
            }
        }
Ejemplo n.º 3
0
    private void Awake()
    {
        m_userInput  = new MouseAndKbInput();
        m_matchInput = new MatchInput(m_userInput);

        LoadMatchScene();
    }
Ejemplo n.º 4
0
 public static void ForceValid(ref MatchInput input, int mask)
 {
     for (var i = 0; i < input.PlayerCount; i++)
     {
         input.PlayerInputs[i].IsValid = (mask & (1 << i)) != 0;
     }
 }
Ejemplo n.º 5
0
        public void AddMatch(MatchInput input)
        {
            var foostatsChannel = _channelFactory.CreateChannel();
            var async           = foostatsChannel.BeginAddMatch(input, null, null);

            foostatsChannel.EndAddMatch(async);
        }
Ejemplo n.º 6
0
 internal Client(INetworkClient client, MatchConfig config) : base(client, config)
 {
     CurrentInput = new MatchInput(config);
     InputContext = new MatchInputContext(CurrentInput);
     NetworkClient.OnRecievedInputs += OnRecievedInputs;
     NetworkClient.OnRecievedState  += OnRecievedState;
 }
Ejemplo n.º 7
0
        public byte[] Exec(BaseMatchData stateObj, MatchInput matchInput)
        {
            MatchReport resultEntity = null;
            var         home         = stateObj.Home.ManagerId;
            var         away         = stateObj.Away.ManagerId;

            int i = 0;

            do
            {
                try
                {
                    byte[] process = null;
                    //固定新手引导首场
                    if (ShareUtil.IsAppRXYC && stateObj.IsGuide && stateObj.MatchType == (int)EnumMatchType.PlayerKill)
                    {
                        process = MatchReportCache.Instance().GetReport();
                    }
                    if (null == process)
                    {
                        process = _matchClient.CreateMatch(matchInput);
                    }
                    if (process != null && process.Length > 10)
                    {
                        resultEntity = NB.Match.Base.Util.IOUtil.BinRead <MatchReport>(process, 0);
                    }
                    if (resultEntity == null)
                    {
                        throw new Exception("the callback MatchStream is empty");
                    }
                    else
                    {
                        if (stateObj.NoDraw && resultEntity.HomeScore == resultEntity.AwayScore)
                        {
                            i++;
                        }
                        else
                        {
                            stateObj.ErrorCode  = (int)MessageCode.Success;
                            stateObj.Home.Score = resultEntity.HomeScore;
                            stateObj.Away.Score = resultEntity.AwayScore;
                            return(process);
                        }
                    }
                }
                catch (Exception ex)
                {
                    i++;

                    if (i >= MATCHRetryTimes)
                    {
                        SystemlogMgr.Error("MatchThread Exec", string.Format("Home:{0},Away:{1},Message:{2},StackTrace:{3}", home, away, ex.Message, ex.StackTrace));
                        //SystemlogMgr.Error("MatchThread Exec", ex);
                        stateObj.ErrorCode = (int)MessageCode.Exception;
                        return(null);
                    }
                }
            }while (i < MATCHRetryTimes);
            return(null);
        }
Ejemplo n.º 8
0
        public MatchInput SampleInput()
        {
            var devices  = InputManager.Devices;
            var newInput = input.Clone();

            for (var i = 0; i < newInput.PlayerCount; i++)
            {
                var playerConfig = config.PlayerConfigs[i];
                var playerId     = playerConfig.LocalPlayerID;
                if (!playerConfig.IsLocal || playerId >= devices.Count)
                {
                    newInput.PlayerInputs[i] = new PlayerInput {
                        IsValid = playerConfig.IsLocal
                    };
                    continue;
                }
                UpdatePlayerInput(ref newInput.PlayerInputs[i], devices[(int)playerId]);
                if (playerId == 0)
                {
                    newInput.PlayerInputs[i].MergeWith(KeyboardInput());
                }
            }
            input = newInput;
            return(newInput);
        }
Ejemplo n.º 9
0
 public TestInputSource(MatchConfig config)
 {
     input = new MatchInput(config);
     for (int i = 0; i < input.PlayerCount; i++)
     {
         input.PlayerInputs[i].IsValid = true;
     }
 }
Ejemplo n.º 10
0
 public MatchReport(MatchInput input)
     : this()
 {
     this.ZipNo     = ReportAsset.RPTZipNo;
     this.VerNo     = ReportAsset.RPTVerNo;
     this.MatchType = input.MatchType;
     this.MapId     = input.MapId;
 }
Ejemplo n.º 11
0
 internal Server(INetworkServer server, MatchConfig config) : base(server, config)
 {
     // TODO(james7132): Run server simulation for momentary state syncs
     NetworkServer.ReceivedInputs += OnRecievedInputs;
     CurrentInput = new MatchInput(config);
     NextInput    = new MatchInput(config);
     InputBuffer  = new MatchInput[1];
 }
Ejemplo n.º 12
0
 public MatchInput SampleInput()
 {
     input = new MatchInput(input.PlayerCount);
     for (var i = 0; i < input.PlayerCount; i++)
     {
         input[i] = playerInputs[i].SampleInput();
     }
     return(input);
 }
Ejemplo n.º 13
0
 public async Task AddMatchAsnyc(MatchInput input)
 {
     var foostatsChannel = _channelFactory.CreateChannel();
     await Task.Factory.FromAsync(
         foostatsChannel.BeginAddMatch,
         foostatsChannel.EndAddMatch,
         input,
         foostatsChannel);
 }
Ejemplo n.º 14
0
 public static void ForceValid(ref MatchInput input, int mask)
 {
     for (var i = 0; i < input.PlayerCount; i++)
     {
         var playerInput = input[i];
         playerInput.IsValid = (mask & (1 << i)) != 0;
         input[i]            = playerInput;
     }
 }
Ejemplo n.º 15
0
 public TestInputSource(MatchConfig config)
 {
     input = new MatchInput(config);
     for (int i = 0; i < input.PlayerCount; i++)
     {
         var playerInput = input[i];
         playerInput.IsValid = true;
         input[i]            = playerInput;
     }
 }
Ejemplo n.º 16
0
    public static MatchInput RandomInput(int players)
    {
        var input = new MatchInput(players);

        for (var i = 0; i < input.PlayerCount; i++)
        {
            input[i] = RandomPlayerInput();
        }
        return(input);
    }
Ejemplo n.º 17
0
 internal Server(INetworkServer server, MatchConfig config) : base(server, config)
 {
     NetworkServer.ReceivedInputs += OnRecievedInputs;
     InputContext    = new MatchInputContext(config);
     LatestInput     = new MatchInput[1];
     LatestInput[0]  = new MatchInput(config);
     InputHistory    = new InputHistory <MatchInput>(LatestInput[0]);
     NetworkConfig   = Config.Get <NetworkConfig>();
     ClientTimesteps = new Dictionary <uint, uint>();
     StateSendTimer  = 0;
 }
Ejemplo n.º 18
0
        public async Task <IActionResult> Post([FromBody] MatchInput match)
        {
            var result = await _matchApplicationService.InsertAsync(match);

            if (result != null)
            {
                return(Created("", result));
            }

            return(BadRequest());
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            MatchInput input = new MatchInput();

            input.source = "{{{}{{}}{{{}}}}}}";
            input.start  = '{';
            input.end    = '}';
            MatchOutput result = input.match();

            result.printResult();
        }
        public BufferedInputSource(int bufferSize, IInputSource baseInputSource)
        {
            this.baseInputSource = baseInputSource;
            buffer = new MatchInput[bufferSize];
            MatchInput sampledBaseInput = baseInputSource.SampleInput();

            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = sampledBaseInput;
            }
        }
Ejemplo n.º 21
0
            void OnRecievedInputs(uint timestep, ArraySlice <MatchInput> inputs)
            {
                //TODO(james7132): Cache/buffer inputs to smooth out gameplay
                if (timestep != Timestep + 1)
                {
                    return;
                }
                var newInput = inputs[0];

                Assert.IsTrue(newInput.IsValid);
                CurrentInput = newInput;
            }
Ejemplo n.º 22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="matchEntity"></param>
        /// <param name="transferMatchEntity"></param>
        /// <returns></returns>
        public byte[] CreateMatch(MatchInput matchInput)
        {
            //var watch = new Stopwatch();
            //watch.Start();
            var resultEntityByte = proxy.CreateMatchToBin(matchInput);

            //watch.Stop();
            //SysteminfologMgr.Insert("Server-CreateMatchNewInterface", "Time:[" + watch.ElapsedMilliseconds.ToString("N0") + "ms]");
            //CodeTimer outputmatchTimer = new CodeTimer("ResolverEngine-Convert");
            //outputmatchTimer.Record();

            return(resultEntityByte);
        }
Ejemplo n.º 23
0
    public void LogMatchInput(MatchInput matchinput)
    {
        string sMatchInput = string.Format("mi:{0}", matchinput.iPlayerActing);

        int[] arnSerializedMatchInput = matchinput.Serialize();

        sMatchInput += LibConversions.ArToStr(arnSerializedMatchInput);

        //Also print out a friendly human-readable input
        sMatchInput += "\n" + matchinput.ToString();

        WriteToMatchLogFile(sMatchInput);
    }
Ejemplo n.º 24
0
            void ForwardSimulate()
            {
                MatchInput input          = InputHistory.Current.Input;
                var        newestTimestep = InputHistory.Newest.Timestep;
                var        state          = CurrentState;

                while (input.IsValid && InputHistory.Current.Timestep < newestTimestep)
                {
                    InputContext.Update(input);
                    Simulation.Simulate(ref state, InputContext);
                    input = InputHistory.Step();
                }
                CurrentState = state;
            }
    public void Simulate_each_simulate_decreases_remaining_time()
    {
        var timeMatchRule = new TimeMatchRule();
        var config        = new MatchConfig {
            Stocks = 5, PlayerConfigs = new PlayerConfig[4]
        };
        var state = new MatchState(config)
        {
            Time = 100
        };
        var input        = new MatchInput(config);
        var inputContext = new MatchInputContext(input);

        Assert.AreEqual(99, timeMatchRule.Simulate(state, inputContext).Time);
    }
Ejemplo n.º 26
0
 public MatchEntity(MatchInput input)
 {
     _status.Round  = -1;
     _status.Minute = -1;
     //_status.TotalRound = Convert.ToInt32(input.TranTime / Defines.Match.ROUND_TIME);
     _status.TotalRound = 2 * Convert.ToInt32(input.TranTime / Defines.Match.ROUND_TIME);
     input.HomeManager.BalanceProp();
     input.AwayManager.BalanceProp();
     this._input       = input;
     this._football    = new Football(this);
     this._homeManager = new Manager(input.HomeManager, this, Side.Home);
     this._awayManager = new Manager(input.AwayManager, this, Side.Away);
     this._openSide    = this.RandomBool() ? Side.Home : Side.Away;
     this._report      = new MatchReport(input);
 }
Ejemplo n.º 27
0
 public InControlInputSource(MatchConfig config)
 {
     input        = new MatchInput(config);
     ValidMask    = 0;
     playerInputs = new IInputSource <PlayerInput> [config.PlayerCount];
     for (var i = 0; i < config.PlayerCount; i++)
     {
         playerInputs[i] = new InControlPlayerInputSource(config.PlayerConfigs[i]);
         if (!config.PlayerConfigs[i].IsLocal)
         {
             continue;
         }
         ValidMask |= (byte)(1 << i);
     }
     Debug.Log($"Valid Mask: {ValidMask}");
 }
Ejemplo n.º 28
0
 public InControlInputSource(MatchConfig config)
 {
     this.config       = config;
     controllerMapping = new PlayerControllerMapping();
     input             = new MatchInput(config);
     ValidMask         = 0;
     for (var i = 0; i < config.PlayerCount; i++)
     {
         if (!config.PlayerConfigs[i].IsLocal)
         {
             continue;
         }
         ValidMask |= (byte)(1 << i);
     }
     Debug.Log($"Valid Mask: {ValidMask}");
 }
Ejemplo n.º 29
0
        public static MatchInput CreateDebugMatch(int tranTime, double homePropVal, double awayPropVal)
        {
            var obj = new MatchInput();

            obj.MatchId   = Guid.NewGuid();
            obj.TranTime  = tranTime;
            obj.MapId     = 1;
            obj.MatchType = 1;
            Guid homeId = new Guid("E5F9AE02-5754-4E0B-9ABE-A3CE00FE9D2A");
            Guid awayId = Guid.NewGuid();

            obj.HomeManager = CreateDebugManager(true, homeId, 0, 9, homePropVal);
            obj.AwayManager = CreateDebugManager(false, awayId, 1, 10, awayPropVal);
            FillFormData(obj);
            return(obj);
        }
Ejemplo n.º 30
0
            void ForwardSimulate(uint timestep, ArraySlice <MatchInput> inputs)
            {
                InputHistory.MergeWith(timestep, inputs);
                MatchInput input = InputHistory.Current.Input;

                InputContext.Reset(input);
                int count          = 0;
                var newestTimestep = InputHistory.Newest.Timestep;

                while (input.IsValid && InputHistory.Current.Timestep < newestTimestep)
                {
                    count++;
                    InputContext.Update(input);
                    CurrentState = Simulation.Simulate(CurrentState, InputContext);
                    input        = InputHistory.Step();
                }
            }