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); }