private Piece HandleBeetleFromStackMove(BeetleStack stack, Hex from, Hex to) { Piece actualPiece = stack.top; Piece newPiece = BeetleStack.PopBeetleStack(stack); _boardPieceArray[from.column, from.row] = newPiece; _playedPieces.Remove(stack); _playedPieces.Add(newPiece, from); return(actualPiece); }
/// <summary> /// Produces valid notation, but does not validate the move for the given board. /// </summary> /// <param name="move"></param> /// <param name="board"></param> /// <returns></returns> internal static string GetNotationForMove(Move move, Board board) { //TODO fix problem where beetle moves generate a "next to myself" reference piece string referencePieceNotation; string targetPieceNotation = GetNotationForPiece(move.pieceToMove); if (board.hivailableSpaces.Count == 1) { referencePieceNotation = "."; } else if (move.referencePiece != null) { referencePieceNotation = GetNotationForPiece(move.referencePiece); referencePieceNotation = string.Format(Neighborhood.neighborDirectionNotationTemplates[(int)move.targetPosition], referencePieceNotation); } else if (!move.hex.Equals(Board.invalidHex)) { Piece refPiece = null; if (board.TryGetPieceAtHex(move.hex, out refPiece)) { // assume this is a beetle moving on top of another piece referencePieceNotation = GetNotationForPiece(refPiece); } else { Hex refHex = Board.invalidHex; Position refPosition = Position.center; bool found = false; int i = 0; // zero is center. we dont care about center while (!found && i < Neighborhood.neighborDirections.Length) { i++; refHex = Neighborhood.neighborDirections[i] + move.hex; refPosition = Neighborhood.GetOpposite((Position)i); if (board.TryGetPieceAtHex(refHex, out refPiece)) { found = !refPiece.Equals(move.pieceToMove); } } // must be a first move if (!found) { referencePieceNotation = "."; } else { referencePieceNotation = GetNotationForPiece(refPiece); if (referencePieceNotation == targetPieceNotation) { if (refPiece is BeetleStack) { refPiece = BeetleStack.PopBeetleStack((BeetleStack)refPiece); } else { } referencePieceNotation = GetNotationForPiece(refPiece); } referencePieceNotation = string.Format(Neighborhood.neighborDirectionNotationTemplates[(int)refPosition], referencePieceNotation); } } } else { // must be a first move referencePieceNotation = "."; } return(targetPieceNotation + " " + referencePieceNotation); }