Jump to content
Dicaste

ChessBOT

Recommended Posts

Firstly Hi;

I wrote some script for Aquariaum Chess GUI(Graphical User Interface). Actually its working but i have some problems with "MoveWindMouseEx" :(.

 

15Ien.png

 

As you see codes working fine. I want to use "Move" variable.

 

Move := 'E2E4';

WriteLn('File'+Left(GetLetters(Move),1));
WriteLn('Rank'+Left(GetNumbers(Move),1));
WriteLn('File'+Right(GetLetters(Move),1));
WriteLn('Rank'+Right(GetNumbers(Move),1));

 

Outputs: FileE, Rank2, FileE, Rank4 working fine but in MoveWindMouseEx No.

 

MoveWindMouseEx('File'+Left(GetLetters(Move),1),'Rank'+Left(GetNumbers(Move),1),0,0,10); <-- This code is not working. I tried everyting i can. Converting is not solution or i couldnt :D

 

Thanks for help.

 

Regards Dicaste.

15Ien.png

Link to comment
Share on other sites

MoveWindMouseEx works with coordinates, whereas you are trying to input strings (text) to it.. That's why it is not working.

 

Solution: create a TBoxArray of those chess slots, with it you can click the correct slots.

 

This is what I am talking about:

 

[scar]const

START_X = 999; // REPLACE with real X-coordinate. (RED PIXEL)

START_Y = 999; // REPLACE with real Y-coordinate. (RED PIXEL)

 

var

ChessSlots: T2DBoxArray;

 

function BoxCenter(bx: TBox): TPoint;

begin

if (bx.X1 > bx.X2) or (bx.Y1 > bx.Y2) then

Exit;

Result.X := Round(bx.X1 + (bx.X2 - bx.X1) / 2);

Result.Y := Round(bx.Y1 + (bx.Y2 - bx.Y1) / 2);

end;

 

function BoxToStr(bx: TBox): string;

begin

Result := (IntToStr(bx.X1) + ', ' + IntToStr(bx.Y1) + ', ' +

IntToStr(bx.X2) + ', ' + IntToStr(bx.Y2));

end;

 

function BuildChessSlots: T2DBoxArray;

var

id, r, c: Integer;

begin

SetLength(Result, 8);

for r := 0 to 7 do

begin

SetLength(Result[r], 8);

for c := 0 to 7 do

begin

id := ((r * 8) + c); // 8 = Columns

Result[r][c].X1 := START_X + ((id mod 8) * 79); // 8 = Columns ... 79 = Chess slot WIDTH + 1.

Result[r][c].Y1 := START_Y + ((id div 8) * 79); // 8 = Columns ... 79 = Chess slot HEIGHT + 1.

Result[r][c].X2 := (START_X + ((id mod 8) * 79) + 78); // 8 = Columns ... 79 = Chess slot WIDTH + 1 ... 78 = Chess slot WIDTH.

Result[r][c].Y2 := (START_Y + ((id div 8) * 79) + 78); // 8 = Columns ... 79 = Chess slot HEIGHT + 1 ... 78 = Chess slot HEIGHT.

end;

end;

end;

 

function GetChessSlot(chessRow: Integer; chessColumn: char): TBox;

var

oC: Integer;

begin

oC := Ord(chessColumn);

if not InRange(chessRow, 1, 8) or not InRange(oC, 97, 104) then

Exit;

Result := ChessSlots[(8 - chessRow)][(104 - oC)];

end;

 

procedure PrintChessSlots;

var

r, c: Integer;

chessColumns: array of Char;

chessRows: TIntArray;

begin

chessColumns := ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];

chessRows := [8, 7, 6, 5, 4, 3, 2, 1];

for r := 0 to 7 do

for c := 0 to 7 do

WriteLn(chessColumns[c] + IntToStr(chessRows[r]) + ' AREA: ' + BoxToStr(GetChessSlot(chessRows[r], chessColumns[c])));

SetLength(chessColumns, 0);

SetLength(chessRows, 0);

end;

 

