예제 #1
0
        public ClockViewModel()
        {
            //setup the preferences of the user.
            var dateFormat = ClockConfiguration.GetPreference(ClockConfiguration.Preferences.DateFormat);

            if (dateFormat == null)
            {
                dateFormat = DateFormats.First().Value;
                ClockConfiguration.SetPreference(ClockConfiguration.Preferences.DateFormat, dateFormat);
            }
            SelectedDateFormat = dateFormat;

            var timeFormat = ClockConfiguration.GetPreference(ClockConfiguration.Preferences.TimeFormat);

            if (timeFormat == null)
            {
                timeFormat = TimeFormats.First().Value;
                ClockConfiguration.SetPreference(ClockConfiguration.Preferences.TimeFormat, timeFormat);
            }

            SelectedTimeFormat = timeFormat;

            _timer          = new DispatcherTimer();
            _timer.Interval = new TimeSpan(0, 0, 1);
            _timer.Tick    += timer_Tick;
            _timer.Start();
        }
예제 #2
0
파일: Game.cs 프로젝트: prezz/Firoz-Chess
        /// <summary>
        /// Sets the clock configuration. Setting the configuration will
        /// only have effect if the game hasn't started yet.
        /// </summary>
        /// <param name="clockConfiguration">The configuration to set</param>
        public void SetClockConfiguration(ClockConfiguration clockConfiguration)
        {
            if (UndoCount == 0 && RedoCount == 0)
            {
                if (m_clock != null)
                {
                    m_clock.StopClock();
                    m_clock.WhiteClockNotifier -= WhiteClockEventHandler;
                    m_clock.BlackClockNotifier -= BlackClockEventHandler;
                }

                switch (clockConfiguration.ClockType)
                {
                case ClockType.Conventional:
                    m_clock = new ConventionalClock(clockConfiguration.ConventionalMoves, clockConfiguration.ConventionalTime);
                    break;

                case ClockType.Incremental:
                    m_clock = new IncrementalClock(clockConfiguration.IncrementStartTime, clockConfiguration.IncrementPlusTime);
                    break;

                case ClockType.None:
                    m_clock = new NoneClock();
                    break;
                }

                m_clock.WhiteClockNotifier += WhiteClockEventHandler;
                m_clock.BlackClockNotifier += BlackClockEventHandler;
                m_clock.RaiseTimeNotifyEvent();
            }
        }
예제 #3
0
        public void SetupProfilingTest()
        {
            PositionEditor editor = m_chessFacade.PositionEditor;

            editor[Square.E2]            = Piece.None;
            editor[Square.E4]            = Piece.WhitePawn;
            editor[Square.E7]            = Piece.None;
            editor[Square.E5]            = Piece.BlackPawn;
            editor[Square.G1]            = Piece.None;
            editor[Square.F3]            = Piece.WhiteKnight;
            editor[Square.B8]            = Piece.None;
            editor[Square.C6]            = Piece.BlackKnight;
            m_chessFacade.PositionEditor = editor;

            ClockConfiguration clockConfig = m_chessFacade.ClockConfiguration;

            clockConfig.ClockType            = ClockType.None;
            m_chessFacade.ClockConfiguration = clockConfig;

            EngineConfiguration engineConfig = m_chessFacade.EngineConfiguration;

            engineConfig.EngineAutoPlay       = false;
            engineConfig.UseBook              = false;
            engineConfig.MaxSearchTime        = new TimeSpan(0, 5, 0);
            engineConfig.MaxSearchDepth       = 5;
            m_chessFacade.EngineConfiguration = engineConfig;
        }
예제 #4
0
파일: Game.cs 프로젝트: prezz/Firoz-Chess
        /// <summary>
        /// Initializes a new instance of the Game class.
        /// </summary>
        /// <param name="board">A board holding the layout this game will be initialized with. If this parameter is null a standard layout will be created.</param>
        /// <param name="clockConfiguration">The type of clock to use for this game.</param>
        public Game(Board board, ClockConfiguration clockConfiguration)
        {
            m_board = (board == null) ? new Board() : new Board(board);

              m_possibleMoves = new MoveOrganizer();
              m_undoMoveHistory = new Stack<Move>();
              m_redoMoveHistory = new Stack<Move>();

              SetClockConfiguration(clockConfiguration);

              HandleGameHasChanged();
        }
