Пример #1
0
        public static CEngine SelectOpponent(CEngine engine)
        {
            engineList.SortPosition(engine);
            List <CEngine> el = new List <CEngine>();

            foreach (CEngine e in engineList.list)
            {
                if (e != engine)
                {
                    el.Add(e);
                }
            }
            if (el.Count == 0)
            {
                return(engine);
            }
            for (int n = 0; n < el.Count - 1; n++)
            {
                CEngine e = ChooseOpponent(engine, el[n], el[n + 1]);
                if (e != null)
                {
                    return(e);
                }
            }
            return(el[0]);
        }
Пример #2
0
        public CEngine NextTournament(CEngine e, bool rotate = true, bool back = false)
        {
            SortElo();
            int i = GetIndex(e.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);
                }
                e = list[i];
                if (e.tournament > 0)
                {
                    break;
                }
            }
            return(e);
        }
Пример #3
0
        public static CEngine ChooseOpponent(CEngine engine, CEngine engine1, CEngine engine2)
        {
            tourList.CountGames(engine.name, engine1.name, out int rw1, out int rl1, out int rd1);
            tourList.CountGames(engine.name, engine2.name, out int rw2, out int rl2, out int rd2);
            if ((engine.GetElo() > engine1.GetElo()) != (rw1 > rl1))
            {
                return(engine1);
            }
            if ((engine.GetElo() > engine2.GetElo()) != (rw2 > rl2))
            {
                return(engine2);
            }
            int count1 = (rw1 + rl1 + rd1);
            int count2 = (rw2 + rl2 + rd2);

            if (count1 * 1.1 <= count2 << 1)
            {
                return(engine1);
            }
            if (count2 * 1.1 <= count1 >> 1)
            {
                return(engine2);
            }
            return(null);
        }
Пример #4
0
 private void listBox1_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         indexFirst       = -1;
         tournament       = -1;
         listBox1.Capture = true;
         int index = listBox1.IndexFromPoint(e.Location);
         if ((index >= 0) && (index < listBox1.Items.Count))
         {
             var     item = listBox1.Items[index];
             string  name = item.ToString();
             CEngine eng  = FormChess.engineList.GetEngine(name);
             indexFirst = index;
             tournament = eng.tournament > 0 ? 0 : 1;
             if (eng.SetTournament(tournament == 1))
             {
                 listBox1.Refresh();
                 if (engine == eng)
                 {
                     SelectEngine();
                 }
             }
         }
     }
 }
Пример #5
0
 public static void SetRepeition(CEngine e, CEngine o)
 {
     if ((engine != e.name) || (opponent != o.name))
     {
         engine   = e.name;
         opponent = o.name;
         SaveToIni();
         tourList.CountGames(e.name, o.name, out int rw, out int rl, out _);
         if (games == 0)
         {
             repetition = e.tournament;
             if ((e.GetElo() > o.GetElo()) != (rw > rl))
             {
                 repetition++;
             }
             if (e.hisElo.list.Count < o.hisElo.list.Count)
             {
                 repetition++;
             }
             rotate = true;
         }
     }
     games++;
     rotate ^= true;
 }
Пример #6
0
        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }
            string  name     = listBox1.Items[e.Index].ToString();
            CEngine eng      = FormChess.engineList.GetEngine(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 (!eng.FileExists())
            {
                e = new DrawItemEventArgs(e.Graphics, e.Font, e.Bounds, e.Index, e.State, Color.White, CBoard.colorRed);
                b = Brushes.White;
            }
            else if (eng.tournament > 0)
            {
                e = new DrawItemEventArgs(e.Graphics, e.Font, e.Bounds, e.Index, e.State, Color.Black, CBoard.colorMessage);
            }
            e.DrawBackground();
            e.Graphics.DrawString(name, e.Font, b, e.Bounds, StringFormat.GenericDefault);
            e.DrawFocusRectangle();
        }
Пример #7
0
 void SelectEngine(string name)
 {
     engine = FormChess.engineList.GetEngine(name);
     if (engine != null)
     {
         SelectEngine(engine);
     }
 }
Пример #8
0
 public void SetElo()
 {
     SortElo();
     for (int n = 0; n < list.Count; n++)
     {
         CEngine e = list[n];
         e.SetElo(GetOptElo(n));
     }
 }
Пример #9
0
        public void SetElo(string name)
        {
            CEngine engine = GetEngine(name);

            if (engine != null)
            {
                engine.SetElo(0);
                SetElo();
            }
        }
Пример #10
0
        public void Check(CEngineList el)
        {
            CEngine e = el.GetEngine(engine);

            if (e == null)
            {
                engine = "Human";
                SaveToIni();
            }
        }
Пример #11
0
        private void ButCreate_Click(object sender, EventArgs e)
        {
            string  name   = tbEngineName.Text;
            CEngine engine = new CEngine(name);

            FormChess.engineList.list.Add(engine);
            SaveToIni(engine);
            MessageBox.Show($"Chess {engine.name} has been created");
            CData.reset = true;
        }
