Ejemplo n.º 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]);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
                 }
             }
         }
     }
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 7
0
 void SelectEngine(string name)
 {
     engine = FormChess.engineList.GetEngine(name);
     if (engine != null)
     {
         SelectEngine(engine);
     }
 }
Ejemplo n.º 8
0
 public void SetElo()
 {
     SortElo();
     for (int n = 0; n < list.Count; n++)
     {
         CEngine e = list[n];
         e.SetElo(GetOptElo(n));
     }
 }
Ejemplo n.º 9
0
        public void SetElo(string name)
        {
            CEngine engine = GetEngine(name);

            if (engine != null)
            {
                engine.SetElo(0);
                SetElo();
            }
        }
Ejemplo n.º 10
0
        public void Check(CEngineList el)
        {
            CEngine e = el.GetEngine(engine);

            if (e == null)
            {
                engine = "Human";
                SaveToIni();
            }
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            });
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
         }
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 24
0
 void SelectEngine(CEngine e)
 {
     engine = e;
     SelectEngine();
 }