Some Challenges

closed account (S6k9GNh0)
I've been wanting to do something with programming recently to keep myself sharp (since I've been rather lazy lately). So I've come up with some challenges. These aren't very defined unfortunately so some suggestions might be handy.

Challenge #1: A library that can restore and create console sessions must be used! Create an area in console that indicates an array of switches. A switch can be represented by anything, including blank space. However, the area needs to be outlined and made apparent by something other than blank space.

Here's the interesting part. This area of switches is to be completely controlled by some sort of scripting language that can optionally be provided at runtime. Initialization, manipulation, and destruction are all handled by this scripting language. Individual "expressions" should be excepted during the program. Here's an example result and script that gives that result.

Result:
#######
#-++++#
#+++++#
#+++++#
#+++++#
#######


Example script:
init 5 4         #Initialize a 5x4 area
set 0 0 off      #Set (0,0) to off
quit             #The output is erased here and console is restored! Output above was taken before this command. 


Post your own version! I'll post mine soon.
Also, it doesn't have to be in C++. There is no specification for what scripting language you use or how you create your own pseudo-language (or you could just use XML or something).

EDIT: There will be other challenges later as I think of them.
Last edited on
Does it have to use ncurses?
closed account (S6k9GNh0)
Well... I wanted it to be restricted to console (which slightly simplifies things) and ncurses is the only updated and cross-platform console manip library I know of.
I was going to use the .Net framework with C#. It has most if not all of the capabilities of ncurses.

[edit] I think this is right: http://pastebin.com/E7M5e0hN
The code's not beautiful and there are some bugs but I think it does what you're asking for.

You use it by first setting the width and height, and then setting the switches. Each switch is sw# where # is the switch's number. I could (and probably should) have done it as co-ordinates but I didn't, so you'll have to figure out the switch numbers yourself (y * width + x). You set a switch to true or false to turn it on or off.
Last edited on
closed account (S6k9GNh0)
Yeah, that makes sense. That's fine. I didn't really think about that.
Topic archived. No new replies allowed.