예제 #5
0
파일: Game.cs 프로젝트: prezz/Firoz-Chess
        /// <summary>
        /// Initializes a new instance of the Game class.
        /// </summary>
        /// <param name="board">A board holding the layout this game will be initialized with. If this parameter is null a standard layout will be created.</param>
        /// <param name="clockConfiguration">The type of clock to use for this game.</param>
        public Game(Board board, ClockConfiguration clockConfiguration)
        {
            m_board = (board == null) ? new Board() : new Board(board);

            m_possibleMoves   = new MoveOrganizer();
            m_undoMoveHistory = new Stack <Move>();
            m_redoMoveHistory = new Stack <Move>();

            SetClockConfiguration(clockConfiguration);

            HandleGameHasChanged();
        }
예제 #6
0
        private ConfigurationForm(JointConfiguration currentConfig)
        {
            InitializeComponent();

            m_comboBoxClockType.Items.Add(ClockType.Conventional);
            m_comboBoxClockType.Items.Add(ClockType.Incremental);
            m_comboBoxClockType.Items.Add(ClockType.None);

            m_engineConfiguration = currentConfig.EngineConfiguration;
            m_clockConfiguration  = currentConfig.ClockConfiguration;

            m_checkBoxEngine.Checked   = m_engineConfiguration.EngineAutoPlay;
            m_checkBoxBook.Checked     = m_engineConfiguration.UseBook;
            m_numericSearchTime.Value  = (decimal)m_engineConfiguration.MaxSearchTime.TotalSeconds;
            m_numericSearchDepth.Value = m_engineConfiguration.MaxSearchDepth;

            m_comboBoxClockType.SelectedItem   = m_clockConfiguration.ClockType;
            m_numericConventionalMoves.Value   = m_clockConfiguration.ConventionalMoves;
            m_numericConventionalMinutes.Value = (decimal)m_clockConfiguration.ConventionalTime.TotalMinutes;

            m_numericIncrementStart.Value = (decimal)m_clockConfiguration.IncrementStartTime.TotalMinutes;
            m_numericIncrementPlus.Value  = (decimal)m_clockConfiguration.IncrementPlusTime.TotalSeconds;
        }
예제 #7
0
 public JointConfiguration(EngineConfiguration engineConfiguration, ClockConfiguration clockConfiguration)
 {
     m_engineConfiguration = engineConfiguration;
     m_clockConfiguration  = clockConfiguration;
 }