begin

ClearDebug;

ChessSlots := BuildChessSlots;

PrintChessSlots;

SetLength(ChessSlots, 0);

end.[/scar]

 

Look at where the GREEN arrow is pointing to, there is the location of START_X and START_Y (coordinates), that RED pixel of the image (AND PICK THAT VERY SAME PIXEL, it must be exactly SAME):

 

l0lfh.png

Edited by Janilabo
Link to comment
Share on other sites

MoveWindMouseEx works with coordinates, whereas you are trying to input strings (text) to it.. That's why it is not working.

 

Solution: create a TBoxArray of those chess slots, with it you can click the correct slots.

 

This is what I am talking about:

 

[scar]const

START_X = 999; // REPLACE with real X-coordinate. (RED PIXEL)

START_Y = 999; // REPLACE with real Y-coordinate. (RED PIXEL)

 

var

ChessSlots: T2DBoxArray;

 

function BoxCenter(bx: TBox): TPoint;

begin

if (bx.X1 > bx.X2) or (bx.Y1 > bx.Y2) then

Exit;

Result.X := Round(bx.X1 + (bx.X2 - bx.X1) / 2);

Result.Y := Round(bx.Y1 + (bx.Y2 - bx.Y1) / 2);

end;

 

function BoxToStr(bx: TBox): string;

begin

Result := (IntToStr(bx.X1) + ', ' + IntToStr(bx.Y1) + ', ' +

IntToStr(bx.X2) + ', ' + IntToStr(bx.Y2));

end;

 

function BuildChessSlots: T2DBoxArray;

var

id, r, c: Integer;

begin

SetLength(Result, 8);

for r := 0 to 7 do

begin

SetLength(Result[r], 8);

for c := 0 to 7 do

begin

id := ((r * 8) + c); // 8 = Columns

Result[r][c].X1 := START_X + ((id mod 8) * 79); // 8 = Columns ... 79 = Chess slot WIDTH + 1.

Result[r][c].Y1 := START_Y + ((id div 8) * 79); // 8 = Columns ... 79 = Chess slot HEIGHT + 1.

Result[r][c].X2 := (START_X + ((id mod 8) * 79) + 78); // 8 = Columns ... 79 = Chess slot WIDTH + 1 ... 78 = Chess slot WIDTH.

Result[r][c].Y2 := (START_Y + ((id div 8) * 79) + 78); // 8 = Columns ... 79 = Chess slot HEIGHT + 1 ... 78 = Chess slot HEIGHT.

end;

end;

end;

 

function GetChessSlot(chessRow: Integer; chessColumn: char): TBox;

var

oC: Integer;

begin

oC := Ord(chessColumn);

if not InRange(chessRow, 1, 8) or not InRange(oC, 97, 104) then

Exit;

Result := ChessSlots[(8 - chessRow)][(104 - oC)];

end;

 

procedure PrintChessSlots;

var

r, c: Integer;

chessColumns: array of Char;

chessRows: TIntArray;

begin

chessColumns := ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];

chessRows := [8, 7, 6, 5, 4, 3, 2, 1];

for r := 0 to 7 do

for c := 0 to 7 do

WriteLn(chessColumns[c] + IntToStr(chessRows[r]) + ' AREA: ' + BoxToStr(GetChessSlot(chessRows[r], chessColumns[c])));

end;

 

begin

ClearDebug;

ChessSlots := BuildChessSlots;

PrintChessSlots;

SetLength(ChessSlots, 0);

end.[/scar]

 

Look at where the GREEN arrow is pointing to, there is the location of START_X and START_Y (coordinates), that RED pixel of the image (AND PICK THAT VERY SAME PIXEL, it must be exactly SAME):

 

l0lfh.png

 

Wow, this code is amazing. I use change client button better :D. Thanks for helping.

 

---------- Post added at 11:14 AM ---------- Previous post was at 11:04 AM ----------

 

How can i get square center ? I'm looked and tried but i cant get A1 square center and how i can move my mouse to center ? Thanks.

 

