I want to write a Minesweeper game in C. Should I have a struct that holds the games state (grid, flag count...

I want to write a Minesweeper game in C. Should I have a struct that holds the games state (grid, flag count, bomb count), or should I hold those in global variables?

Attached: 41gHB8KelXL._SX377_BO1,204,203,200_.jpg (379x499, 27K)

Yes.

No

Maybe

Look at the ECS pattern

You’ve already disregarded best practices by selecting C for minesweeper. May as well just be yourself and global all the way.

Actually, be a madman and use bitsets.

use common lisp instead.

use haskell.

>not using C for all of your hobby projects

Attached: 1503367161662.gif (212x199, 246K)

Why arent you using Ada

I'm only practicing C, I'm not making anything important.

Use a struct. It can sometimes be cleaner, though not thread-safe, to use global variables, but even if you use global variables, you should have them be fields of a single global struct.

Also, keep in mind your global variables do not have to be public / pollute the namespace. You don't have to expose them in the header. You can keep them solely in the implementation file and declare them as static. This will prevent other implementation files from linking against the global variables at link time, which, aside from security / stability, can also prevent multiple definition errors.

A common approach is to shield global variables in this way and only expose in the header a controlled set of functions for manipulating those global variables. The functions are able to access the global variables, but the caller is not.

Example:
// gamestate.c
static struct {
int flagc, bombc, gridh, gridw;
char grid[];
} gamestate;
void dothing(void) {
// do something with gamestate here
}

// gamestate.h
#pragma once
void dothing(void);
// no mention of gamestate

>static struct {
int flagc, bombc, gridh, gridw;
char grid[];
} gamestate;

Actually don't do this, it was just an example, but in writing that example, I forgot, it doesn't make much semantic sense to declare a static instance of a struct with a flexible array member.

Why not? Isn't the only purpose of static here to set the scope of the struct to the source file?

Allow me to rephrase: it doesn't make much semantic sense to declare an instance of a struct with a flexible array member at all.

You can declare a *pointer* to an instance of a struct with a flexible array member, and then, if you want that struct to exist in heap memory, you can assign a malloc to that declared pointer, or if you want it to exist on the stack or in static memory, you can assign the address of a byte array to the declared pointer. But, generally speaking, you should never just outright declare an instance of a struct with a flexible array member.

The reason being, the size a flexible array member contributes to its containing struct is 0. If you just directly declare an instance of the struct, there will be no room in that instance for the array it's supposed to contain. Any indices into that array will point outside the struct and into the following region of whatever memory it's stored in.

Write the state of the game to a XML file, then send it over a ssh session in a VM on a AWS Cloud running CentOS, be sure to have installed FFmpeg and Tensorflow in order to transcode that XML file to a Webm gif and then train the neural network with that pixel data until you have enough information to output a proper .OBJ 3D point cloud file, wich you can use to reconstruct the position of the bombs and the flag count. For better performance you can use an alpha .png image as a grid.

Attached: triangle-face-nigga.jpg (400x400, 28K)

>You’ve already disregarded best practices by selecting C for minesweeper

What's the alternative, genius? C++? Lmfao

get with the times, you dont use languages, you use development stacks

>compile-time template metaprogramming Minesweeper that you play by specifying moves as template parameters

retard

>specifying moves
easy mode, try implementing a tmp ml algorithm to learn the optimal plays at compile time and instantiate them as template parameters

> development stacks
you make me puke