Esempio n. 1
0
 public SpecialRand(SpecialRand seed)
 {
     x = seed.x;
     y = seed.y;
     z = seed.z;
     w = seed.w;
 }
Esempio n. 2
0
        public static GameMain Run(GameConfig gameConfig, string[] fileNames,
                                   bool enableSkippingRender,
                                   Logger gameLogger, AiLogger[] aiLoggers, SpecialRand fixedRandom = null,
                                   IServiceProvider serviceProvider = null, MonoGameControl gameControl = null,
                                   GraphicsDevice graphicsDevice    = null)
        {
            var gameMain = new GameMain(gameConfig, fileNames, enableSkippingRender, gameLogger,
                                        aiLoggers, fixedRandom, serviceProvider, gameControl, graphicsDevice);

            if (!gameMain.EnableSkippingRender)
            {
                gameMain.LaodContent();
            }

            foreach (var field in gameMain._fields)
            {
                field.InitializeGame();
            }
            gameMain._stopwatch.Start();

            return(gameMain);
        }
Esempio n. 3
0
        private GameMain(
            GameConfig gameConfig, string[] fileNames, bool enableSkippingRender,
            Logger gameLogger, AiLogger[] aiLoggers, SpecialRand fixeRandom = null,
            IServiceProvider serviceProvider = null, MonoGameControl gameControl = null,
            GraphicsDevice graphicsDevice    = null)
        {
            EnableSkippingRender = enableSkippingRender;
            GameLogger           = gameLogger;

            if (!EnableSkippingRender)
            {
                if (Content == null)
                {
                    Content = new ContentManager(serviceProvider, "Content");
                }

                _spriteBatch = new SpriteBatch(graphicsDevice);
                _camera      = new Camera(graphicsDevice);
            }

            GameConfig  = gameConfig;
            FixedRandom = fixeRandom ?? new SpecialRand((uint)GameConfig.RandomSeed);

            _fields = new Field[2];
            for (var i = 0; i < 2; ++i)
            {
                var tx = 50 * (i + 1) + 325 * i;
                var ty = 100;
                _fields[i] = new Field(tx, ty, GameConfig, aiLoggers[i], this, _spriteBatch, _camera,
                                       gameControl, fileNames[i]);
                _fields[i].Index = i;
            }
            _fields[0].OtherField = _fields[1];
            _fields[1].OtherField = _fields[0];

            CurrentTurn = TurnEnum.None;
        }
Esempio n. 4
0
        private GameMain(GameConfig gameConfig, ReplayMatchData replayData, Logger gameLogger,
                         AiLogger[] aiLoggers, bool isPersistent, IServiceProvider serviceProvider,
                         MonoGameControl gameControl, GraphicsDevice graphicsDevice, bool isBuildingCaches, SpecialRand fixeRandom = null)
        {
            IsPersistent     = isPersistent;
            GameLogger       = gameLogger;
            IsBuildingCaches = isBuildingCaches;

            if (Content == null)
            {
                Content = new ContentManager(serviceProvider, "Content");
            }

            _spriteBatch = new SpriteBatch(graphicsDevice);
            _camera      = new Camera(graphicsDevice);

            GameConfig  = gameConfig;
            FixedRandom = fixeRandom ?? new SpecialRand((uint)GameConfig.RandomSeed);

            _fields = new Field[2];

            var replayPlayerData = new[]
            { replayData.Player1ReplayData, replayData.Player2ReplayData };

            for (var i = 0; i < 2; ++i)
            {
                var tx = 50 * (i + 1) + 325 * i;
                var ty = 100;

                if (IsPersistent)
                {
                    _fields[i] = new PersistentField(tx, ty, GameConfig, aiLoggers[i], this,
                                                     _spriteBatch, _camera, gameControl, replayPlayerData[i]);
                }
                else
                {
                    _fields[i] = new Field(tx, ty, GameConfig, aiLoggers[i], this, _spriteBatch,
                                           _camera, gameControl, replayPlayerData[i]);
                }

                _fields[i].Index = i;
            }
            _fields[0].OtherField = _fields[1];
            _fields[1].OtherField = _fields[0];

            CurrentTurn = TurnEnum.None;
        }
