Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 04-03-2009, 05:48 AM
DarkAngel DarkAngel is offline
Senior Member
 
Join Date: Sep 2002
Posts: 292
Default chinese chess

hi, all,

I'm finishing my chinese chess component and I got stuck at this: how to check if the king, after a specified move, is in check by enemy's canon? (attach canon rules:
The Cannon moves like an orthodox rook along a rank or file, but to capture
must hop over one piece of either color (the "frame") and continue on the line
beyond until encountering an opposing piece. This piece is then removed from
the board and the Cannon occupies its square).

I have a function like below:

function TCChess.BlackInCheckAfter(oldcr, newcr: cross):Boolean; //check if black king is in check after a move;

var
v: Char;
pos: String;
x,y,r,res,k,i: Integer;
kingcr: Cross; //enumerated type A9 - I0 9x10 crosses, kingcr means black KING here;

begin

Result:=TRUE;

pos:=StrPas(@Fposition[1]);

v:=pos[Integer(oldcr)];
pos[Integer(oldcr)]:=' ';
pos[Integer(newcr)]:=v;

for r:=1 to 91 do
begin
res:=r;
if (pos[r]='j') then //find black king;
Break;
end;

kingcr:=Cross(res);
if (res>90) then
Exit;

//rook check
for x:=-1 to 1 do
if (x<>0) then
for r:=1 to 8 do
begin
v:=pos[Integer(MouseTocross(XPos(kingcr)+x*r,YPos(kingcr) ))];
if (v='Z') then //find rook then exit;
begin
Exit;
end;
if (v<>' ')then
Break;
end;

for y:=-1 to 1 do
begin
if (y<>0) then
for r:=1 to 9 do
begin
v:=pos[Integer(MouseTocross(XPos(kingcr),YPos(kingcr)+r*y ))];
if (v='Z') then
begin
Result:=TRUE;
Exit;
end;
if (v<>' ')then
Break;
end;
end;

//canon check;
??? here I need help, there are at the beginning two canons at each side.

Result:=FALSE;
end;

The canon captures quite differently, can anybody have an idea on how to check if the king is in check by enemy's canon?

Thank you in advance.



DarkAngel
^-^
Reply With Quote
  #2  
Old 04-03-2009, 12:09 PM
chris_w chris_w is offline
Senior Member
 
Join Date: Jan 2004
Posts: 1,397
Default RE: chinese chess

[pre]
If this function works, then just use it to see if the canon can
capture the king.

http://www.delphipages.com/threads/t...81737&G=181683
[/pre]
[pre]
"There is a theory which states that if ever anybody discovers
exactly what the Universe is for and why it is here, it will
instantly disappear and be replaced by something even more
bizarre and inexplicable. There is another theory which states
that this has already happened."
-- Douglas Adams
[/pre]

Chris
Reply With Quote
  #3  
Old 04-03-2009, 02:45 PM
DarkAngel DarkAngel is offline
Senior Member
 
Join Date: Sep 2002
Posts: 292
Default RE: chinese chess

this function decide if canon move is legal or not,it is not what i want thanks anyway

DarkAngel
^-^
Reply With Quote
  #4  
Old 04-04-2009, 12:10 AM
chris_w chris_w is offline
Senior Member
 
Join Date: Jan 2004
Posts: 1,397
Default RE: chinese chess

If it's not legal for it to capture the king then the king must not be in check??

Chris
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 10:56 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.