Пример #12
0
        public string GetParameters(CEngine e)
        {
            if (e == null)
            {
                return("");
            }
            string p = parameters.Replace("[engine]", e.name).Replace("[uci]", $@"{Directory.GetCurrentDirectory()}\engines\uci\");

            return(p);
        }
Пример #13
0
        private void cbEngineList_SelectedIndexChanged(object sender, EventArgs e)
        {
            CEngine engine = FormChess.engineList.GetEngine(cbEngineList.Text);

            if (engine != null)
            {
                locked = true;
                richTextBox1.Clear();
                process.SetProgram($@"{AppDomain.CurrentDomain.BaseDirectory}Engines\{engine.file}", engine.parameters);
            }
        }
Пример #14
0
 public int GetIndex(string name)
 {
     for (int n = 0; n < list.Count; n++)
     {
         CEngine engine = list[n];
         if (engine.name == name)
         {
             return(n);
         }
     }
     return(-1);
 }
Пример #15
0
        public int LoadFromIni()
        {
            list.Clear();
            List <string> en = CEngineList.iniFile.ReadKeyList("engine");

            foreach (string name in en)
            {
                CEngine engine = new CEngine(name);
                engine.LoadFromIni();
                list.Add(engine);
            }
            AutoUpdate();
            return(en.Count);
        }
Пример #16
0
        public void Add(CEngine e)
        {
            e.name = e.GetName();
            int index = GetIndex(e.name);

            if (index >= 0)
            {
                list[index] = e;
            }
            else
            {
                list.Add(e);
            }
        }
Пример #17
0
        public void SortPosition(CEngine engine)
        {
            SortElo();
            FillPosition();
            int position = engine.position;

            foreach (CEngine e in list)
            {
                e.position = Math.Abs(position - e.position);
            }
            list.Sort(delegate(CEngine e1, CEngine e2)
            {
                return(e1.position - e2.position);
            });
        }
Пример #18
0
        public static CEngine SelectEngine()
        {
            CEngine e = engineList.GetEngine(engine);

            if (e == null)
            {
                e = SelectRare();
            }
            if ((games >= repetition) && (games > 0))
            {
                e     = engineList.NextTournament(e);
                games = 0;
            }
            return(e);
        }
Пример #19
0
        public static CEngine SelectRare()
        {
            int     count  = 0;
            CEngine result = null;

            foreach (CEngine e in engineList.list)
            {
                int c = tourList.CountGames(e.name);
                if (count <= c)
                {
                    count  = c;
                    result = e;
                }
            }
            return(result);
        }
Пример #20
0
 public void AutoUpdate()
 {
     foreach (string fn in CData.fileEngineUci)
     {
         string  name   = Path.GetFileNameWithoutExtension(fn);
         string  file   = $@"Uci\{fn}";
         CEngine engine = GetEngineByFile(file);
         if (engine == null)
         {
             engine = GetEngine(name);
             if (engine == null)
             {
                 engine          = new CEngine(name);
                 engine.protocol = CProtocol.uci;
                 list.Add(engine);
             }
             engine.file = file;
             engine.SaveToIni();
         }
     }
     foreach (string fn in CData.fileEngineWb)
     {
         string  name   = Path.GetFileNameWithoutExtension(fn);
         string  file   = $@"Winboard\{fn}";
         CEngine engine = GetEngineByFile(file);
         if (engine == null)
         {
             engine = GetEngine(name);
             if (engine == null)
             {
                 engine          = new CEngine(name);
                 engine.protocol = CProtocol.winboard;
                 list.Add(engine);
             }
             engine.file = file;
             engine.SaveToIni();
         }
     }
     for (int n = list.Count - 1; n >= 0; n--)
     {
         CEngine e = list[n];
         if (e.IsAuto() && !e.FileExists())
         {
             DeleteEngine(e.name);
         }
     }
 }
Пример #21
0
        void SaveToIni(CEngine e)
        {
            e.name         = tbEngineName.Text;
            e.file         = cbFileList.Text;
            e.protocol     = CData.StrToProtocol(cbProtocol.Text);
            e.parameters   = tbParameters.Text;
            e.modeStandard = cbModeStandard.Checked;
            e.elo          = nudElo.Value.ToString();
            e.tournament   = (int)nudTournament.Value;
            e.options      = GetOptions();
            e.SaveToIni();
            UpdateListBox();
            int index = listBox1.FindString(e.name);

            if (index == -1)
            {
                return;
            }
            listBox1.SetSelected(index, true);
        }
Пример #22
0
        void SelectEngines(int first, int last, bool t)
        {
            int  f = first < last ? first : last;
            int  l = first < last ? last : first;
            bool r = false;

            for (int n = f; n <= l; n++)
            {
                var     item = listBox1.Items[n];
                string  name = item.ToString();
                CEngine eng  = FormChess.engineList.GetEngine(name);
                if (eng.SetTournament(t))
                {
                    r = true;
                }
            }
            if (r)
            {
                listBox1.Refresh();
                SelectEngine();
            }
        }
Пример #23
0
 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);
     }
 }
Пример #24
0
 void SelectEngine(CEngine e)
 {
     engine = e;
     SelectEngine();
 }