コード例 #1
0
ファイル: Game.cs プロジェクト: Deathblade226/Chess
        /// <summary>
        /// Serialize the Game object as XML String
        /// </summary>
        /// <returns>XML containing the Game object state XML</returns>
        public XmlNode XmlSerialize(XmlDocument xmlDoc)
        {
            XmlElement xmlGame = xmlDoc.CreateElement("Game");

            // Append game state attributes
            xmlGame.AppendChild(XMLHelper.CreateNodeWithValue(xmlDoc, "DoNullMovePruning", DoNullMovePruning.ToString()));
            xmlGame.AppendChild(XMLHelper.CreateNodeWithValue(xmlDoc, "DoPrincipleVariation", DoPrincipleVariation.ToString()));
            xmlGame.AppendChild(XMLHelper.CreateNodeWithValue(xmlDoc, "DoQuiescentSearch", DoQuiescentSearch.ToString()));

            // Append the Game turn info
            xmlGame.AppendChild(XMLHelper.CreateNodeWithValue(xmlDoc, "GameTurn", GameTurn.ToString()));

            // Append the Board State
            xmlGame.AppendChild(Board.XmlSerialize(xmlDoc));

            // Append the Player Info
            xmlGame.AppendChild(XMLHelper.CreateNodeWithXmlValue(xmlDoc, "WhitePlayer", XMLHelper.XmlSerialize(typeof(Player), m_WhitePlayer)));
            xmlGame.AppendChild(XMLHelper.CreateNodeWithXmlValue(xmlDoc, "BlackPlayer", XMLHelper.XmlSerialize(typeof(Player), m_BlackPlayer)));

            object[] moves = m_MovesHistory.ToArray();

            // Store all the moves from the move history
            string xml = "";

            for (int i = moves.Length - 1; i >= 0; i--)
            {
                Move move = (Move)moves[i];
                xml += XMLHelper.XmlSerialize(typeof(Move), move);
            }
            xmlGame.AppendChild(XMLHelper.CreateNodeWithXmlValue(xmlDoc, "MovesHistory", xml));

            // Create the Checksome to avoid user temporing of the file
            string checksum = GetChecksum(xmlGame.InnerXml);

            (xmlGame as XmlElement).SetAttribute("Checksum", checksum);
            (xmlGame as XmlElement).SetAttribute("Version", "1.2");

            // Return this as String
            return(xmlGame);
        }
コード例 #2
0
ファイル: Side.cs プロジェクト: yonzarecki/MagiciansChess
 /// <summary>
 /// DeSerialize the Side object from XML String
 /// </summary>
 /// <returns>XML containing the Side object state XML</returns>
 public void XmlDeserialize(XmlNode xmlSide)
 {
     // Serialize and append to the side object
     m_side = (SideType)XMLHelper.XmlDeserialize(typeof(SideType), xmlSide.InnerXml);
 }