root/trunk/README

Revision 45, 6.6 kB (checked in by jtv, 8 months ago)

Updated email addresses, URLs.

Line 
1 libmines - http://pqxx.org/development/mines/
2
3 Welcome to libmines, a reusable library for building Minesweeper games.
4
5 Introduction
6 ------------
7
8 This package is for programmers who want to write their own version of the
9 famous little puzzle game.  (If you think you know the game from soup to nuts
10 and it's boring, do read on).  Building libmines requires a somewhat Unix-like
11 system and the GNU version of "make"--it may be installed on your system as
12 "gmake".
13
14 Everybody's got their own version of Minesweeper.  All of them are essentially
15 the same, with different user interfaces--often just so they can use different
16 user-interface toolkits.
17
18 Mostly these versions are "good enough."  But the way we programmers like to do
19 things, once everyone agrees what something should do at its core, we call it
20 "well-understood" and separate the core from the parts that everyone wants to do
21 differently.  That's what libmines is: it provides the heart of the game, the
22 "game logic," with some room for variation, so you can build your own new user
23 interface without having to write the actual puzzle part all over again.  Of
24 course libmines is Free Software (or Open Source, as some prefer to say) so feel
25 free to change it and give it to your friends.  Better yet, once you know what
26 you want changed in the library to suit your own project, share your wishes and
27 changes with the author so everyone can benefit!
28
29 Doing things this way makes the programming easier for everyone.  It also makes
30 for cleaner code.  It's a great way to learn programming, from making one's
31 first steps with a programming language to practicing one's software-engineering
32 skills.  And perhaps most of all, it makes it easy to do really new stuff with
33 the game!
34
35 A very basic text-based command line client is included, which is meant mostly
36 for testing.  But there's also a simple CGI program: set up your web server to
37 provide access to it, and you can play the game in your browser through the
38 Internet.  An example is running on pqxx.org--see the main development page.
39
40 Those sample user interfaces aren't great, so here's your chance.  Perhaps you
41 can be the one to write a much better one.  Or be the first to build an online
42 multiplayer version.  Or figure out new ways to present the playing field.  If
43 you want to do it all in 3D, well, we can talk.
44
45
46 Boring!
47 -------
48
49 Your average Minesweeper gets boring fairly quickly.  You may even think of it
50 as mindless--one visitor found the project page by searching the Internet for
51 "Minesweeper and other mindless games."  Well, with libmines, it doesn't have to
52 be.
53
54 Most Minesweeper games work like this: you click on a mineless square to reveal
55 it.  The square will then show the number of mines neighbouring it.  If there
56 are no nearby mines, all surrounding squares will also be revealed, and if some
57 of those also show zeroes, their neighbours will be revealed and so on.  Then
58 you go on to the next obviously mineless square, until the game finally becomes
59 harder.  A large portion of the mistakes come from accidentally clicking in the
60 wrong place, clicking with the wrong mouse button, or simply boredom and
61 drifting attention.  Yes, the game becomes mindless pretty quickly that way.
62
63 That's why libmines goes a little further.  You can specify various levels of
64 intelligence.  Level zero doesn't "auto-reveal" anything at all, just what you
65 click on.  Level one does it for squares that aren't near mines, like the other
66 versions of the game.  Level two is smarter: it will also reveal squares that
67 are near mines, as long as all those mines have already been accounted for.  And
68 conversely, it also recognizes the situation where all remaining neighbours of a
69 field must be mines.  What remains are the interesting situations where you need
70 to do some actual thinking.  This way, the game is over much sooner--or you can
71 play much bigger fields with more mines.  You can do the thinking, and leave the
72 dumb work to the library.
73
74 Another way to make things interesting again is to vary the rules a bit.  You
75 can show squares outside the actual playing fields, so the player can see what
76 squares are safe to click on as starting points.  That eliminates the silly
77 guessing at the beginning of the game, as you look for a usable starting point.
78 You can let the user mark possible mines with flags, as most versions of the
79 game do, or you can make it a fatal mistake to get this wrong, or you can do a
80 bit of both.  Players can have multiple lives if you want.  If you would like to
81 do really exotic things like add or remove mines during the game, or make them
82 move around, they may not be possible yet but we can add them.
83
84
85 Writing your own
86 ----------------
87
88 The native language for libmines is C++.  If that is the language you want to
89 write your game in, that's easy.  If it's not, there is also an API in C that,
90 with a few small exceptions, supports all of the native features.  Most if not
91 all other programming languages offer ways to call C functions, so this should
92 be enough to support user interfaces in just about any language out there.
93
94 Saving games is also possible, of course.  The file format consists of a few
95 lines describing the playing field, followed by a compact base64-encoded binary
96 representation of the field itself (two bits per square: "is mined" and "has
97 been revealed").  The data is written to a memory buffer provided by you; if you
98 want to add data of your own, you can write that to file before or after the
99 buffer's contents.
100
101 The saved-game feature was designed for performance.  That may seem silly: how
102 often do you want to save a game, and how long can it take?  We could have made
103 things slower and more flexible, but doing that yourself shouldn't be hard.  The
104 fast, compact format lets you go to other extremes: the included web user
105 interface saves every game to a file after every move, and reloads it every time
106 the field is displayed.  That will scale to enormous playing fields and huge
107 numbers of simultaneous games.  Future versions could optimize it even further
108 by storing games in shared memory.  Or someone might want to write a version for
109 mobile phones or other small devices, and keep game state in a tiny bit of
110 non-volatile memory.
111
112 To start using libmines in C++, take a look at the source files with names
113 ending in ".hxx".  These headers define the C++ API.  The C interface is defined
114 in a header called c_abi.h.
115
116 For more easily readable documentation on how to use libmines in your own
117 program, see the documentation in the "doc" directory.  If you would like to
118 have this documentation generated in other formats such as LaTeX, ensure that
119 the documentation extractor "doxygen" is installed on your system; edit the
120 configuration file doc/Doxyfile accordingly, then run "make".
121
Note: See TracBrowser for help on using the browser.