Пример #1
0
 public bool CanExecute(IChessEngine engine)
 {
     // TODO
     // TODO - for uci data check correctness of the initial position,
     // and correctness of the moves (at least basic test)
     return true;
 }
Пример #2
0
        private void StartGameButton_Click(object sender, EventArgs e)
        {
            this.Game = new ChessGame();
            if (!String.IsNullOrEmpty(fileToLoad))
            {
                this.Game.Board.LoadFromFile(fileToLoad);
            }
            ChessPiece computerSuit;
            if (WhiteRadioButton.Checked)
            {
                this.Game.PlayerTypes[ChessPiece.White] = PlayerType.Human;
                this.Game.PlayerTypes[ChessPiece.Black] = PlayerType.Computer;
                computerSuit = ChessPiece.Black;
            }
            else
            {
                this.Game.PlayerTypes[ChessPiece.White] = PlayerType.Computer;
                this.Game.PlayerTypes[ChessPiece.Black] = PlayerType.Human;
                computerSuit = ChessPiece.White;
            }

            this.Visualizer = new BasicVisualizer.BasicVizualizer();
            this.Visualizer.Init(this.Game);
            var engine = new ChessEngines.AlphaBeta();
            engine.LoggingEnabled = true;
            string logFileName = DateTime.Now.ToString("LOG_yyyy-MM-dd_HH-mm-ss") + ".txt";
            engine.LogFilePath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), logFileName);
            this.ChessEngine = engine;
            this.Game.Engine = this.ChessEngine;
            this.ChessEngine.Init(this.Game.Board, computerSuit, true);

            // Start game
            this.Game.Start();
        }
Пример #3
0
 private static long CountMoves(IChessEngine engine, int depthPly)
 {
     if (depthPly < 0)
     {
         return(0L);
     }
     else if (depthPly == 1)
     {
         return(engine.GetLegalMoves().LongCount());
     }
     else
     {
         var legalMoves = new List <Move>(engine.GetLegalMoves());
         return(legalMoves.Sum(move =>
         {
             if (move.IsPromotion)
             {
                 Assert.IsTrue(engine.TryPlayMove(move.OriginSquare, move.DestSquare, move.GetPromoteToPiece()));
             }
             else
             {
                 Assert.IsTrue(engine.TryPlayMove(move.OriginSquare, move.DestSquare));
             }
             var result = CountMoves(engine, depthPly - 1);
             Assert.IsTrue(engine.TryUndoMove());
             return result;
         }));
     }
 }
Пример #4
0
 public bool CanExecute(IChessEngine engine)
 {
     // TODO - check a lot more things here...
     if (m_move.IsPromotion)
     {
         return m_move.IsSame(engine.GetLegalMove(m_move.From, m_move.To,
             m_move.PromoteTo));
     }
     else
     {
         return m_move.IsSame(engine.GetLegalMove(m_move.From, m_move.To));
     }
 }
Пример #5
0
 public void Execute(IChessEngine engine)
 {
     // TODO - check error codes
     if (m_data != null)
     {
         var position = Factory.Instance.CreatePosition(m_data);
         ((Engine)engine).CurrentPosition = position;
     }
     else
     {
         ((Engine)engine).SetGameData(m_uci_data);
     }
 }
Пример #6
0
 private static Thread CreateConsoleWriteThread(IChessEngine engine)
 {
     var t = new Thread(() =>
     {
         for (;;)
         {
             var text = engine.OutputMessageQueue.DequeueBlocking();
             if (text != null)
             {
                 Console.WriteLine(text);
             }
         }
     });
     t.Name = "Console write thread";
     return t;
 }
Пример #7
0
 private static Thread CreateConsoleReadThread(IChessEngine engine)
 {
     var t = new Thread(() =>
     {
         for (;;)
         {
             var message = Console.ReadLine();
             message = message.Trim();
             if (!string.IsNullOrEmpty(message))
             {
                 engine.InputMessageQueue.Enqueue(message);
             }
         }
     });
     t.Name = "Console read thread";
     return t;
 }