---------- Post added at 11:18 AM ---------- Previous post was at 11:14 AM ----------

 

My code:

 

[sCAR]

program ChessBOT;

 

var

LeftX, LeftY, RightX, RightY, CenterX, CenterY: Integer;

FileA, FileB, FileC, FileD, FileE, FileF, FileG, FileH: Integer;

Rank1, Rank2, Rank3, Rank4, Rank5, Rank6, Rank7, Rank8: Integer;

SquareX, SquareY: Integer;

Timer: Integer;

MouseX, MouseY: Integer;

MouseSpeed1, MouseSpeed2: Integer;

Move: String;

 

begin;

 

GetClientDimensions(RightX, RightY);

RightX := RightX;

RightY := RightY;

LeftX := 0;

LeftY := 0;

CenterX := (LeftX + RightX) div 2;

CenterY := (LeftY + RightY) div 2;

SquareX := (LeftX + RightX) div 16;

SquareY := (LeftX + RightX) div 16;

Timer := 1000;

MouseSpeed1 := 15;

MouseSpeed2 := 10;

 

FileA := CenterX div 8;

FileB := FileA + (SquareY * 2);

FileC := FileA + (SquareX * 4);

FileD := FileA + (SquareX * 6);

FileE := FileA + (SquareX * 8);

FileF := FileA + (SquareX * 10);

FileG := FileA + (SquareX * 12);

FileH := FileA + (SquareX * 14);

Rank1 := Rank8 - (SquareY * -15);

Rank2 := Rank8 - (SquareY * -13);

Rank3 := Rank8 - (SquareY * -11);

Rank4 := Rank8 - (SquareY * -9);

Rank5 := Rank8 - (SquareY * -7);

Rank6 := Rank8 - (SquareY * -5);

Rank7 := Rank8 - (SquareY * -3);

Rank8 := CenterY div 8;

 

 

Move := 'E2E4';

 

WriteLn('File'+Left(GetLetters(Move),1));

WriteLn('Rank'+Left(GetNumbers(Move),1));

WriteLn('File'+Right(GetLetters(Move),1));

WriteLn('Rank'+Right(GetNumbers(Move),1));

 

// Wait a second.

Wait(Timer);

 

// E2 to E4

MoveWindMouseEx(FileE,Rank2,0,0,MouseSpeed1);

GetMousePos(MouseX,MouseY);

HoldMouse(MouseX,MouseY,True);

MoveWindMouseEx(FileE,Rank4,0,0,MouseSpeed2);

GetMousePos(MouseX,MouseY);

ReleaseMouse(MouseX,MouseY,True);

 

end.

 

[/scar]

Edited by Dicaste
Link to comment
Share on other sites

Would this work? :)

 

[scar]program ChessBOT;

 

type

TChessSlot = record

row: Integer;

column: Char;

end;

 

const

TIMER = 1000;

MOUSE_SPEED1 = 15;

MOUSE_SPEED2 = 10;

 

var

CLIENT_W, CLIENT_H: Integer;

START_X, START_Y: Integer;

ChessSlots: T2DBoxArray;

 

function BoxCenter(bx: TBox): TPoint;

begin

if (bx.X1 > bx.X2) or (bx.Y1 > bx.Y2) then

Exit;

Result.X := Round(bx.X1 + (bx.X2 - bx.X1) / 2);

Result.Y := Round(bx.Y1 + (bx.Y2 - bx.Y1) / 2);

end;

 

function BoxToStr(bx: TBox): string;

begin

Result := (IntToStr(bx.X1) + ', ' + IntToStr(bx.Y1) + ', ' +

IntToStr(bx.X2) + ', ' + IntToStr(bx.Y2));

end;

 

function BuildChessSlots: T2DBoxArray;

var

id, r, c: Integer;

begin

SetLength(Result, 8);

for r := 0 to 7 do

begin

SetLength(Result[r], 8);

for c := 0 to 7 do

begin

id := ((r * 8) + c); // 8 = Columns

Result[r][c].X1 := START_X + ((id mod 8) * 79);

