Пример #1
0
        /// <summary>
        /// Look for capture variations for horizon effect
        /// </summary>
        /// <param name="alpha"></param>
        /// <param name="beta"></param>
        /// <param name="nodeCount"></param>
        /// <returns></returns>
        int QuiescenceSearch(int alpha, int beta, ref int nodeCount)
        {
            nodeCount++;



            int eval = Evaluation.Evaluate(Board);

            if (eval >= beta)
            {
                return(beta);
            }


            if (eval > alpha)
            {
                alpha = eval;
            }

            var moves = MVVLVASorting(Board.GenerateMoves());

            foreach (var capture in moves)
            {
                Board.MakeMove(capture);

                eval = -QuiescenceSearch(-beta, -alpha, ref nodeCount);

                Board.TakeBackMove(capture);



                if (eval >= beta) // The move is too good
                {
                    return(beta);
                }

                if (eval > alpha)// Best move so far
                {
                    alpha = eval;
                }
            }


            return(alpha);
        }
Пример #2
0
        /// <summary>
        /// Process incoming commands
        /// </summary>
        /// <param name="input">Incoming string from interface</param>
        public void Comunication(string input)
        {
            string command     = input.Split(' ').First();
            string messageBody = input.Substring(command.Length).Trim();

            switch (command)
            {
            case "protover":
            {
                if (messageBody == "2")
                {
                    Console.WriteLine(@"feature  setboard=1 usermove=1 colors=0 reuse=1 time=1 myname=""The Turk"" name=1 done=1");
                }
                break;
            }

            case "force":
            {
                force = force ? false : true;
                break;
            }

            case "new":
            {
                engine.Board.SetUpBoard();
                GameHistory.Clear();
                force = true;
                break;
            }

            case "setboard":
            {
                engine.Board.Fen = messageBody;
                GameHistory.Clear();
                break;
            }

            case "quit":
            {
                Environment.Exit(Environment.ExitCode);
                break;
            }

            case "usermove":
            {
                ReceivedMove(messageBody);
                if (force)         //Make move after received a move
                {
                    Console.WriteLine("force mode is on");
                    var result = engine.Search(timer.timeForPerMove);
                    Console.WriteLine("move " + result.BestLine.First().IONotation());
                    engine.Board.MakeMove(result.BestLine.First());
                    GameHistory.Push(result.BestLine.First());
                }
                break;
            }

            case "go":
            {
                force = true;
                var result = engine.Search(timer.timeForPerMove);
                Console.WriteLine("move " + result.BestLine.First().IONotation());
                engine.Board.MakeMove(result.BestLine.First());
                GameHistory.Push(result.BestLine.First());
                break;
            }

            case "undo":
            {
                engine.Board.TakeBackMove(GameHistory.Pop());
                break;
            }

            case "level":
            {
                timer = new ChessClock(messageBody);
                break;
            }

            case "st":
            {
                timer = new ChessClock("0 0 " + messageBody);
                break;
            }

            case "fen":     //just for testing purposes
            {
                engine.Board.Fen = "rn4kr/4p1bp/2pp4/1p3P1Q/2P1P3/6R1/PBp3PP/RN4K1 w - - 0 24 ";
                GameHistory.Clear();
                break;
            }

            case "score":     //just for testing purposes
            {
                var score = Evaluation.Evaluate(engine.Board);
                engine.Board.ShowBoard();
                Console.WriteLine("score : " + score);
                break;
            }

            case "show":     //just for testing purposes
            {
                engine.Board.ShowBoard();
                break;
            }
            }
        }