예제 #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();
 }