Example #1
0
        public Field(
            float px, float py,
            GameConfig gameConfig, AiLogger aiLogger, GameMain gameMain, SpriteBatch spriteBatch, Camera camera,
            MonoGameControl gameControl, ReplayPlayerData replayPlayerData)
        {
            SpriteBatch = spriteBatch;
            Camera      = camera;
            GameMain    = gameMain;
            GameConfig  = gameConfig;
            AiLogger    = aiLogger;
            X           = px;
            Y           = py;

            _ojamaQueues = new Queue <OjamaBall> [Column + 1];
            for (var i = 1; i <= Column; ++i)
            {
                _ojamaQueues[i] = new Queue <OjamaBall>();
            }

            _balls   = new Ball[Column, Row];
            BallSize = Math.Min(FieldWidth / Column, FieldHeight / Row);

            Initialize();

            Player = new ReplayPlayer(this, GameMain, replayPlayerData);
        }
Example #2
0
        public PersistentField(float px, float py, GameConfig gameConfig, AiLogger aiLogger,
                               GameMain gameMain, SpriteBatch spriteBatch, Camera camera, MonoGameControl gameControl,
                               ReplayPlayerData replayPlayerData)
            : base(
                px, py, gameConfig, aiLogger, gameMain, spriteBatch, camera, gameControl,
                replayPlayerData)
        {
            _crossParticle = new CrossParticle(SpriteBatch, Camera, GameMain, this)
            {
                IsPersistent = true
            };
            _crossParticle.LoadContent();

            _turnCaches.Add(new TurnCache(this));
            _replayPlayerData = replayPlayerData;
        }
            private string Match(string player1FileName, string player2FileName, string replayPath)
            {
                var replayGameData = new ReplayGameData();
                var gameConfig     = new GameConfig(GameConfig)
                {
                    Player1WonCount = 0,
                    Player2WonCount = 0,
                    RandomSeed      = Environment.TickCount
                };

                var player1WonCount = 0;
                var player2WonCount = 0;

                var fileNames = new[]
                { player1FileName, player2FileName };

                GameMain gameMain = null;

                var flipped = false;

                for (var i = 0; (i < 4) || (player1WonCount == player2WonCount); ++i)
                {
                    fileNames[0] = flipped ? player2FileName : player1FileName;
                    fileNames[1] = flipped ? player1FileName : player2FileName;
                    gameConfig.Player1WonCount = flipped ? player2WonCount : player1WonCount;
                    gameConfig.Player2WonCount = flipped ? player1WonCount : player2WonCount;

                    var currentRandom = gameMain?.FixedRandom ??
                                        new SpecialRand((uint)gameConfig.RandomSeed);
                    gameMain?.Dispose();
                    var gameLogger = new Logger();
                    gameLogger.EnableWritingConsole = true;
                    var aiLoggers = new[] { new AiLogger(), new AiLogger() };
                    gameMain = GameMain.Run(GameConfig, fileNames, true, gameLogger, aiLoggers,
                                            new SpecialRand(currentRandom));

                    while (gameMain.CurrentState == GameMain.GameStateEnum.Running)
                    {
                        Thread.Sleep(30);
                        gameMain.Update();
                    }

                    Console.WriteLine("終わり");
                    if (gameMain.CurrentState == GameMain.GameStateEnum.Player1Won)
                    {
                        if (flipped)
                        {
                            player2WonCount++;
                        }
                        else
                        {
                            player1WonCount++;
                        }
                    }
                    else if (gameMain.CurrentState == GameMain.GameStateEnum.Player2Won)
                    {
                        if (flipped)
                        {
                            player1WonCount++;
                        }
                        else
                        {
                            player2WonCount++;
                        }
                    }

                    aiLoggers[0].WaitEvents();
                    aiLoggers[1].WaitEvents();
                    gameLogger.WaitEvent();

                    var aiPlayer1 = gameMain.GetPlayer(0) as AiPlayer;
                    var aiPlayer2 = gameMain.GetPlayer(1) as AiPlayer;

                    var player1Replay = new ReplayPlayerData {
                        LeftTimeOnLaunched = aiPlayer1.LeftTimeOnLaunched,
                        LeftThinkTimes     = aiPlayer1.LeftThinkTimes,
                        OutputLines        = aiPlayer1.AiOutputs
                    };

                    var player2Replay = new ReplayPlayerData {
                        LeftTimeOnLaunched = aiPlayer2.LeftTimeOnLaunched,
                        LeftThinkTimes     = aiPlayer2.LeftThinkTimes,
                        OutputLines        = aiPlayer2.AiOutputs
                    };

                    var match = new ReplayMatchData {
                        Player1ReplayData = player1Replay,
                        Player2ReplayData = player2Replay,
                        GameConfig        = new GameConfig(gameConfig),
                        GameRandom        = currentRandom
                    };

                    replayGameData.Matches.Add(match);

                    if (i < 4)
                    {
                        flipped = !flipped;
                    }
                    else
                    {
                        flipped = _random.Next(0, 2) == 0;
                    }

                    if ((i < 4) && (3 - i < Math.Abs(player1WonCount - player2WonCount)))
                    {
                        break;
                    }
                }

                Directory.CreateDirectory(replayPath);
                replayGameData.Save(replayPath + "replay.txt");

                return(player1WonCount < player2WonCount ? player2FileName : player1FileName);
            }
 public ReplayPlayer(Field field, GameMain gameMain, ReplayPlayerData replayPlayerData)
     : base(field, gameMain)
 {
     _replayData = replayPlayerData;
 }