minesweeper/GetPixel()

Hi, I'm trying to write a program that plays a minesweeper game by itself. I
think I can write all of the code just fine, but I don't know how to have the
program realize which buttons are which in real time. I was thinking that I could just have it return the color of a certain pixel inside the button since the numbers have different colors. I tried using GetPixel(), but I don't know what exactly to #include, or what namespace to use. If someone could explain that or give me any other ideas that would be great! Thanks.

Here is my attempt for code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <cstdlib>
#include <Windows.h>
#using <mscorlib.dll>

using namespace std;
using namespace System;

void click(int x, int y)
{
	SetCursorPos(x, y);
	Sleep(50);
	mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
	mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
}
int main()
{
	click(1451, 13); //minimize
	//click(813, 373); //main app
	//click(834, 514); //center
	click(762, 455); //start
	// Get the color of a pixel within myBitmap.
	Color pixelColor = myBitmap->GetPixel(50, 50);
}
Last edited on
I'm sorry, i can't understand what myBitmap is and where is declared/defined...
it's just some code I found online, screwing around trying to figure something out. I have no idea how to use bitmap really.
Ok, as it is now, this code will not even compile, because there are a lot of function/member not declared anywhere.
I suggest to you to start reading how to get a pixel from the screen with the windows API, or how to catch the mouse input...
Not a direct answer to your question, but I've done a couple of similar stuff before and my experience is that it's much less painful to use Autoit instead of C/C++ for such tasks.

Some hints:

- You don't have to 'search' the desktop in order to locate the minesweeper window. Just manually place your mouse in ~ the middle of the top left block, and then use some PixelGetColor calls to detect the actual bounds of the block. Obviously, you need to also know the dimensions of a block in minesweeper in order to implement this correctly.

- If you don't want to have to find the exact pixel offsets you have to look at inside a block to decide its type, you can simply use PixelSearch on the whole block. For example, if you find a green pixel anywhere inside the block, it means it's a number 2 block. This approach will be slow, though. But it's easy to set up and you can always change it later.

Some useful links:

https://www.autoitscript.com/autoit3/docs/functions/HotKeySet.htm
https://www.autoitscript.com/autoit3/docs/functions/MouseGetPos.htm
https://www.autoitscript.com/autoit3/docs/functions/MouseClick.htm
https://www.autoitscript.com/autoit3/docs/functions/PixelGetColor.htm
https://www.autoitscript.com/autoit3/docs/functions/PixelSearch.htm
Topic archived. No new replies allowed.