Jump to content

Creating a numerical display for Tetris


Nedcim

Recommended Posts

I'm using the random game play of Tetris as a simplified approach to model more complicated systems. Instead of starting with zero rows of blocks, I start with nine rows as shown in the attached photo. Every game starts with a different degree of initial difficulty based on random starting position of each block and the placement of open spaces. I have a method for calculating this difficulty based on several factors. Each time a block falls and is put into position the difficultly level will change. I set ten sub-goals based when the difficulty level falls below a certain number. I want a numerical display to be able to track the time it takes to reach each sub-goal. I'm not sure how to enter the data from the game into a program to get an numerical output in real time. Any ideas?

 

post-125487-0-83820400-1491290648_thumb.png

 

Link to comment
Share on other sites

You should know how to do collision detection before you do this. You could for instance increase the speed of the blocks after each collision. Alternativel​y you could change the difficulty each time a new block is created. Just note that the original tetris game actually had an end and is not infinite. I dunno if the original tetris game was really random it wouldn't make sense if you randomly only got one type of block.

Edited by fiveworlds
Link to comment
Share on other sites

I want to use the data from the game in algorithm to output as a numerical display.That requires some type of onscreen reader that can convert the live game into data that can I can enter into any various programs.

Link to comment
Share on other sites

Okay so basically you want to hack tetris. You would need to screen grab and throw out useless data then work out the dimensions of the game. Then you would read the game's pixel data and note when a collision happened. Sounds like a lot of work much easier to just make tetris.

Link to comment
Share on other sites

I want to use the data from the game in algorithm to output as a numerical display.That requires some type of onscreen reader that can convert the live game into data that can I can enter into any various programs.

 

It's possible to make such application, which will be periodically screen-capturing specified window,

and then analyze pixel by pixel, received bitmap.

 

In C/C++, in Windows application, you can use GetDIBits function

https://msdn.microsoft.com/en-us/library/windows/desktop/dd144879(v=vs.85).aspx

Link to comment
Share on other sites

 

It's possible to make such application, which will be periodically screen-capturing specified window,

and then analyze pixel by pixel, received bitmap.

 

In C/C++, in Windows application, you can use GetDIBits function

https://msdn.microsoft.com/en-us/library/windows/desktop/dd144879(v=vs.85).aspx

I'd suggest you limit the area in the image your code had to analyse and use an ocr package. This is still going to be worse than finding an open source Tetris and getting it to extract what you need.

Link to comment
Share on other sites

I'd suggest you limit the area in the image your code had to analyse and use an ocr package. This is still going to be worse than finding an open source Tetris and getting it to extract what you need.

 

GetDIBits() function doesn't allow to specify which part of bitmap will be captured (just start row and height).

Programmer would have to make duplicate of device context (HDC) and/or bitmap (HBITMAP) first.

It takes HDC as argument (which will be returned by, enumeration of windows (EnumWindows()) present in the desktop, and then GetDC() (or copy of it))

So it'll be already truncated to size of HWND window it belongs to (from screen-shot OP provided, playfield to analyze is significant area of window).

 

OCR? Optical Character Recognition?

There is no characters to recognize in Tetris game playfield.. Just blocks with different colors.

 

Once you have bitmap or device context, one can use GetPixel()

https://msdn.microsoft.com/en-us/library/windows/desktop/dd144909(v=vs.85).aspx

to read pixel color, as COLORREF structure.

If it's black, no block is present in specified location.

Edited by Sensei
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.