Tuesday, May 4, 2010

About C / C++ / C#: Programming Challenge 35 is Go!

If you can't see this email, click here

About.com

C / C++ / C#

Fundamentals

Tips & Tools

Going Pro



From David Bolton, your Guide to C / C++ / C#
If you know chess then you'll know the Knight's moves. But how quickly can your program move a Knight round a large chessboard? That's this month's challenge, details below. I've also been taking a closer look at .NET 4 and while it's early days it has some interesting features especially if you like very big numbers... Have a great week!

Programming Challenge 35 - Knight's Tour
Knight's Tour in chessThis challenge is the classic moving a Knight round a chess board so it visits every square just once. Your application must do it in the fastest possible time. The only thing is that the chess board is 20 x 20 in size but otherwise it's the same puzzle. In the tour the Knight starts at the top left hand square which is numbered 1 and your program must output all the moves to see it visiting every square. It doesn't have to finish at the starting point! There's a lot on the web with a variety of different algorithms and even some interesting art work and music but this challenge is just about processing speed!

More on .NET 4.0
Apart from the keyword Dynamic and C# compiler inference, the .NET 4.0 Framework is more a series of smaller improvements rather than major new functionality. For instance garbage collection has improved with a new background garbage collector. Coding contracts which let you check that code behaves as it should is assisted by the new System.Diagnostics.Contracts namespace. This contains classes that adds preconditions, postconditions, and object invariants. If you like big numbers, then the new BigInteger class will be of use. It lets you create very big numbers with no upper or lower bound. Typically you initialize them from an existing int type or from a byte array or hexadecimal string. This is an example from Microsoft's help. byte[] byteArray = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; BigInteger newBigInt = new BigInteger(byteArray) ; Console.WriteLine("The value of newBigInt is {0} (or 0x{0:x}).", newBigInt) ; // The example displays the following output: // The value of newBigInt is 4759477275222530853130 (or 0x102030405060708090a). BigIntegers are immutable, so if you increment one it creates a new copy of it. This can slow down your programs so use them with care. I'll look at more new features next week.

On Poker Bots and PokerPirate
Anyone who has ever played online poker has dreamed I guess of writing a poker bot that can play online Poker 24x7 and earn you an income. The cold harsh glare of reality would no doubt poke several big holes in that dream. For instance online casinos don't like poker bots; they will notice a player who is online 24x7 and put 2 and 2 together. Anyway if poker bots become ubiquitous, it's going to end up as a battle of the best bots. My guess is that there may be some money to be made this way but for how long is anybody's guess. That said, the Codingthewheel.com blog had a great series of posts on coding Poker bots and there is now an open source Windows C++ bot called PokerPirate. It needs MySQL and the C interface to mysql files to be compilable and is only for one poker tournament (Royal Vegas Poker) but if you have an interest in poker and programming, it's a good place to start! The author developed it 5 years ago and according to him recouped his development costs through winnings! I downloaded the code and compiled it with Microsoft Visual C++ Express 2010 and after successfully upgrading it compiled ok apart from the missing mysql.h. You can get this (and the other files you need with it) from the Connector/C library which you download from MySQL Downloads. Note you may have to register for that but it's free.

Never Programmed Before? Start Here
Learn how to program computers as a living or just for recreational fun. Find out how to make a computer do what you want.

 


C / C++ / C# Ads
Featured Articles
Other Blogs You might find Interesting
Welcome to the C Area with Articles about C Programming
Welcome to the C++ Area with Articles about C++ Development
Welcome to the C Sharp Area with Articles about C Sharp Development
Learn about Commercial Software Development
All about Games Programming

 

More from About.com

Disney Trip Planner
Everything you need to plan the perfect Disney vacation -- from when to go and what to do, to saving money and picking a hotel. More >



Join About.com's User Panel!
Share your opinions and help us make About.com more relevant, informative and enjoyable to use. More>




This newsletter is written by:
David Bolton
C / C++ / C# Guide
Email Me | My Blog | My Forum
 
Sign up for more free newsletters on your favorite topics
You are receiving this newsletter because you subscribed to the About C / C++ / C# newsletter. If you wish to change your email address or unsubscribe, please click here.

About respects your privacy: Our Privacy Policy

Contact Information:
249 West 17th Street
New York, NY, 10011

© 2010 About.com
 


Must Reads
Programming Challenges
About C, C++ and C#
C++ for Beginners
C++ Programming
Intro to OOP

Advertisement

No comments: