示例#1
0
        public Match(Game game, PGNGame pgn, IDebugMessageLog messageLog, TimerFactory timerFactory)
        {
            Game             = game;
            StartDelay       = 0;
            IsFinished       = false;
            m_gameInProgress = false;
            m_paused         = false;
            PGN            = pgn;
            Moves          = new List <Movement>();
            m_timerFactory = new TimerFactory();
            m_startTimer   = timerFactory.NewTimer();
            m_timeControl  = new TimeControl[2];
            m_messageLog   = messageLog;
            Adjudicator    = new GameAdjudicator();

            m_player    = new Player[2];
            m_adaptor   = new EngineGameAdaptor[2];
            m_book      = new OpeningBook[2];
            m_bookDepth = new int[2];
            for (int i = 0; i < 2; i++)
            {
                m_player[i]    = null;
                m_book[i]      = null;
                m_bookDepth[i] = 0;
            }

            HumanEnabled = delegate { };
            Started      = delegate { };
            FENChanged   = delegate { };
            MoveMade     = delegate { };
            Finished     = delegate { };
        }
示例#2
0
        //	Forces the player to play move as its next move
        public void MakeBookMove(List <Movement> move)
        {
            TimeControl.StartTimer();
            MakeMove(move);
            TimeControl.Update();
            Evaluation.IsBookEval = true;

            MoveMade(this, move);
        }
示例#3
0
 public void SetTimeControl(TimeControl timeControl, int side = -1)
 {
     if (side != 0)
     {
         m_timeControl[1] = timeControl.Clone();
     }
     if (side != 1)
     {
         m_timeControl[0] = timeControl.Clone();
     }
 }
示例#4
0
 public bool Equals(TimeControl other)
 {
     return
         (MovesPerTC == other.MovesPerTC &&
          TimePerTC == other.TimePerTC &&
          TimePerMove == other.TimePerMove &&
          TimeIncrement == other.TimeIncrement &&
          PlyLimit == other.PlyLimit &&
          NodeLimit == other.NodeLimit &&
          Infinite == other.Infinite);
 }
示例#5
0
 public void AttachGame(int side, Player opponent, Game game, TimeControl timeControl)
 {
     claimedResult = false;
     Evaluation.Clear();
     Opponent    = opponent;
     Game        = game;
     Side        = side;
     TimeControl = timeControl;
     if (side == game.CurrentSide)
     {
         State = PlayerState.Thinking;
     }
     else
     {
         State = PlayerState.Observing;
     }
 }
示例#6
0
        // *** OPERATIONS *** //

        //	Prepares the player for a new chess game, and then calls
        //	startGame() to start the game.
        //
        //	param side: The side (color) the player should play as. It
        //	can be NoSide if the player is in force/observer mode.
        //	param opponent: The opposing player.
        //	param board: The chessboard on which the game is played.
        public void NewGame(int side, Player opponent, Game game)
        {
            //Q_ASSERT( opponent != 0 );
            //Q_ASSERT( board != 0 );
            //Q_ASSERT( isReady() );
            //Q_ASSERT( m_state != Disconnected );

            claimedResult = false;
            Evaluation.Clear();
            Opponent = opponent;
            Game     = game;
            Side     = side;
            TimeControl.Initialize();

            State = PlayerState.Observing;
            startGame();
        }
示例#7
0
        //	Creates a new TimeControl that has the exact same values as this one
        public TimeControl Clone()
        {
            TimeControl clone = new TimeControl();

            clone.Infinite      = Infinite;
            clone.MovesPerTC    = MovesPerTC;
            clone.TimePerTC     = TimePerTC;
            clone.TimeIncrement = TimeIncrement;
            clone.TimePerMove   = TimePerMove;
            clone.TimeLeft      = TimeLeft;
            clone.MovesLeft     = MovesLeft;
            clone.PlyLimit      = PlyLimit;
            clone.NodeLimit     = NodeLimit;
            clone.ExpiryMargin  = ExpiryMargin;
            clone.lastMoveTime  = lastMoveTime;
            clone.expired       = expired;
            return(clone);
        }
