Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the Card array generation logic #1 #9

Conversation

Abhishek-Punhani
Copy link

@Abhishek-Punhani Abhishek-Punhani commented May 27, 2024

Fixes #1 Implement the Card array generation logic
#2 Implement card shuffling logic

export default function getShuffledCardDeck() {
// generating cards of each color

for(let col of colors){
for(let val of values){
if(val.length==1){
for(let i=0;i<2;i++){
makeCard("number",col,val);
if(val==0) break;

    }
}else{
    for(let i=0;i<2;i++){
        makeCard("special",col,val);
    }
}

}
}
// generating special cards
for(let sc of specialCards){
for(let i=0;i<4;i++){
makeCard("special","wild",sc);
}
}
let shuffledDeck= shuffle(deck)
return shuffledDeck
}
function makeCard(type, color, value) {
let card={
id:uuidv4(),
type:type,
color:color,
value:value,
};
deck.push(card);
}
function shuffle(deck) {
let n = deck.length;

for (let i = n - 1; i > 0; i--) {
// Pick a random index from 0 to i (inclusive)
let j = Math.floor(Math.random() * (i + 1));

// Swap the elements at indices i and j
[deck[i], deck[j]] = [deck[j], deck[i]];

}

return deck;
}
function makeCard can modified as per the need
generated 108 cards deck as per requirements and given conditions

@kuv2707
Copy link
Collaborator

kuv2707 commented May 27, 2024

Hi @Abhishek-Punhani, Great to see your zeal! But there are few issues with the PR.

It seems you hadn't fetched the latest changes before starting your work, or created the branch before today. The main branch has had many force pushes in the past couple days (removing some poorly worded or useless commits), due to which the commit history in the main branch is different from the branch in your fork. Hence you see 17 commits in the PR, and a large diff, while your commits were only 2. It was in anticipation of this, that we asked you to start contributing from June 1. But that's no issue. I can help you fix things.

Additionally, it is recommended to solve only one issue in one PR, as it helps in keeping track of contributions.

You should run git fetch upstream to sync the changes, and create a new branch (from upstream/main) for each issue, and use git cherry-pick command to copy the relevant commits from this branch to the new branches ( or you may write the code again).

You can then make fresh PRs, one for each issue. If you need further help, we can use this thread or you can DM me.

@Abhishek-Punhani Abhishek-Punhani deleted the fix-issue-implementing-card-array-generation branch May 28, 2024 10:01
@Abhishek-Punhani Abhishek-Punhani restored the fix-issue-implementing-card-array-generation branch May 28, 2024 10:01
@Abhishek-Punhani Abhishek-Punhani force-pushed the fix-issue-implementing-card-array-generation branch from 33797f4 to 4b976b4 Compare May 28, 2024 12:49
@Abhishek-Punhani Abhishek-Punhani deleted the fix-issue-implementing-card-array-generation branch May 28, 2024 13:16
@Abhishek-Punhani Abhishek-Punhani restored the fix-issue-implementing-card-array-generation branch May 28, 2024 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the Card array generation logic
2 participants