Exemple #1
0
        public void WriteXml(XmlSave X)
        {
            X.StartTag("player");
            X.Attribute("nick", NickName);
            X.Attribute("rank", Rank);
            X.Attribute("rating", Rating);

            string SexString = "";
            switch (Sex)
            {
                case Sex.Unknown: SexString = "U"; break;
                case Sex.Female: SexString = "F"; break;
                case Sex.Male: SexString = "M"; break;
                case Sex.Computer: SexString = "C"; break;
            }

            X.Attribute("sex", SexString);

            X.EndTag();
        }
Exemple #2
0
        public void Save(string FileName)
        {
            if (!Directory.Exists("round")) Directory.CreateDirectory("round");

            FileName = "round/" + FileName;

            XmlSave X = new XmlSave(FileName);
            this.FileName = FileName;

            if (PlayerCount == 3) X.Xml3Man();

            X.StartXML("mjround");

            X.WriteTag("version", "value", 175);
            X.WriteTag("hash", "value", Hash);
            X.WriteTag("game", "index", Index);
            X.WriteTag("playercount", "value", PlayerCount);
            X.WriteTag("lobby", "value", Lobby);
            X.WriteTag("lobbytype", "value", Convert.ToInt32(LobbyType));
            X.WriteTag("round", "index", CurrentRound);
            X.WriteTag("result", "value", StringResult);
            X.WriteTag("drawreason", "value", DrawReason);
            X.WriteTag("riichistick", "value", RiichiStick);
            X.WriteTag("renchanstick", "value", RenchanStick);
            X.WriteTag("balancebefore", BalanceBefore);
            X.WriteTag("balanceafter", BalanceAfter);
            X.WriteTag("pay", Pay);
            X.WriteTag("winner", Winner);
            X.WriteTag("loser", Loser);
            X.WriteTag("openedsets", OpenedSets);
            X.WriteTag("naki", Naki);
            X.WriteTag("riichi", Riichi);
            X.WriteTag("wind", Wind);
            X.WriteTag("dealer", Dealer);
            X.WriteTag("stepcount", StepCount);
            X.WriteTag("tempai", Tempai);
            X.WriteTag("firstdora", "pointer", FirstDora);

            // Wall
            if(Wall != null)
            {
                string Tiles = String.Join(",", Wall.Tiles.Select(p => p.ToString()).ToArray());
                string Dice = String.Join(",", Wall.Dice.Select(p => p.ToString()).ToArray());

                X.StartTag("wall");
                X.Attribute("tiles", Tiles);
                X.Attribute("dice", Dice);

                X.EndTag();
            }

            // Dora
            {
                X.StartTag("dora");
                X.Attribute("count", Dora.Count);

                for (int j = 0; j < Dora.Count; j++)
                {
                    X.WriteTag("dora", "pointer", Dora[j]);
                }

                X.EndTag();
            }

            if (UraDora.Count > 0)
            {
                X.StartTag("uradora");
                X.Attribute("count", UraDora.Count);

                for (int j = 0; j < UraDora.Count; j++)
                {
                    X.WriteTag("dora", "pointer", UraDora[j]);
                }

                X.EndTag();
            }

            // Start hands
            {
                X.StartTag("hands");
                for (int i = 0; i < PlayerCount; i++)
                {
                    X.StartTag("hand");
                    X.Attribute("player", i);

                    StartHands[i].WriteXml(X);

                    X.EndTag();
                }

                X.EndTag();
            }

            // Actions
            {
                X.StartTag("steps");
                X.Attribute("count", Steps.Count);

                for (int j = 0; j < Steps.Count; j++)
                {
                    Steps[j].WriteXml(X);
                }

                X.EndTag();
            }

            // Shanten dynamic
            {
                X.StartTag("shantenlist");
                for (int i = 0; i < PlayerCount; i++)
                {
                    if (Shanten[i].Count == 0) continue;

                    X.StartTag("shanten");
                    X.Attribute("player", i);
                    X.Attribute("count", Shanten[i].Count);

                    for (int j = 0; j < Shanten[i].Count; j++) X.WriteTag("step", "value", Shanten[i][j]);

                    X.EndTag();
                }

                X.EndTag();
            }

            // Yaku list
            {
                for (int i = 0; i < PlayerCount; i++)
                {
                    if (Yaku[i].Count == 0) continue;

                    X.StartTag("agari");
                    X.Attribute("player", i);
                    X.Attribute("han", HanCount[i]);
                    X.Attribute("fu", FuCount[i]);
                    X.Attribute("cost", Cost[i]);
                    {
                        X.StartTag("yakulist");
                        X.Attribute("count", Yaku[i].Count);
                        for (int j = 0; j < Yaku[i].Count; j++)
                        {
                            X.StartTag("yaku");

                            X.Attribute("index", Yaku[i][j].Index);
                            X.Attribute("cost", Yaku[i][j].Cost);

                            X.EndTag();
                        }
                        X.EndTag();
                    }

                    if (Winner[i])
                    {
                        // Waiting hand
                        List<int> WaitingList = WinWaiting[i];

                        X.StartTag("waitings");
                        X.Attribute("count", WaitingList.Count);
                        for (int k = 0; k < WaitingList.Count; k++)
                        {
                            X.WriteTag("waiting", "value", WaitingList[k]);
                        }
                        X.EndTag();
                    }
                    X.EndTag();
                }
            }

            X.EndXML();
            X.Close();
        }
