• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 19:52
CET 01:52
KST 09:52
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
RSL Offline FInals Sea Duckling Open (Global, Bronze-Diamond) $5,000+ WardiTV 2025 Championship Constellation Cup - Main Event - Stellar Fest RSL Revival: Season 3
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
Which season is the best in ASL? BW General Discussion Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET [Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
ZeroSpace Megathread Stormgate/Frost Giant Megathread Nintendo Switch Thread The Perfect Game Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread US Politics Mega-thread The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
James Bond movies ranking - pa…
Topin
Esports Earnings: Bigger Pri…
TrAiDoS
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1527 users

The Big Programming Thread - Page 25

Forum Index > General Forum
Post a Reply
Prev 1 23 24 25 26 27 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
catamorphist
Profile Joined May 2010
United States297 Posts
November 19 2010 01:15 GMT
#481
On November 19 2010 00:35 KaiserJohan wrote:
Hmm, anyone know if there really is no way of getting the size of a class instance in C#? sizeof only returns the size of the pointers, and Marshal.Sizeof does not work on class instances.

It kinda makes the #1 solution to object-to-byte streaming hard :p

Anyone know any other way of getting size of a class instance in C#? (imho it feels like a major limitation if its not possible)



Why does it make that hard? Write out the length of the serialized object to the stream before you write the object. Read the length, and then read the object. Problem solved.

No, there isn't a framework method for crawling all the references and getting the size like that. But that wouldn't be what you want, anyway. You want the length of the serialized representation, and if you're using any reference types that you didn't write yourself, then the serialized length might well be different from the size in memory.
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
Cambium
Profile Blog Joined June 2004
United States16368 Posts
Last Edited: 2010-11-19 07:17:02
November 19 2010 07:15 GMT
#482
Anyone good with NP-C reductions want to lend me a hand here?

Tree Reconstruction Problem:

Given a collection of trees: T_1, T_2, ..., T_n
and a positive integer m

Decide whether there exists a tree T of size at most m, such that T_1,...T_n are all isomorphic to a subtree* of T.

Prove that TreeRec is NP-complete

+ Show Spoiler [*Subtree isomorphism] +

Given H and G, H is isomorphic to a subtree in G iff
For function h: V(H) -> V(G) (vertices of a graph)
For every edge (u, v) in H, there exist vertices h(u) and h(v) joined by an edge in G.


Anyway, I tried these reductions:
Subgraph isomorphism (I couldn't really link trees with graphs, not to mention N trees)
Clique (I tried linking "m" to a clique of size "m", didn't work out; but I think this is the closest one I have)
3-SAT (I got stuck)
m-SAT (I got even more stuck)

I e-mailed my TA for some help, and they suggested that I try 3-colour, and I got no luck with that either.

Given the decision problem, it takes "m" as an input, the reduction problem should also use "m" somewhere (that's why I tried m-SAT), and I don't really understand where I could go with 3-colour.

Help/hints would be greatly appreciated...
When you want something, all the universe conspires in helping you to achieve it.
mmp
Profile Blog Joined April 2009
United States2130 Posts
November 19 2010 07:28 GMT
#483
On November 14 2010 01:24 Osmoses wrote:
Hey gang,

I've been working on a game recently, a grid based strategy game focusing on good performance, but now I've started working on pathing, since I want something like workers responding to clicks, and the performance is taking a hit. If it's just corridors, it's easy, big O of 1 most of the time, but once I start working with open spaces, it gets alot more complicated trying to find the shortest path with the least amount of work.

I'm trying out a couple of different methods of going about this right now, but in the meantime I thought I'd ask if anyone can recommend a good book or something concerning 2d pathing? Below is a screenshot of a potential stage, with a example start and end marker placed.

[image loading]

If your A* is too slow then heuristic may need tweaking, you may need some common sense performance tweaks, and above all you want to break down the problem into easy steps. Try double-ended searching to waypoints along the path and store these results somewhere. Also, don't waste your time searching on trivially small spaces - you can build a hash table of precomputed paths based on the pattern of impassable terrain (like, 3x3 or 4v4).

Even more badass is to just guess the answer.
I (λ (foo) (and (<3 foo) ( T_T foo) (RAGE foo) )) Starcraft
MasterOfChaos
Profile Blog Joined April 2007
Germany2896 Posts
Last Edited: 2010-11-19 09:10:41
November 19 2010 09:09 GMT
#484
@KaiserJohan
If you want to serialize .net objects why don't you an existing serializer. And writing a serializer is easy compared to writing a deserializer.
* WCF is can serialize objects in order to send them over the network
* There is BinarySerializer which can serialize most object graphs
* There are several Proto-Buf serializers which are really fast and the serialized data they produce can be (if you create a protobuf description file) used from other languages or different versions of your program.
* There are XmlSerializer and some Json serializers, but they are probably not what you want.

And register or stackoverflow. Very good site for concrete programming questions with definite answers, but bad for discussions.
LiquipediaOne eye to kill. Two eyes to live.
HaN-
Profile Blog Joined June 2009
France1920 Posts
November 22 2010 10:03 GMT
#485
[image loading]
Calendaraka Foxhan
Pawsom
Profile Blog Joined February 2009
United States928 Posts
November 23 2010 15:02 GMT
#486
I have a basic C# question thats really giving me a lot of trouble. Note, this the first assignment or program I've ever attempted to use C# for. The point of the assignment is to teach the chain of responsibility design pattern.

Basically, the code looks like this.


Abstract_Handler.cs
+ Show Spoiler +

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CIS476_Project3_Example1
{

public class Abstract_Handler
{
protected Abstract_Handler next;
public Abstract_Handler()
{
next = null;
}
public void addLink(ref Abstract_Handler n)
{
if (next != null)
{
next.addLink(ref n);
}
else
{
next = n;
}
}
public virtual void handleRequest(ref Request x)
{
next.handleRequest(ref x);
}
}
}


USD_Handler.cs
+ Show Spoiler +

namespace CIS476_Project3_Example1
{
public class USD_Handler : Abstract_Handler
{
public const float EURO_TO_USD_RATE = 1.04f;

public override void handleRequest(ref Request x)
{
x.value_1 *= EURO_TO_USD_RATE;

if ( x.CurrencyType != 0 )
{
handleRequest(ref x);
}
}
}
}



Inside of Main( ) I call the following code:
+ Show Spoiler +



/* Instantiate Handlers */
USD_Handler USD = new USD_Handler();/* Root */
CAD_Handler CAD = new CAD_Handler();/* Link 2 */
AUD_Handler AUD = new AUD_Handler();/* Link 3 */


/* Create Chain of Responsibility */
USD.addLink( ref CAD );
USD.addLink( ref AUD );



Now when I build, I get an error flagging those last 2 signs that says soemthing along the lines of Abstract_Handler.addLink(ref Abstract_Handler) has the wrong parameter, even though USD, CAD, AUD Handlers are all subclasses of the abstract handler. Am I doing something wrong with inheritance or virtual function overloading? Am I using references correctly? At this point I really have no idea. I tried C# because of how easy GUI work seems to be.

For reference, here's my entire program written in C++.
http://codepad.org/KJ87r5fs
Craton
Profile Blog Joined December 2009
United States17274 Posts
Last Edited: 2010-11-23 18:17:58
November 23 2010 17:43 GMT
#487
I'm fiddling around with it (my C# is so-so). It'd help if you posted your Request class (and the other classes so I can test w/ them).

It looks like you're using ref where you don't need to be or at least wrong somehow. Not sure atm. If I could just figure out why I'm throwing a NullReferenceException after finishing the last conversion I'd be set...

http://codepad.org/7rZRxHl9 Seems to be working.

As I understand it, objects passed around in C# are inherently passed by reference. C# also doesn't have pointers.
twitch.tv/cratonz
Pawsom
Profile Blog Joined February 2009
United States928 Posts
November 23 2010 19:29 GMT
#488
On November 24 2010 02:43 Craton wrote:
As I understand it, objects passed around in C# are inherently passed by reference.


Thanks a ton for your help man. Cleared up quite a few things. After working almost entirely on embedded C code the past two years, I'm starting to overthink some things in these higher level languages it seems :p
catamorphist
Profile Joined May 2010
United States297 Posts
November 24 2010 00:23 GMT
#489
On November 24 2010 02:43 Craton wrote:
As I understand it, objects passed around in C# are inherently passed by reference. C# also doesn't have pointers.


Nitpicker's corner: C# does have pointers, but they're not useful for this. C# objects aren't exactly passed by reference in the same way that C++ functions can pass by reference:


void swap(int &x, int &y) { // in C++
int temp = x;
x = y;
y = temp;
}

void swap(MyType x, MyType y) { // in C#
MyType temp = x;
x = y; // NOT doing the same thing!
y = temp; // caller's reference will not be swapped!
}


It would be accurate to say that C# passes object references by value. When a function receives a reference type as a parameter, it receives a new reference to the same object. If the object is mutable and you change fields on that object, they'll be visible to anyone else who has a reference to the same object. (This is the case with your Request object.) However, you don't have the same reference that the caller has, and you can't make the caller's reference point to a different object, or to null.

So that's what the ref keyword is for. If you use ref parameters, you're actually passing by reference in the C++ sense.


void swap(ref MyType x, ref MyType y) { // this works like C++
// ...
}
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
Craton
Profile Blog Joined December 2009
United States17274 Posts
November 24 2010 00:44 GMT
#490
It would be accurate to say that C# passes object references by value. When a function receives a reference type as a parameter, it receives a new reference to the same object.

What is the difference between the two?
twitch.tv/cratonz
catamorphist
Profile Joined May 2010
United States297 Posts
Last Edited: 2010-11-24 01:14:18
November 24 2010 01:11 GMT
#491

public static void Main(string[] args)
{
object alpha = new object(),
beta = new object();

// at this point in time, we have two references, alpha and beta.
// each one is pointing to some object somewhere on the heap

SetToNullA(alpha);
SetToNullB(ref beta);

// alpha is not null. beta is null.
}

static void SetToNullA(object x)
{
// we passed the reference to alpha by value, making a copy of it.

// now we have THREE references, alpha, beta, and x.

// x is pointing to the same object as alpha -- it's a copy
// of alpha. we could change things about that object using x.

// but x is not alpha. if we set x to null,
// that does not mean alpha is null. this function is a no-op

x = null;
}

static void SetToNullB(ref object y)
{
// we passed the reference to beta by reference.

// y is the same reference as beta. if we set y
// to null, then beta is null, too.

y = null;
}
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
HowitZer
Profile Joined February 2003
United States1610 Posts
November 24 2010 04:21 GMT
#492
On November 24 2010 09:44 Craton wrote:
Show nested quote +
It would be accurate to say that C# passes object references by value. When a function receives a reference type as a parameter, it receives a new reference to the same object.

What is the difference between the two?


When you send an object in C# by default it is like a pointer in C++

void mowlawn(LawnMower* mower) c++

void mowlawn(LawnMower mower) c#

Those are equivalent. In both cases setting mower to something else in the function has no effect on the original pointer to mower that was sent in.

void mowlawn(LawnMower& mower) c++

void mowlawn(ref LawnMower mower) c#

And these two are the same thing. If you change what mower points to in the function, the caller mower pointer is changed.
Human teleportation, molecular decimation, breakdown and reformation is inherently purging. It makes a man acute.
KaiserJohan
Profile Joined May 2010
Sweden1808 Posts
November 24 2010 19:52 GMT
#493
On November 22 2010 19:03 HaN- wrote:
[image loading]



Hahaha, you sir win the intarwebz
England will fight to the last American
MasterOfChaos
Profile Blog Joined April 2007
Germany2896 Posts
November 24 2010 20:04 GMT
#494
On November 24 2010 13:21 HowitZer wrote:
void mowlawn(LawnMower& mower) c++
void mowlawn(ref LawnMower mower) c#

And these two are the same thing.

Those two are completely different. The C# code is more like
void mowlawn(LawnMower** mower)

"What is the difference between the two?"
pass by reference would imply that the variables you normally work with have value sematics. But they are references themselves. And when you pass the reference to a function it gets copied, just like a value would be copied.
LiquipediaOne eye to kill. Two eyes to live.
VIB
Profile Blog Joined November 2007
Brazil3567 Posts
November 26 2010 18:52 GMT
#495
Just wanted to let you guys know that these days I finally learned about www.stackoverflow.com and my life changed since then. That's the best website in the history of the internet. If you code on any level and haven't been there yet, you should.

The community is awesomely well organized, it's impressive. TL could get some ideas from there. Their system really works well.
Great people talk about ideas. Average people talk about things. Small people talk about other people.
dapierow
Profile Blog Joined April 2010
Serbia1316 Posts
November 26 2010 21:01 GMT
#496
Hi guys first time poster here, I have a question about creating a square wave table in JAVA

Ive found out that the formula for it is amplitude at max (127) for half the cycle and then zero for the other half \

so the wavetable is only 2 elements

my given frequency is 440 hz and my sample rate is 44100

can anyone help me out for creating a private instance variable for an array of integers that represent a wave table? the consturcter has to be the code for creating and populating the array



Eat.Sleep.Starcraft 2
KaiserJohan
Profile Joined May 2010
Sweden1808 Posts
Last Edited: 2010-11-29 00:03:13
November 28 2010 23:40 GMT
#497
EDIT: Nevermind, my bad >_>
England will fight to the last American
holdthephone
Profile Blog Joined August 2010
United States523 Posts
November 30 2010 06:20 GMT
#498
I really screwed this semester up, and if worst comes to worst I may even have to retake one of my comp sci classes. I'll probably be dropping from my 3.25 gpa to a 2.6 -- honestly haven't felt this terrible for a long time.

Am I screwed now for finding an internship? Does gpa play a big role in finding work? I'm headed into my 2nd semester of junior year and kind of feel like i'm way behind the pack. I'm straight As from here on out, swear to god -- but has the damage already been done?
catamorphist
Profile Joined May 2010
United States297 Posts
Last Edited: 2010-11-30 07:13:09
November 30 2010 07:11 GMT
#499
Competence plays a big role in finding work; there is a huge, perpetual shortage of competent programmers. If you can point at reasonable-quality open-source work that you have done you are automatically sitting on top of the pile, unless you're trying to intern at Google. Worry about your Github exclusively instead of worrying about your GPA.
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
pinkranger15
Profile Joined June 2010
Philippines1597 Posts
December 01 2010 14:28 GMT
#500
hey guys. i'm having a problem right now about the correct algorithm to use in computing exponent. we all know that the basic way to do it is by iteration ( 2^4 = 2 * 2 * 2* 2), but i want to do it recursively so that i will execute faster.

for example, if my exponent is an even number, i have to divide it by 2 until it will not be divided anymore, it will look like this
+ Show Spoiler +
2^e = 2^e/2 * 2^e/2
or
2^8 = 2^4 * 2^4
2^4 = 2^2 * 2^2
2^2 = 2^1 * 2^1
or
2^10 = 2^5 * 2^5
2^5 = 2^4 * 2
2^4 = 2^2 * 2^2


and if my exponent is an odd number, it will look like this
+ Show Spoiler +
2^e = 2^(e-1) * 2
or
2^5 = 2^4 * 2
2^4 = 2^2 * 2^2
2^2 = 2^1 * 2^1


i did my best, and my head is really aching right now. i hope someone will be able to help me. here is the code that i made.


else if (e%2 == 0){ // if the exponent is even
for (i = 0; i < e; i++){
e = e/2;
if (e%2 == 0){
for (i = 0; i < e; i++){
res = res * b;
res = 2*res;
}
}

else if (e%2 == 1){
z = e-1;
for (i = 0; i < z; i++){
res = res * b;
res = 2*res;
}
res = res * b;
}
}
printf("%d\n\n", res);
}

else if (e%2 == 1){ // if the exponent is odd
for (i = 0; i <= e; i++){
e = (e-1) * e;
e = e/2;
res = res * b;
}
printf("%d\n\n", res);
}




thanks guys!
yoyo!
Prev 1 23 24 25 26 27 1032 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
00:00
WardiTV Mondays #62
CranKy Ducklings89
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft424
elazer 208
CosmosSc2 43
Nathanias 0
StarCraft: Brood War
Artosis 613
Larva 163
Bale 12
Dota 2
syndereN965
monkeys_forever355
League of Legends
C9.Mang0256
Counter-Strike
Foxcn217
Other Games
summit1g9929
tarik_tv4756
Grubby4701
FrodaN765
Day[9].tv560
shahzam391
RotterdaM168
Maynarde126
Mew2King66
ViBE33
ToD10
Organizations
Other Games
gamesdonequick563
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• davetesta18
• Hupsaiya 4
• Kozan
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• RayReign 41
• blackmanpl 19
• Azhi_Dahaki9
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• Ler63
League of Legends
• Doublelift4281
Other Games
• imaqtpie1443
• Day9tv560
Upcoming Events
The PondCast
9h 8m
OSC
15h 8m
Demi vs Mixu
Nicoract vs TBD
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
Replay Cast
23h 8m
Korean StarCraft League
2 days
CranKy Ducklings
2 days
WardiTV 2025
2 days
SC Evo League
2 days
BSL 21
2 days
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
2 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
3 days
[ Show More ]
WardiTV 2025
3 days
OSC
3 days
BSL 21
3 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
4 days
Wardi Open
4 days
StarCraft2.fi
4 days
Monday Night Weeklies
4 days
Replay Cast
4 days
WardiTV 2025
5 days
StarCraft2.fi
5 days
PiGosaur Monday
6 days
StarCraft2.fi
6 days
Tenacious Turtle Tussle
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.