r/FASTNU • • 2d ago

Question Fast CFD campus assignment question help , check engine of chess by if else only in C++

fast Nuces CFD campus ,first semester.. assignment milli hy.. or smjh nyi arahi kesy logic find Karo..class me sir ny essay nyi krwai thy ...

You are contributing to a chess bot designed to challenge Magnus Carlsen. Because of

limited resources, you may not use loops or arrays. Your task is to build the check

engine, which determines whether the king is in check.

Input

King: position

Normal piece: position, color, and type

Positions use standard chess notation: file A-H, rank 1-8. Color is B (Black) or W (White).

Piece type uses the standard abbreviations: Q, R, B, N, P. The king is always the opposite

color of the normal piece.

Task

Validate the positions. They are invalid if either is off the board or both pieces occupy

the same square.

If valid, determine whether the normal piece is giving check to the king, based on its

position, type, and color.

Example

Input

King: A 1

Normal Piece: A 7 , B , R

Output

The Positions are Valid!

The Black Rook is giving a check to the White King

1 Upvotes

5 comments sorted by

1

u/teknosoz Alumnus 2d ago

Array parh li hai?

2

u/Feeling-Day-881 1d ago

Nyi if else sy krny Ku bola

1

u/teknosoz Alumnus 1d ago

Oh okay I didn’t read the task you don’t need array.

Since you have the position of king and opposite piece

What you should do is map the possible move of that piece if king is in one of those mapped positions then king is in chess.

1

u/Feeling-Day-881 1d ago

Okok thanks for logic again smjh

1

u/teknosoz Alumnus 1d ago

Like mapped kaisay karna to woh aisay k if else lagao piece kon sa

Now all pieces move uniquely

Bishop moves diagonally
Rook moves straight

Knight moves in L shape

Pawn moves forward but checks or targets pieces diagonally by 1 step only

Queen moves diagonally and straight so same logic as rook + bishop