Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project2;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- var
- figurePos: string;
- xK,yK,xF,yF, figureIndex:integer;
- figures: array[1..6] of string;
- {function GetValidPos(typeF:string):string;
- procedure SetKingPos(position: string);
- Procedure SetFigurePos(position: string);
- procedure InitFigure();
- function ValidChoice():integer;
- function CheckAttack(xK,yK,xF,yF:integer; figure: string):boolean; }
- procedure InitFigure();
- begin
- figures[1]:= 'Pawn';
- figures[2]:= 'Knight';
- figures[3]:= 'Rock';
- figures[4]:= 'Bishop';
- figures[5]:= 'Queen';
- figures[6]:= 'King';
- end;
- function GetValidPos(typeF:string):string;
- begin
- while true do
- begin
- Write('Enter the ',typeF,''#39's position(etc. 5F, 4B):');
- Readln(figurePos);
- figurePos:=Trim(figurePos);
- if (( Length(figurePos) = 2) and (ord(figurePos[1]) in [49..56]) and (ord(figurePos[2]) in [65..72])) then
- break
- end;
- Result:= figurePos;
- end;
- function ValidChoice():integer;
- begin
- while true do
- begin
- Writeln('Select the number of opponent'#39's chess figure:');
- Writeln('1.Pawn 2.Knight 3.Rock 4.Bishop 5.Queen 6.King');
- Readln(figureIndex);
- if figureIndex in [1..6] then
- break
- end;
- Result:= figureIndex;
- end;
- procedure SetKingPos(position: string);
- begin
- xK := ord(position[1])-ord('0');
- yK := ord(position[2])-ord('A') +1;
- end;
- Procedure SetFigurePos(position: string);
- begin
- xF := ord(position[1])-ord('0');
- yF := ord(position[2])-ord('A') +1;
- end;
- function CheckAttack(xK,yK,xF,yF:integer; var figure: string):boolean;
- begin
- if figure = 'Pawn' then
- Result:= (abs(xK-xF) = 1) and (xF-xK = 1);
- if figure = 'Knight' then
- Result:= (((abs(xK-xF) = 2) and (abs(yK-yF) = 1)) xor ((abs(xK-xF) = 1) and (abs(yK-yF) = 2)));
- if figure = 'Rock'then
- Result:= ((xK-xF = 0) xor (yK-yF =0));
- if figure = 'Bishop'then //
- Result:= (abs(xK-xF) = abs(yK-yF));
- if figure = 'Queen'then
- Result:= ((abs(xK-xF) = abs(yK-yF)) xor ((xK-xF = 0) xor (yK-yF =0)));
- if figure = 'King'then
- Result:= (abs(xK-xF)<=1) or (abs(yK-yF)<=1);
- end;
- begin
- InitFigure();
- Writeln('1A-1H - white side, 8A-8H - black side');
- SetKingPos(GetValidPos('future White ' + figures[6])); //xK yK
- figureIndex := ValidChoice;
- SetFigurePos(GetValidPos('Black ' + figures[figureIndex])); //xF yF
- if CheckAttack(xK, yK, xF, yF, figures[figureIndex]) then
- writeln('The move is impossible.')
- else
- writeln('The move is possible.');
- readln;
- end.
Add Comment
Please, Sign In to add comment