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); }
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(); }
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]); }
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); }
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; }
void TryAdd(string br, string p) { if ((br != "none") && !ParametersExists(p)) { CBook b = new CBook(); b.exe = br; b.parameters = p; list.Add(b); } }
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; }
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); }
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); }
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; }
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); } } } }
public void Add(CBook b) { b.name = b.GetName(); int index = GetIndex(b.name); if (index >= 0) { list[index] = b; } else { list.Add(b); } }
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); }); }
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); }
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; }
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); }
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); }
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); } }