示例#8
0
        //	Emits the player's move, and a timeout signal if the
        //	move came too late.
        protected void emitMove(List <Movement> moves)
        {
            if (State == PlayerState.Thinking)
            {
                State = PlayerState.Observing;
            }

            TimeControl.Update();
            Evaluation.Time = TimeControl.LastMoveTime;

            timer.Stop();
            if (false && TimeControl.Expired)              /* TODO: enforce human time control? */
            {
                forfeit(ResultType.Timeout);
                return;
            }

            MoveMade(this, moves);
        }
示例#9
0
        private void startClock()
        {
            if (State != PlayerState.Thinking)
            {
                return;
            }

            Evaluation.Clear();

            if (TimeControl.IsValid)
            {
                StartedThinking(TimeControl.TimeLeft);
            }

            TimeControl.StartTimer();

            if (!TimeControl.Infinite)
            {
                long t = TimeControl.TimeLeft + TimeControl.ExpiryMargin;
                timer.Interval = (int)((t >= 0 ? t : 0) + 200);                  /* Warning - unsafe cast */
                timer.Start();
            }
        }
示例#10
0
        protected override void startGame()
        {
            drawOnNextMove = false;
            gotResult      = false;
            forceMode      = false;
            nextMove       = null;

            //	send the "new" command
            Write("new");

            //	send the "variant" command?
            if (Game.Name != "Chess")
            {
                //	Inform the engine of the variant we are playing.  If we are using
                //	an EngineGameAdaptor, use the name specified in the adaptor
                //	(which is the game the engine thinks we are playing.)
                Write("variant " + (Adaptor != null ? Adaptor.XBoardName : Game.GameAttribute.XBoardName));
            }

            //	send the "setboard" command?
            if ((Game.GameAttribute.TagList != null && Game.GameAttribute.TagList.Contains("Random Array")) ||
                (Adaptor != null && Adaptor.IssueSetboard))                  //	||  board()->fenString() != board()->defaultFenString())
            {
                SetBoard(Adaptor != null ? Adaptor.TranslateFEN(Game.FENStart) : Game.FENStart);
            }

            //	send the time controls
            TimeControl myTc = TimeControl;

            if (myTc.Infinite)
            {
                if (myTc.PlyLimit == 0 && myTc.NodeLimit == 0)
                {
                    Write(string.Format("st {0}", infiniteSec));
                }
            }
            else if (myTc.TimePerMove > 0)
            {
                Write(string.Format("st {0}", myTc.TimePerMove / 1000));
            }
            else
            {
                Write(string.Format("level {0} {1} {2}", myTc.MovesPerTC, msToXboardTime(myTc.TimePerTC), (double)myTc.TimeIncrement / 1000.0));
            }

            if (myTc.PlyLimit > 0)
            {
                Write(string.Format("sd {0}", myTc.PlyLimit));
            }
            if (myTc.NodeLimit > 0)
            {
                if (ftNps)
                {
                    Write(string.Format("st 1\nnps {0}", myTc.NodeLimit));
                }
                else
                {
                    throw new Exception("Engine doesn't support the nps command");
                }
            }

            //	send the "post" command to show thinking
            Write("post");

            //	send the "easy" command to disable pondering
            Write("easy");
            setForceMode(true);

            //	inform the engine of the opponent's type and name
            if (ftName)
            {
                if (!Opponent.IsHuman)
                {
                    Write("computer");
                }
                Write("name " + Opponent.Name);
            }

            //	if the Game has any moves already played, send them
            //	now while we are in "force" mode
            List <Movement> moves = new List <Movement>();

            for (int nMove = 0; nMove < Game.GameMoveNumber; nMove++)
            {
                int      turnNumber;
                MoveInfo moveMade = Game.GetHistoricalMove(nMove, out turnNumber);
                //	we do not play the moves one-by-one but first accumulate all the
                //	moves by the same player to accomodate multi-move variants
                if (moves.Count > 0 && moves[0].Player != moveMade.Player)
                {
                    MakeMove(moves);
                    moves.Clear();
                }
                moves.Add(moveMade);
            }
            if (moves.Count > 0)
            {
                MakeMove(moves);
            }
        }