Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple scan instructions, only first one works.
#1
Hello,

I wrote a macro that searches a chess board (here an example from lichess.org, because of lack of other at the moment) and determines the coordinates (which I'll make it pair with the positions A1->H8 in a later phaze) and the number of said pieces.

It has an output of the coordinates and the number of pieces for each piece type.

When I comment out all scan instructions, but one, it works fine for the one enabled. It doesn't matter which one, as long as I have the rest commented out. When I have 2 or more not commented out, it will only scan the first one.

For example:

If I only scan for the black pawns:

Code:
Copy      Help
scan("$desktop$\lichess\Pawn_Black6.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 BP) ;;Scan for the postions of the black pawns.

Will output:

Quote:White Pawn coordinates
Total=0
Black Pawn coordinates
left=524 top=305 right=539 bottom=339
left=588 top=305 right=603 bottom=339
left=652 top=305 right=667 bottom=339
left=716 top=305 right=731 bottom=339
left=780 top=305 right=795 bottom=339
left=844 top=305 right=859 bottom=339
left=908 top=305 right=923 bottom=339
left=972 top=305 right=987 bottom=339
Total=8
White Knight coordinates
Total=0
Black Knight coordinates
Total=0
White Bishop coordinates
Total=0
Black Bishop coordinates
Total=0
White Rook coordinates
Total=0
Black Rook coordinates
Total=0
White Queen coordinates
Total=0
Black Queen coordinates
Total=0
White King coordinates
Total=0
Black King coordinates
Total=0

Which is what I expect. Only a result for the black pawns.

However,

If I do this:

Code:
Copy      Help
scan("$desktop$\lichess\Pawn_White.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 WP) ;;Scan for the postions of the white pawns.
scan("$desktop$\lichess\Pawn_Black6.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 BP) ;;Scan for the postions of the black pawns.

While having the other scan instruction commented out, the output is:

Quote:White Pawn coordinates
left=528 top=615 right=535 bottom=658
left=592 top=615 right=599 bottom=658
left=656 top=615 right=663 bottom=658
left=720 top=615 right=727 bottom=658
left=784 top=615 right=791 bottom=658
left=848 top=615 right=855 bottom=658
left=912 top=615 right=919 bottom=658
left=976 top=615 right=983 bottom=658
Total=8
Black Pawn coordinates
Total=0
White Knight coordinates
Total=0
Black Knight coordinates
Total=0
White Bishop coordinates
Total=0
Black Bishop coordinates
Total=0
White Rook coordinates
Total=0
Black Rook coordinates
Total=0
White Queen coordinates
Total=0
Black Queen coordinates
Total=0
White King coordinates
Total=0
Black King coordinates
Total=0

A result for the white pawns, but no result for the black pawns as if they were never scanned. This goes for all other scan instructions as well.

Any idea how I could solve this? Is it possible to bypass this issue by creating a function for this scan? If so, how do I do this?

Thanks a lot in advance.

EDIT:

My OS: Windows 7 Home Premium, Service Pack 1.
QM version: 2.4.3.4



Here is the full code (with all scan instructions enabled):

Macro method2
Code:
Copy      Help
;Empty Spot=1, White Pawn=2, Black Pawn=4, White Knight=8, Black Knight=16, White Bishop=32, Black Bishop=64, White Rook=128, Black Rook=256, White Queen=512, Black Queen=1024, witteWhite King=2048, Black King=4096 -> This has its use for later
int w1=act(win("Board editor • lichess.org - Mozilla Firefox" "MozillaWindowClass"))
ARRAY(RECT) WP ;;Array for coordniates of white pawns.
ARRAY(RECT) BP ;;Array for coordniates of black pawns.
ARRAY(RECT) WN ;;Array for coordniates of white knights.
ARRAY(RECT) BN ;;Array for coordniates of black knights.
ARRAY(RECT) WB ;;Array for coordniates of white bishops.
ARRAY(RECT) BB ;;Array for coordniates of black bishops.
ARRAY(RECT) WR ;;Array for coordniates of white rooks.
ARRAY(RECT) BR ;;Array for coordniates of black rooks.
ARRAY(RECT) WQ ;;Array for coordniates of white queens.
ARRAY(RECT) BQ ;;Array for coordniates of black queens.
ARRAY(RECT) WK ;;Array for coordniates of white king.
ARRAY(RECT) BK ;;Array for coordniates of black king.
int bigleft
int bigtop
int bigright
int bigbottom
bigleft=500 ;;left x coordinate chess board.
bigtop=225 ;;top y coordinate chess board.
bigright=1012 ;;right x coordinate chess board.
bigbottom=737 ;;bottom y coordinate chess board.
RECT q ;;This rectengular will equal the dimensions and position of the chess board.
q.left=bigleft
q.top=bigtop
q.right=bigright
q.bottom=bigbottom
RECT NWP ;;individual coordniates of white pawns.
RECT NBP ;;individual coordniates of black pawns.
RECT NWN ;;individual coordniates of white knights.
RECT NBN ;;individual coordniates of black knights.
RECT NWB ;;individual coordniates of white bishops.
RECT NBB ;;individual coordniates of black bishops.
RECT NWR ;;individual coordniates of white rooks.
RECT NBR ;;individual coordniates of black rooks.
RECT NWQ ;;individual coordniates of white queens.
RECT NBQ ;;individual coordniates of black queens.
RECT NWK ;;individual coordniates of white king.
RECT NBK ;;individual coordniates of black king.
scan("$desktop$\lichess\Pawn_White.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 WP) ;;Scan for the postions of the white pawns.
scan("$desktop$\lichess\Pawn_Black6.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 BP) ;;Scan for the postions of the black pawns.
scan("$desktop$\lichess\Knight_White.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 WN) ;;Scan for the postions of the white knights.
scan("$desktop$\lichess\Knight_Black.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 BN) ;;Scan for the postions of the black knights.
scan("$desktop$\lichess\Bishop_White.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 WB) ;;Scan for the postions of the white bishops.
scan("$desktop$\lichess\Bishop_Black.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 BB) ;;Scan for the postions of the black bishops.
scan("$desktop$\lichess\Rook_White2.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 WR) ;;Scan for the postions of the white rooks.
scan("$desktop$\lichess\Rook_Black2.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 BR) ;;Scan for the postions of the black rooks.
scan("$desktop$\lichess\Queen_White.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 WQ) ;;Scan for the postions of the white queens.
scan("$desktop$\lichess\Queen_Black.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 BQ) ;;Scan for the postions of the black queens.
scan("$desktop$\lichess\King_White.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 WK) ;;Scan for the postion of the white king.
scan("$desktop$\lichess\King_Black.bmp" "Board editor • lichess.org - Mozilla Firefox" q 1 20 BK) ;;Scan for the postions of the black king.
out "White Pawn coordinates";;output coordinates of white pawns and total number.
int A
for A 0 WP.len
,NWP=WP[A]
,out "left=%i top=%i right=%i bottom=%i" NWP.left NWP.top NWP.right NWP.bottom
out "Total=%i" A
WP.redim
out "Black Pawn coordinates";;output coordinates of Black pawns and total number.
int B
for B 0 BP.len
,NBP=BP[B]
,out "left=%i top=%i right=%i bottom=%i" NBP.left NBP.top NBP.right NBP.bottom
out "Total=%i" B
BP.redim
out "White Knight coordinates";;output coordinates of white knights and total number.
int C
for C 0 WN.len
,NWN=WN[C]
,out "left=%i top=%i right=%i bottom=%i" NWN.left NWN.top NWN.right NWN.bottom
out "Total=%i" C
WN.redim
out "Black Knight coordinates";;output coordinates of black knights and total number.
int D
for D 0 BN.len
,NBN=BN[D]
,out "left=%i top=%i right=%i bottom=%i" NBN.left NBN.top NBN.right NBN.bottom
out "Total=%i" D
BN.redim
out "White Bishop coordinates";;output coordinates of white bishops and total number.
int E
for E 0 WB.len
,NWB=WB[E]
,out "left=%i top=%i right=%i bottom=%i" NWB.left NWB.top NWB.right NWB.bottom
out "Total=%i" E
WB.redim
out "Black Bishop coordinates";;output coordinates of black bishops and total number.
int F
for F 0 BB.len
,NBB=BB[F]
,out "left=%i top=%i right=%i bottom=%i" NBB.left NBB.top NBB.right NBB.bottom
out "Total=%i" F
BB.redim
out "White Rook coordinates";;output coordinates of white rooks and total number.
int G
for G 0 WR.len
,NWR=WR[G]
,out "left=%i top=%i right=%i bottom=%i" NWR.left NWR.top NWR.right NWR.bottom
out "Total=%i" G
WR.redim
out "Black Rook coordinates";;output coordinates of black rooks and total number.
int H
for H 0 BR.len
,NBR=BR[H]
,out "left=%i top=%i right=%i bottom=%i" NBR.left NBR.top NBR.right NBR.bottom
out "Total=%i" H
BP.redim
out "White Queen coordinates";;output coordinates of white queens and total number.
int I
for I 0 WQ.len
,NWQ=WQ[I]
,out "left=%i top=%i right=%i bottom=%i" NWQ.left NWQ.top NWQ.right NWQ.bottom
out "Total=%i" I
WQ.redim
out "Black Queen coordinates";;output coordinates of black queens and total number.
int J
for J 0 BQ.len
,NBQ=BQ[J]
,out "left=%i top=%i right=%i bottom=%i" NBQ.left NBQ.top NBQ.right NBQ.bottom
out "Total=%i" J
BQ.redim
out "White King coordinates";;output coordinates of white king and total number. Total number should obviously be "1".
int K
for K 0 WK.len
,NWK=WK[K]
,out "left=%i top=%i right=%i bottom=%i" NWK.left NWK.top NWK.right NWK.bottom
out "Total=%i" K
WK.redim
out "Black King coordinates";;output coordinates of black king and total number. Total number should obviously be "1".
int L
for L 0 BK.len
,NBK=BK[L]
,out "left=%i top=%i right=%i bottom=%i" NBK.left NBK.top NBK.right NBK.bottom
out "Total=%i" L
BK.redim

And the a cropped screenshot of the chess board:

[Image: SZQRo22.png]
#2
scan overwrites q. Set q before each scan call. Create a function, then will be less code.

Macro Macro2759
Code:
Copy      Help
;...
int w=win("Board editor • lichess.org - Mozilla Firefox")
sub.Scan(w "Pawn_White" WP) ;;Scan for the postions of the white pawns.
sub.Scan(w "Pawn_Black6" BP) ;;Scan for the postions of the black pawns.
;...


#sub Scan
function hwnd $image ARRAY(RECT)&a

RECT q ;;This rectengular will equal the dimensions and position of the chess board.
SetRect &q 500 225 1012 737
scan(F"$desktop$\lichess\{image}.bmp" hwnd q 1 20 a)
#3
Thanks, it works Smile

Another question:

How would a function/sub for the

Macro method2
Code:
Copy      Help
out "White Pawn coordinates";;output coordinates of white pawns and total number.
int A
for A 0 WP.len
,NWP=WP[A]
,out "left=%i top=%i right=%i bottom=%i" NWP.left NWP.top NWP.right NWP.bottom
out "Total=%i" A
WP.redim
out "Black Pawn coordinates";;output coordinates of Black pawns and total number.
int B
for B 0 BP.len
,NBP=BP[B]
,out "left=%i top=%i right=%i bottom=%i" NBP.left NBP.top NBP.right NBP.bottom
out "Total=%i" B
BP.redim
out "White Knight coordinates";;output coordinates of white knights and total number.
int C
for C 0 WN.len
,NWN=WN[C]
,out "left=%i top=%i right=%i bottom=%i" NWN.left NWN.top NWN.right NWN.bottom
out "Total=%i" C
WN.redim
out "Black Knight coordinates";;output coordinates of black knights and total number.
int D
for D 0 BN.len
,NBN=BN[D]
,out "left=%i top=%i right=%i bottom=%i" NBN.left NBN.top NBN.right NBN.bottom
out "Total=%i" D
BN.redim
out "White Bishop coordinates";;output coordinates of white bishops and total number.
int E
for E 0 WB.len
,NWB=WB[E]
,out "left=%i top=%i right=%i bottom=%i" NWB.left NWB.top NWB.right NWB.bottom
out "Total=%i" E
WB.redim
out "Black Bishop coordinates";;output coordinates of black bishops and total number.
int F
for F 0 BB.len
,NBB=BB[F]
,out "left=%i top=%i right=%i bottom=%i" NBB.left NBB.top NBB.right NBB.bottom
out "Total=%i" F
BB.redim
out "White Rook coordinates";;output coordinates of white rooks and total number.
int G
for G 0 WR.len
,NWR=WR[G]
,out "left=%i top=%i right=%i bottom=%i" NWR.left NWR.top NWR.right NWR.bottom
out "Total=%i" G
WR.redim
out "Black Rook coordinates";;output coordinates of black rooks and total number.
int H
for H 0 BR.len
,NBR=BR[H]
,out "left=%i top=%i right=%i bottom=%i" NBR.left NBR.top NBR.right NBR.bottom
out "Total=%i" H
BP.redim
out "White Queen coordinates";;output coordinates of white queens and total number.
int I
for I 0 WQ.len
,NWQ=WQ[I]
,out "left=%i top=%i right=%i bottom=%i" NWQ.left NWQ.top NWQ.right NWQ.bottom
out "Total=%i" I
WQ.redim
out "Black Queen coordinates";;output coordinates of black queens and total number.
int J
for J 0 BQ.len
,NBQ=BQ[J]
,out "left=%i top=%i right=%i bottom=%i" NBQ.left NBQ.top NBQ.right NBQ.bottom
out "Total=%i" J
BQ.redim
out "White King coordinates";;output coordinates of white king and total number. Total number should obviously be "1".
int K
for K 0 WK.len
,NWK=WK[K]
,out "left=%i top=%i right=%i bottom=%i" NWK.left NWK.top NWK.right NWK.bottom
out "Total=%i" K
WK.redim
out "Black King coordinates";;output coordinates of black king and total number. Total number should obviously be "1".
int L
for L 0 BK.len
,NBK=BK[L]
,out "left=%i top=%i right=%i bottom=%i" NBK.left NBK.top NBK.right NBK.bottom
out "Total=%i" L
BK.redim

part look like?
#4
Add this code at the end of sub Scan code:
Macro Macro2759
Code:
Copy      Help
out F"{image} coordinates"
int i
for i 0 a.len
,RECT& r=a[i]
,out "left=%i top=%i right=%i bottom=%i" r.left r.top r.right r.bottom
out "Total=%i" i

and delete all that part of macro code.
#5
Thanks.


Forum Jump:


Users browsing this thread: 1 Guest(s)