예제 #8
0
        static void Main(string[] args)
        {
            ChessFacade chess = new ChessFacade();

            chess.WhitePawnPromoted += new EventHandler <PromotionEventArgs>(chess_WhitePawnPromoted);
            chess.BlackPawnPromoted += new EventHandler <PromotionEventArgs>(chess_BlackPawnPromoted);
            chess.StatusInfo        += new EventHandler <GameStatusEventArgs>(chess_StatusChanged);

            EngineConfiguration engConfig = chess.EngineConfiguration;

            engConfig.EngineAutoPlay  = false;
            chess.EngineConfiguration = engConfig;

            ClockConfiguration clockConfig = chess.ClockConfiguration;

            clockConfig.ClockType    = ClockType.None;
            chess.ClockConfiguration = clockConfig;

            StreamReader file;

            if (args.Length == 1)
            {
                file = File.OpenText(args[0]);
            }
            else
            {
                file = File.OpenText(@"..\..\input\book_1.00.pgn");
            }

            int           lineCounter = 0;
            string        line;
            StringBuilder gameString = new StringBuilder();

            while ((line = file.ReadLine()) != null)
            {
                ++lineCounter;
                if (line.Length > 0 && line[0] != '[')
                {
                    gameString.Append(line);
                    if (line[line.Length - 1] != '.')
                    {
                        gameString.Append(" ");
                    }
                }
                else if (gameString.Length > 0)
                {
                    bool     breaking   = false;
                    string[] lineBlocks = gameString.ToString().Split(new char[] { ' ' });

                    PieceColor winner = PieceColor.None;
                    if (lineBlocks[lineBlocks.Length - 2] == "1-0")
                    {
                        winner = PieceColor.White;
                    }
                    else if (lineBlocks[lineBlocks.Length - 2] == "0-1")
                    {
                        winner = PieceColor.Black;
                    }
                    else if (lineBlocks[lineBlocks.Length - 2] == "1/2-1/2" || lineBlocks[lineBlocks.Length - 2] == "*")
                    {
                        winner = PieceColor.None;
                    }
                    else
                    {
                        Console.WriteLine("Unknown result");
                    }

                    int itLength = Math.Min(lineBlocks.Length, 20);
                    for (int i = 0; i < itLength; ++i)
                    {
                        string lineBlock = lineBlocks[i];
                        if (lineBlock != "" && lineBlock != "*" && lineBlock != "1-0" && lineBlock != "0-1" && lineBlock != "1/2-1/2")
                        {
                            PgnMove pgnMove = new PgnMove(lineBlock);

                            for (Square square = Square.A1; square <= Square.H8; ++square)
                            {
                                if ((pgnMove.PieceToPlay == chess.PieceAt(square)) &&
                                    (pgnMove.FromFile == -1 || pgnMove.FromFile == ChessFacade.File(square)) &&
                                    (pgnMove.FromRank == -1 || pgnMove.FromRank == ChessFacade.Rank(square)))
                                {
                                    promotion = pgnMove.PromotionPiece;
                                    if (chess.PerformMove(square, pgnMove.DestinationSquare))
                                    {
                                        //Console.Write(square + "-" + pgnMove.DestinationSquare + " | ");
                                        if (winner == PieceColor.None)
                                        {
                                            chess.AddToOpeningBook(1);
                                        }
                                        else if (winner == pgnMove.ColorToPlay)
                                        {
                                            chess.AddToOpeningBook(2);
                                        }
                                        //else
                                        //	chess.AddToOpeningBook(1);
                                        break;
                                    }
                                }

                                if (square == Square.H8)
                                {
                                    Console.WriteLine("No move performed: " + lineCounter);
                                    Console.ReadLine();
                                    breaking = true;
                                    break;
                                }
                            }
                        }

                        if (breaking)
                        {
                            break;
                        }
                    }

                    //Console.WriteLine("new game");
                    gameString = new StringBuilder();
                    while (chess.UndoCount > 0)
                    {
                        chess.UndoMove();
                    }
                }

                if (lineCounter % 1000 == 0)
                {
                    Console.WriteLine(lineCounter.ToString());
                }
            }

            chess.SaveOpeningBook();
            Console.WriteLine("Done");
            Console.ReadLine();
        }
예제 #9
0
파일: Game.cs 프로젝트: prezz/Firoz-Chess
        /// <summary>
        /// Sets the clock configuration. Setting the configuration will
        /// only have effect if the game hasn't started yet.
        /// </summary>
        /// <param name="clockConfiguration">The configuration to set</param>
        public void SetClockConfiguration(ClockConfiguration clockConfiguration)
        {
            if (UndoCount == 0 && RedoCount == 0)
              {
            if (m_clock != null)
            {
              m_clock.StopClock();
              m_clock.WhiteClockNotifier -= WhiteClockEventHandler;
              m_clock.BlackClockNotifier -= BlackClockEventHandler;
            }

            switch (clockConfiguration.ClockType)
            {
              case ClockType.Conventional:
            m_clock = new ConventionalClock(clockConfiguration.ConventionalMoves, clockConfiguration.ConventionalTime);
            break;

              case ClockType.Incremental:
            m_clock = new IncrementalClock(clockConfiguration.IncrementStartTime, clockConfiguration.IncrementPlusTime);
            break;

              case ClockType.None:
            m_clock = new NoneClock();
            break;
            }

            m_clock.WhiteClockNotifier += WhiteClockEventHandler;
            m_clock.BlackClockNotifier += BlackClockEventHandler;
            m_clock.RaiseTimeNotifyEvent();
              }
        }