Esempio n. 5
0
        public static GameMain Run(GameConfig gameConfig, ReplayMatchData replayData,
                                   Logger gameLogger, AiLogger[] aiLoggers, bool isPersistent,
                                   IServiceProvider serviceProvider, MonoGameControl gameControl,
                                   GraphicsDevice graphicsDevice, bool isBuildingCaches, SpecialRand fixedRandom = null)
        {
            var gameMain = new GameMain(gameConfig, replayData, gameLogger, aiLoggers, isPersistent,
                                        serviceProvider, gameControl, graphicsDevice, isBuildingCaches, fixedRandom);

            gameMain.LaodContent();

            foreach (var field in gameMain._fields)
            {
                field.InitializeGame();
            }
            gameMain._stopwatch.Start();

            return(gameMain);
        }
        public void ReadFromStreamReader(StreamReader reader)
        {
            {
                var gameInfo = reader.ReadLine().Trim().Split(' ');
                if (gameInfo.Length != 7)
                {
                    throw new InvalidDataException();
                }

                int column, row, minchain, colorsNum, randomSeed, player1Won, player2Won;
                if (!int.TryParse(gameInfo[0], out column) ||
                    !int.TryParse(gameInfo[1], out row) ||
                    !int.TryParse(gameInfo[2], out minchain) ||
                    !int.TryParse(gameInfo[3], out colorsNum) ||
                    !int.TryParse(gameInfo[4], out randomSeed) ||
                    !int.TryParse(gameInfo[5], out player1Won) ||
                    !int.TryParse(gameInfo[6], out player2Won))
                {
                    throw new InvalidDataException();
                }

                GameConfig = new GameConfig {
                    Column       = column,
                    Row          = row,
                    MinChain     = minchain,
                    ColorsNumber = colorsNum,
                    RandomSeed   = randomSeed
                };
            }

            {
                uint x, y, z, w;
                var  rawSeed = reader.ReadLine().Trim().Split(' ');
                if (!uint.TryParse(rawSeed[0], out x) ||
                    !uint.TryParse(rawSeed[1], out y) ||
                    !uint.TryParse(rawSeed[2], out z) ||
                    !uint.TryParse(rawSeed[3], out w))
                {
                    throw new InvalidDataException();
                }

                GameRandom = new SpecialRand(x, y, z, w);
            }

            Player1ReplayData = Player1ReplayData ?? new ReplayPlayerData();
            Player2ReplayData = Player2ReplayData ?? new ReplayPlayerData();

            var wonCounts = reader.ReadLine().Trim().Split(' ');

            if (wonCounts.Length != 2)
            {
                throw new InvalidDataException();
            }

            var rawLunchTimes = reader.ReadLine().Trim().Split(' ');

            if (rawLunchTimes.Length != 2)
            {
                throw new InvalidDataException();
            }

            int player1LunchTime;
            int player2LunchTime;

            if (!int.TryParse(rawLunchTimes[0], out player1LunchTime) ||
                !int.TryParse(rawLunchTimes[1], out player2LunchTime))
            {
                throw new InvalidDataException();
            }

            Player1ReplayData.LeftTimeOnLaunched = player1LunchTime;
            Player2ReplayData.LeftTimeOnLaunched = player2LunchTime;

            var inputLineNums = new int[2];
            var rawInputNums  = reader.ReadLine().Trim().Split(' ');

            if (!int.TryParse(rawInputNums[0], out inputLineNums[0]) ||
                !int.TryParse(rawInputNums[1], out inputLineNums[1]))
            {
                throw new InvalidDataException();
            }

            var inputLines = new[]
            { new List <string>(inputLineNums[0]), new List <string>(inputLineNums[1]) };

            var totalThinkTimes = new[]
            { new List <int>(inputLineNums[0]), new List <int>(inputLineNums[1]) };

            for (var i = 0; i < 2; ++i)
            {
                for (var j = 0; j < inputLineNums[i]; ++j)
                {
                    inputLines[i].Add(reader.ReadLine().Trim());

                    var raw = reader.ReadLine().Trim();
                    int time;
                    if (!int.TryParse(raw, out time))
                    {
                        throw new InvalidDataException();
                    }
                    totalThinkTimes[i].Add(time);
                }
            }

            Player1ReplayData.OutputLines    = inputLines[0];
            Player1ReplayData.LeftThinkTimes = totalThinkTimes[0];
            Player2ReplayData.OutputLines    = inputLines[1];
            Player2ReplayData.LeftThinkTimes = totalThinkTimes[1];
        }
 /// <summary>
 ///     使用する玉の色からランダムに一色選び返す。
 /// </summary>
 /// <returns>ランダムな色</returns>
 public Color GetRandomColor(SpecialRand random) => Colors[random.Next(ColorsNumber)];