Ejemplo n.º 1
0
        private void MakeReplayData(string filename)
        {
            string[] replayFileLines = File.ReadAllLines(filename);

            name01 = replayFileLines[0];
            name02 = replayFileLines[1];
            string LifeTime = replayFileLines[2];

            GameEngine gameEngine = new GameEngine();

            int  turn   = 3;
            char result = Config.Draw;

            while (true)
            {
                var nextPlayer = gameEngine.NextColor;
                var nextTable  = gameEngine.NextTable;

                if (nextPlayer == Config.Draw)
                {
                    result = gameEngine.Winner;
                    break;
                }

                var coms = replayFileLines[turn].Split(' ');
                turn++;

                string command = coms[0] + " " + coms[1];

                Data data = new Data();

                data.turn  = nextPlayer;
                data.table = (char[, ])gameEngine.NextTableChar.Clone();

                int blackCount = 0;
                int whiteCount = 0;
                for (int y = 0; y < Config.Size; y++)
                {
                    for (int x = 0; x < Config.Size; x++)
                    {
                        if (data.table[y, x] == Config.Black)
                        {
                            blackCount++;
                        }
                        else if (data.table[y, x] == Config.White)
                        {
                            whiteCount++;
                        }
                    }
                }

                data.pos.X      = int.Parse(coms[0]);
                data.pos.Y      = int.Parse(coms[1]);
                data.blackCount = blackCount;
                data.whiteCount = whiteCount;

                int time = int.Parse(coms[2]);
                if (nextPlayer == Config.Black)
                {
                    data.blackTimer = coms[2];

                    if (replayDatas.Count == 0)
                    {
                        data.whiteTimer = LifeTime;
                    }
                    else
                    {
                        data.whiteTimer = replayDatas.Last().whiteTimer;
                    }

                    if (time < 0)
                    {
                        result = Config.White;
                        break;
                    }
                }
                else if (nextPlayer == Config.White)
                {
                    data.whiteTimer = coms[2];
                    data.blackTimer = replayDatas.Last().blackTimer;

                    if (time < 0)
                    {
                        result = Config.Black;
                        break;
                    }
                }

                replayDatas.Add(data);

                if (gameEngine.CheckPosition(command, nextPlayer))
                {
                    gameEngine.Put(command, nextPlayer);
                }
                else
                {
                    if (nextPlayer == Config.Black)
                    {
                        result = Config.White;
                        break;
                    }
                    else if (nextPlayer == Config.White)
                    {
                        result = Config.Black;
                        break;
                    }
                }
            }

            Data endData = new Data();

            endData.table = gameEngine.NextTableChar;

            int endBlackCount = 0;
            int endWhiteCount = 0;

            for (int y = 0; y < Config.Size; y++)
            {
                for (int x = 0; x < Config.Size; x++)
                {
                    if (endData.table[y, x] == Config.Black)
                    {
                        endBlackCount++;
                    }
                    else if (endData.table[y, x] == Config.White)
                    {
                        endWhiteCount++;
                    }
                }
            }

            endData.blackCount = endBlackCount;
            endData.whiteCount = endWhiteCount;

            endData.blackTimer = replayDatas.Last().blackTimer;
            endData.whiteTimer = replayDatas.Last().whiteTimer;

            replayDatas.Add(endData);
        }