Result[r][c].Y1 := START_Y + ((id div 8) * 79);

Result[r][c].X2 := (START_X + ((id mod 8) * 79) + 78);

Result[r][c].Y2 := (START_Y + ((id div 8) * 79) + 78);

end;

end;

end;

 

function GetChessSlot(chessRow: Integer; chessColumn: Char): TBox;

var

oC: Integer;

begin

oC := Ord(chessColumn);

if not InRange(chessRow, 1, 8) or not InRange(oC, 97, 104) then

Exit;

Result := ChessSlots[(8 - chessRow)][(104 - oC)];

end;

 

procedure PrintChessSlots;

var

r, c: Integer;

chessColumns: array of Char;

chessRows: TIntArray;

begin

chessColumns := ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];

chessRows := [8, 7, 6, 5, 4, 3, 2, 1];

for r := 0 to 7 do

for c := 0 to 7 do

WriteLn(chessColumns[c] + IntToStr(chessRows[r]) + ' AREA: ' + BoxToStr(GetChessSlot(chessRows[r], chessColumns[c])));

SetLength(chessColumns, 0);

SetLength(chessRows, 0);

end;

 

function ChessSlot(column: Char; row: Integer): TChessSlot;

begin

Result.column := column;

Result.row := row;

end;

 

procedure MakeAMove(fromSlot: TChessSlot; toSlot: TChessSlot);

var

moveStartPt, moveFinishPt: TPoint;

x, y: Integer;

begin

moveStartPt := BoxCenter(GetChessSlot(fromSlot.row, fromSlot.column));

moveFinishPt := BoxCenter(GetChessSlot(toSlot.row, toSlot.column));

MoveMouseSmooth(moveStartPt.X + RandomRange(-9, 9), moveStartPt.Y + RandomRange(-9, 9));

GetMousePos(x, y);

HoldMouse(x, y, True);

MoveMouseSmooth(moveFinishPt.X + RandomRange(-9, 9), moveFinishPt.Y + RandomRange(-9, 9));

GetMousePos(x, y);

ReleaseMouse(x, y, True);

end;

 

begin;

ClearDebug;

GetClientDimensions(CLIENT_W, CLIENT_H);

ActivateClient;

if not FindColor(START_X, START_Y, 11590641, 0, 0, (CLIENT_W - 1), (CLIENT_H - 1)) then

Exit;

Wait(TIMER);

ChessSlots := BuildChessSlots;

WriteLn('*** BUILT CHESS TABLE ***');

PrintChessSlots;

WriteLN('*** BUILT CHESS TABLE ***');

{ E2 to E4 }

MakeAMove(ChessSlot('e', 2), ChessSlot('e', 4));

{ E2 to E4 }

SetLength(ChessSlots, 0);

end.[/scar]

 

I improved the code, you no longer pick the start coordinate manually.. It will be picked AUTOMATICALLY using FindColor method. :)

Enjoy!

 

-Jani

Edited by Janilabo
UPDATE, UPDATE!
  • Confused 1
Link to comment
Share on other sites

Would this work? :)

 

[scar]

program ChessBOT;

 

type

TChessSlot = record

row: Integer;

column: Char;

end;

 

const

TIMER = 1000;

MOUSE_SPEED1 = 15;

MOUSE_SPEED2 = 10;

 

var

CLIENT_W, CLIENT_H: Integer;

START_X, START_Y: Integer;

ChessSlots: T2DBoxArray;

 

function BoxCenter(bx: TBox): TPoint;

begin

if (bx.X1 > bx.X2) or (bx.Y1 > bx.Y2) then

Exit;

Result.X := Round(bx.X1 + (bx.X2 - bx.X1) / 2);

Result.Y := Round(bx.Y1 + (bx.Y2 - bx.Y1) / 2);

end;

 

function BoxToStr(bx: TBox): string;

begin

Result := (IntToStr(bx.X1) + ', ' + IntToStr(bx.Y1) + ', ' +

IntToStr(bx.X2) + ', ' + IntToStr(bx.Y2));

