public void DoGameTurn() { DoMove(); //If new move is replacing previous move without redo if (GameBoard.TurnCounter != GameBoard.TempTurnCounter && !IsNextMoveRedo) { MoveHistory.RemoveAll(item => { int index = MoveHistory.IndexOf(item); return(index > GameBoard.TempTurnCounter - 1); }); GameBoard.TurnCounter = GameBoard.TempTurnCounter; } //If redo move replayed if (IsNextMoveRedo) { GameBoard.TempTurnCounter += 1; IsPlayerWTurn = (GameBoard.TempTurnCounter % 2 != 1); } //If standard move else { GameBoard.TurnCounter += 1; GameBoard.TempTurnCounter = GameBoard.TurnCounter; IsPlayerWTurn = (GameBoard.TurnCounter % 2 != 1); MoveHistory.Add(new List <int>(Move)); } IsNextMoveRedo = false; if (IsGameEndTriggered(GameBoard.GameArray)) { } }
public void Move(Direction direction) { LastMove = new Move(State, direction); MoveHistory.Add(LastMove); State = LastMove.EndState; ULongMagic.SetRandomSquare(ref State, rnd); }
private void BackgroundWorkCompleted(object sender, RunWorkerCompletedEventArgs e) { if (!e.Cancelled) { _lastSearch = (SearchResult)e.Result; if (_lastSearch.BestMove >= 0 && CurrentState.IsValidMove(_lastSearch.BestMove)) { bool growthHappened = CurrentState.MakeMove(_lastSearch.BestMove); MoveHistory.Add(_lastSearch.BestMove); if (growthHappened) { MoveHistory.Add(Constants.AllGrowMove); } OnMoveMade?.Invoke(growthHappened); if (CurrentState.State == GameState.GameOver) { OnGameOver?.Invoke(CurrentState.Winner, CurrentState.Winner == Player.Draw ? VictoryType.InfiniteEruption : VictoryType.AntipodePathCreation); } else { ComputerPlay(); } } else { // If an engine doesn't find a move, then he adjourns the game CurrentState.Winner = CurrentState.Player == Player.One ? Player.Two : Player.One; OnGameOver?.Invoke(CurrentState.Winner, _lastSearch.Timeout ? VictoryType.OpponentTimeout : VictoryType.ArenaAdjudication); } } }
public void ApplyMove(IGameMove move) { TicTacToeMove m = move as TicTacToeMove; SetPosition(m.Position, CurrentPlayer); MoveHistory.Add(m); mPlayer = -mPlayer; mGameOver = GameIsOver(); }
public void ApplyMove(IGameMove move) { TicTacToeMove m = move as TicTacToeMove; SetPosition(m.Position, CurrentPlayer); mWeight += mPlayer * mWeights[m.Position.Row, m.Position.Col]; MoveHistory.Add(m); mPlayer = -mPlayer; mGameOver = GameIsOver(); }
public void MakeMove(int move) { if (CurrentState.IsValidMove(move)) { bool growthHappened = CurrentState.MakeMove(move); MoveHistory.Add(move); if (growthHappened) { MoveHistory.Add(Constants.AllGrowMove); } OnMoveMade?.Invoke(growthHappened); if (CurrentState.State == GameState.GameOver) { OnGameOver?.Invoke(CurrentState.Winner, CurrentState.Winner == Player.Draw ? VictoryType.InfiniteEruption : VictoryType.AntipodePathCreation); } else { ComputerPlay(); } } }
public override string Move(Cell Target, Board ChessBoard) { MoveHistory.Add(Pos.GetBoardPosition() + " => " + Target.Figure.Pos.GetBoardPosition()); if ((this.Color.Equals(ChessColor.White) && Target.Figure.Pos.Y == 0) || (this.Color.Equals(ChessColor.Black) && Target.Figure.Pos.Y == 7)) { PawnPromotion NewPP = new PawnPromotion(this); NewPP.Owner = Application.Current.MainWindow; NewPP.ShowDialog(); ChessBoard.cells[Pos.X, Pos.Y].Figure = (BaseFigure)Activator.CreateInstance(NewPP.PromotionType, Pos, Color); } Position TempPos = Target.Figure.Pos; Target.Figure = ChessBoard.cells[Pos.X, Pos.Y].Figure; ChessBoard.cells[Pos.X, Pos.Y].Figure = new BaseFigure(Pos); Target.Figure.Pos = TempPos; return(MoveHistory[MoveHistory.Count - 1]); }
public void AddToMoveHistory(Square fromSquare, Square toSquare, Piece capturedPiece, bool queensideCastle, bool kingsideCastle, CheckStatus checkStatus) { int turnNumber = 1; if (MoveHistory.Count > 0) { if (MoveHistory.Last().Piece.Color == Color.White) { turnNumber = MoveHistory.Last().TurnNumber; } else { turnNumber = MoveHistory.Last().TurnNumber + 1; } } if (capturedPiece == null) { MoveHistory.Add(new Move(turnNumber, toSquare.Piece, fromSquare, toSquare, queensideCastle, kingsideCastle, checkStatus)); } else { MoveHistory.Add(new Move(turnNumber, toSquare.Piece, capturedPiece, fromSquare, toSquare, queensideCastle, kingsideCastle, checkStatus)); } }
private void RedoButton_Click(object sender, RoutedEventArgs e) { if (UndoHistory.Count < 1) { return; } Untrack(); Move lastMove = UndoHistory.Last(); Cell target = BoardGrid.GetCellAt(lastMove.Target); target.Selected = false; target.Filled = true; Cell source = BoardGrid.GetCellAt(lastMove.Source); Cell middle = BoardGrid.GetMiddleCell(source, target); middle.Filled = false; source.Filled = false; MoveHistory.Add(lastMove); UndoHistory.RemoveAt(UndoHistory.Count - 1); }
private void OnEnable() { Message.Subscribe <UndoRequested>(_ => history.Undo(), this); Message.Subscribe <LevelReset>(_ => history.Reset(), this); Message.Subscribe <PieceMoved>(p => history.Add(p), this); }
/// <summary> /// Applies the given move to the board state. /// </summary> /// <param name="m">a move that is assumed to be valid</param> public void ApplyMove(IGameMove move) { OthelloMove m = move as OthelloMove; // If the move is a pass, then we do very little. if (m.IsPass) { PassCount++; } else { PassCount = 0; // Otherwise update the board at the move's position with the current player. mBoard[m.Position.Row, m.Position.Col] = (sbyte)mCurrentPlayer; Value += mCurrentPlayer; Weight += mCurrentPlayer * mWeights[m.Position.Row, m.Position.Col]; // Iterate through all 8 directions radially from the move's position. for (int rDelta = -1; rDelta <= 1; rDelta++) { for (int cDelta = -1; cDelta <= 1; cDelta++) { if (rDelta == 0 && cDelta == 0) { continue; } // Repeatedly move in the selected direction, as long as we find "enemy" squares. BoardPosition newPos = m.Position; int steps = 0; do { newPos = newPos.Translate(rDelta, cDelta); steps++; } while (PositionInBounds(newPos) && PositionIsEnemy(newPos, mCurrentPlayer)); // This is a valid direction of flips if we moved at least 2 squares, and ended in bounds and on a // "friendly" square. if (steps > 1 && PositionInBounds(newPos) && mBoard[newPos.Row, newPos.Col] == mCurrentPlayer) { // Record this direction in the move's flipsets so the move can be undone. m.AddFlipSet( new OthelloMove.FlipSet() { RowDelta = rDelta, ColDelta = cDelta, Count = steps - 1 }); // The FlipSet constructor takes no parameters; this syntax allows us to construct a FlipSet // and initialize many of its properties in one expression. // Repeatedly walk back the way we came, updating the board with the current player's piece. newPos = newPos.Translate(-rDelta, -cDelta); while (steps > 1) { mBoard[newPos.Row, newPos.Col] = (sbyte)mCurrentPlayer; Value += 2 * mCurrentPlayer; Weight += 2 * mCurrentPlayer * mWeights[newPos.Row, newPos.Col]; newPos = newPos.Translate(-rDelta, -cDelta); steps--; } } } } } // Update the rest of the board state. mCurrentPlayer = -mCurrentPlayer; MoveHistory.Add(m); }
public void SetPosition(MovePosition movePosition) { MovePosition = movePosition; MoveHistory.Add(MovePosition); }
private void SaveMove(Cell source, Cell target) { MoveHistory.Add(new Move(source.Position, target.Position)); UndoHistory.Clear(); }