private void btnUndo_Click(object sender, EventArgs e) { CancelInteraction(); int undoCount = 1; if (_aiLevels[1 ^ (_game.Ply & 1)].HasValue) { undoCount = 2; } undoCount = Math.Min(undoCount, _gameRecord.MoveNotations.Count); for (int i = 0; i < undoCount; i++) { var lastNotation = _gameRecord.MoveNotations.RemoveLast(); var move = _movesOfNotation[lastNotation]; if (move == null) { throw new ApplicationException("Critical move error"); // this shouldn't ever happen } move.TakeBackMove(_game); _game.Ply--; _movesOfNotation.Remove(lastNotation); _navigating = true; if (_historyForm != null) { _historyForm.RemoveLastPly(); } _navigating = false; } _boardView.InvalidateRender(); PrepareTurn(); }
public void CancelPreview() { if (_move != null) { _boardView.ClearHighlights(); _move.TakeBackMove(_game); _boardView.InvalidateRender(); _move = null; } _boardView.CarryVisible = true; }
public void Cancel() { CancelPreview(); if (_move != null) { _move.TakeBackMove(_game); _boardView.InvalidateRender(); _move = null; } _boardView.CarryClear(); }
void ProcessMove(IMove move = null, TakEngine.Notation.MoveNotation notation = null, bool alreadyExecuted = false) { if (move == null && notation == null) { throw new ArgumentException("move and notation cannot both be null"); } if (notation == null) { if (!TakEngine.Notation.MoveNotation.TryParse(move.Notate(), out notation)) { throw new ApplicationException("Critical move error"); } } else if (move == null) { _tempMoveList.Clear(); Helper.EnumerateMoves(_tempMoveList, _game, _ai.NormalPositions); move = notation.MatchLegalMove(_tempMoveList); if (move == null) { throw new ApplicationException("Illegal move: " + notation.Text); } } if (!alreadyExecuted) { move.MakeMove(_game); } if (!_gameRecord.MoveNotations.Contains(notation)) // if opening an existing game file then we may have already loaded the notation { _gameRecord.MoveNotations.Add(notation); } _navigating = true; if (_historyForm != null) { _historyForm.AddPly(notation.Text); } _navigating = false; _movesOfNotation[notation] = move; _game.Ply++; _boardView.InvalidateRender(); }
private void timer1_Tick(object sender, EventArgs e) { timer1.Stop(); bool gameOver; int eval; _evaluator.Evaluate(_game, out eval, out gameOver); if (gameOver) { _game.Clear(); } _boardView.InvalidateRender(); backgroundWorker.RunWorkerAsync(_game.DeepCopy()); }