end;

 

function BuildChessSlots: T2DBoxArray;

var

id, r, c: Integer;

begin

SetLength(Result, 8);

for r := 0 to 7 do

begin

SetLength(Result[r], 8);

for c := 0 to 7 do

begin

id := ((r * 8) + c); // 8 = Columns

Result[r][c].X1 := START_X + ((id mod 8) * 79);

Result[r][c].Y1 := START_Y + ((id div 8) * 79);

Result[r][c].X2 := (START_X + ((id mod 8) * 79) + 78);

Result[r][c].Y2 := (START_Y + ((id div 8) * 79) + 78);

end;

end;

end;

 

function GetChessSlot(chessRow: Integer; chessColumn: Char): TBox;

var

oC: Integer;

begin

oC := Ord(chessColumn);

if not InRange(chessRow, 1, 8) or not InRange(oC, 97, 104) then

Exit;

Result := ChessSlots[(8 - chessRow)][(104 - oC)];

end;

 

procedure PrintChessSlots;

var

r, c: Integer;

chessColumns: array of Char;

chessRows: TIntArray;

begin

chessColumns := ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];

chessRows := [8, 7, 6, 5, 4, 3, 2, 1];

for r := 0 to 7 do

for c := 0 to 7 do

WriteLn(chessColumns[c] + IntToStr(chessRows[r]) + ' AREA: ' + BoxToStr(GetChessSlot(chessRows[r], chessColumns[c])));

SetLength(chessColumns, 0);

SetLength(chessRows, 0);

end;

 

function ChessSlot(column: Char; row: Integer): TChessSlot;

begin

Result.column := column;

Result.row := row;

end;

 

procedure MakeAMove(fromSlot: TChessSlot; toSlot: TChessSlot);

var

moveStartPt, moveFinishPt: TPoint;

x, y: Integer;

begin

moveStartPt := BoxCenter(GetChessSlot(fromSlot.row, fromSlot.column));

moveFinishPt := BoxCenter(GetChessSlot(toSlot.row, toSlot.column));

MoveMouseSmooth(moveStartPt.X + RandomRange(-9, 9), moveStartPt.Y + RandomRange(-9, 9));

GetMousePos(x, y);

HoldMouse(x, y, True);

MoveMouseSmooth(moveFinishPt.X + RandomRange(-9, 9), moveFinishPt.Y + RandomRange(-9, 9));

GetMousePos(x, y);

ReleaseMouse(x, y, True);

end;

 

begin;

ClearDebug;

GetClientDimensions(CLIENT_W, CLIENT_H);

ActivateClient;

if not FindColor(START_X, START_Y, 11590641, 0, 0, (CLIENT_W - 1), (CLIENT_H - 1)) then

Exit;

Wait(TIMER);

ChessSlots := BuildChessSlots;

WriteLn('*** BUILT CHESS TABLE ***');

PrintChessSlots;

WriteLN('*** BUILT CHESS TABLE ***');

{ E2 to E4 }

MakeAMove(ChessSlot('e', 2), ChessSlot('e', 4));

{ E2 to E4 }

SetLength(ChessSlots, 0);

end.[/scar]

 

I improved the code, you no longer pick the start coordinate manually.. It will be picked AUTOMATICALLY using FindColor method. :)

Enjoy!

 

-Jani

 

Its working well. I love it and i have changed codes too. :D

 

[scar]

program ChessBOT;

 

var

LColor: Integer;

LeftX, LeftY, RightX, RightY, CenterX, CenterY: LongINT;

SquareX, SquareY: Integer;

FileA, FileB, FileC, FileD, FileE, FileF, FileG, FileH: LongINT;

Rank1, Rank2, Rank3, Rank4, Rank5, Rank6, Rank7, Rank8: LongINT;

MouseX, MouseY: Integer;

 

begin

 

LColor := 11590641;

 

if FindColor(MouseX,MouseY,LColor,LeftX,LeftY,RightX,RightY) then

begin

