public void Execute() { player = playerGroup.GetPlayerByIndex(moveRequest.playerIndex); Assert.IsNotNull(player); playedCard = player.hand.GetCard(moveRequest.handIndex); Assert.IsNotNull(playedCard); if (moveRequest.piecePathList != null) { piecePathList = moveRequest.piecePathList; for (int i = 0; i < piecePathList.Count; ++i) { var piecePath = piecePathList[i]; List <BoardPieceGroup> pieceGroupList = board.GetPieceGroupList(); BoardPieceGroup pieceGroup = pieceGroupList[player.index]; BoardPiece piece = pieceGroup.GetPiece(piecePath.pieceIndex); bool isKiller = _isSplitStomp(playedCard); // Kill Other Pieces if (validator.GetPieceHitList(piecePath.path, isKiller, ref hitList)) { _killPieces(hitList); } // Move Piece BoardPosition newPiecePos = piecePath.path.end; board.SetPiecePosition(piece, newPiecePos); } } }
public static Board Create(List <PlayerState> playerList) { Board board = new Board(); // Create Main track with starting pegs for (int i = 0; i < kMainTrackPipCount; ++i) { int owner = -1; PositionType type = PositionType.MAIN_TRACK; int snapTo = i - ((i + kPegsPerEdge) % kPegsPerEdge); int snapToPrefix = (i - snapTo) + 1; int startingPegIndex = snapToPrefix % kStartingPegIndex; int goalStartIndex = snapToPrefix % kGoalTrackEntranceIndex; if (i != 0 && startingPegIndex == 0) { type = PositionType.START_PEG; owner = i / Board.kPegsPerEdge; } else if (i != 0 && goalStartIndex == 0) { type = PositionType.GOAL_TRACK_ENTRANCE; owner = i / Board.kPegsPerEdge;; } BoardPosition position = BoardPosition.Create(type, i, owner); board._mainTrack.Add(position); if (type == PositionType.START_PEG) { board._startingPositions.Add(position); } } board._boardPositionList.AddRange(board._mainTrack); for (int i = 0; i < playerList.Count; ++i) { BoardPosition[] homeTrack = new BoardPosition[PlayerGroup.kMaxPlayerCount]; BoardPosition[] goalTrack = new BoardPosition[PlayerGroup.kMaxPlayerCount]; for (int j = 0; j < playerList.Count; ++j) { homeTrack[j] = BoardPosition.Create(PositionType.HOME, j, i); goalTrack[j] = BoardPosition.Create(PositionType.GOAL_TRACK, j, i); } board._homeTrack.Add(homeTrack); board._goalTrack.Add(goalTrack); board._boardPositionList.AddRange(homeTrack); board._boardPositionList.AddRange(goalTrack); BoardPieceGroup group = BoardPieceGroup.Create(board, i); board._pieceGroupList.Add(group); } return(board); }
public static BoardPieceGroup Create(Board board, int ownerIndex) { BoardPieceGroup group = new BoardPieceGroup(); group.board = board; for (int i = 0; i < kPiecesPerPlayer; ++i) { BoardPosition initialPosition = BoardPosition.Create(PositionType.HOME, i, ownerIndex); BoardPiece piece = BoardPiece.Create(board, initialPosition, ownerIndex, i); group._pieceList.Add(piece); } return(group); }
public void Undo() { //Un-kill things foreach (var entry in killedPositionMap) { board.SetPiecePosition(entry.Key, entry.Value); } //Move back to the old positions if (moveRequest.piecePathList != null) { piecePathList = moveRequest.piecePathList; for (int i = 0; i < piecePathList.Count; ++i) { var piecePath = piecePathList[i]; List <BoardPieceGroup> pieceGroupList = board.GetPieceGroupList(); BoardPieceGroup pieceGroup = pieceGroupList[player.index]; BoardPiece piece = pieceGroup.GetPiece(piecePath.pieceIndex); board.SetPiecePosition(piece, piecePath.path.start); } } }