Пример #8
0
        public MyChessViewModel(Grid gameGrid)
        {
            GameGrid = gameGrid;

            #region Board

            RowDefinition menuRowDefinition = new RowDefinition {
                Height = GridLength.Auto
            };
            GameGrid.RowDefinitions.Add(menuRowDefinition);

            RowDefinition chessBoardRowDefinitionRowDefinition = new RowDefinition();
            GameGrid.RowDefinitions.Add(chessBoardRowDefinitionRowDefinition);

            RowDefinition engineOutputRowDefinition = new RowDefinition {
                Height = new GridLength(100)
            };
            GameGrid.RowDefinitions.Add(engineOutputRowDefinition);

            Menu = new ChessMenuUserControl();
            GameGrid.Children.Add(Menu);
            Grid.SetRow(Menu, 0);

            ChessBoard = new ChessBoardUserControl();
            GameGrid.Children.Add(ChessBoard);
            Grid.SetRow(ChessBoard, 1);

            EngineOutput = new EngineOutputControl();
            GameGrid.Children.Add(EngineOutput);
            Grid.SetRow(EngineOutput, 2);
            #endregion

            #region Engine
            ChessEngine = new ChessEngine2();
            #endregion

            #region Menu
            Menu.SetEventHandler(Command);
            ChessBoard.SetEventHandler(Command);
            #endregion
        }
        public void Execute(IChessEngine engine)
        {
            Debug.Assert(engine != null);

            // Backrank piece positions
            var pieces_backrank_order = new List<Exports.Pieces>()
            {
                Exports.Pieces.Rook, Exports.Pieces.Knight, Exports.Pieces.Bishop,
                Exports.Pieces.Queen, Exports.Pieces.King, Exports.Pieces.Bishop,
                Exports.Pieces.Knight, Exports.Pieces.Rook
            };

            var pieces = new List<PiecePosition>(32);
            for (int column = Chessboard.COLUMN_MIN; column <= Chessboard.COLUMN_MAX;
                ++column)
            {
                pieces.Add(new PiecePosition(Players.White, pieces_backrank_order[column],
                    new ChessboardCell(0, column)));
                pieces.Add(new PiecePosition(Players.Black, pieces_backrank_order[column],
                    new ChessboardCell(7, column)));
                pieces.Add(new PiecePosition(Players.White, Exports.Pieces.Pawn,
                    new ChessboardCell(1, column)));
                pieces.Add(new PiecePosition(Players.Black, Exports.Pieces.Pawn,
                    new ChessboardCell(6, column)));
            }

            var position = Factory.Instance.CreatePosition(new CreatePositionData(
                pieces,
                Players.White,
                Castle.Short | Castle.Long,
                Castle.Short | Castle.Long,
                capture_en_passant_column: null,
                fullmove_number: 1,
                halfmove_clock: 0));

            // TODO - check error code somehow
            ((Engine)engine).CurrentPosition = position;
        }
Пример #10
0
 /// <summary>UciSetOptionCommand implementation</summary>
 /// <param name="engine">engine object</param>
 public override void Execute(IChessEngine engine)
 {
     engine.SendCommandAsync(optionCommand, String.Empty);
 }
Пример #11
0
 /// <summary>UciIsReadyCommand implementation</summary>
 /// <param name="engine">engine object</param>
 public override void Execute(IChessEngine engine)
 {
     stream.WriteLine(UCIChessEngine.IsReady);
 }
Пример #12
0
 /// <summary>UciGoCommand implementation</summary>
 /// <param name="engine">engine object</param>
 public override void Execute(IChessEngine engine)
 {
     engine.SendCommandAsync(moveCommand, UCIChessEngine.BestMoveResponse);
 }
Пример #13
0
 public void Execute(IChessEngine engine)
 {
     ((Engine)engine).PlayMove(m_move);
 }
Пример #14
0
 public override void Run()
 {
     m_engine = Factory.Instance.CreateChessEngine();
     RunTries();
 }
Пример #15
0
 protected void InitEngine()
 {
     m_engine = Factory.Instance.CreateChessEngine();
 }
Пример #16
0
 /// <summary>UciInitCommand implementation</summary>
 /// <param name="engine">engine object</param>
 public override void Execute(IChessEngine engine)
 {
     engine.SendCommandAsync(UCIChessEngine.Uci, UCIChessEngine.UciOk);
 }
Пример #17
0
 public void Execute(IChessEngine engine)
 {
     ((Engine)engine).InitNewGame();
 }
 public bool CanExecute(IChessEngine engine)
 {
     // TODO
     //throw new NotImplementedException();
     return true;
 }
Пример #19
0
 public bool CanExecute(IChessEngine engine)
 {
     return true;
 }
Пример #20
0
 public void Execute(IChessEngine engine)
 {
     ((Engine)engine).RequestQuit();
 }
Пример #21
0
 public KeyboardHandler(IChessEngine engine)
 {
     this.engine = engine;
 }
Пример #22
0
 /// <summary>UciLoadEngineCommand implementation</summary>
 /// <param name="engine">engine object</param>
 public override void Execute(IChessEngine engine)
 {
     engine.LoadEngineProcess(fullPathToExe);
 }
Пример #23
0
 public bool CanExecute(IChessEngine engine)
 {
     return engine.OutputMessageQueue != null;
 }
Пример #24
0
 /// <summary>
 /// Derived classes put their concrete implemenations of each command here
 /// </summary>
 /// <param name="engine">engine object</param>
 public abstract void Execute(IChessEngine engine);
Пример #25
0
 public void Execute(IChessEngine engine)
 {
     ((Engine)engine).WriteToOutput(m_text);
 }
Пример #26
0
 /// <summary>UciNewGameCommand implementation</summary>
 /// <param name="engine">engine object</param>
 public override void Execute(IChessEngine engine)
 {
     engine.SendCommandAsync(UCIChessEngine.UciNewGame, String.Empty);
 }
Пример #27
0
 public void Execute(IChessEngine engine)
 {
     ((Engine)engine).BeginAnalysis();
 }