コード例 #1
0
 public static extern IntPtr cc_launch_async(CCOptions options, CCWeights weights);
コード例 #2
0
ファイル: CC.cs プロジェクト: ssccinng/Cold-Clear-SF
        private void calc_Click(object sender, EventArgs e)
        {
            line_clear();
            IntPtr ptrW = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CCWeights)));

            coldclearcore.cc_default_weights(ptrW);
            CCWeights cCWeights = (CCWeights)Marshal.PtrToStructure(ptrW, typeof(CCWeights));
            IntPtr    ptrOP     = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CCOptions)));

            coldclearcore.cc_default_options(ptrOP);
            CCOptions cCOptions = (CCOptions)Marshal.PtrToStructure(ptrOP, typeof(CCOptions));

            cCOptions.speculate = (char)(0);
            cCOptions.min_nodes = 200000;
            //cCOptions.max_nodes = 50000000;
            //Marshal.StructureToPtr(cCOptions, ptrOP, true);
            //Marshal.StructureToPtr(cCWeights, ptrW, true);
            //ptrBot = coldclearcore.cc_launch_async(ptrOP, ptrW);
            if (ptrBot == (IntPtr)null)
            {
                foreach (string key in ConfigurationManager.AppSettings.AllKeys)
                {
                    if (key == "tslot" || key == "well_column" || key == "min_nodes" || key == "use_hold" ||
                        key == "mode" || key == "use_bag" || key == "threads" || key == "pcloop")
                    {
                        continue;
                    }
                    //string ConfigPath = ConfigurationManager.AppSettings["ConfigPath"].Trim().ToString();
                    Configuration config1 = System.Configuration.ConfigurationManager.OpenExeConfiguration("Cold Clear SF.exe");

                    if (config1.AppSettings.Settings[key].Value == "")
                    {
                        config1.AppSettings.Settings.Add(key, cCWeights.GetType().GetField(key).GetValue(cCWeights).ToString());
                        config1.Save(ConfigurationSaveMode.Modified);
                    }

                    cCWeights.GetType().GetField(key).SetValue(cCWeights, int.Parse(config1.AppSettings.Settings[key].Value));
                }
                Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration("Cold Clear SF.exe");
                cCOptions.min_nodes = ulong.Parse(config.AppSettings.Settings["min_nodes"].Value);
                cCOptions.pcloop    = (char)(char.Parse(config.AppSettings.Settings["pcloop"].Value) - '0');
                //cCOptions.threads = ulong.Parse(config.AppSettings.Settings["threads"].Value);
                cCOptions.mode     = (CCMovementMode)Enum.Parse(typeof(CCMovementMode), "CC_" + config.AppSettings.Settings["mode"].Value);
                cCOptions.use_hold = (char)(char.Parse(config.AppSettings.Settings["use_hold"].Value) - '0');
                string [] ts = config.AppSettings.Settings["tslot"].Value.Split(',');
                //cCWeights.use_bag = (char) (char.Parse(config.AppSettings.Settings["use_bag"].Value) - '0');
                string[] cw = config.AppSettings.Settings["well_column"].Value.Split(',');
                unsafe {
                    for (int i = 0; i < 4; ++i)
                    {
                        cCWeights.tslot[i] = int.Parse(ts[i]);
                    }
                    for (int i = 0; i < 10; ++i)
                    {
                        cCWeights.well_column[i] = int.Parse(cw[i]);
                    }
                }
                ptrBot = coldclearcore.cc_launch_async(cCOptions, cCWeights);
                Thread.Sleep(500);
            }

            char[] f = new char[400];
            for (int i = 0; i < 220; ++i)
            {
                if ((int)(Field[i].Tag) != 0)
                {
                    f[i] = (char)(1);
                }
            }
            coldclearcore.cc_reset_async(ptrBot, f, (char)(0), combo);
            //coldclearcore.cc_destroy_async(ptrBot);
            if (nexttab == null)
            {
                nexttab = new Queue <int>();
            }
            //hold = -1;
            foreach (char mino in nextqueue.Text.ToUpper())
            {
                //nexttab.Enqueue(1);
                //coldclearcore.cc_add_next_piece_async(ptrBot, CCPiece.CC_T);
                nexttab.Enqueue((int)Enum.Parse(typeof(CCPiece), "CC_" + mino));
                coldclearcore.cc_add_next_piece_async(ptrBot, (CCPiece)Enum.Parse(typeof(CCPiece), "CC_" + mino));
            }
            string a = "";

            foreach (int i in nexttab)
            {
                a += block[i];
            }
            Nexttt.Text = "Next: " + a;
            calc.Text   = "计算完毕";
            //while (nexttab.Count > 1)
            //{
            //    coldclearcore.cc_request_next_move(ptrBot, 0);
            //    Thread.Sleep(1000);
            //    while (!coldclearcore.cc_poll_next_move(ptrBot, ptrmove))
            //    {
            //        Thread.Sleep(100);
            //    }
            //    CCMove cCMove = (CCMove)Marshal.PtrToStructure(ptrmove, typeof(CCMove));
            //    int nowb = nexttab.Dequeue();
            //    if (cCMove.hold == 1)
            //    {

            //        if (hold == -1)
            //        {
            //            if (nexttab.Count < 0) break;
            //            hold = nowb;
            //            nowb = nexttab.Dequeue();
            //        }
            //        else
            //        {
            //            int temp;
            //            temp = nowb;
            //            nowb = hold;
            //            hold = temp;
            //        }
            //    }
            //    unsafe
            //    {
            //        for (int i = 0; i < 4; ++i)
            //        {
            //            Field[(cCMove.expected_x[i]) + cCMove.expected_y[i] * 10].Tag = nowb + 2;
            //            Field[(cCMove.expected_x[i]) + cCMove.expected_y[i] * 10].BackColor = minocolor[nowb + 2];
            //            //Field[0].BackColor = Color.Purple;
            //        }
            //    }
            //    //Field[0].Tag = 1;
            //    //Field[0].BackColor = Color.Purple;
            //    //nexttab.Dequeue();
            //    //Thread.Sleep(2000);
            //    //break;
            //    line_clear();
            //}
        }