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; }
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(); }
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; })); } }
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)); } }
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); } }
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; }
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; }
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; }
/// <summary>UciSetOptionCommand implementation</summary> /// <param name="engine">engine object</param> public override void Execute(IChessEngine engine) { engine.SendCommandAsync(optionCommand, String.Empty); }
/// <summary>UciIsReadyCommand implementation</summary> /// <param name="engine">engine object</param> public override void Execute(IChessEngine engine) { stream.WriteLine(UCIChessEngine.IsReady); }
/// <summary>UciGoCommand implementation</summary> /// <param name="engine">engine object</param> public override void Execute(IChessEngine engine) { engine.SendCommandAsync(moveCommand, UCIChessEngine.BestMoveResponse); }
public void Execute(IChessEngine engine) { ((Engine)engine).PlayMove(m_move); }
public override void Run() { m_engine = Factory.Instance.CreateChessEngine(); RunTries(); }
protected void InitEngine() { m_engine = Factory.Instance.CreateChessEngine(); }
/// <summary>UciInitCommand implementation</summary> /// <param name="engine">engine object</param> public override void Execute(IChessEngine engine) { engine.SendCommandAsync(UCIChessEngine.Uci, UCIChessEngine.UciOk); }
public void Execute(IChessEngine engine) { ((Engine)engine).InitNewGame(); }
public bool CanExecute(IChessEngine engine) { // TODO //throw new NotImplementedException(); return true; }
public bool CanExecute(IChessEngine engine) { return true; }
public void Execute(IChessEngine engine) { ((Engine)engine).RequestQuit(); }
public KeyboardHandler(IChessEngine engine) { this.engine = engine; }
/// <summary>UciLoadEngineCommand implementation</summary> /// <param name="engine">engine object</param> public override void Execute(IChessEngine engine) { engine.LoadEngineProcess(fullPathToExe); }
public bool CanExecute(IChessEngine engine) { return engine.OutputMessageQueue != null; }
/// <summary> /// Derived classes put their concrete implemenations of each command here /// </summary> /// <param name="engine">engine object</param> public abstract void Execute(IChessEngine engine);
public void Execute(IChessEngine engine) { ((Engine)engine).WriteToOutput(m_text); }
/// <summary>UciNewGameCommand implementation</summary> /// <param name="engine">engine object</param> public override void Execute(IChessEngine engine) { engine.SendCommandAsync(UCIChessEngine.UciNewGame, String.Empty); }
public void Execute(IChessEngine engine) { ((Engine)engine).BeginAnalysis(); }