aboutsummaryrefslogtreecommitdiff
path: root/random.c (unfollow)
Commit message (Collapse)Author
2023-02-26Be more careful with type of left operand of <<Ben Harris
On a 32-bit system, evaluating 1<<31 causes undefined behaviour because 1 is signed and so it produces signed overflow. UBSan has spotted a couple of occasions where this happens in Puzzles, so in each case I've converted the left operand to the unsigned result type we actually want.
2023-02-18Miscellaneous const fixesBen Harris
These are cases where -Wcast-qual complained and the only change needed was to add or remove a "const" (or sometimes an entire cast).
2013-04-13Giant const patch of doom: add a 'const' to every parameter in everySimon Tatham
puzzle backend function which ought to have it, and propagate those consts through to per-puzzle subroutines as needed. I've recently had to do that to a few specific parameters which were being misused by particular puzzles (r9657, r9830), which suggests that it's probably a good idea to do the whole lot pre-emptively before the next such problem shows up. [originally from svn r9832] [r9657 == 3b250baa02a7332510685948bf17576c397b8ceb] [r9830 == 0b93de904a98f119b1a95d3a53029f1ed4bfb9b3]
2005-10-22Cleanup: rename random_init() to random_new(), because it actuallySimon Tatham
_allocates_ a random_state rather than just initialising one passed in by the caller. [originally from svn r6412]
2005-08-01Various cleanups and clarifications to devel.but; some from RichardSimon Tatham
B and some from me. Also an additional utility function `random_copy' from Richard B, which he says is useful in a new puzzle he's working on and which seems likely to come in handy again at some point. [originally from svn r6153]
2005-06-01Miscellaneous fixes from James Harvey's PalmOS porting work:Simon Tatham
- fixed numerous memory leaks (not Palm-specific) - corrected a couple of 32-bit-int assumptions (vital for Palm but generally a good thing anyway) - lifted a few function pointer types into explicit typedefs (neutral for me but convenient for the source-munging Perl scripts he uses to deal with Palm code segment rules) - lifted a few function-level static arrays into global static arrays (neutral for me but apparently works round a Palm tools bug) - a couple more presets in Rectangles (so that Palm, or any other slow platform which can't handle the larger sizes easily, can still have some variety available) - in Solo, arranged a means of sharing scratch space between calls to nsolve to prevent a lot of redundant malloc/frees (gives a 10% speed increase even on existing platforms) [originally from svn r5897]
2005-05-30Mines now follows the conventional approach of offering a completelySimon Tatham
blank grid until you make the first click; to ensure solubility, it does not generate the mine layout until that click, and then ensures it is solvable starting from that position. This has involved three infrastructure changes: - random.c now offers functions to encode and decode an entire random_state as a string - each puzzle's new_game() is now passed a pointer to the midend itself, which most of them ignore - there's a function in the midend which a game can call back to _rewrite_ its current game description. So Mines now has two entirely separate forms of game ID. One contains the generation-time parameters (n and unique) plus an encoding of a random_state; the other actually encodes the grid once it's been generated, and also contains the initial click position. When called with the latter, new_game() does plausibly normal stuff. When called with the former, it notes down all the details and waits until the first square is opened, and _then_ does the grid generation and updates the game description in the midend. So if, _after_ your first click, you decide you want to share this particular puzzle with someone else, you can do that fine. Also in this checkin, the mine layout is no longer _copied_ between all the game_states on the undo chain. Instead, it's in a separate structure and all game_states share a pointer to it - and the structure is reference-counted to ensure deallocation. [originally from svn r5862]
2005-05-30Initial checkin of my Minesweeper clone, which uses a solver duringSimon Tatham
grid generation to arrange a mine layout that never requires guessing. [originally from svn r5859]
2004-05-03The Windows RNG turns out to only give about 16 bits at a time. ThisSimon Tatham
is (a) pretty feeble, and (b) means that although Net seeds transfer between platforms and still generate the same game, there's a suspicious discrepancy in the typical seed _generated_ by each platform. I have a better RNG kicking around in this code base already, so I'll just use it. Each midend has its own random_state, which it passes to new_game_seed() as required. A handy consequence of this is that initial seed data is now passed to midend_new(), which means that new platform implementors are unlikely to forget to seed the RNG because failure to do so causes a compile error! [originally from svn r4187]
2004-04-28Fix zillions of MSVC compiler warnings. Sigh.Simon Tatham
[originally from svn r4165]
2004-04-26Further general development. Net is now playable, thoughSimon Tatham
configuration is absent as yet. [originally from svn r4145]