public string ToGameString() { StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0}{1}", EnumUtils.GetExpansionPiecesString(ExpansionPieces), BoardStringSeparator); sb.AppendFormat("{0}{1}", BoardState.ToString(), BoardStringSeparator); sb.AppendFormat("{0}[{1}]{2}", CurrentTurnColor.ToString(), CurrentPlayerTurn, BoardStringSeparator); foreach (BoardHistoryItem item in BoardHistory) { sb.AppendFormat("{0}{1}", item.MoveString ?? NotationUtils.ToBoardSpaceMoveString(this, item.Move), BoardStringSeparator); } return(sb.ToString().TrimEnd(BoardStringSeparator)); }
public void Play(Move move, string moveString = null) { if (null == move) { throw new ArgumentNullException(nameof(move)); } if (move.IsPass) { Pass(); return; } if (GameIsOver) { throw new InvalidMoveException(move, "You can't play, the game is over."); } if (!GetValidMoves().Contains(move)) { if (move.Color != CurrentTurnColor) { throw new InvalidMoveException(move, "It's not that player's turn."); } if (!EnumUtils.IsEnabled(move.PieceName, ExpansionPieces)) { throw new InvalidMoveException(move, "That piece is not enabled in this game."); } if (null == move.Position) { throw new InvalidMoveException(move, "You can't put a piece back into your hand."); } if (CurrentPlayerTurn == 1 && move.BugType == BugType.QueenBee) { throw new InvalidMoveException(move, "You can't play your Queen Bee on your first turn."); } Piece targetPiece = GetPiece(move.PieceName); if (!CurrentTurnQueenInPlay) { if (CurrentPlayerTurn == 4 && targetPiece.BugType != BugType.QueenBee) { throw new InvalidMoveException(move, "You must play your Queen Bee on or before your fourth turn."); } else if (targetPiece.InPlay) { throw new InvalidMoveException(move, "You can't move a piece in play until you've played your Queen Bee."); } } if (!PlacingPieceInOrder(targetPiece)) { throw new InvalidMoveException(move, "When there are multiple pieces of the same bug type, you must play the pieces in order."); } if (HasPieceAt(move.Position)) { throw new InvalidMoveException(move, "You can't move there because a piece already exists at that position."); } if (targetPiece.InPlay) { if (!PieceIsOnTop(targetPiece)) { throw new InvalidMoveException(move, "You can't move that piece because it has another piece on top of it."); } else if (!CanMoveWithoutBreakingHive(targetPiece)) { throw new InvalidMoveException(move, "You can't move that piece because it will break the hive."); } } throw new InvalidMoveException(move); } TrustedPlay(move, null != moveString ? NotationUtils.NormalizeBoardSpaceMoveString(moveString) : NotationUtils.ToBoardSpaceMoveString(this, move)); }