automate minesweeper with python

Discussion in 'Python' started by Jay, Jul 1, 2010.

  1. Jay

    Jay Guest

    I would like to create a python script that plays the Windows game
    minesweeper.

    The python code logic and running minesweeper are not problems.
    However, "seeing" the 1-8 in the minesweeper map and clicking on
    squares is. I have no idea how to proceed.
     
    Jay, Jul 1, 2010
    #1
    1. Advertising

  2. On Jul 1, 7:39 am, Jay <> wrote:
    > I would like to create a python script that plays the Windows game
    > minesweeper.
    >
    > The python code logic and running minesweeper are not problems.
    > However, "seeing" the 1-8 in the minesweeper map and clicking on
    > squares is. I have no idea how to proceed.


    you may want to have a look at sikuli
    http://groups.csail.mit.edu/uid/sikuli/
     
    Justin Ezequiel, Jul 1, 2010
    #2
    1. Advertising

  3. Jay

    Jay Guest

    On Jun 30, 6:01 pm, Justin Ezequiel <>
    wrote:
    > On Jul 1, 7:39 am, Jay <> wrote:
    >
    > > I would like to create a python script that plays the Windows game
    > > minesweeper.

    >
    > > The python code logic and running minesweeper are not problems.
    > > However, "seeing" the 1-8 in the minesweeper map and clicking on
    > > squares is. I have no idea how to proceed.

    >
    > you may want to have a look at sikulihttp://groups.csail.mit.edu/uid/sikuli/


    Intresting, but I actually have something already in python I want to
    modify.
     
    Jay, Jul 1, 2010
    #3
  4. Jay

    MRAB Guest

    Jay wrote:
    > On Jun 30, 6:01 pm, Justin Ezequiel <>
    > wrote:
    >> On Jul 1, 7:39 am, Jay <> wrote:
    >>
    >>> I would like to create a python script that plays the Windows game
    >>> minesweeper.
    >>> The python code logic and running minesweeper are not problems.
    >>> However, "seeing" the 1-8 in the minesweeper map and clicking on
    >>> squares is. I have no idea how to proceed.

    >> you may want to have a look at sikulihttp://groups.csail.mit.edu/uid/sikuli/

    >
    > Intresting, but I actually have something already in python I want to
    > modify.


    There's a question here about capturing a window as an image:

    http://bytes.com/topic/python/answers/500826-screen-capturing-windows

    You could then see if you could identify the squares.
     
    MRAB, Jul 1, 2010
    #4
  5. Jay

    Ian Kelly Guest

    On Wed, Jun 30, 2010 at 7:15 PM, Jay <> wrote:
    > On Jun 30, 6:01 pm, Justin Ezequiel <>
    > wrote:
    >> you may want to have a look at sikulihttp://groups.csail.mit.edu/uid/sikuli/

    >
    > Intresting, but I actually have something already in python I want to
    > modify.


    You should be able to use it with Jython. Or if you absolutely must
    run CPython, JPype.
     
    Ian Kelly, Jul 1, 2010
    #5
  6. Jay

    Paul McGuire Guest

    On Jun 30, 6:39 pm, Jay <> wrote:
    > I would like to create a python script that plays the Windows game
    > minesweeper.
    >
    > The python code logic and running minesweeper are not problems.
    > However, "seeing" the 1-8 in the minesweeper map and clicking on
    > squares is. I have no idea how to proceed.


    You can interact with a Windows application using pywinauto (http://
    pywinauto.openqa.org/).

    Sounds like a fun little project - good luck!

    -- Paul
     
    Paul McGuire, Jul 1, 2010
    #6
  7. Jay

    Jay Guest

    pywinauto looks to be almost perfect. All I need now is to read the
    numbers uncovered when a minesweeper square is clicked on, or that I
    just hit a mine.

    On Jun 30, 6:51 pm, Paul McGuire <> wrote:
    > On Jun 30, 6:39 pm, Jay <> wrote:
    >
    > > I would like to create a python script that plays the Windows game
    > > minesweeper.

    >
    > > The python code logic and running minesweeper are not problems.
    > > However, "seeing" the 1-8 in the minesweeper map and clicking on
    > > squares is. I have no idea how to proceed.

    >
    > You can interact with a Windows application using pywinauto (http://
    > pywinauto.openqa.org/).
    >
    > Sounds like a fun little project - good luck!
    >
    > -- Paul
     
    Jay, Jul 1, 2010
    #7
  8. On 7/1/2010 2:52 PM Jay said...
    > pywinauto looks to be almost perfect. All I need now is to read the
    > numbers uncovered when a minesweeper square is clicked on, or that I
    > just hit a mine.
    >


    .... or, you could always win...

    http://www.daniweb.com/forums/thread186209.html

    Emile


    PS -- in about '77 I worked with a guy that had XYZZY as his
    personalized license plate...
     
    Emile van Sebille, Jul 1, 2010
    #8
  9. Jay

    Terry Reedy Guest

    On 7/1/2010 6:42 PM, Emile van Sebille wrote:
    > On 7/1/2010 2:52 PM Jay said...
    >> pywinauto looks to be almost perfect. All I need now is to read the
    >> numbers uncovered when a minesweeper square is clicked on, or that I
    >> just hit a mine.
    >>

    >
    > ... or, you could always win...
    >
    > http://www.daniweb.com/forums/thread186209.html


    Did you actually try it? Though skeptical, I did, briefly, until I
    decided that it probably should have been dated April 1. There is no way
    to enter text into minesweeper, nor to make it full screen, nor, as far
    as I know, for it to toggle pixels outside its window.

    --
    Terry Jan Reedy
     
    Terry Reedy, Jul 2, 2010
    #9
  10. On 7/1/2010 6:17 PM Terry Reedy said...
    > On 7/1/2010 6:42 PM, Emile van Sebille wrote:
    >> On 7/1/2010 2:52 PM Jay said...
    >>> pywinauto looks to be almost perfect. All I need now is to read the
    >>> numbers uncovered when a minesweeper square is clicked on, or that I
    >>> just hit a mine.
    >>>

    >>
    >> ... or, you could always win...
    >>
    >> http://www.daniweb.com/forums/thread186209.html

    >
    > Did you actually try it? Though skeptical, I did, briefly, until I
    > decided that it probably should have been dated April 1. There is no way
    > to enter text into minesweeper, nor to make it full screen, nor, as far
    > as I know, for it to toggle pixels outside its window.
    >


    Yes. It works.

    Emile
     
    Emile van Sebille, Jul 2, 2010
    #10
  11. Jay

    Ian Kelly Guest

    On Thu, Jul 1, 2010 at 7:17 PM, Terry Reedy <> wrote:
    > Did you actually try it? Though skeptical, I did, briefly, until I decided
    > that it probably should have been dated April 1. There is no way to enter
    > text into minesweeper, nor to make it full screen, nor, as far as I know,
    > for it to toggle pixels outside its window.


    Your objections are invalid. The fact that Minesweeper does not have
    a text control does not mean that it cannot receive keypresses, and
    the exterior pixel could hypothetically be implemented as a 1-pixel
    borderless window belonging to the Minesweeper application.

    There are enough details from enough different persons on the web,
    with few if any dissenting opinions, that I'm inclined to believe it
    probably works. I can't test it myself, though, because it apparently
    no longer works in Windows Vista or 7, and I no longer have an XP box
    around.
     
    Ian Kelly, Jul 2, 2010
    #11
  12. Jay

    Ethan Furman Guest

    Terry Reedy wrote:
    > On 7/1/2010 6:42 PM, Emile van Sebille wrote:
    >
    >> On 7/1/2010 2:52 PM Jay said...
    >>
    >>> pywinauto looks to be almost perfect. All I need now is to read the
    >>> numbers uncovered when a minesweeper square is clicked on, or that I
    >>> just hit a mine.
    >>>

    >>
    >> ... or, you could always win...
    >>
    >> http://www.daniweb.com/forums/thread186209.html

    >
    >
    > Did you actually try it? Though skeptical, I did, briefly, until I
    > decided that it probably should have been dated April 1. There is no way
    > to enter text into minesweeper, nor to make it full screen, nor, as far
    > as I know, for it to toggle pixels outside its window.


    The pixel can be hard to see depending on your background colors and
    whether your screen is adjusted correctly (I could see the white, but
    not the black). But on XP Pro is still works.

    ~Ethan~
     
    Ethan Furman, Jul 2, 2010
    #12
  13. Jay

    Terry Reedy Guest

    On 7/1/2010 10:18 PM, Emile van Sebille wrote:
    > On 7/1/2010 6:17 PM Terry Reedy said...
    >> On 7/1/2010 6:42 PM, Emile van Sebille wrote:
    >>> On 7/1/2010 2:52 PM Jay said...
    >>>> pywinauto looks to be almost perfect. All I need now is to read the
    >>>> numbers uncovered when a minesweeper square is clicked on, or that I
    >>>> just hit a mine.
    >>>>
    >>>
    >>> ... or, you could always win...
    >>>
    >>> http://www.daniweb.com/forums/thread186209.html

    >>
    >> Did you actually try it? Though skeptical, I did, briefly, until I
    >> decided that it probably should have been dated April 1. There is no way
    >> to enter text into minesweeper, nor to make it full screen, nor, as far
    >> as I know, for it to toggle pixels outside its window.
    >>

    >
    > Yes. It works.


    Thanks all. I tried again with other windows minimized so that the upper
    left pixel is medium brown from the wallpaper, and I can make out the
    white pixel. A maximized unfocued background window has that pixel
    normally black surrounded by light blue pixels that make one white pixel
    harder to see for imperfect eyes. Live, post errors, and learn ;-).

    --
    Terry Jan Reedy
     
    Terry Reedy, Jul 2, 2010
    #13
  14. Jay

    Carl Banks Guest

    On Jul 2, 6:17 am, superpollo <> wrote:
    > Ethan Furman ha scritto:
    >
    >
    >
    > > Terry Reedy wrote:
    > >> On 7/1/2010 6:42 PM, Emile van Sebille wrote:

    >
    > >>> On 7/1/2010 2:52 PM Jay said...

    >
    > >>>> pywinauto looks to be almost perfect. All I need now is to read the
    > >>>> numbers uncovered when a minesweeper square is clicked on, or that I
    > >>>> just hit a mine.

    >
    > >>> ... or, you could always win...

    >
    > >>>http://www.daniweb.com/forums/thread186209.html

    >
    > >> Did you actually try it? Though skeptical, I did, briefly, until I
    > >> decided that it probably should have been dated April 1. There is no
    > >> way to enter text into minesweeper, nor to make it full screen, nor,
    > >> as far as I know, for it to toggle pixels outside its window.

    >
    > > The pixel can be hard to see depending on your background colors and
    > > whether your screen is adjusted correctly (I could see the white, but
    > > not the black).  But on XP Pro is still works.

    >
    > works for me too


    I'm confirming that it even works with Wine emulator in Linux.


    Carl Banks
     
    Carl Banks, Jul 2, 2010
    #14
  15. Jay

    Jay Guest

    On Jul 2, 2:13 pm, Terry Reedy <> wrote:
    > On 7/1/2010 10:18 PM, Emile van Sebille wrote:
    >
    >
    >
    >
    >
    > > On 7/1/2010 6:17 PM Terry Reedy said...
    > >> On 7/1/2010 6:42 PM, Emile van Sebille wrote:
    > >>> On 7/1/2010 2:52 PM Jay said...
    > >>>> pywinauto looks to be almost perfect. All I need now is to read the
    > >>>> numbers uncovered when a minesweeper square is clicked on, or that I
    > >>>> just hit a mine.

    >
    > >>> ... or, you could always win...

    >
    > >>>http://www.daniweb.com/forums/thread186209.html

    >
    > >> Did you actually try it? Though skeptical, I did, briefly, until I
    > >> decided that it probably should have been dated April 1. There is no way
    > >> to enter text into minesweeper, nor to make it full screen, nor, as far
    > >> as I know, for it to toggle pixels outside its window.

    >
    > > Yes. It works.

    >
    > Thanks all. I tried again with other windows minimized so that the upper
    > left pixel is medium brown from the wallpaper, and I can make out the
    > white pixel. A maximized unfocued background window has that pixel
    > normally black surrounded by light blue pixels that make one white pixel
    > harder to see for imperfect eyes.  Live, post errors, and learn ;-).
    >
    > --
    > Terry Jan Reedy- Hide quoted text -
    >
    > - Show quoted text -


    OK, so how does a program read the pixel?
     
    Jay, Jul 2, 2010
    #15
  16. On 7/2/2010 2:38 PM Jay said...
    >
    > OK, so how does a program read the pixel?


    Well, you start with a screen capture utility. I'd check is pywinauto
    provides that access...

    Emile
     
    Emile van Sebille, Jul 2, 2010
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KeiverH

    Minesweeper |BuscaMinas|

    KeiverH, May 7, 2005, in forum: C++
    Replies:
    0
    Views:
    951
    KeiverH
    May 7, 2005
  2. Heiko Wundram
    Replies:
    7
    Views:
    1,176
    Heiko Wundram
    Jul 15, 2004
  3. Terry Reedy
    Replies:
    2
    Views:
    447
    Heiko Wundram
    Jul 14, 2004
  4. Heiko Wundram
    Replies:
    2
    Views:
    448
    Heiko Wundram
    Jul 14, 2004
  5. Heiko Wundram
    Replies:
    1
    Views:
    420
    Matteo Dell'Amico
    Jul 23, 2004
Loading...

Share This Page