Skip Navigation

Search

Blackjack game - array has 0s in first 24 elements immediately after initialising with values from 1 to 13

EDIT: Literally 1 second after I pressed the post button I got an idea and thats what it was. Why does that always happen? xD

The solution was that my player_hand[] and dealer_hand[] arrays had a size of DECK_SIZE / 2, but I was initialising them to 0 from within the for loop where I was initialising the deck[] array (which has a size of DECK_SIZE), so the last 24 0s of one of those where overflowing into deck[]...

Hello everyone!

I am trying to make a simple blackjack (21) game in C, to practice some pointer stuff, and I am running into an issue with the function that initialises all my arrays. The way I am going about setting everything up, I have an integer array for a standard deck of 52 cards (values from 1 to 13, each 4 times), an integer array for the shuffled deck, and 2 more arrays for the player and dealer hands (irrelevant at this point as they are not used yet).

My issue is that after successfully initialising the deck array (the non-shuffled one) and outputting the values from within the for loop that sets them, I get what I expect to see which is:

1, 2, 3, ..., 13, 1, 2, 3, ..., 13, ... (so on for 52 cards).

But when I output each value from a different for loop in the same function, the first 24 elements (0-23) are 0s each time I run it. I can not figure out why that would be. I ran my program through valgrind which reported that there were no memory leaks.

Here is the relevant code:

```c #define DECK_SIZE 52

int initialise_decks(int* deck, int* shuffled_deck, int* player_hand, int* dealer_hand, int size) { printf("=================INITIALISING==================\n"); for (int i = 0; i < size; i++) { deck[i] = (i % 13) + 1; player_hand[i] = 0; dealer_hand[i] = 0;

printf("deck[%d]: %d\n", i, deck[i]); }

printf("+++++++++++++++++++++++++++++++++++++++\n"); for (int i = 0; i < size; i++) { printf("deck[%d]: %d\n", i, deck[i]); } printf("+++++++++++++++++++++++++++++++++++++++\n");

return INITIALISE_DECKS_SUCCESS; }

int main() { srand(time(0));

int deck[DECK_SIZE]; int shuffled_deck[DECK_SIZE]; int player_hand[DECK_SIZE / 2]; int dealer_hand[DECK_SIZE / 2];

int initialise_status = initialise_decks(deck, shuffled_deck, player_hand, dealer_hand, DECK_SIZE); if (initialise_status != INITIALISE_DECKS_SUCCESS) { return INITILIASE_DECKS_FAIL; }

return PROCESS_EXIT_NORMAL; } ```

If you need to try it out for yourself here is the link to the github repo

6

why local user.mail overrides global user.mail in git?

So, I have a GPG key with two noreply email addresses. One for codeberg.org and one email address for github.com. When using the [email protected] of codeberg as user.mail globally, I can make commits which show up as verified on codeberg.org. But if use the same mail as my git user.mail the commit on github will show up as unverified. Even though the particular repo's mail is set to the noreply email address of github which can be verified with git config user.mail but for some reason the global ~/.gitconfig mail is used to perform committs. Am I doing GPG management wrong or anything else wrong?

11

Is “multiplex” a proper name for bit concatenation?

I don’t remember the first time I saw this word but I suspect the word multiplex is not the proper one. How would you name this: ``` Shot name is multiplexed as 15:17, where:

  • The first 15 bits stores the sequence number.
  • The last 17 bits stores the shot number. ``` Thanks in advance!

EDIT: Thanks all! So it seems packed is the proper word. With pack/unpack being the name of the process.

5

Can't access squid proxy via nodejs with axios

I'm not sure in which community to ask this, if you know of a better one let me know.

I already have squid proxy working, if I set up my browser or curl to use the proxy all sites work properly. But when I try to make a request with axios it doesn't work.

Here are the logs of squid The first two lines are successful google connections are from a browser. The 3rd line is a successful to google using curl. The 4th line is a successful to ipify using curl. The last two ones are the ones from node using axios squid_proxy | 1693406310.165 12043 127.0.0.1 TCP_TUNNEL/200 56694 CONNECT www.google.com:443 - HIER_DIRECT/142.250.217.132 - squid_proxy | 1693406310.166 10681 127.0.0.1 TCP_TUNNEL/200 47267 CONNECT apis.google.com:443 - HIER_DIRECT/142.250.176.14 - squid_proxy | 1693406325.551 497 127.0.0.1 TCP_TUNNEL/200 24778 CONNECT www.google.com:443 - HIER_DIRECT/142.250.217.132 - squid_proxy | 1693406336.829 403 127.0.0.1 TCP_TUNNEL/200 7082 CONNECT api.ipify.org:443 - HIER_DIRECT/64.185.227.156 - squid_proxy | 1693406361.410 12590 127.0.0.1 TCP_MISS/503 4358 GET https://api.ipify.org/? - HIER_NONE/- text/html squid_proxy | 1693406361.889 385 127.0.0.1 TCP_MISS/502 3948 GET https://www.google.com/ - HIER_DIRECT/142.250.217.132 text/html

The errors sent to axios are these: ```

ipify

[No Error] (TLS code: SQUID_TLS_ERR_CONNECT+GNUTLS_E_FATAL_ALERT_RECEIVED) SSL handshake error (SQUID_TLS_ERR_CONNECT) This proxy and the remote host failed to negotiate a mutually acceptable security settings for handling your request. It is possible that the remote host does not support secure connections, or the proxy is not satisfied with the host security credentials.

google

The system returned: [No Error] ```

My code looks like this ``` const axios = new Axios({ proxy: { host: proxyIP, port: proxyPort, protocol: 'http' } });

const ip = await axios.get('https://api.ipify.org?format=json'); console.log(ip.data);

const res = await axios.get('https://www.google.com'); console.log(res.data); ```

Any idea what might be happening?

I'm not sure if axios handles the connection in a different way since the logs from the browser show CONNECT and axios shows GET, but maybe that's because it's failing to actually connect and it only logs the request method.

3

How to decide what to do with command line parameters?

This is solved, I was being dumb. Please see second EDIT below

This isn't really language specific, but if it helps I'm using Python. I can get the parameters just fine with the Traitlets module, but I'm still a novice really and figuring out which patterns to use is challenging.

Say you have a bunch of command line parameters. Some are booleans, where their presence means True, absence means False. Other parameters must accept one text string, and others can be used multiple times to build a list of strings.

It feels inefficient/wrong to use a bunch of IF/THEN/ELSE statements to decide what to do with the parameters, and prone to edge case errors. Is there a pattern that would invoke the correct method based on the combination of input parameters?

Examples: ``` app thing --dry-run --create --name=newname01 --name=newname02 --verbose

app thing --create --name=newname01 --name=newname02 --name=newname03

app job --cancel -i 01 -i 02 -i 03 ```

EDIT: Via the Traitlets module, I get those arguments parsed and accessible as self.argname, so getting them into my app is working great. It's just deciding what to do with them that is confusing me.

Thank you, sorry for my noobness.

EDIT2: I think I understand where I'm going wrong:

I'm creating subcommands based on objects, not actions. i.e. appname thing --action should really be appname action --thing. Once things are divided up into actions, assigning things to those actions will be much, much easier and straightforward.

Sorry for a confusing and fairly pointless post :(

18