public Pgn(ChessPosition position) { Event = position.Event; Site = position.Site; Date = position.Date; Round = position.Round; White = position.White; Black = position.Black; Result = position.Result; StringBuilder sb = new StringBuilder(); int plyNr = position.GameStartPlyNr; StringBuilder c = new StringBuilder(); // Current line string s; if (plyNr % 2 == 1) c.Append(plyNr / 2 + 1).Append(". ..."); foreach (ChessMove move in position.MoveHistory) { s = ""; if (plyNr % 2 == 0) s = ((plyNr / 2 + 1).ToString() + "."); s += move.Text + " "; if (c.Length + s.Length > 80) { // If the line length will go over 80 then append the current line to the sb and reset the current line to the string that would have put it over sb.AppendLine(c.ToString()); c.Clear(); } c.Append(s); plyNr++; } sb.Append(c); MoveText = sb.ToString(); }
public ViewModel() { rng = new Random(); position = new ChessPosition(); gameStartPly = position.GameStartPlyNr; possibleMoves = new ObservableCollection<ChessMove>(); moveHistory = new ObservableCollection<ChessMove>(); chessPieces = new ObservableCollection<ChessPiece>(); remakeObservableCollections(); newGameCommand = new DelegateCommand(newGame); movePieceCommand = new DelegateCommand(movePiece); makeMoveCommand = new DelegateCommand(makeMove); undoMoveCommand = new DelegateCommand(undoMove); gotoStartCommand = new DelegateCommand(gotoStart); gotoEndCommand = new DelegateCommand(gotoEnd); remakeMoveCommand = new DelegateCommand(remakeMove); makeRandomMoveCommand = new DelegateCommand(makeRandomMove); makeMovesFromClipboardCommand = new DelegateCommand(makeMovesFromClipboard); gotoGamePlyCommand = new DelegateCommand(gotoGamePly); makeBestMoveCommand = new DelegateCommand(makeBestMove); stopSearchCommand = new DelegateCommand(stopSearch); saveCommand = new DelegateCommand(save); worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); position.PrincUpdated += new EventHandler(position_PrincUpdated); }
static void Main(string[] args) { ChessPosition pos = new ChessPosition(); string fenStr = "8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1"; int total, leaves, castles; for (int d = 1; d <= 5; d++) { } Console.ReadLine(); }