private bool Captured(ReplayMeta meta)
        {
            var ai = aiFilter.SelectedItem.ToString();

            var top    = SizeGroups[sizeFilter.SelectedIndex].Item2;
            var bottom = SizeGroups[sizeFilter.SelectedIndex].Item1;

            if (!(meta.AiName == ai || ai == "*"))
            {
                return(false);
            }
            if (!(meta.PunterCount >= bottom && meta.PunterCount <= top))
            {
                return(false);
            }

            var ourScore = meta.Scores.First(s => s.punter == meta.OurPunter).score;
            var count    = meta.Scores.Count(s => s.score < ourScore) + 1;
            var win      = count == meta.Scores.Length;

            return((loseFilter.Checked || win) && (winFilter.Checked || !win));
        }
Exemple #2
0
 public ReplayFullData(ReplayMeta meta, ReplayData data)
 {
     Meta = meta;
     Data = data;
 }
        public Tuple <ReplayMeta, ReplayData> RunGame(IAi ai)
        {
            var setup = connection.ReadSetup();

            var state = new State
            {
                map      = setup.map,
                punter   = setup.punter,
                punters  = setup.punters,
                settings = setup.settings
            };

            AiSetupDecision setupDecision;

            try
            {
                setupDecision = ai.Setup(state, new Services(state));
            }
            catch
            {
                var handshake = JsonConvert.SerializeObject(new HandshakeIn {
                    you = botName
                });
                var input = JsonConvert.SerializeObject(setup, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });
                File.WriteAllText($@"error-setup-{DateTime.UtcNow.ToString("O").Replace(":", "_")}.json", $@"{handshake.Length}:{handshake}{input.Length}:{input}");
                throw;
            }

            if (!state.settings.futures && setupDecision.futures?.Any() == true)
            {
                throw new InvalidOperationException($"BUG in Ai {ai.Name} - futures are not supported");
            }
            state.aiSetupDecision = new AiInfoSetupDecision
            {
                name    = ai.Name,
                version = ai.Version,
                futures = setupDecision.futures,
                reason  = setupDecision.reason
            };

            connection.WriteSetupReply(new SetupOut {
                ready = setup.punter, futures = setupDecision.futures
            });

            var allMoves = new List <Move>();

            var serverResponse = connection.ReadNextTurn();

            while (!serverResponse.IsScoring())
            {
                var moves = serverResponse.move.moves.OrderBy(m => m.GetPunter()).ToArray();

                moves = moves.Skip(setup.punter).Concat(moves.Take(setup.punter)).ToArray();
                var gameplay = JsonConvert.SerializeObject(serverResponse, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });

                allMoves.AddRange(moves);

                state.ApplyMoves(moves);

                AiMoveDecision moveDecision;
                try
                {
                    moveDecision = ai.GetNextMove(state, new Services(state));
                }
                catch
                {
                    var handshake = JsonConvert.SerializeObject(new { you = "kontur.ru" });
                    File.WriteAllText($@"error-turn-{DateTime.UtcNow.ToString("O").Replace(":", "_")}.json", $@"{handshake.Length}:{handshake}{gameplay.Length}:{gameplay}");
                    throw;
                }
                var aiInfoMoveDecision = new AiInfoMoveDecision
                {
                    name    = ai.Name,
                    version = ai.Version,
                    move    = moveDecision.move,
                    reason  = moveDecision.reason
                };
                state.ValidateMove(aiInfoMoveDecision);
                state.lastAiMoveDecision = aiInfoMoveDecision;

                connection.WriteMove(moveDecision.move);
                serverResponse = connection.ReadNextTurn();
            }

            var stopIn = serverResponse.stop;

            allMoves.AddRange(stopIn.moves);

            var meta = new ReplayMeta(DateTime.UtcNow, ai.Name, ai.Version, "", setup.punter, setup.punters, stopIn.scores);
            var data = new ReplayData(setup.map, allMoves, state.aiSetupDecision.futures);

            return(Tuple.Create(meta, data));
        }