Exemple #3
0
        public void WriteXml(XmlSave X)
        {
            switch (Type)
            {
            case StepType.STEP_DRAWTILE:     // Draw fram wall
                X.StartTag("drawtile");
                X.Attribute("player", Player);
                X.Attribute("tile", Tile);

                WriteDanger(X);

                X.EndTag();
                break;

            case StepType.STEP_DISCARDTILE:  // Discard
                X.StartTag("discardtile");
                X.Attribute("player", Player);
                X.Attribute("tile", Tile);
                X.Attribute("shanten", Shanten);

                if (Furiten)
                    X.Attribute("furiten", 1);

                WriteWaiting(X);
                
                X.EndTag();
                break;

            case StepType.STEP_DRAWDEADTILE: // Draw from dead wall
                X.StartTag("drawdeadtile");
                X.Attribute("player", Player);
                X.Attribute("tile", Tile);

                WriteDanger(X);

                X.EndTag();
                break;

            case StepType.STEP_NAKI:         // Naki
                X.StartTag("naki");
                X.Attribute("player", Player);
                NakiData.WriteXml(X);
                WriteWaiting(X);
                WriteDanger(X);

                X.EndTag();
                break;

            case StepType.STEP_RIICHI:       // Riichi!
                X.StartTag("riichi1");
                X.Attribute("player", Player);

                X.EndTag();
                break;

            case StepType.STEP_RIICHI1000:   // Pay for riichi
                X.StartTag("riichi2");
                X.Attribute("player", Player);

                X.EndTag();
                break;

            case StepType.STEP_TSUMO:        // Tsumo
                X.StartTag("tsumo");
                X.Attribute("player", Player);

                X.EndTag();
                break;

            case StepType.STEP_RON:          // Ron
                X.StartTag("ron");
                X.Attribute("player", Player);
                X.Attribute("from", FromWho);

                X.EndTag();
                break;
 
            case StepType.STEP_DRAW:         // Draw
                X.StartTag("draw");
                X.Attribute("reason", Reason);

                X.EndTag();
                break;

            case StepType.STEP_NEWDORA:      // Open next dora indicator
                X.StartTag("newdora");
                X.Attribute("tile", Tile);
                X.EndTag();
                break;

            case StepType.STEP_DISCONNECT:   // Player disconnected
                X.StartTag("disconnect");
                X.Attribute("player", Player);

                X.EndTag();
                break;

            case StepType.STEP_CONNECT:       // Player connected
                X.StartTag("connect");
                X.Attribute("player", Player);

                X.EndTag();
                break;
            }
        }
Exemple #4
0
        private void WriteDanger(XmlSave X)
        {
            if (Danger == null) return;

            X.StartTag("danger");
            X.Attribute("count", Danger.Length);
            for (int i = 0; i < Danger.Length; i++)
            {
                X.StartTag("tile");
                X.Attribute("value", Danger[i]);

                X.EndTag();
            }
            X.EndTag();
        }
