コード例 #1
0
        public static CBook ChooseOpponent(CBook book, CBook book1, CBook book2)
        {
            tourList.CountGames(book.name, book1.name, out int rw1, out int rl1, out int rd1);
            tourList.CountGames(book.name, book2.name, out int rw2, out int rl2, out int rd2);
            if ((book.GetElo() > book1.GetElo()) != (rw1 > rl1))
            {
                return(book1);
            }
            if ((book.GetElo() > book2.GetElo()) != (rw2 > rl2))
            {
                return(book2);
            }
            int count1 = (rw1 + rl1 + rd1);
            int count2 = (rw2 + rl2 + rd2);

            if (count1 * 1.1 <= count2 << 1)
            {
                return(book1);
            }
            if (count2 * 1.1 <= count1 >> 1)
            {
                return(book2);
            }
            return(null);
        }
コード例 #2
0
        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }
            string name     = listBox1.Items[e.Index].ToString();
            CBook  book     = FormChess.bookList.GetBook(name);
            bool   selected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;
            Brush  b        = Brushes.Black;

            if (selected)
            {
                e = new DrawItemEventArgs(e.Graphics, e.Font, e.Bounds, e.Index, e.State ^ DrawItemState.Selected, CBoard.colorMessage, CBoard.colorChartD);
                b = Brushes.White;
            }
            else if (!book.FileExists())
            {
                e = new DrawItemEventArgs(e.Graphics, e.Font, e.Bounds, e.Index, e.State, Color.White, CBoard.colorRed);
                b = Brushes.White;
            }
            e.DrawBackground();
            e.Graphics.DrawString(name, e.Font, b, e.Bounds, StringFormat.GenericDefault);
            e.DrawFocusRectangle();
        }
コード例 #3
0
        public static CBook SelectOpponent(CBook book)
        {
            bookList.SortPosition(book);
            List <CBook> bl = new List <CBook>();

            foreach (CBook b in bookList.list)
            {
                if (b != book)
                {
                    bl.Add(b);
                }
            }
            if (bl.Count == 0)
            {
                return(book);
            }
            for (int n = 0; n < bl.Count - 1; n++)
            {
                CBook b = ChooseOpponent(book, bl[n], bl[n + 1]);
                if (b != null)
                {
                    return(b);
                }
            }
            return(bl[0]);
        }
コード例 #4
0
ファイル: CBookList.cs プロジェクト: Thibor/RapChessGui
        public CBook NextTournament(CBook b, bool rotate = true, bool back = false)
        {
            SortElo();
            int i = GetIndex(b.name);

            for (int n = 0; n < list.Count - 1; n++)
            {
                if (back)
                {
                    i--;
                }
                else
                {
                    i++;
                }
                if (rotate)
                {
                    i = (i + list.Count) % list.Count;
                }
                else
                if ((i < 0) || (i >= list.Count))
                {
                    return(null);
                }
                b = list[i];
                if (b.tournament > 0)
                {
                    break;
                }
            }
            return(b);
        }
コード例 #5
0
 public static void SetRepeition(CBook b, CBook o)
 {
     if ((book != b.name) || (opponent != o.name))
     {
         book     = b.name;
         opponent = o.name;
         SaveToIni();
         tourList.CountGames(b.name, o.name, out int rw, out int rl, out _);
         if (games == 0)
         {
             repetition = b.tournament;
             if ((b.GetElo() > o.GetElo()) != (rw > rl))
             {
                 repetition++;
             }
             if (b.hisElo.list.Count < o.hisElo.list.Count)
             {
                 repetition++;
             }
             rotate = true;
         }
     }
     games++;
     rotate ^= true;
 }
コード例 #6
0
ファイル: CBookList.cs プロジェクト: Thibor/RapChessGui
 void TryAdd(string br, string p)
 {
     if ((br != "none") && !ParametersExists(p))
     {
         CBook b = new CBook();
         b.exe        = br;
         b.parameters = p;
         list.Add(b);
     }
 }
コード例 #7
0
        private void ButCreate_Click(object sender, EventArgs e)
        {
            string name   = tbReaderName.Text;
            CBook  reader = new CBook(name);

            reader.exe = cbBookReaderList.Text;
            FormChess.bookList.list.Add(reader);
            SaveToIni(reader);
            MessageBox.Show($"Book reader {reader.name} has been created");
            CData.reset = true;
        }
コード例 #8
0
ファイル: CBookList.cs プロジェクト: Thibor/RapChessGui
 public int GetIndex(string name)
 {
     for (int n = 0; n < list.Count; n++)
     {
         CBook br = list[n];
         if (br.name == name)
         {
             return(n);
         }
     }
     return(-1);
 }
