I've gotten a little lazy lately. I've been spending too much time playing Minions of Mirth, watching television and series DVDs and hadn't done any programming. I decided it was time to see what I could still do. I was originally thinking of doing an implementation of Tic Tac Toe, but opted for Magic Square because it has been a while and the logic is simpler.
Magic Square was a game on Merlin, the Electronic Wizard, which was released by Parker Brothers sometime in the late 1970s. It is played on a three by three matrix.
The object was to light all squares but the center square.
I actually learned to program before GUIs were popular and have the most experience writing for the command line. I opted to start with C++ for the console on an Intel based Mac Mini running OS X 10.5 (Leopard). By the time I realized I needed to use the CURSES library I had already started. The C++ I used is little more than bastardized C, and should compile on any machine which has a curses library available. Porting to C is trivial. I had to research how to use the curses library, read up on makefiles and refresh my memory on namespace, and would have saved time if I had just opted for C.
The C++ should probably be implemented using a board class, but I was always more into top down design as opposed to object oriented. I might rewrite if I get around to creating a CGI or Java version.
I assumed you would use your numeric keypad for input. However, it uses the numbers, so if you don't have the keypad, 123 is the bottom row. Any other input will quit the current game and insult you appropriately. The game requires at least 19 rows and 51 columns on your terminal, but could be modified to run on a much smaller screen by editing mgksqrout.cpp.
All the downloads below contain the full source. All have the executable file for the indicated platform if any. I keep /usr/local/bin in my PATH, and 'sudo make install' will copy the executable magicSquare to that directory on my Mac and my Ubuntu machine. Modify the Makefile as appropriate, or just copy the executable file to a directory in your path. This is currently a command line program and should be launched from the command line or terminal - it may or may not work if you double click on it in a GUI depending on your environment.
The only problem I ran into on HAIKU compiling from source was linking.
At the command prompt:
Edit the Makefile changing the following:
MANPATH should include at least /boot/system/documentation/man and /boot/home/config/non-packaged/man.
At the command prompt:
I decided to do a javascript version. I'm unfamiliar with programming in javascript and I did a lot of experimenting. It's not the cleanest code around, but it gets the job done. It should work in any browser with javascript enabled. The rewrite is from scratch, and I opted for a quick hack to initialize which does have a bug. There is no test to see if it was initialized with the winning screen. The probability is of this occurring is about 1:512. The artwork was created using 'The Gimp'.
I added a copy for the C64. It was written using VICE.
The program is written in BASIC, is not optimized, and is S..L...O....W.
Mount the disk image in the emulator and type:
I've done some playing around with BASIC-64 as well as CC65 and added these to the D64 image below. The CC65 version is a complete rewrite. It displays the number of moves and allows you to customize colors.
I'm not a big Atari guy, but I did acquire a Atari 800 XL and have been playing around with it a bit.
I included a complete rewrite of magicsquare in Atari BASIC developed using Altirra. The disk includes the main program MS.BAS, with ATASCII.BAS to show the main character set, and SETCOLOR.BAS to allow you to play with the colors.
MS.BAS uses text mode and does not take advantage of color. It is significantly faster than my C64 version though. The programs have been tested on the Atari 800 XL.
I didn't bother adding a readme or license to the source. Though I'd appreciate a mention or a link back to my site if you distribute it, the programs and source may be distributed freely.