internal ZNGameDatabaseNode(ZNGameDatabase db, ZNGameDatabaseNode parent, ZNGame value)
 {
     databaseInternal = db;
     parentInternal   = parent;
     childrenInternal = new List <ZNGameDatabaseNode>();
     valueInternal    = value;
 }
예제 #2
0
 public ZNGameDatabaseEnumerator(ZNGameDatabase d)
 {
     data    = d;
     current = data.Root;
 }
예제 #3
0
        private int CreateBookWithDescription(byte[] description, string path)
        {
            if (File.Exists(path + ".ogb"))
            {
                File.Move(path + ".ogb", path + DateTime.Now + ".ogb");
            }
            FileStream writer = new FileStream(path, FileMode.CreateNew, FileAccess.Write, FileShare.None, 40960, true);
            StreamReader reader = File.OpenText(path);
            string line;
            byte depth = (byte)description.Length;
            ZNGameDatabase gameDatabase = new ZNGameDatabase(depth);
            StringBuilder pgnGame = new StringBuilder();
            ZNGame game;
            int gamesInDatabase;

            while (true)
            {
                line = reader.ReadLine();
                if (line == null) break;
                pgnGame.Append(line);
                if (IsWholePGNGame(pgnGame.ToString()))
                {
                    game = GetGameFromPGN(pgnGame.ToString());
                    if (game != null)
                    {
                        gameDatabase.Add(game);
                    }
                    // TODO: Creating of file with damaged games.
                    pgnGame.Clear();
                }
            }
            reader.Close();
            Thread.Sleep(125); // For gameDatabase.Sort();

            gameDatabase.Comprim();
            ZNGameDatabase gameDatabaseShallower;
            List<ZNGame> gamesForDelete;

            for (byte step = 1; step < depth; step++)
            {
                gamesForDelete = new List<ZNGame>();

                gameDatabaseShallower = gameDatabase.Clone() as ZNGameDatabase;
                gameDatabaseShallower.Comprim(step);

                gamesInDatabase = 0;
                foreach (ZNGame g in gameDatabaseShallower) gamesInDatabase += g.Number;

                int neededMostPlayed = (int)Math.Ceiling(description[step] / Math.E);

                List<ZNPair<int, ZNGame>> mostPlayed = new List<ZNPair<int, ZNGame>>();
                List<ZNPair<int, ZNGame>> bestRated = new List<ZNPair<int, ZNGame>>();
                int numberBound = gamesInDatabase / (description[step] * description[step]);
                int howtimesPlayed;
                ArrayList mostPlayedCount = new ArrayList(new int[neededMostPlayed]);
                ArrayList bestRatedCount = new ArrayList(new int[step - neededMostPlayed]);

                foreach (ZNGame g in gameDatabaseShallower)
                {
                    howtimesPlayed = g.Number;
                    if (howtimesPlayed >= numberBound)
                    {
                        g.Rating = (byte)Math.Round(Math.Sqrt(g.Number / gamesInDatabase) * (g.Halfpoints / (g.Number * 2)) * (g.Halfpoints / (g.Number * 2)) / byte.MaxValue);
                        if (howtimesPlayed > (int)mostPlayedCount[0])
                        {
                            mostPlayed.Add(new ZNPair<int, ZNGame>(howtimesPlayed, g));
                            mostPlayedCount[0] = howtimesPlayed;
                            mostPlayedCount.Sort();
                        }
                        mostPlayed.Sort();
                        // TODO: Sekundarni razeni dle hodnocení
                        mostPlayed.RemoveRange(0, mostPlayed.Count - neededMostPlayed - 1);

                        gameDatabaseShallower.Remove(g);

                        if (g.Rating > (int)bestRatedCount[0])
                        {
                            bestRated.Add(new ZNPair<int, ZNGame>(howtimesPlayed, g));
                            bestRatedCount[0] = howtimesPlayed;
                            bestRatedCount.Sort();
                        }
                        bestRated.Sort();
                        // TODO: Sekundarni razeni dle hodnocení
                        bestRated.RemoveRange(0, mostPlayed.Count - step + neededMostPlayed - 1);
                    }
                    else
                    {
                        gamesForDelete.Add(g);
                    }
                }

                // TODO: Je to opravdu funkcni asyncronni volani?
                IAsyncResult result;
                gameDatabase.RemoveTheseAndTheirChildren(gameDatabaseShallower, out result);
                WriteGamesToFileFixedLengths(writer, gameDatabaseShallower);
                while (!result.IsCompleted)
                {
                    Thread.Sleep(125);
                }

                writer.Close();
            }

            return ZNConstants.EXIT_SUCCESS;
        }
예제 #4
0
 private void WriteGamesToFileFixedLengths(FileStream writer, ZNGameDatabase gameDatabaseShallower)
 {
     throw new NotImplementedException();
 }
 internal void RemoveTheseAndTheirChildren(ZNGameDatabase gameDatabaseShallower, out IAsyncResult result)
 {
     throw new NotImplementedException();
 }
 internal void RemoveTheseAndTheirChildren(ZNGameDatabase gameDatabaseShallower, out IAsyncResult result)
 {
     throw new NotImplementedException();
 }
 public ZNGameDatabaseEnumerator(ZNGameDatabase d)
 {
     data = d;
     current = data.Root;
 }