コード例 #9
0
ファイル: CBookList.cs プロジェクト: Thibor/RapChessGui
        public int LoadFromIni()
        {
            list.Clear();
            List <string> bl = CBookList.iniFile.ReadKeyList("book");

            foreach (string name in bl)
            {
                var br = new CBook(name);
                br.LoadFromIni();
                list.Add(br);
            }
            return(bl.Count);
        }
コード例 #10
0
        void ClickUpdate()
        {
            CBook book = FormChess.bookList.GetBook(curBookName);

            if (book == null)
            {
                return;
            }
            CBookList.iniFile.DeleteKey($"book>{book.name}");
            SaveToIni(book);
            MessageBox.Show($"Reader {book.name} has been modified");
            CData.reset = true;
        }
コード例 #11
0
ファイル: CBookList.cs プロジェクト: Thibor/RapChessGui
 void TryDel(string dir)
 {
     for (int n = list.Count - 1; n >= 0; n--)
     {
         CBook book = list[n];
         if (book.parameters.IndexOf(dir) == 0)
         {
             if (!book.FileExists() || !book.ParametersExists())
             {
                 DeleteBook(book.name);
             }
         }
     }
 }
コード例 #12
0
ファイル: CBookList.cs プロジェクト: Thibor/RapChessGui
        public void Add(CBook b)
        {
            b.name = b.GetName();
            int index = GetIndex(b.name);

            if (index >= 0)
            {
                list[index] = b;
            }
            else
            {
                list.Add(b);
            }
        }
コード例 #13
0
ファイル: CBookList.cs プロジェクト: Thibor/RapChessGui
        public void SortPosition(CBook book)
        {
            SortElo();
            FillPosition();
            int position = book.position;

            foreach (CBook b in list)
            {
                b.position = Math.Abs(position - b.position);
            }
            list.Sort(delegate(CBook b1, CBook b2)
            {
                return(b1.position - b2.position);
            });
        }
コード例 #14
0
        public static CBook SelectBook()
        {
            CBook b = bookList.GetBook(book);

            if (b == null)
            {
                b = SelectRare();
            }
            if ((games >= repetition) && (games > 0))
            {
                b     = bookList.NextTournament(b);
                games = 0;
            }
            return(b);
        }
コード例 #15
0
        void SelectReader(string name)
        {
            CBook book = FormChess.bookList.GetBook(name);

            if (book == null)
            {
                return;
            }
            tbReaderName.Text     = book.name;
            cbBookReaderList.Text = book.exe;
            tbParameters.Text     = book.parameters;
            nudElo.Value          = Convert.ToInt32(book.elo);
            nudTournament.Value   = book.tournament;
            curBookName           = book.name;
        }
コード例 #16
0
        public static CBook SelectRare()
        {
            int   count  = 0;
            CBook result = null;

            foreach (CBook b in bookList.list)
            {
                int c = tourList.CountGames(b.name);
                if (count <= c)
                {
                    count  = c;
                    result = b;
                }
            }
            return(result);
        }
コード例 #17
0
        void SaveToIni(CBook book)
        {
            book.name       = tbReaderName.Text;
            book.exe        = cbBookReaderList.Text;
            book.parameters = tbParameters.Text;
            book.elo        = nudElo.Value.ToString();
            book.tournament = (int)nudTournament.Value;
            book.SaveToIni();
            curBookName = book.name;
            UpdateListBox();
            int index = listBox1.FindString(book.name);

            if (index == -1)
            {
                return;
            }
            listBox1.SetSelected(index, true);
        }
コード例 #18
0
ファイル: CGamerList.cs プロジェクト: Thibor/RapChessGui
 public void SetPlayer(CPlayer p)
 {
     player = p;
     book   = FormChess.bookList.GetBook(p.book);
     engine = FormChess.engineList.GetEngine(p.engine);
     bookPro.Terminate();
     enginePro.Terminate();
     if (book == null)
     {
         p.book = CData.none;
     }
     else
     {
         bookPro.SetProgram($@"{AppDomain.CurrentDomain.BaseDirectory}Books\{book.exe}", book.GetParameters(engine));
     }
     if (engine == null)
     {
         p.engine = "Human";
     }
     else
     {
         enginePro.SetProgram($@"{AppDomain.CurrentDomain.BaseDirectory}Engines\{engine.file}", engine.parameters, FormOptions.spamOff);
     }
 }