Exemple #5
0
        private void WriteWaiting(XmlSave X)
        {
            if (Waiting == null) return;

            X.StartTag("waiting");
            X.Attribute("count", Waiting.Length);
            for (int i = 0; i < Waiting.Length; i++)
            {
                X.StartTag("tiletype");
                X.Attribute("value", Waiting[i]);

                X.EndTag();
            }
            X.EndTag();
        }
Exemple #6
0
        public void WriteXml(XmlSave X)
        {
            X.StartTag("nakidata");
            X.Attribute("value", Convert.ToInt16(Type));
            X.Attribute("from", FromWho);
            X.Attribute("count", Tiles.Count);

            for (int i = 0; i < Tiles.Count; i++)
            {
                X.StartTag("tile");
                X.Attribute("value", Tiles[i]);

                X.EndTag();
            }

            X.EndTag();
        }
Exemple #7
0
        public void SaveXml(string FileName)
        {
            XmlSave X = new XmlSave(FileName);

            if (PlayerCount == 3) X.Xml3Man();

            X.StartXML("mjreplay");

            // replay ID
            X.WriteTag("hash", "value", Hash);
            X.WriteTag("playercount", "value", PlayerCount);
            X.WriteTag("lobby", "value", Lobby);
            X.WriteTag("lobbytype", "value", Convert.ToInt32(LobbyType));
            X.WriteTag("result", Result);
            X.WriteTag("balance", Balance);
            X.WriteTag("place", Place);

            {
                X.StartTag("playerlist");

                for (int j = 0; j < PlayerCount; j++)
                {
                    Players[j].WriteXml(X);
                }
                X.EndTag();
            }

            {
                X.StartTag("roundlist");
                X.Attribute("count", Rounds.Count);
                for (int i = 0; i < Rounds.Count; i++)
                {
                    if(Rounds[i].FileName.CompareTo("") == 0) Rounds[i].FileName = Hash + "_" + i.ToString() + ".xml";

                    X.StartTag("round");
                    X.Attribute("index", i);
                    X.Attribute("filename", Rounds[i].FileName);

                    // Results
                    {
                        int[] StepCount = new int[4];
                        for (int j = 0; j < 4; j++) StepCount[j] = 0;
                        for (int j = 0; j < Rounds[i].Steps.Count; j++)
                        {
                            if (Rounds[i].Steps[j].Type == StepType.STEP_DISCARDTILE) StepCount[Rounds[i].Steps[j].Player]++;
                        }

                        X.WriteTag("round", "index", Rounds[i].CurrentRound);
                        X.WriteTag("renchan", "index", Rounds[i].RenchanStick);
                        X.WriteTag("result", "value", Rounds[i].StringResult);

                        X.WriteTag("balancebefore", Rounds[i].BalanceBefore);
                        X.WriteTag("balanceafter", Rounds[i].BalanceAfter);
                        X.WriteTag("pay", Rounds[i].Pay);
                        X.WriteTag("han", Rounds[i].HanCount);
                        X.WriteTag("fu", Rounds[i].FuCount);
                        X.WriteTag("cost", Rounds[i].Cost);
                        X.WriteTag("steps", StepCount);
                        X.WriteTag("winner", Rounds[i].Winner);
                        X.WriteTag("loser", Rounds[i].Loser);
                        X.WriteTag("openedsets", Rounds[i].OpenedSets);
                        X.WriteTag("riichi", Rounds[i].Riichi);
                        X.WriteTag("dealer", Rounds[i].Dealer);
                    }

                    X.EndTag();
                }
                X.EndTag();
            }

            X.EndXML();
            X.Close();
        }
Exemple #8
0
        public void WriteXml(XmlSave X)
        {
            int TileCount = 0;
            for (int i = 0; i < Tiles.Length; i++) if (Tiles[i] >= 0) TileCount++;

            // Closed part
            X.StartTag("tiles");
            X.Attribute("count", TileCount);

            for(int i = 0; i < Tiles.Length; i++)
            {
                if (Tiles[i] < 0) continue;

                X.WriteTag("tile", "value", Tiles[i]); 
            }

            X.EndTag();

            // Opened part
            if (Naki.Count > 0)
            {
                X.StartTag("naki");
                X.Attribute("count", Naki.Count);
                for (int i = 0; i < Naki.Count; i++)
                {
                    Naki[i].WriteXml(X);
                }
                X.EndTag();
            }
        }