예제 #1
0
        public void ReadGameHistory()
        {
            string directory = Path.Combine(@"C:\TicTacToeGames", "Data");

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            string filePath = Path.Combine(directory, "TicTacToe.dat");

            if (File.Exists(filePath))
            {
                using (var sr = new StreamReader(filePath))
                {
                    string data    = sr.ReadToEnd();
                    var    items   = data.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    var    records = items.Select(itm =>
                                                  Newtonsoft.Json.JsonConvert.DeserializeObject <Tuple <string, Dictionary <int, Tuple <GameMove, MoveStats> > > > (itm));
                    MoveTree = new GameTree();
                    foreach (var rec in records)
                    {
                        MoveTree.Tree.Add(rec.Item1, rec.Item2);
                    }
                }
            }
        }
예제 #2
0
            GameTree MakeMove(GameMove mv, Board brd)
            {
                GameTree res = null;

                if (tree.Contains(mv))
                {
                    res        = tree[mv];
                    res.Parent = this;
                }
                else
                {
                    res        = new GameTree(brd);
                    tree[mv]   = res;
                    res.Parent = this;
                }
                return(res);
            }
예제 #3
0
 internal GameHistory()
 {
     History  = new List <BoardMove>();
     MoveTree = new GameTree();
 }