The task for this month’s Exercise is to extract a structure member from a void pointer for use in the quick-sort compare() function. This isn’t a solution you can readily find on the Interwebs.
Continue reading
Author Archives: dgookin
The Knight’s Tour
The task is truly complex: Navigating a knight around a chessboard, visiting each square but never the same square twice. It took me a while to code, and I don’t think my solution is particularly elegant, but it works.
Continue reading
Quick Sorting Structures
Difficulty: ★ ★ ★ ★
I’ve covered the miraculous qsort() function elsewhere in this blog. It’s nifty, allowing you to sort all kinds of data with your only job being to code a compare() function. Most coders these days just copy-paste this function and call it good. But for sorting an array of structures, more brain muscle is required.
Continue reading
Setting Up the Knight’s Tour
I first read about the Knight’s Tour when I was a kid. My mom bought the Time Life series of books on computers. It it, the Knight’s Tour program is presented, which fascinated me. After all this time, I finally set out to code the tour myself.
Continue reading
Plotting the Knight’s Next Move
The next step in hopping a knight around a chessboard is determining which squares from its current position represent valid moves. Code must be combined from last week’s lesson (setting the knight on the chessboard at a random spot) with the movement code presented a few lessons back.
Continue reading
Why, There’s the Knight!
Continuing from last week’s Lesson, the task is now to combine the chessboard output from this month’s Exercise solution with the knight’s random location. This step is the next one leading to the result, which is to plot how a knight moves on a chessboard.
Continue reading
Output a Colorful Chessboard – Solution
This month’s Exercise may not seem that difficult, especially given the variety of grid challenges and dimensional array lessons I’ve posted on this blog. Obviously, you need a nested loop. The tough part, however, is generating the grid of alternating colors.
Continue reading
From Linear Array to Row/Column
A chessboard is a gird, traditionally eight-by-eight squares for 64 positions. This game matrix can be implemented in code in a variety of ways, with a two-dimensional array being the most obvious. But this option isn’t what I chose when programming how a knight moves (from last week’s Lesson).
Continue reading
Output a Colorful Chessboard
Difficulty: ★ ★ ★ ☆
Text mode need not be so dreary when it comes to generating a game of chess. You have several options, all of which stink to varying degrees.
Continue reading
Plotting Knight Moves
Computers and chess go together like Mr. Spock and Star Trek. The character of Spock is pure genius, a crazy addition to the mix that provided depth and wonder to the TV show and later movies. In chess, it’s the knight that provides the crazy addition, making the game of chess more than an advanced variation on checkers.
Continue reading