private void PlacePawn(Move move) { if (move.Player != NextPlayer || move.To < 0 || !HasPawnsInHand(move.Player)) { throw new InvalidOperationException(); } else { GameBoard.PlaceAt(move.To, move.Player); GameHistory.SaveMove(move); if (move.Player == FieldState.White) { _whitesInHand--; } else if (move.Player == FieldState.Black) { _blacksInHand--; } if (GameBoard.GetField(move.To).IsInMill()) { CaptureEvent?.Invoke(this, move.Player); } else { NextPlayer = (FieldState)(-(int)NextPlayer); GameHistory.SaveState(GameBoard.ToString()); NextPlayersTurnEvent?.Invoke(this, NextPlayer); } } }
private void MovePawn(Move move) { if (move.Player != NextPlayer) { throw new InvalidOperationException(); } else if (move.From < 0 || move.To < 0) { GameEnded = true; Winner = (FieldState)(-(int)NextPlayer); GameEndedEvent?.Invoke(this, (FieldState)(-(int)NextPlayer)); } else { GameBoard.RemoveFrom(move.From); GameBoard.PlaceAt(move.To, move.Player); GameHistory.SaveMove(move); if (GameBoard.GetField(move.To).IsInMill()) { CaptureEvent?.Invoke(this, move.Player); } else { bool isDraw = GameHistory.SaveState(GameBoard.ToString()); if (isDraw) { GameEnded = true; GameEndedEvent?.Invoke(this, FieldState.Empty); } else { NextPlayer = (FieldState)(-(int)NextPlayer); NextPlayersTurnEvent?.Invoke(this, NextPlayer); } } } }