public void Capture(Move move) { if (move.Player != NextPlayer || move.From < 0) { throw new InvalidOperationException(); } else { GameBoard.RemoveFrom(move.From); GameHistory.SaveMove(move); bool isDraw = GameHistory.SaveState(GameBoard.ToString()); if (isDraw) { GameEnded = true; GameEndedEvent?.Invoke(this, FieldState.Empty); } else if (_whitesInHand == 0 && _blacksInHand == 0 && GameBoard.GetFieldsCount((FieldState)(-(int)NextPlayer)) < 3) { GameEnded = true; Winner = NextPlayer; GameEndedEvent?.Invoke(this, NextPlayer); } else { NextPlayer = (FieldState)(-(int)NextPlayer); NextPlayersTurnEvent?.Invoke(this, NextPlayer); } } UpdateStatsEvent?.Invoke(this, move); }
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); } } } }