LeftX := MouseX;

LeftY := MouseY;

end;

 

GetClientDimensions(RightX,RightY);

CenterX := (LeftX + RightX) div 2;

CenterY := (LeftY + RightY) div 2;

 

MoveMouse(CenterX,CenterY);

 

SquareX := (CenterX div 8) - LeftX;

SquareY := (CenterY div 8) + LeftY;

 

FileA := CenterX div 8;

Rank8 := CenterY div 8;

 

FileB := FileA + (SquareX * 2);

FileC := FileA + (SquareX * 4);

FileD := FileA + (SquareX * 6);

FileE := FileA + (SquareX * 8);

FileF := FileA + (SquareX * 10);

FileG := FileA + (SquareX * 12);

FileH := FileA + (SquareX * 14);

 

Rank8 := CenterY div 8;

Rank7 := Rank8 + (SquareY * 2);

Rank6 := Rank8 + (SquareY * 4);

Rank5 := Rank8 + (SquareY * 6);

Rank4 := Rank8 + (SquareY * 8);

Rank3 := Rank8 + (SquareY * 10);

Rank2 := Rank8 + (SquareY * 12);

Rank1 := Rank8 + (SquareY * 14);

 

MoveMouse(FileE,Rank2);

GetMousePos(MouseX,MouseY);

HoldMouse(MouseX,MouseY,True);

MoveMouse(FileE,Rank4);

GetMousePos(MouseX,MouseY);

ReleaseMouse(MouseX,MouseY,True);

 

Wait(1000);

 

MoveMouse(FileC,Rank7);

GetMousePos(MouseX,MouseY);

HoldMouse(MouseX,MouseY,True);

MoveMouse(FileC,Rank5);

GetMousePos(MouseX,MouseY);

ReleaseMouse(MouseX,MouseY,True);

 

end.

[/scar]

 

---------- Post added at 03:12 PM ---------- Previous post was at 03:03 PM ----------

 

Oh there is a some problem. Files probably reversed. E2E4 is D2D4, A2A4 is H2H4. Anyway you can take coordinates from my code. Stable. File* = X Coordinates. Rank* = Y Coordinates.

SquareX = X distance from Left Top Corner.

SquareY is same for Y.

I need to learn arrays. UTube :D Thanks anyway.

Edited by Dicaste
Link to comment
Share on other sites

Its working well. I love it and i have changed codes too. :D

 

[sCAR]

program ChessBOT;

 

var

LColor: Integer;

LeftX, LeftY, RightX, RightY, CenterX, CenterY: LongINT;

SquareX, SquareY: Integer;

FileA, FileB, FileC, FileD, FileE, FileF, FileG, FileH: LongINT;

Rank1, Rank2, Rank3, Rank4, Rank5, Rank6, Rank7, Rank8: LongINT;

MouseX, MouseY: Integer;

 

begin

 

LColor := 11590641;

 

if FindColor(MouseX,MouseY,LColor,LeftX,LeftY,RightX,RightY) then

begin

LeftX := MouseX;

LeftY := MouseY;

end;

 

GetClientDimensions(RightX,RightY);

CenterX := (LeftX + RightX) div 2;

CenterY := (LeftY + RightY) div 2;

 

MoveMouse(CenterX,CenterY);

 

SquareX := (CenterX div 8) - LeftX;

SquareY := (CenterY div 8) + LeftY;

 

FileA := CenterX div 8;

Rank8 := CenterY div 8;

 

FileB := FileA + (SquareX * 2);

FileC := FileA + (SquareX * 4);

FileD := FileA + (SquareX * 6);

FileE := FileA + (SquareX * 8);

FileF := FileA + (SquareX * 10);

FileG := FileA + (SquareX * 12);

FileH := FileA + (SquareX * 14);

 

Rank8 := CenterY div 8;

Rank7 := Rank8 + (SquareY * 2);

Rank6 := Rank8 + (SquareY * 4);

Rank5 := Rank8 + (SquareY * 6);

Rank4 := Rank8 + (SquareY * 8);

