Beispiel #1
0
 /// <summary>
 /// Runs all tests 27-127
 /// </summary>
 //[TestCase]
 public void Run_All()
 {
     for (int i = 27; i <= 127; i++)
     {
         var clock = new Clock(i);
         var result = clock.Start();
         Assert.IsTrue(result.StartsWith(i.ToString()));
     }
 }
		/// <summary>
		/// 启动计时器
		/// </summary>
		/// <param name="interval">计时器间隔</param>
		/// <param name="count">执行次数</param>
		/// <param name="key">计时器标志</param>
		/// <param name="func">回调函数</param>
		public static bool Start(float interval, int count, string key, TimerCallBackHandle func)
		{
			Clock ck = new Clock();
			
			if (!mapClock.ContainsKey(key))
			{
				mapClock.Add(key, ck);
				ck.Start(interval, count, func);
			}
			else
			{
				return false;
			}

			return true;
		}
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _taskInstance = taskInstance;
            _deferral = _taskInstance.GetDeferral();
            _taskInstance.Canceled += TaskInstance_Canceled;
            var gpio = GpioController.GetDefault();

            // turn off red en green led
            //var red = gpio.OpenPin(35);
            //red.Write(GpioPinValue.Low);
            //red.SetDriveMode(GpioPinDriveMode.Output);
            //var green = gpio.OpenPin(47);
            //green.Write(GpioPinValue.Low);
            //green.SetDriveMode(GpioPinDriveMode.Output);

            // power cycle +3v3 to reset all I2C devices
            //_shdn = gpio.OpenPin(5);
            //_shdn.Write(GpioPinValue.High);
            //_shdn.SetDriveMode(GpioPinDriveMode.Output);
            //_shdn.Write(GpioPinValue.Low);
            //// wait to discharge all capacitors
            //Task.Delay(3000).GetAwaiter().GetResult();
            //_shdn.Write(GpioPinValue.High);

            _heater = gpio.OpenPin(16);
            _heater.Write(GpioPinValue.Low);
            _heater.SetDriveMode(GpioPinDriveMode.Output);

            _clock = new Clock();
            _clock.Start();

            await Init();
            await _clock.Init();

            _bme280 = new BME280();
            await _bme280.Init();

            //_timer2 = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick2, TimeSpan.FromMilliseconds(4));
            _timer3 = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick3, TimeSpan.FromMinutes(1));
        }
Beispiel #4
0
        public override SearchResult Search(Board board, int color,int depth)
        {
            SearchResult searchResult = new SearchResult();
            //board.CurrentColor = color;
            //PrepareToSolve(board);
            int alpha = -MaxScore - 1;
            int beta = MaxScore + 1;
            int opp =  color.Opp();

            Clock clock = new Clock();
            clock.Start();
            //Roulette roulette = new Roulette();
            //board.RefreshHash();

            int score = -MaxScore;
            int eval;
            //是否调用零窗口的标志
            bool foundPv = false;

            var moves = rule.FindFlips(board, color).ToList();

            if (moves.Count == 0) {
                return new SearchResult() { Move = -1 };
            }

            //if (moves.Count == 1) {
            //    return new SearchResult() { Move = moves.First().Pos };
            //}

            for (int i = 0; i < moves.Count; i++) {
                var pos = moves[i].Pos;
                //下棋
                //---------------------------
                int flipCount = board.MakeMove(pos, color);

                searchResult.Nodes++;
                //检测
                if (foundPv) {
                    //调用零窗口
                    eval = -FastestFirstSolve(board, -alpha - 1, -alpha, depth - 1, searchResult, opp, color);
                    if ((eval > alpha) && (eval < beta)) {
                        eval = -FastestFirstSolve(board, -beta, -eval, depth - 1, searchResult, opp, color);
                        //eval = -FastestFirstMidSolve( -beta, -alpha, oppcolor, depth - 1);
                    }
                }
                else {
                    eval = -FastestFirstSolve(board, -beta, -alpha, depth - 1, searchResult, opp, color);
                }

                //em.ReLink();
                //---------------------------
                //Eval.StepsPop(color);
                //恢复到上一步
                board.Reback(pos, flipCount, opp);

                searchResult.Message += string.Format("({0}:{1})", pos, eval);
                if (eval > score) {
                    score = eval;
                    //更新位置
                    searchResult.Move = pos;
                    searchResult.Score = score;

                    if (eval > alpha) {
                        if (eval >= beta) {
                            //剪枝
                            break;
                        }
                        alpha = eval;
                        foundPv = true;
                    }
                }
            }

            clock.Stop();

            searchResult.TimeSpan = clock.Elapsed;

            return searchResult;
        }
Beispiel #5
0
 public void Run_ReturnsStringStartingWithTheNumberOfBallsGiven()
 {
     var expected = 27;
     var clock = new Clock(expected);
     Assert.IsTrue(clock.Start().StartsWith(expected.ToString()));
 }
Beispiel #6
0
 public void Run_Returns378DaysWhenGiven45Balls()
 {
     var clock = new Clock(45);
     Assert.AreEqual("45 balls cycle after 378 days", clock.Start());
 }
Beispiel #7
0
 public void Run_Returns15DaysWhenGiven30Balls()
 {
     var clock = new Clock(30);
     Assert.AreEqual("30 balls cycle after 15 days", clock.Start());
 }