• Hey Guest. Check out your NeoGAF Wrapped 2025 results here!

Your Programming FUCK YEAH moments.

Status
Not open for further replies.
wolfmat said:
Toma, C#, right?

The = operator doesn't just work on Lists in a specific manner; rather, it just happens to also work on Lists like it does everywhere else. In that regard, the described behavior is to be expected. (Especially if you consider that the = operator cannot be overloaded in C#)

If you're absolutely sure you have to clone a collection along with all its data, then there are multiple ways to go about it.

From an object-oriented programmer's point of view, I'd probably build a factory method that returns a new instance of an element's type that holds the identical data, then write an extension that uses said factory method on each element in your source list, and puts each result of the factory method into your newly-built result list, then returns that at the end. Or something.

From a hacker's point of view, I'd assure shit's [Serializable()] and implements ISerialize; then I'd binary-serialize into a memory stream, then deserialize into a null object. That might be a hack, but it's a rather good one.

Yeah I did use the OOP method you mentioned. I thought that was just a work around for something more easier. Someone said earlier: "If you need to write 50 lines of code for something, there is probably an easier way.", so I thought I was thinking about it too complicated. That serializable stuff doesnt seem to be shorter as well, but I didnt figure out how to properly use it. But if I can do anything with that OOP method, and I dont necessarily need the serializable stuff, thats fine by me.
 
Toma said:
Yeah I did use the OOP method you mentioned. I thought that was just a work around for something more easier. Someone said earlier: "If you need to write 50 lines of code for something, there is probably an easier way.", so I thought I was thinking about it complicated. That serializable stuff doesnt seem to be shorter as well, but I didnt figure out how to properly use it. But if I can do anything with that OOP method, and I dont necessarily need the serializable stuff, thats fine by me.
Operative word being "probably", not "necessarily" :)

In general though, yes if you find yourself throwing code at a problem, you usually need to take a step back and think about what you're doing to see if there is a better way.
 
deadbeef said:
Operative word being "probably", not "necessarily" :)

In general though, yes if you find yourself throwing code at a problem, you usually need to take a step back and think about what you're doing to see if there is a better way.

Yeah, I understand. I was just thinking that there might be a better way :) Doesnt seem that way, but hey, asking doesnt cost anything.

Funny how fast you spotted that comment, though :P
 
Update!

Xs6EX.jpg


-Create the 2nd half of the matchmaking system (just mirror the first half)
-add a way to simulate remaining games of a day, that werent played already
-Save system

I also finally thought of making those boxes not editable.
The "simulation" for now, is just random numbers between 0-5 goals for each team. I plan to add at least a strength measurement system that will decide how much goals they can score.
I want to make that a bit more intricate later, though. Don't know whether I'll be succesful with that.

Okay, now that this is done.. time to tackle the save system.
 
You could implement a save system by using serialization. It's really great. Really easy and fast. Just hold your data to save in an object that is also serializable. Upon save, serialize that object to file. Upon load, deserialize from file. Do some trivial sanity checking, also.

That makes a lot more sense, is a lot less prone to errors, more trivially scaleable, easier to parse (don't need to parse anything, yay) etc. than writing / reading number by number into / from a txt file (usually the first approach that comes to mind).
 
wolfmat said:
You could implement a save system by using serialization. It's really great. Really easy and fast. Just hold your data to save in an object that is also serializable. Upon save, serialize that object to file. Upon load, deserialize from file. Do some trivial sanity checking, also.

That makes a lot more sense, is a lot less prone to errors, more trivially scaleable, easier to parse (don't need to parse anything, yay) etc. than writing / reading number by number into / from a txt file (usually the first approach that comes to mind).

Careful using the built-in binary serialization or you could end up without backwards-compatibility support. For instance, you add a new feature to your program and all of a sudden you can't decode a previous save. You're better off writing your own serialization/de-serialization routines to account for this.
 
deadbeef said:
Careful using the built-in binary serialization or you could end up without backwards-compatibility support. For instance, you add a new feature to your program and all of a sudden you can't decode a previous save. You're better off writing your own serialization/de-serialization routines to account for this.
Or go the XML route, since that's already builtin.
 
wolfmat said:
Or go the XML route, since that's already builtin.
True. All I know is I got horribly burnt using binary serialization once because I was moving too damn fast and didn't understand the implications of what I was doing.
 
deadbeef said:
True. All I know is I got horribly burnt using binary serialization once because I was moving too damn fast and didn't understand the implications of what I was doing.
I think your advice was very valuable, by the way; sorry for not pointing that out.
 
Toma said:
I have... no... clue what you guys are talking about...

Can someone explain to me what a "serializable" tag actually does?

I try to get through understanding this tutorial about it:
http://www.switchonthecode.com/tutorials/csharp-tutorial-serialize-objects-to-a-file

But I actually have no clue what I am doing with that. Hopefully I understand this at some point.


Serialization lets an instance of a serializable class be saved to a file. So after a user creates a league and runs some simulations, he saves the data to a file, and later opens the simulation back up and he's right back to where he was before.

There are two ways that .NET supports serialization - built-in support and user-provided support.

Built-in support includes methods that are already provided for you by .NET to write your objects to a file and re-instantiate objects from a file. User-provided support means that you write your own routines that write your objects to files and re-instantiate them from files in whatever method you want. For instance, if you were so inclined, you could write your simulations out as tweets on twitter.com as long as your deserialization routine properly read from twitter.com to reinstantiate your objects.


Of the built-in support, there are two methods: binary and XML serialization. Binary serialization means that binary data is written to disk, or basically, data that is not human-readable; ones and zeroes; gobbledy-gook. XML serialization means that the items are tagged and written as an XML document. Look up XML on wikipedia if you want to know what it is, and don't.

I was pointing out a problem with binary serialization, that, if you binary serialize an object at some point (create a SAVEFILE), and then later modify the class(es) that are contained in the SAVEFILE by adding additional data (for instance, adding a TeamMascot attribute), then when you go to reinstantiate the SAVEFILE, it won't match the class and the built-in serialization will just throw an exception.

I got myself into a situation where the object that I serialized was the result of hours of meticulous work with an application. Then I changed the class, and couldn't open that file again, thus losing hours and hours of meticulous work.
 
Ah okay, that clears that a bit up in my mind. Now I only need to get it to work. Cant try that now as I am still working, but as always, I'll report back :)

Thanks for explaining!
 
That actually reminds me of something I read one time - that some of the botnets are configured to check for commands on a pre-established twitter account, so that the person running the botnet can post commands on twitter for his/her botnet to carry out.

Pretty neat!
 
deadbeef said:
That actually reminds me of something I read one time - that some of the botnets are configured to check for commands on a pre-established twitter account, so that the person running the botnet can post commands on twitter for his/her botnet to carry out.

Pretty neat!

Hm, I'd definitely like to look into posting and directly reading from a online source. I found a tutorial how to do that with a Twitter account, hopefully its not too difficult to change that to a blogspot account or whatever. It would be awesome if I could post the table online automatically. I'll use this program for FIFA sessions with a friend, and up to now I was only thinking about saving it into a txt file and sending it to him via mail.
 
Yesss, got the save system to work as well. Still has a few kinks, as its making problems with an uneven amount of teams. It tries to save a value in a team that doesnt exist I believe. But I'll figure that out. Only need to add an exception on one place (I still need to find).

No idea what to to directly after fixing a few bugs, but I am sure I'll find something. I am leaning towards making it into a more interesting football sim, adding random players with some stats to each team and decide the games outcome with these stats.
 
Still working on the side effects of that bug that occurs with an uneven number of teams, but I am coming along. Currently its working but it chops off the last few matches while save/loading. Well... its an improvement over "not working at all", so there's that. I also included an instant "goto" field for the matches. Handy, so I wont need to click 20 times to get to day 21.

Another question though:

I'd like to open a new window (or get another "event") by clicking on a match or a button related to it:
PR6US.jpg


Obviously I cant put any buttons etc there beforehand, since I dont know how many matches there'll be. Is there any easy way to do this? Either including a button after each match, or making the match clickable?
 
Found it!

However it has a stupid shadow to the sides and under it:

fwLLg.jpg


I used this code:

Button btn = new Button();
btn.Parent = richTextBox7;
btn.Height = 45;
btn.Width = 75;
btn.BringToFront();
richTextBox7.Controls.Add(btn);
btn.Location = new Point(50, 50);
btn.Visible = true;
btn.BackColor = Color.Gray;

btn.Click += new EventHandler(ButtonActionClick);
Does anyone know how to get rid of that shadow?
 
I've been doing a little game in C++ for the last 3 months, as the final project of a masters course in videogames programming I'm taking.
I'm relatively new to programming, started taking it seriously about one year ago, and I've learnt a lot since then.
Yesterday, though, I had the biggest fuck yeah moment in all my programmer life.
Let me put the situation in perspective:

-A couple of weeks ago my laptop died. I lost nothing related to the project because I had backups, but I spent 4 or 5 days trying to fix the laptop, realizing it couldn't be fixed, borrowing a computer from my parents, installing everything from scratch, realizing the computer was too old and wouldn't work, borrowing another computer, and finally making it work again.
- My router broke also two weeks ago, so I've been with very limited internet access since then, which means I couldn't look for anything online.
- The project was due last Monday, but luckily I got a few extra days because of the problems with my laptop, so in the end it's due tomorrow.
- I wanted to implement a pathfinding routine for the enemies to chase the player. As of yesterday, it was mainly working, but the enemies would get stuck when there were too many walls to avoid, and it wouldn't always find the best path.
-For the last 7 days, I've finished working my job at 18:00, got home, and been working in the project (mostly the pathfinding algorithm) well until 23:00.
- Yesterday evening, I finally got it to work flawlessly.

I had such a relief when I saw that I could place wall after wall and the enemy would sort it!
So many days of hard work totally paid off when I was sitting in front of my computer with such a huge smile on my face.
I hadn't felt such a sense of accomplishment for a very long time.

This means the biggest and most important part of my game is finished, and I have a couple of afternoons left to polish a few little things.

Fuck yeah!
 
Implemented a Ball Tree today and increased the speed of my similar image search from ~4 million images per second to ~120 million per second. Still hoping I can get some more, just need to fiddle with the specifics a bit.

Before I implemented it, I had my hopes up that I'd hit a billion/s, lol.
 
Status
Not open for further replies.
Top Bottom