Rank3 := Rank8 + (SquareY * 10);

Rank2 := Rank8 + (SquareY * 12);

Rank1 := Rank8 + (SquareY * 14);

 

MoveMouse(FileE,Rank2);

GetMousePos(MouseX,MouseY);

HoldMouse(MouseX,MouseY,True);

MoveMouse(FileE,Rank4);

GetMousePos(MouseX,MouseY);

ReleaseMouse(MouseX,MouseY,True);

 

Wait(1000);

 

MoveMouse(FileC,Rank7);

GetMousePos(MouseX,MouseY);

HoldMouse(MouseX,MouseY,True);

MoveMouse(FileC,Rank5);

GetMousePos(MouseX,MouseY);

ReleaseMouse(MouseX,MouseY,True);

 

end.

[/sCAR]

 

---------- Post added at 03:12 PM ---------- Previous post was at 03:03 PM ----------

 

Oh there is a some problem. Files probably reversed. E2E4 is D2D4, A2A4 is H2H4. Anyway you can take coordinates from my code. Stable. File* = X Coordinates. Rank* = Y Coordinates.

SquareX = X distance from Left Top Corner.

SquareY is same for Y.

I need to learn arrays. UTube :D Thanks anyway.

Arrays, basically rows of memory. A0 could be the first cell then A1. So how does this work in SCAR?

 

First you have to set the length of the array (pretty certain you must do this). So SetArrayLength(Arr, 5); Sets the Array Arr to have 5 cells. The cells for arrays in SCAR start at 0. So for a loop you would do. for i := 0 to 4 do. Arrays initialized:

Arr[0] := 1; The [] are a must unless you do Arr := [1, 2, 3]; - with multiple values. So you could do this.

 

For i := 0 to 4 do

Arr := 1;

So, each one in Arr is a cell e.g: Arr[0], Arr[1], Arr[2], Arr[3], and Arr[4] not Arr[5] because the length is 5 and arrays start at 0

That would set each cell of memory in the Arr to hold a value of 1.

Sorry if I'm a bit off on this.

Link to comment
Share on other sites

Codes updated.

 

[scar]

program ChessBOT;

 

var

LColor: Integer;

LeftX, LeftY, RightX, RightY, CenterX, CenterY: LongINT;

SquareX, SquareY: Integer;

Files: Array [1..8] of Integer;

Ranks: Array [1..8] of Integer;

MouseX, MouseY: Integer;

i: Integer;

 

begin

 

LColor := 11590641;

 

if FindColor(MouseX,MouseY,LColor,LeftX,LeftY,RightX,RightY) then

begin

LeftX := MouseX;

LeftY := MouseY;

end;

 

GetClientDimensions(RightX,RightY);

 

CenterX := (LeftX + RightX) div 2;

CenterY := (LeftY + RightY) div 2;

 

SquareX := (CenterX div 8) - LeftX;

SquareY := (CenterY div 8) + LeftY;

 

i := 2;

Files[1] := CenterX div 8;

Files[2] := Files[1] + (SquareX * i);

i := i + 2;

Files[3] := Files[1] + (SquareX * i);

i := i + 2;

Files[4] := Files[1] + (SquareX * i);

i := i + 2;

Files[5] := Files[1] + (SquareX * i);

i := i + 2;

Files[6] := Files[1] + (SquareX * i);

i := i + 2;

Files[7] := Files[1] + (SquareX * i);

i := i + 2;

Files[8] := Files[1] + (SquareX * i);

i := i + 2;

 

i := 2;

Ranks[8] := CenterY div 8;

Ranks[7] := Ranks[8] + (SquareY * i);

i := i + 2;

Ranks[6] := Ranks[8] + (SquareY * i);

i := i + 2;

Ranks[5] := Ranks[8] + (SquareY * i);

i := i + 2;

Ranks[4] := Ranks[8] + (SquareY * i);

i := i + 2;

Ranks[3] := Ranks[8] + (SquareY * i);

i := i + 2;

