summaryrefslogtreecommitdiff
path: root/Aktywator/PBN.cs
blob: ad7ac99b78148d0adb6a2a66ed5f51fd39659134 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Aktywator
{
    class PBN
    {
        public HandRecord[] handRecords;
        protected int lowBoard;
        protected int highBoard;
        private int _count;
        public int count
        {
            get { return _count; }
        }

        public PBN(string filename, int lowBoard, int highBoard)
        {
            this.handRecords = new HandRecord[highBoard + 1];

            StreamReader f = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read));
            try
            {
                int board = lowBoard;
                bool canBeRead = false;
                _count = 0;
                while (!f.EndOfStream && (board <= highBoard))
                {
                    string line = f.ReadLine();
                    if (line.Trim() == "[Board \"" + board + "\"]")
                        canBeRead = true;
                    else if (canBeRead && (line.Substring(0, 6) == "[Deal "))
                    {
                        line = line.Substring(line.IndexOf(':') + 1);
                        line = line.Substring(0, line.IndexOf('"'));
                        handRecords[board] = new HandRecord(line);
                        canBeRead = false;
                        _count++;
                        board++;
                    }
                }
            }
            finally
            {
                f.Close();
            }
        }

    }
}