Nedcim Posted April 4, 2017 Share Posted April 4, 2017 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? Link to comment Share on other sites More sharing options...
fiveworlds Posted April 4, 2017 Share Posted April 4, 2017 (edited) 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. Alternatively 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 April 4, 2017 by fiveworlds Link to comment Share on other sites More sharing options...
Nedcim Posted April 5, 2017 Author Share Posted April 5, 2017 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 More sharing options...
Endy0816 Posted April 5, 2017 Share Posted April 5, 2017 Easiest way would be to change the game program to provide it for you. Otherwise would have to look into screen scraping software. Link to comment Share on other sites More sharing options...
fiveworlds Posted April 5, 2017 Share Posted April 5, 2017 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 More sharing options...
Sensei Posted April 5, 2017 Share Posted April 5, 2017 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 More sharing options...
Klaynos Posted April 5, 2017 Share Posted April 5, 2017 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 More sharing options...
Sensei Posted April 5, 2017 Share Posted April 5, 2017 (edited) 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 April 5, 2017 by Sensei Link to comment Share on other sites More sharing options...
Klaynos Posted April 5, 2017 Share Posted April 5, 2017 I was thinking if you knew the lines and score you could work it out. But I now think I'm wrong. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now