The game is developing in C Language. It is a minesweeper game. It is very interesting. Every students may be find some primary idea of game developing in C. It is just develope in C so the game is in Compiler version 1.0001
1. Department of Electrical and Computer Engineering
CSE 115 Lab Project Report
Minesweeper Game Development
Section:06
Group Number
Members: Junayed
Date of submission:13th
August,2015.
Abstract
2. Minesweeper is a popular computer game included in the Microsoft Windows releases in the
last 20 years. It is a simple one-player game consisting of a m × n initially blank grid. Under
the squares of the board, K mines are distributed randomly. In the standard Microsoft version,
the board has 16 ×16 fields and 40 mines. The goal of the player is to uncover all non-mine
fields and at the beginning he only knows the number of mines K. However, each time a non-
mine field is opened, the number of mines around this is displayed. For example, if two
appears on an opened square, this means that two of its neighbors contain mines. This number
is referred to as value of the square. Neighbors of a square are all squares adjacent to this, that
is all that have a common edge or corner with it. Thus, a square in the middle of the board has
eight neighbors while a square in a corner has only three. If there are no mines around an
opened square, all its neighbors are automatically opened, as they are known to be safe.
However, if the player uncovers a mine, the game is lost. He can, however, mark fields as
mine when he expects them to contain a mine. This may be, for instance, the case when a
square in a corner displays three, as this corresponds to the number of its neighbors. Thus, at
each move the player can either open a square or mark one as mine, or unmark a marked
square. Despite the simple rules of the game, beginners only win 35% of the time. This is
partly due to random moves like the first one of each game and partly to the difficulty of
applying logical and probabilistic reasoning for finding the safe or best moves in each
situation on the board. Computer scientists have realized that the game is difficult not only for
humans but also for computers. Indeed, multiple solvers have been implemented by using
various approaches.
3.
4. Acknowledgements
In the present scenario, where the world is taking breath at a high pace, technologies have
now become an integral part of our life. And computers are directly related to our daily day
life. As a part of technology we are given with an excellent opportunity to learn computers by
our institute under the guidance of one of the best Lecturer of Computer Science
in Bangladesh Arshed M Choudhury Lessons by Mounota Majid Natasha (NMM) during
the classes proved to be of great help .We learned great qualities like Professionalism, Team
work, Self Assessment, etc. which are sure to play an important role in our life. Last but
not the least we will also like to thank our very helpful lab instructor Raihana Zannat was
there always to help us in any difficulties to clear our doubts. Overall it was a great
journey and again a big thanks to our lecturer.
5. Contents
<Update the table of contents by right-clicking on it and selecting Update Field… and then
select page numbers only.>
Introduction <This is Heading 1>...............................................................
A section (Initial Brief) <This is style Heading 2>.................................................................
A subsection <This is style Heading 3>............................................................................................
Context...................................................................................................................................
Aims and Objectives..............................................................................................................
Background Research...................................................................................
Background on Company.......................................................................................................
Background study on research papers....................................................................................
Problem Context.....................................................................................................................
Considerations................................................................................................
Legal Considerations..............................................................................................................
Ethical Considerations............................................................................................................
Social Considerations.............................................................................................................
Professional Considerations...................................................................................................
Further Chapters (Technical Development)...........................................
System Design........................................................................................................................
System Implementation..........................................................................................................
System Testing and Results....................................................................................................
Conclusions and Critical Evaluation........................................................
Achievements.........................................................................................................................
Future Enhancements/ Further Developments (if your work is related to developing
something as part of your internship).....................................................................................
Personal Reflection.................................................................................................................
References and Bibliography......................................................................
Appendices- as appropriate.........................................................................
Appendix A............................................................................................................................
Appendix B............................................................................................................................
6. 1. Introduction : Minesweeper Game Development
1.1. Initial Brief
In our country we use computers for various purposes. The well-known OS available
in our country is Microsoft Windows. As we know that Microsoft has various
applications. It has approach above technology. Minesweeper is a popular computer
game included in the Microsoft Windows releases in the last 20 years. Microsoft
launched it as a system application. Although Minesweeper is a hard game, various
approaches for solving it have been applied. We made a console version of
minesweeper using C with DOS framework.
2.1. Context
Many working principles of IT and CS, such as programming languages, computer
architectures, operating systems, network communication, database, graphical user
interface (GUI), graphics, image processing, parallel processing, multi-threads, real-
time systems, device drivers, data acquisition, algorithms, numerical analysis, and
computer game, are based on or reflected in the functionalities and features of C. The
experience in C will help students understand the working principles of these
important concepts in IT and CS. Therefore, C is required for the CS major in almost
all universities. Certain languages and tools are typically used to solve domain
specific problems. Therefore, the ability to understand and learn new languages is
important. All other modern languages borrowed heavily from C. Once students
learned C, it is easy for them to learn by themselves any other computer languages
without much difficulty.
2.2. Aims and Objectives
A goal can, in our case, be defined in different stages. We want to create an
application that will help the library manage its facilities by making them more
accessible and offering them to the general student population in a way which
promotes structure, predictability, democracy and order. This is the main use of the
application, a use we can expect to see and one that we through research have found
to be a typical and reliable product, that people will use if implemented. We wish to
design this application, and conduct usability testing to promote a typical industrial
process, gaining us experience and confidence in future work. Having this foundation,
we wished to try something new and innovative.
.
7. 1. Background Research
Here is a very small minesweeper configuration and we will be using this as our simple
example:
1
2
2
2
1
A simple example of minesweeper
Those of you that have played minesweeper before should be able to solve this configuration
as best as you can using the intuition that you have learned from playing many games. That is
good, but I want a robust math-based solution to this problem. So let's look at what this
Minesweeper configuration tells us. The first thing that I note here is that we have five
squares that have not been clicked yet. They are our ‘unknowns'; these squares either contain
mines or they do not, there is no other alternative. So since they are our unknowns then let's
label them and make them our variables. I have done that in the following image:
X1 1
X2 2
X3 2
X4 2
X5 1
All of the unknown squares labelled from x1 to x5. Each of them either contains a mine or it doesn't.
Now for any un-clicked square xi look at the square x1, let's say that if it is a mine then it has
a value of 1 and if it is not then it has a value of 0. Therefore mines are ones and non-mines
are zeros; simple. Now take a look at the top right hand corner square of the previous image;
it contains a 1 (from here on in we will call clicked squares that contain numbers ‘numbered
squares'). That means that it is adjacent to one, and only one, mine. So first we look to see
which non-clicked squares are adjacent to it and we discover that x1 and x2 are the only
squares adjacent to it. Therefore we know that the number of mines in both X1 and X2 must
add up to equal 1. Another way of writing that is the following:
X1 + X2 = 1
Now we can come up with similar equations for the other numbered squares on the right hand
side of the simple Minesweeper example. If we do that we get the following equations:
X1 + X2 = 1
X1 + X2 + X3 = 2
X2 + X3 + X4 = 2
8. X3 + X4 + X5 = 2
You may not be able to see (just yet) why the previous set of equations is incredibly useful,
but the key insight here is to realise that you now have a set of five linear equations with five
variables. It will be even clearer if you let me add in the co-efficient and the non-clicked
squares that had co-efficient of zero:
1X1 + 1X2 + 0X3 + 0X4 + 0X5 = 1
1X1 + 1X2 + 1X3 + 0X4 + 0X5 = 2
0X1 + 1X2 + 1X3 + 1X4 + 0X5 = 2
0X1 + 0X2 + 1X3 + 1X4 + 1X5 = 2
0X1 + 0X2 + 0X3 + 1X4 + 1X5 = 1
So, we got the matrix...
X =
1 1 0 0 0 = 1
1 1 1 0 0 = 2
0 1 1 1 0 = 2
0 0 1 1 1 = 2
0 0 0 1 1 = 1
At this point in time we want to get a solution to this matrix so, as usual, we Gaussian
Eliminate to find a solution. The solution is on the next line but I recommend that you solve
this yourself on a pen and paper if you have one handy. If you don't then you can take my
word for it and just move to the next line:
X =
1 1 0 0 0 = 1
0 1 1 1 0 = 2
0 0 1 0 0 = 1
0 0 0 1 1 = 1
0 0 0 0 0 = 0
On first glance at this eliminated matrix you can immediately tell that there is no unique
solution to the vector x (this is where I am relying upon your prerequisite knowledge). This
may mislead you into thinking that the Gaussian Elimination failed but that would be
incorrect; it worked perfectly and it has given us a partial solution to the vector x. To see why
you need to remember that each non-clicked square in the minesweeper grid is either a mine
underneath or it is not a mine (1 or 0). Therefore each value in the vector x has the following
property:
Xi є {0, 1}
9. Every value x is either a 1 or a 0. This means that the matrix above has an extra property that
we do not get when the expected values of the vector x could be anything in a set of infinite
numbers, like the set of integers or real’s. Remember that we are in the Boolean set and this
will all make sense. To understand this property lets take a look at the third row of the
eliminated matrix. As you can see X3 is the only column of the matrix with a non-zero co-
efficient and the row adds to give 1. Setting X3 to be 1 is the only value that makes the row
work (conversely, if it last value in the row was 0 then X3 would have to be zero). This means
that we can tell that X3 is a mine even though we do not know what the other squares are. It is
interesting to note that we can only tell that from the Gaussian eliminated matrix; not the
original matrix. So even though the elimination does not find a complete solution it still
simplifies the matrix and allows us to get partial solutions.
Finishing the Simple Example:
So now let's wind back to the Gaussian Eliminated matrix. As we can see the only row that
we can apply this rule to is row 3 which tells us that x3 is a mine. Therefore we can flag that
square:
1
2
╪ 2
2
1
The final result of our simple minesweeper configuration.
And that is it for our simple example; we have worked out as much as we possibly can
without more information. The game is still in progress but if we want to move forward we
would have to make a guess or some probability based decision that could fail. This method
of solving Minesweeper only works for grids that are completely solvable without guesswork
and it is my future plan to expand this method to include probabilistic analysis as well.
1.1. Background on Company
Pretend each of the rows in the above image are unique rows taken from unique matrices
(what I am trying to say is that each row above is not correlated, they are all unique). Let me
deal with each row in a dot point:
If we take a look at the first row you should be able to tell that x1 and x4 are both mines
because that is the only way that they will equal 2. If you look at the second row you can see
that both x1 and x4 must not be mines because that is the only possible solution for x1 + x4 =
0 when the only potential values for any x are ones and zeroes. The third row is interesting
because it has a negative number, that means that the equation is x1 - x4 = 1. This can only be
true if x1 is a mine and x4 is not. Now things start to get interesting, clearly we need some
concept of a minimum and maximum bound for each equation. In this example the maximum
value the equation could take is 1 and the minimum value that it could take is minus one.
Since this row meets that upper bound we can solve for it. This is the same as the previous
example except that it meets the lower bound. This also means that we can solve for it.
10. 1.2. Background study on research papers
In the game of Minesweeper, a single player faces a grid representing a random minefield and
a fix minefield. Player has to choose the option of levels. After that, whenever he picks
(clicks in) a cell c, the game terminates if this cell contains a mine, or an area is uncovered,
starting from c, stopping at cells having at least one adjacent mine, and with the number of
adjacent mines marked on each uncovered cell. Previous table shows the result of selecting
the cell c in the bottom-left corner of an 9×9 minefield. The process is repeated until the game
ends (i) successfully if only mined cells remain, or
(ii) unsuccessfully if a mined cell is picked.
An important computational sort is typically put into goring out which cells may or may not
contain a mine given the observed values (or even computing the probability to contain a
mine). One usually reasons about the cells for which observed values in the vicinity give
some information, i.e., cells marked with.
1.3. Problem Context
Taking what we have learned from the simple example we can create an algorithm that is a
fair bit more robust:
Get a list of the squares that contain numbers AND are adjacent to at-least one square that has
not been clicked or flagged. For every numbered square in the list assign a unique matrix
column number to that square. This is so that we can map our Matrix columns to
Minesweeper squares. For every numbered square in the list create a matrix row that
represents the adjacent non-clicked squares and the number they touch. Don't forget to put
zeroes in all of the matrix columns that are not adjacent. Gaussian Eliminate Attempt to use
standard matrix reduction, and the special rule that we developed, to get a partial (or even
full) solution to the the current Minesweeper configuration. Remember to tackle the matrix
from the bottom row up so that you can make use of partial solutions as you go. Use the
(possibly partial) solution you worked out to generate the list of clicks that should be made:
flagging known mines and clicking known empty squares. Leave everything else alone and
wait for more information. Keep running all of the previous steps in a loop until you either
cannot make any moves (meaning that you cannot get further without guessing) or until the
game is finished and won.
1.4.
This code is not the most beautiful code that I have ever written. I wrote it all myself
to avoid spurious dependencies in the hope of easy cross platform compilation. I have
not even used RAII principles in this code and frankly that makes the delete's
sprinkled all over the code quite ugly. If I was writing this without a care in the world
for dependencies then I would have used Boost and gained a large amount of nice
looking code for free. Also the solver looks like a bit of a monster method at the
moment, sorry, it should be re-factored.
11. 1. Considerations
1.1. Legal Considerations
In feasibility study we had undergone through various steps which are describe as
under: Identify the origin of the information at different level. Identify the expectation
of user from the computerized system. Analyze the drawback of existing system.
1.2. Professional Considerations
There will be two levels : 1.Easy
2.Difficult
It helps user to choose board. Easy level contains some fixed mines.
12. 1. Further Chapters (Technical Development)
The header file we call through the program developments are:
#include <stdio.h>#include <stdlib.h>#include <time.h>#include <ctype.h>
The functions we call for different purposes to build our mine board, game board, for
displaying welcome massage, using functions for users input arrays, for the results,
for the win and loss:
void build_board();void build_board_1();void build_gboard();void
print_board();void print_gboard();void print_gboard_1();int findnearbymines(int,
int);void flushoutnearbymines(int, int);void loss();void win();int
checkforwin();void playagain();void display_welcome();void start_game();void
start_game_1();
We use various conditions on mines fields and levels. We use switch() as to define
levels. To print the matrix of our game board:
# loops: print actual board row w/ column numbers.
for(i = 0; i < BOARDSIZE; i++)
for(j = 0; j < BOARDSIZE; j++)
# arrays: To set mine through the board
//(5, 0) (7, 2) (6, 3) (8, 3) (0, 4) (7, 4) (4, 5) (8, 6) (8, 7) (2,8)
board[5][0]='*';
board[7][2]='*';
board[6][3]='*';
board[8][3]='*';
board[0][4]='*';
board[7][4]='*';
board[4][5]='*';
board[8][6]='*';
board[8][7]='*';
board[2][8]='*';
13. We are added a features to our projects that is made for the differences. We
define two levels and first one is made with define mines is called easy level. The
second part of the game is full of random mines.
# a set of c code to set random mine in difficult level
srand(time(NULL));
for(j=0;j<BOARDSIZE; j++)
{ int random = rand()%(BOARDSIZE - 1) + 1;
board[i][j] = '*';
}
We are made our code long to satisfying the facility of our users.
1.1. System Design
As we can see the general solution to getting more information from each row is to to
work out the lower and upper bounds and see if the value on the other side of the
equality is the same as one of the bounds. If it is then it is known that there is only
one possible configuration of mines that will allow that to occur and you can quickly
rattle that off. Because of that uniqueness property it can only apply this rule to a row
if it is equal to an upper or lower bound; if it does not then multiple solutions are
possible and you have strayed into the area of probabilistic analysis that this blog post
will not attempt to cover. This grid shows what logic you use, on a per-square basis,
to partially solve the matrix:
Row meets lower bound Not Mine Mine
Row meets upper bound Mine Not Mine
Row meets neither bounds Unsure Unsure
It can be used this rule on any Gaussian Eliminated Minesweeper matrix to get partial
solutions from rows.
1.2. System Implementation
Minesweeper Solving approaches vary from cellular automata and genetic algorithms
at the beginning of the Minesweeper research to constraints satisfaction, graphical
models, and learning in more recent years. More than 10 years ago, Adamatzky [1]
constructs a cellular automaton that populates n × n board in Ω(n), each cell of the
automaton having 25 neighbors and 27 states. Quartetti [2] uses a genetic algorithm
and achieves good results on 6 × 6 board with one mine but is unable to run the
experiments on 8 × 8 board. The approach is adapted by [3] but then abandoned.
More recently, Kamenetsky and Hui Teo [4] construct a graphical model for each
14. occurring position on the board. Their idea is to find safe and, if no such exist, best
moves, by identifying cliques. Very good performance is achieved, the standard game
is won in about 45% of the cases and an average of 77% of the squares is uncovered.
However, global constraints cannot be handled efficiently. Two papers apply learning
strategies. First, Castillo and Wrobe [5]use inductive learning programming
techniques, especially adaptive inductive learning. For 8 × 8 board with 10 mines,
four rules are successfully learned by the agent: the two of the Single Point Strategy
and two others for local combinations of two and three squares. Performance of 52%
wins is achieved and it increases to 60% when additional probabilities are used.
Again, no global strategy is applied. To overcome this and with the idea that model
counting should perform better, Nakov and Wei [6] apply a reinforcement learning
strategy. They reward an agent when its action is successful, that is, one field is either
opened or marked as mine whithout loosing the game. In addition, they use numerous
techniques for cutting the state space like working on the problem graph, exploiting
simmetries and sure moves. Although for a 4×4 board the approach is successful, it is
not able to generate all possible states for a 5 × 5 board, neither to approximate the
function. Later papers on reinforcement learning reference this study as an argument
that designing such a Minesweeper agent is possible but highly complex.
1.3. System Testing and Results
Name of test Input(given) Output(expected) Output(program) Shot(Reference)
Is the program run
properly?
Run Welcome message
on
Console Screen
Welcome message
on
Console Screen
Appendix A
1.1
Can you choose the
level?
Yes;
Level easy
Selecting level
options
Selecting level
options
Appendix A
1.2
Easy board(9x9) (After choosing
level easy-1)
Board(9x9) Board(9x9) Appendix A
1.3
Mine is
in fixed position
Given inputs
from *clients*
Show the mines in
console
Show the mines in
consoles
Appendix A
1.4
Hit mines Hit on mine (If
wrong
prediction)
Lost the game Lost the game Appendix A
1.5
15. Predict all correct
mines
Location of
mines(row,col)
Win the game Win the game Appendix A
1.6
Choose all the
empty slots except
mines
All slots are open
except mines
Win the game Win the game Appendix A
1.7
Difficult
Board(12x12)
(After choosing
level difficult-2)
Board(12x12) Board(12x12) Appendix B
2.1
Mine random
position
Random
input(row,col)
Open slots or mine Open slots or mine Appendix B
2.2
Hit the mine Wrong by
predicting and
Hit
Lost the game Lost the game Appendix B
2.2
Conclusions and Critical Evaluation
Although Minesweeper is a hard game, various approaches for solving it have been
applied. This paper has revealed and compared some of them in order to identify their
strengths and weaknesses. Six different agents have been developed: one random, one
for the Single Point Strategy, one Greedy agent, and three constraints agents. They
have been tested and compared in different scenarios with respect to overall result,
average moves per game, and time consumption. In most of the situations, the
constraints agents perform best. However, at high mine density and especially with
jokers, the Single Point Strategy proves to be more efficient. The main disadvantage
of the constraints agents is that the backtracking algorithm is exponential and, thus,
very expensive. Therefore, even a slight decrease of the number of squares considered
by search and a randomization of the choice of nodes can significantly improve the
performance. That is also the most important issue to improve and to consider by
further Minesweeper implementations. One very successful solution of the problem is
the separation of relevant unknown fields into sets [7]. This allows the generation of
more solutions for each state of the game and, thus, the computation of more accurate
probabilities for good moves. In terms of testing, appropriate measures should be
identif ied. For the reported experiments, the most popular ones have been used as
they are able to reflect the differences between the agents. However, they give no
information about the reasons for losses, for example, which could give more insights
into the actual performance of the agents. To conclude, this paper has confirmed the
proposition that constraints agents are an appropriate way for solving Minesweeper
games. However, it has also shown that depending on the parameters of the game,
16. other approaches may perform better. Further investigations of the Minesweeper
game and of the different solving alternatives are required in order to identify which
approach should be used in which situations as well as for improving the performance
of the existing solving algorithms.
Achievements
We design our project as an new era of consoler based games. The actual project is
designed for showing the overall strategic performance and make the experienced
level to step up.
Future Enhancements/ Further Developments
We have design our first game development project minesweeper game. As a first
project we have various lacking of facilities in that version. We couldn't have RGB
based consoler. We will develop the board size with the mines. Having face some
peculiarities we try to make that game user friendly.
Personal Reflection
##You should reflect briefly on what you have gained from the experience of
developing any product/software/hardware/any other work during your internship, in
terms of greater technical knowledge and your operational experience in managing a
task.
References and Bibliography
[1] A. Adamatzky, "How cellular automaton plays minesweeper," Applied
Mathematics and Computation, vol. 85, pp. 127-137, 1997. [2] C. Quartetti,
"Evolving a program to play the game minesweeper," in Genetic Algorithms and
Genetic Programming at Stanford, J. R. Koza, Ed. Stanford, California, 94305-3079
USA: Stanford Bookstore, Jun. 1998, pp. 312-318. [3] S. J. Rhee, "Evolving strategies
for the minesweeper game using genetic programming," in Genetic Algorithms and
Genetic Programming at Stanford, J. R. Koza, Ed. Stanford, California, 94305-3079
USA: Stanford Bookstore, Jun. 2000, pp. 312-318. [4] D. Kamenetsky and C. H. Teo,
"Graphical models for minesweeper," Project report, 2007. [5] L. P. Castillo and S.
Wrobel, "Learning minesweeper with multirelational learning," in Proceedings of the
18th international joint conference on Artificial intelligence. San Francisco, CA,
USA: Morgan Kaufmann Publishers Inc., 2003, pp. 533-538. [6] P. Nakov and Z.
Wei, "MINESWEEPER, #MINESWEEPER," 2003. [7] R. Collet, "Playing the
minesweeper with constraints," in Multiparadigm Programming in Mozart/Oz, ser.
Lecture Notes in Computer Science, P. Van Roy, Ed. Springer Berlin / Heidelberg,
2005, vol. 3389, pp. 251-262.
17. Appendices- as appropriate
Minesweeper Game Development
Features
Some of the features that is available to the user:
There are two levels in the board.
1.Easy
2.Difficult
Easy Level:
Easy level contains a board size 9x9 and it has a fixed mine place.
Difficult Level:
Difficult level contains a board size 12x12 and it has random mine
placement.
User can choose a level first.
Option to choose row and column for user wished.
User can predict if there is mine or not.
In case of losing, Dialog box will show TWO options: New Game, Exit
Minesweeper.
We are showing the Minesweeper Board at last, when the User get lost.
(Board is showing the place of mines.)
Uncover a mine, and game ends. Uncover a empty dots, and user keep
playing. Uncover a number, and it tells user how many mines lay hidden
in the 9 by 9 surrounding squares-Information user use to deduce which
nearby squares are safe to click.
If user suspects a square conceals a mine, user can uncover that mine. Study
the patterns. If two dots in a row display (3,3) then you know three mines
are probably lined up beside that row. If a square says 8, every surrounding
square is mined. Explore the unexplored. Not sure where to click next? Try
clearing some unexplored territory.
18. If user is able to uncover all mines by suspecting or if user can uncover all
slots excepts mines then wins. If user predicts the wrong slot as mine the
game will continue User could not win until he predicts the correct mine
location. If user hits a mine then loss.
Appendix A
Figure:1.1
Figure:1.2