Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7033473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:04:12+00:00 2026-05-28T01:04:12+00:00

I am trying to write a frame program that allows you to play Texas

  • 0

I am trying to write a frame program that allows you to play Texas Hold’em Poker. And I am having trouble with function hasPair that decides if CurrentPlayer has a Pair:

  public bool hasPair(Player CurrentPlayer)
        {
            bool flag;
            Card[] SevenCards = new Card[7];

            SevenCards[0].Color = CurrentPlayer.Card1.Color;
            SevenCards[0].Number = CurrentPlayer.Card1.Number;
            SevenCards[1].Color = CurrentPlayer.Color2;
            SevenCards[1].Number = CurrentPlayer.Number2;

            SevenCards[2] = Ground.Card1;
            SevenCards[3] = Ground.Card2;
            SevenCards[4] = Ground.Card3;
            SevenCards[5] = Ground.Card4;
            SevenCards[6] = Ground.Card5;

            flag = isThere_Pair(SevenCards); 

            return flag;
        }

And here is how CurrentPlayer receives its cards:

    public void Deal_Cards(Player Player)
    {
        int Color1, No1, Color2, No2;

        while (true)
        {


        dealhelper1:

            Color1 = (RandomColor.Next() % 4);
            No1 = ((RandomNo.Next() % 13));


            if (CardDeck[Color1, No1].isChosen == true)
            {
                goto dealhelper1;
            }

            if (CardDeck[Color1, No1].isChosen == false)
            {
                Player.Card1.Color = Color1;

                Player.Card1.Number = No1+1;
                Player.Card1.imagePath = CardDeck[Color1, No1].imagePath;

                Player.Color1 = CardDeck[Color1, No1].Color;
                Player.Number1 = CardDeck[Color1, No1].Number;                   

                CardDeck[Color1, No1].isChosen = true;
                break;
            }
        }

        while (true)
        {
            dealhelper2:

            Color2 = (RandomColor.Next() % 4);
            No2 = ((RandomNo.Next() % 13));

            if (CardDeck[Color2, No2].isChosen == true)
            {
                goto dealhelper2;
            }

            if (CardDeck[Color2, No2].isChosen == false)
            {
                CardDeck[Color2, No2].isChosen = true;


                Player.Card2.Color = Color2;
                Player.Card2.Number = (No2)+1;

                Player.Color2 = CardDeck[Color2, No2].Color;
                Player.Number2 = CardDeck[Color2, No2].Number;
                break;
            }
        }

        display_Player_Cards(Player);
    }

But in the hasPair function, CurrentPlayer‘s cards’ numbers and colors are 0. I tried it in different ways but when I ask in a query, i cannot get the player cards’ number values, although they have been initialized by the Deal_Cards function. Ground’s cards have no problem, though.

interestingly, display_Player_Cards(Player) function works correctly (so it takes the values successfully and displays the cards) .

I use public variables of type Player (struct) like:

    public Player P1 = new Player();
    public Player AI = new Player();

Why can’t they hold their values? How can I solve this issue?
Thanks for help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:04:13+00:00Added an answer on May 28, 2026 at 1:04 am

    The issue your running into here is that struct’s are passed by value in .Net. Hence the Deal_Cards method receives a copy of the Player instance and assigns cards to that copy. The original value passed to Deal_Cards is unmodified.

    To fix this you need to either make Player a class or pass it by reference. I highly recomend making Player a class. Having mutable structs is just a path to pain and hard to track down bugs like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to write a simple program that takes 5 images and allows you
I'm trying to write a function to accept a data.frame ( x ) and
I'm trying to write a regex function that will identify and replace a single
I am trying to write a c++ program that would read key frames from
I'm trying to write a piece of software that allows one to click on
I'm having trouble outputting a data.frame using write.csv using UTF-16 character encoding. Background: I
I'm trying to write a function that behaves as follows, but it is proving
Trying to write a PowerShell cmdlet that will mute the sound at start, unless
Trying to write a couple of functions that will encrypt or decrypt a file
im trying to write an app that will display a list off lines from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.