/// <summary> /// Ctor /// </summary> /// <param name="game"> FICS Game</param> /// <param name="chessBoardCtl"> Chess board control</param> /// <param name="iMoveTimeout"> Move timeout in second</param> /// <param name="actionMoveTimeOut"> Action to call if move timeout</param> /// <param name="actionGameFinished"> Action to do when game is finished</param> public GameIntf(FICSGame game, SrcChess2.ChessBoardControl chessBoardCtl, int?iMoveTimeout, Action <GameIntf> actionMoveTimeOut, Action <GameIntf, TerminationE, string> actionGameFinished) { Game = game; ChessBoardCtl = chessBoardCtl; BoardCreated = false; m_chessBoard = new SrcChess2.ChessBoard(); m_parser = new SrcChess2.PgnParser(m_chessBoard); m_queueMove = new Queue <Style12MoveLine>(16); m_spanTotalWhiteTime = TimeSpan.Zero; m_spanTotalBlackTime = TimeSpan.Zero; m_spanOriginalMaxTime = (game.PlayerTimeInMin == 0) ? (TimeSpan?)null : TimeSpan.FromMinutes(game.PlayerTimeInMin); m_listInitialMoves = new List <SrcChess2.MoveExt>(128); m_actionGameFinished = actionGameFinished; Termination = TerminationE.None; m_iMoveTimeOut = iMoveTimeout.HasValue ? iMoveTimeout.Value : int.MaxValue; m_pgnGame = new SrcChess2.PgnGame(true /*bAttrList*/, true /*bMoveList*/); m_pgnGame.attrs.Add("Event", "FICS Game " + game.GameId.ToString()); m_pgnGame.attrs.Add("Site", "FICS Server"); m_pgnGame.attrs.Add("White", game.WhitePlayer); m_pgnGame.attrs.Add("Black", game.BlackPlayer); if (game.PlayerTimeInMin != 0 && chessBoardCtl != null) { chessBoardCtl.GameTimer.MaxWhitePlayTime = TimeSpan.FromMinutes(game.PlayerTimeInMin); chessBoardCtl.GameTimer.MaxBlackPlayTime = TimeSpan.FromMinutes(game.PlayerTimeInMin); chessBoardCtl.GameTimer.MoveIncInSec = game.IncTimeInSec; } if (iMoveTimeout != 0 && actionMoveTimeOut != null) { m_timerMoveTimeout = new System.Threading.Timer(TimerCallback, actionMoveTimeOut, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); } }
/// <summary> /// Convert the board to a PGN game /// </summary> /// <param name="chessBoard"> Chess board</param> /// <param name="spanWhite"> Time played by white</param> /// <param name="spanBlack"> Time played by black</param> /// <returns></returns> private string GetPGNGame(SrcChess2.ChessBoard chessBoard, TimeSpan spanWhite, TimeSpan spanBlack) { string strRetVal; strRetVal = SrcChess2.PgnUtil.GetPGNFromBoard(chessBoard, false /*bIncludeRedoMove*/, m_pgnGame.Event, "FICS Server", DateTime.Now.ToString(), "1", m_pgnGame.WhitePlayer, m_pgnGame.BlackPlayer, SrcChess2.PlayerTypeE.Human, SrcChess2.PlayerTypeE.Human, m_pgnGame.WhiteSpan, m_pgnGame.BlackSpan); return(strRetVal); }