Friday, May 10, 2024
HomeC ProgrammingOutput a Colourful Chessboard | C For Dummies Weblog

Output a Colourful Chessboard | C For Dummies Weblog


Issue: ★ ★ ★ ☆

Textual content mode needn’t be so dreary in the case of producing a sport of chess. You will have a number of choices, all of which stink to various levels.

The worst is proven in Determine 1, which is one thing I concocted in a brutal try to create an unpleasant textual content mode chessboard. I’m certain some classic mainframe within the Seventies pressured customers to endure taking part in chess on such a factor. Yikes.

Determine 1. What may very well be a possible chess sport on a terminal again in 1974.

Higher is to make use of coloration to trend a light-weight, pleasant model of a textual content mode chessboard. I lined ASNI coloration textual content output in a publish from earlier this yr. You might use such strategies to generate output resembling proven in Determine 2.

colorful ANSI chessboard

Determine 1. A greater textual content mode chessboard created with ANSI coloration output.

Your problem for this month’s Train is to put in writing code that generates the chessboard in Determine 2 as output. This job could appear trivial, however the difficultly stage rises as a result of the grid exhibits alternating colours. If you first write your code, you may even see a striped sample, not a grid. Additional selections are required to output a grid.

As talked about earlier, seek advice from the ANSI coloration Classes for particulars on coloration output in C. The 2 codes/colours I take advantage of are outlined in my resolution as:

#outline COLOR_WHITE "x1b[30;47m"
#define COLOR_CYAN "x1b[30;46m"

Both set black text in the foreground, but white and cyan colors for the background, as lovingly shown in Figure 2.

Please try this exercise on your own before you check out my solution, which I’ll post in a week. This code is used in later posts to generate chessboard output for my Knight Moves series of lessons.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments