Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Poll

What programming topic would you want the next challenge to be about?  (It might be a good opportunity to focus on a subject you're not familiar with or to reinforce knowledge on one that you already know)

Control Flow
- 2 (2.2%)
Arrays, Strings, Pointers, and References
- 8 (9%)
Functions
- 4 (4.5%)
Basic object-oriented programming
- 30 (33.7%)
A bit more advanced OOP (Composition, Operator overloading, Inheritance, Virtual Functions)
- 18 (20.2%)
Templates
- 8 (9%)
Other (Explain)
- 4 (4.5%)
Working with files?  (Streams)
- 15 (16.9%)

Total Members Voted: 89


Pages: 1 ... 21 22 [23] 24 25 ... 78

Author Topic: Programming Challenges & Resources (#bay12prog) Initiative  (Read 95887 times)

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #330 on: August 09, 2010, 08:59:57 pm »

Thank you very much Blacken.

I found that first link, but not that second example.
Much more useful.



Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Blacken

  • Bay Watcher
  • Orange Polar Bear
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #331 on: August 09, 2010, 09:02:27 pm »

I am sure you found a link to Google, yes. Google mastery assures you find the right one.

Signed,
Apparently A Goddamn Google Master
Logged
"There's vermin fish, which fisherdwarves catch, and animal fish, which catch fisherdwarves." - Flame11235

Jamp

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #332 on: August 10, 2010, 03:30:45 pm »

big and awesome post by blacken

Hi, I have some prior programming experience, but my education in this area is very non-consistent (still high school), so I decided to do the exercises, in Python, and then maybe in C or C++.
I am at third item now (:P hope I will make it to the end), but there are some things I am not sure about. There maybe could be list of basic methods for each data structure to implement, because I don't actually know what to program :D. Like I made insert, append, set, get but there are also mentioned things like searching for linked list, what does it? Also a Python-specific questions (but may relate to other higher-level languages), there is no mechanism for getting memory, i made malloc function returning array chunks and interface in python just means class with empty methods? And thinking about sane api for tree, again not sure what is it, maybe I'll just try to make all the methods in "Common Operations" section.
I may provide my code when I get done more of the exercises if somebody wants, for my and hopefully others reference.

Logged

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #333 on: August 11, 2010, 03:08:40 pm »

Does anyone know how to change the amount of lines the console window will hold?

The scroll history isn't long enough for me, so I'm hoping there is a way to extend it.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #334 on: August 11, 2010, 03:33:25 pm »

I'm assuming you're on windows, because you're calling it a console.

There's 300 lines, if you need more than 300 lines, you may wish to reconsider your method of output.

Right-click the window bar and click on properties. Screen Buffer Size is the size of the history, and Window Size is the size of the window.
Logged

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #335 on: August 11, 2010, 04:13:16 pm »

If that is possible, it should be possible to set that in my program code.

I'll look up the windows commands for that myself.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #336 on: August 11, 2010, 05:41:05 pm »

I wouldn't do that if I were you. Just program.exe > output.txt or something like that. It'll pipe the standard output of your program to a text file for you (or program.exe 2> output.txt if you're outputting to stderr).

Once again, is there any unavoidable reason you need more than 300 lines of history? I'm just curious. We might be able to suggest better alternatives.

EDIT:
Scratch that. We will be able to suggest better alternatives.
« Last Edit: August 11, 2010, 05:46:54 pm by Normandy »
Logged

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #337 on: August 11, 2010, 06:59:16 pm »

That output thing sounds great. How do I do that output text thing?

Maybe a tiny sample, a dabbling few lines of C++?

I'm making a text based adventure that has optional debug text,
 and it prints out huge swaths of primarily useless information
 which only becomes useful in the event of a bug.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #338 on: August 11, 2010, 07:07:44 pm »

Spoiler (click to show/hide)
I'll look up the C++ methods in a sec, maybe.
Edit: found an example, you can submit a whole directory path if you want, or just the filename to use the same directory.

Code: [Select]
    #include <fstream.h>
    int main()
    {
        fstream file_op("c:\\CoderSource_file.txt",ios::out);

        file_op<<"Test Write to file";
        file_op.close();
        return 0;
    }

easy as pie. Even more impressive, is if you split them up into two different programs so you can have one programs input connected to another program's output.

one program writes to in, one program writes to out.
reciever < source.
I know this works in C, and I expect no different from C++

hell if filereciever is a text file, you don't actually need to open a different stream type.
just invoke your program with a cmd, filerecieve.txt < output
 

I'm assuming
« Last Edit: August 11, 2010, 07:20:00 pm by eerr »
Logged

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #339 on: August 11, 2010, 07:23:15 pm »

It's when you run the program. It's not a code thing. eerr is correct, but if you're working with outside APIs that's not always possible. When you run the program, you'll do something like this on the command line:

myprogram.exe

Instead of just doing that, type this:

myprogram.exe > output.txt
Logged

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #340 on: August 11, 2010, 07:47:11 pm »

Wait, so should I just open a file at the beginning of main and write everything both to the console window, and a text file?
That doesn't sound intuitive.

I just want everything that goes console to be mirror into text.
Is there a better way to do that?
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #341 on: August 11, 2010, 08:46:09 pm »

In C, and I assume C++

three streams are opened by default.
a standard in,
a standard out,
a standard error.

when opened plain with the console,
standard out prints to the console, and standard in reads console input.
coute, and cin, I think?

you just need to open a file (which works as a stream,) and print to that, as well.
(identical to coute, if you open it with "a" for append? I dunno)

Theres also a pipe-shenanigan method that I don't know.

Wait, so should I just open a file at the beginning of main and write everything both to the console window, and a text file?
That doesn't sound intuitive.

I just want everything that goes console to be mirror into text.
Is there a better way to do that?
reading more carefully,
Theres a command for forking a stream into two streams, I just don't know it.
It's not hard to write twice instead of once -.-
« Last Edit: August 11, 2010, 08:52:25 pm by eerr »
Logged

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #342 on: August 11, 2010, 08:55:09 pm »

Just write a method output_string(string str) { cout << str; file_op << str; }. file_op is a global variable that you open during your main method. There is an even better way of doing it, but it's slightly more complex.

EDIT:
Now that it's not late at night / early in the morning and I'm more lucid:

You should not be outputting giant swaths of information to the console for you to read. That is the job of the debugger and the computer. gdb will output large swaths of debug information if you really need it, but I doubt it. When you're debugging, you should be using asserts, not outputting information for yourself to read. And when an assert goes wrong, you can use your debugger to print a stack trace, output the relevant variables, whatever. It's not just good programming practice, it's actually far easier.

Suppose you want to make sure your movement function is working properly. You do something like this:
Code: [Select]
oldX = player.x
player.moveLeft()
assert(oldX - player.x == 1) //this is assuming moving left will decrease the x coordinate by one

You should not be reading debug data off the console to make sure that the player is moving correctly. Don't fix bugs as they happen; check them ahead of time. Of course, this is a very simple example, but when you're dealing with very complex examples (especially with large calculations), this is a godsend.
« Last Edit: August 12, 2010, 11:28:06 am by Normandy »
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #343 on: August 12, 2010, 04:07:20 pm »

What's the best and/or easiest way of figuring out how long a particular section of code spends running in C++ (for optimization purposes)?
I'm using MSVC++ 2008 EE if that helps.
« Last Edit: August 12, 2010, 07:01:07 pm by alway »
Logged

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #344 on: August 12, 2010, 06:33:02 pm »

*shrug*
Logged
Pages: 1 ... 21 22 [23] 24 25 ... 78