0% found this document useful (0 votes)
65 views

How Chess

Chess is a difficult problem to solve programmatically. Our resident genius solved it in C++ using over 80 lines of code by calculating for each piece position whether it lay in the path of another piece, which would print that it was in danger. Boolean functions were used for each piece type, with functions to check if a knight was one move away, if a bishop laid along diagonals, if a rook was horizontal or vertical, and if a queen was in the path of a rook or bishop. The solutions are explained in hopes that they will help train for next year's contest.

Uploaded by

Daniel Nazareth
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

How Chess

Chess is a difficult problem to solve programmatically. Our resident genius solved it in C++ using over 80 lines of code by calculating for each piece position whether it lay in the path of another piece, which would print that it was in danger. Boolean functions were used for each piece type, with functions to check if a knight was one move away, if a bishop laid along diagonals, if a rook was horizontal or vertical, and if a queen was in the path of a rook or bishop. The solutions are explained in hopes that they will help train for next year's contest.

Uploaded by

Daniel Nazareth
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Chess

Difficulty: Hard

Along with TicTacToe, nobody solved this problem correctly. And unlike TicTacToe, nobody
even tried to solve this problem.

Our resident genius decided not to write a program in Basic, since it would be extremely long to
code. In fact, his solution in C++ takes over 80 lines of code.

The way our resident genius solved this problem, for each position, he calculated whether or not
each piece lay in the path of another piece. If it did, he would print out that the piece was in danger
by the other piece.

He employed extensive use of Boolean functions, one for each piece type. Knight found if a knight
lay one move away in two lines of code. Bool Bishop found out if a piece laid along it’s diagonals,
and Bool Rook found if a piece laid along a horizontal or vertical line, and Queen found if it was in
the path of rook or bishop.

Well, that’s all the solutions. I hope these made sense to you, and that you can use these
explanations to help train for next years contest. See you all next year!

Ryan McGarry
President of USD ACM
Doug Jennewein
Vice President of USD ACM
\t itha Lurz
Secretary/Treasurer of USD ACM

You might also like