Ejemplo n.º 1
0
 void _engine_MoveReceived(object sender, UCIMoveEventArgs e)
 {
     if (MoveReceived != null)
     {
         MoveReceived(sender, e);
     }
 }
Ejemplo n.º 2
0
        public void DoMove()
        {
            if (IsClosed)
            {
                return;
            }

            if (BookMoves.rowIndex == -1)
            {
                isExpired = true;
                return;
            }

            Move m = BookMoves.CurrentMove();

            if (m == null)
            {
                isExpired = true;
                return;
            }

            isExpired          = false;
            BookMoves.rowIndex = 0;

            if (MoveReceived != null)
            {
                UCIMoveEventArgs e = new UCIMoveEventArgs(m.From, m.To);
                MoveReceived(this, e);
            }
        }
Ejemplo n.º 3
0
 void book_MoveReceived(object sender, UCIMoveEventArgs e)
 {
     moveFounded = true;
     if (EventMoveReceived != null)
     {
         EventMoveReceived(this, e);
     }
 }
Ejemplo n.º 4
0
        public void SearchMove(string fen)
        {
            string[] movePositions = GetMovePositions(fen);

            if (!string.IsNullOrEmpty(movePositions[0]))
            {
                if (MoveReceived != null)
                {
                    string           moveFrom = movePositions[0];
                    string           moveTo   = movePositions[1];
                    UCIMoveEventArgs e        = new UCIMoveEventArgs(moveFrom, moveTo);
                    MoveReceived(this, e);
                }
            }
        }
Ejemplo n.º 5
0
        private void ProcessBestMove(string uciData)
        {
            if (!HasGame || IsPaused)
            {
                return;
            }

            TestDebugger.Instance.Write("UI2E >>  " + EngineName + " : Best Moves : " + uciData);
            if (!uciData.Contains("bestmove ponder") && !uciData.Contains("bestmove  ponder"))
            {
                bestMoves = uciData.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                string ParentMoves = this.Game.Moves.GetParentsStr(this.Game.CurrentMove);

                if (bestMoves.Length >= 2)
                {
                    IsMoveInProgress = false;
                    string moveFrom = bestMoves[1].Substring(0, 2);
                    string moveTo   = bestMoves[1].Substring(2, 2);
                    this.Game.BestMove = bestMoves[1];
                    if (IsBestMoveWithPonder)
                    {
                        this.Game.PonderMove = bestMoves[3];
                    }
                    else
                    {
                        this.Game.PonderMove = subPonderMove;
                    }
                    if (isPonderMiss)
                    {
                        isPonderMiss         = false;
                        IsPonderMoveResponse = false;
                        OnClearAnalysis();
                        if (this.Game.Flags.IsBoardSetByFen)
                        {
                            SendPositionGoWithoutCheckingPonderHit(false, this.Game.InitialBoardFen, ParentMoves, this.Game.Clock.WhiteTime * 1000, this.Game.Clock.BlackTime * 1000);
                        }
                        else
                        {
                            SendPositionGoWithoutCheckingPonderHit(false, string.Empty, ParentMoves, this.Game.Clock.WhiteTime * 1000, this.Game.Clock.BlackTime * 1000);
                        }
                        SendStop();
                        return;
                    }
                    if (this.Game.Flags.IsInfiniteAnalysisStopped)
                    {
                        return;
                    }

                    if (((!IsPonderMove || this.Game.Flags.IsInfiniteAnalysisStopped) && this.Game.Flags.IsInfiniteAnalysisOff) || (this.Game.Flags.IsInfiniteAnalysisOn && this.Game.Flags.IsForceEngineToMoveInInfiniteAnalysis))
                    {
                        isSendStop = false;

                        if (this.Game.Flags.IsInfiniteAnalysisStopped)
                        {
                            this.Game.Flags.IsInfiniteAnalysisStopped = false;
                        }

                        if (this.Game.Flags.IsFirtMove && this.Game.Flags.IsForceEngineToMove && !this.Game.Flags.IsInfiniteAnalysisOn)
                        {
                            IsPonderMove = !IsPonderMove;
                        }

                        if (this.Game.CurrentPlayer.Book == null || !this.Game.CurrentPlayer.Book.IsAvailable)
                        {
                            if (MoveReceived != null)
                            {
                                UCIMoveEventArgs e = new UCIMoveEventArgs(moveFrom, moveTo);
                                MoveReceived(this, e);
                            }
                        }
                    }

                    if (!ProcessPonder)
                    {
                        return;
                    }

                    IsPonderMove = !IsPonderMove;

                    if ((IsPonderMove && this.Game.Flags.IsInfiniteAnalysisOff) || (this.Game.Flags.IsInfiniteAnalysisOn && this.Game.Flags.IsForceEngineToMoveInInfiniteAnalysis))
                    {
                        if (bestMoves.Length == 4)
                        {
                            this.Game.PreviousPonderMove = bestMoves[3];
                        }
                        else
                        {
                            this.Game.PreviousPonderMove = subPonderMove;
                        }

                        if (IsKibitzer)
                        {
                            return;
                        }

                        if (this.Game.Flags.IsInfiniteAnalysisOff)
                        {
                            if (!string.IsNullOrEmpty(this.Game.PonderMove))
                            {
                                if (ParentMoves.EndsWith(this.Game.BestMove))
                                {
                                    if (this.Game.Flags.IsBoardSetByFen)
                                    {
                                        SendPositionGo(true, this.Game.InitialBoardFen, ParentMoves + " " + this.Game.PonderMove, this.Game.Clock.WhiteTime * 1000, this.Game.Clock.BlackTime * 1000);
                                    }
                                    else
                                    {
                                        SendPositionGo(true, string.Empty, ParentMoves + " " + this.Game.PonderMove, this.Game.Clock.WhiteTime * 1000, this.Game.Clock.BlackTime * 1000);
                                    }
                                }
                                else
                                {
                                    if (this.Game.Flags.IsBoardSetByFen)
                                    {
                                        SendPositionGo(true, this.Game.InitialBoardFen, ParentMoves + " " + this.Game.BestMove + " " + this.Game.PonderMove, this.Game.Clock.WhiteTime * 1000, this.Game.Clock.BlackTime * 1000);
                                    }
                                    else
                                    {
                                        SendPositionGo(true, string.Empty, ParentMoves + " " + this.Game.BestMove + " " + this.Game.PonderMove, this.Game.Clock.WhiteTime * 1000, this.Game.Clock.BlackTime * 1000);
                                    }
                                }
                            }
                            IsPonderMove         = !IsPonderMove;
                            IsPonderMoveResponse = true;
                        }
                    }
                }
            }
            else
            {
                this.Game.PonderMove = "";
                IsPonderMove         = false;
            }
            isInfiniteCommandInProgress = false;
        }