Ranks[2] := Ranks[8] + (SquareY * i);

i := i + 2;

Ranks[1] := Ranks[8] + (SquareY * i);

 

MoveMouse(Files[3],Ranks[5]);

 

end.

[/scar]

 

I'm still working. Thanks for array advice.

 

---------- Post added at 04:08 PM ---------- Previous post was at 03:49 PM ----------

 

for used.

 

[scar]program ChessBOT;

 

var

LColor: Integer;

LeftX, LeftY, RightX, RightY, CenterX, CenterY: LongINT;

SquareX, SquareY: Integer;

Files: Array [1..8] of Integer;

Ranks: Array [1..8] of Integer;

MouseX, MouseY: Integer;

i, x: Integer;

 

begin

 

LColor := 11590641;

 

if FindColor(MouseX,MouseY,LColor,LeftX,LeftY,RightX,RightY) then

begin

LeftX := MouseX;

LeftY := MouseY;

end;

 

GetClientDimensions(RightX,RightY);

 

CenterX := (LeftX + RightX) div 2;

CenterY := (LeftY + RightY) div 2;

 

SquareX := (CenterX div 8) - LeftX;

SquareY := (CenterY div 8) + LeftY;

 

Files[1] := CenterX div 8;

Ranks[8] := CenterY div 8;

 

x := 2

for i := 2 to 8 do

begin

Files := Files[1] + (SquareX * x);

x := x + 2;

end;

 

x := 2

for i := 2 to 8 do

begin

Ranks := Ranks[8] + (SquareY * x);

x := x + 2;

end;

 

MoveMouse(Files[5],Ranks[5]);

 

end.[/scar]

 

Is there any function to "Absolute value" ? Ranks not working. Rank[1] = Rank8 :D Thanks.

 

---------- Post added at 04:16 PM ---------- Previous post was at 04:08 PM ----------

 

Problem solved.

 

[scar]program ChessBOT;

 

var

LColor: Integer;

LeftX, LeftY, RightX, RightY, CenterX, CenterY: LongINT;

SquareX, SquareY: Integer;

Files: Array [1..8] of Integer;

Ranks: Array [1..8] of Integer;

MouseX, MouseY: Integer;

i, x: Integer;

 

begin

 

LColor := 11590641;

 

if FindColor(MouseX,MouseY,LColor,LeftX,LeftY,RightX,RightY) then

begin

LeftX := MouseX;

LeftY := MouseY;

end;

 

GetClientDimensions(RightX,RightY);

 

CenterX := (LeftX + RightX) div 2;

CenterY := (LeftY + RightY) div 2;

 

SquareX := (CenterX div 8) - LeftX;

SquareY := (CenterY div 8) + LeftY;

 

Files[1] := CenterX div 8;

Ranks[8] := CenterY div 8;

 

x := 2

for i := 2 to 8 do

begin

Files := Files[1] + (SquareX * x);

x := x + 2;

end;

 

x := 2

for i := 1 to 7 do

begin

Ranks[8 - i] := Ranks[8] + (SquareY * x);

x := x + 2;

end;

 

MoveMouse(Files[5],Ranks[5]);

 

end.[/scar]

 

---------- Post added at 04:16 PM ---------- Previous post was at 04:16 PM ----------

 

 

---------- Post added at 04:54 PM ---------- Previous post was at 04:16 PM ----------

 

Hi again sorry for those questions. I'm asking a lot. Annoying :D I tried to write function like "MakeMove" but cant.

 

MakeMove(E2,E4); or MakeMove(E,2,E,4); something like that. It should be return this;

 

MoveMouseSmooth(Files[5],Ranks[2]);

GetMousePos(MouseX,MouseY);

HoldMouse(MouseX,MouseY,True);

MoveMouseSmooth(Files[5],Ranks[4]);

GetMousePos(MouseX,MouseY);

ReleaseMouse(MouseX,MouseY,True);

 

Files = A B C D E F G H

Ranks = 1 2 3 4 5 6 7 8

 

Thanks.

Edited by Dicaste
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...