static void Main(string[] args) { var options = CCOptions.Default(); options.threads = 2; options.max_nodes = 100000; var weights = CCWeights.Default(); NextGenerator g = new NextGenerator(); CCPieceBag bag = CCPieceBag.Full(); bool[] field = new bool[400]; using (var cc = new Bot(options, weights, field, bag, CCPiece.CC_None, false, 0)) { for (int i = 0; i < 10; i++) { cc.AddNextPiece(g.Next()); } Thread.Sleep(100); for (int i = 0; i < 20; i++) { PrintMovePlan(cc.GetNextMoveAndPlans(0)); cc.AddNextPiece(g.Next()); Thread.Sleep(100); } cc.Reset(field, false, 0); PrintMovePlan(cc.GetNextMoveAndPlans(0)); } }
// helper method to reduce the amount of generate code for each cipher algorithm static internal IntPtr Create(CCOperation operation, CCAlgorithm algorithm, CCOptions options, byte[] key, byte[] iv) { if (key == null) { throw new CryptographicException("A null key was provided"); } // unlike the .NET framework CommonCrypto does not support two-keys triple-des (128 bits) ref: #6967 if ((algorithm == CCAlgorithm.TripleDES) && (key.Length == 16)) { byte[] key3 = new byte [24]; Buffer.BlockCopy(key, 0, key3, 0, 16); Buffer.BlockCopy(key, 0, key3, 16, 8); key = key3; } IntPtr cryptor = IntPtr.Zero; CCCryptorStatus status = Cryptor.CCCryptorCreate(operation, algorithm, options, key, (IntPtr)key.Length, iv, ref cryptor); if (status != CCCryptorStatus.Success) { throw new CryptographicUnexpectedOperationException(); } return(cryptor); }
// helper method to reduce the amount of generate code for each cipher algorithm static internal IntPtr Create (CCOperation operation, CCAlgorithm algorithm, CCOptions options, byte[] key, byte[] iv) { if (key == null) throw new CryptographicException ("A null key was provided"); // unlike the .NET framework CommonCrypto does not support two-keys triple-des (128 bits) ref: #6967 if ((algorithm == CCAlgorithm.TripleDES) && (key.Length == 16)) { byte[] key3 = new byte [24]; Buffer.BlockCopy (key, 0, key3, 0, 16); Buffer.BlockCopy (key, 0, key3, 16, 8); key = key3; } IntPtr cryptor = IntPtr.Zero; CCCryptorStatus status = Cryptor.CCCryptorCreate (operation, algorithm, options, key, (IntPtr) key.Length, iv, ref cryptor); if (status != CCCryptorStatus.Success) throw new CryptographicUnexpectedOperationException (); return cryptor; }
public static extern IntPtr cc_launch_async(CCOptions options, CCWeights weights);
public static extern void cc_default_options(out CCOptions options);
public async void newGame() { if (ptrBot != (IntPtr)null) { //return; coldclearcore.cc_destroy_async(ptrBot); } 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)); 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("ColdCleartetr.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("ColdCleartetr.exe"); //botname = config.AppSettings.Settings["botname"].Value; pbs = 60.0 / int.Parse(config.AppSettings.Settings["bpm"].Value); cCOptions.min_nodes = uint.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); acv = true; }
extern internal static CCCryptorStatus CCCryptorCreate (CCOperation op, CCAlgorithm alg, CCOptions options, /* const void* */ byte[] key, /* size_t */ IntPtr keyLength, /* const void* */ byte[] iv, /* CCCryptorRef* */ ref IntPtr cryptorRef);
extern internal static CCCryptorStatus CCCryptorCreate(CCOperation op, CCAlgorithm alg, CCOptions options, /* const void* */ byte[] key, /* size_t */ IntPtr keyLength, /* const void* */ byte[] iv, /* CCCryptorRef* */ ref IntPtr cryptorRef);