Dylan Smith : winemine: Set mines after first choice.

Alexandre Julliard julliard at winehq.org
Wed Jun 25 04:47:19 CDT 2008


Module: wine
Branch: master
Commit: 04f925e72ce4c87dbdf503072dd58e4e444d3760
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=04f925e72ce4c87dbdf503072dd58e4e444d3760

Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date:   Tue Jun 24 14:09:42 2008 -0400

winemine: Set mines after first choice.

The first choice never is on a mine in Windows.  This can be tested by
making a custom game with as many mines as possible, and then playing
the start of many games, and the first choice will never be on a mine.

This is done to make the game reasonable, since after the first choice
there will at least be some information given to make the next choice.

---

 programs/winemine/main.c |   46 +++++++++++++++++++++++++++-------------------
 programs/winemine/main.h |    2 +-
 2 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/programs/winemine/main.c b/programs/winemine/main.c
index f4a48d0..2d17536 100644
--- a/programs/winemine/main.c
+++ b/programs/winemine/main.c
@@ -452,13 +452,24 @@ static void MoveOnScreen(RECT* rect)
 void CreateBoard( BOARD *p_board )
 {
     int left, top, bottom, right;
+    unsigned col, row;
     RECT wnd_rect;
 
     p_board->mb = MB_NONE;
     p_board->boxes_left = p_board->cols * p_board->rows - p_board->mines;
     p_board->num_flags = 0;
 
-    CreateBoxes( p_board );
+    /* Create the boxes...
+     * We actually create them with an empty border,
+     * so special care doesn't have to be taken on the edges
+     */
+    for( col = 0; col <= p_board->cols + 1; col++ )
+      for( row = 0; row <= p_board->rows + 1; row++ ) {
+        p_board->box[col][row].IsPressed = FALSE;
+        p_board->box[col][row].IsMine = FALSE;
+        p_board->box[col][row].FlagType = NORMAL;
+        p_board->box[col][row].NumMines = 0;
+      }
 
     p_board->width = p_board->cols * MINE_WIDTH + BOARD_WMARGIN * 2;
 
@@ -531,30 +542,21 @@ void CheckLevel( BOARD *p_board )
     if( p_board->mines < BEGINNER_MINES )
         p_board->mines = BEGINNER_MINES;
 
-    if( p_board->mines > p_board->cols * p_board->rows - 1 )
-        p_board->mines = p_board->cols * p_board->rows - 1;
+    if( p_board->mines > p_board->cols * p_board->rows - 2 )
+        p_board->mines = p_board->cols * p_board->rows - 2;
 }
 
-
-void CreateBoxes( BOARD *p_board )
+/* Randomly places mines everywhere except the selected box. */
+void PlaceMines ( BOARD *p_board, int selected_col, int selected_row )
 {
     int i, j;
     unsigned col, row;
 
     srand( (unsigned) time( NULL ) );
 
-    /* Create the boxes...
-     * We actually create them with an empty border,
-     * so special care doesn't have to be taken on the edges
-     */
-
-    for( col = 0; col <= p_board->cols + 1; col++ )
-      for( row = 0; row <= p_board->rows + 1; row++ ) {
-        p_board->box[col][row].IsPressed = FALSE;
-        p_board->box[col][row].IsMine = FALSE;
-        p_board->box[col][row].FlagType = NORMAL;
-        p_board->box[col][row].NumMines = 0;
-      }
+    /* Temporarily place a mine at the selected box until all the other
+     * mines are placed, this avoids checking in the mine creation loop. */
+    p_board->box[selected_col][selected_row].IsMine = TRUE;
 
     /* create mines */
     i = 0;
@@ -568,11 +570,13 @@ void CreateBoxes( BOARD *p_board )
         }
     }
 
+    /* Remove temporarily placed mine for selected box */
+    p_board->box[selected_col][selected_row].IsMine = FALSE;
+
     /*
      * Now we label the remaining boxes with the
      * number of mines surrounding them.
      */
-
     for( col = 1; col < p_board->cols + 1; col++ )
     for( row = 1; row < p_board->rows + 1; row++ ) {
         for( i = -1; i <= 1; i++ )
@@ -838,8 +842,12 @@ void TestMines( BOARD *p_board, POINT pt, int msg )
                     p_board->press.x, p_board->press.y );
         p_board->press.x = 0;
         p_board->press.y = 0;
-        if( p_board->box[col][row].FlagType != FLAG )
+        if( p_board->box[col][row].FlagType != FLAG
+            && p_board->status != PLAYING )
+        {
             p_board->status = PLAYING;
+            PlaceMines( p_board, col, row );
+        }
         CompleteBox( p_board, col, row );
         break;
 
diff --git a/programs/winemine/main.h b/programs/winemine/main.h
index 37fa768..16fcb2e 100644
--- a/programs/winemine/main.h
+++ b/programs/winemine/main.h
@@ -134,7 +134,7 @@ void CheckLevel( BOARD *p_board );
 
 void CreateBoard( BOARD *p_board );
 
-void CreateBoxes( BOARD *p_board );
+void PlaceMines ( BOARD *p_board, int selected_col, int selected_row );
 
 void TestBoard( HWND hWnd, BOARD *p_board, int x, int y, int msg );
 




More information about the wine-cvs mailing list