• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 08:53
CET 14:53
KST 22:53
  • 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
TL.net Map Contest #21: Winners10Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
StarCraft, SC2, HotS, WC3, Returning to Blizzcon!33$5,000+ WardiTV 2025 Championship6[BSL21] RO32 Group Stage4Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win10
StarCraft 2
General
Mech is the composition that needs teleportation t TL.net Map Contest #21: Winners Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win RotterdaM "Serral is the GOAT, and it's not close" 5.0.15 Patch Balance Hotfix (2025-10-8)
Tourneys
Constellation Cup - Main Event - Stellar Fest $5,000+ WardiTV 2025 Championship Sparkling Tuna Cup - Weekly Open Tournament Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
[ASL20] Ask the mapmakers — Drop your questions BW General Discussion [BSL21] RO32 Group Stage BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review
Tourneys
[Megathread] Daily Proleagues [ASL20] Grand Finals [BSL21] RO32 Group B - Sunday 21:00 CET [BSL21] RO32 Group A - Saturday 21:00 CET
Strategy
Current Meta PvZ map balance How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile Should offensive tower rushing be viable in RTS games? Dawn of War IV
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine YouTube Thread Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1394 users

The Big Programming Thread - Page 95

Forum Index > General Forum
Post a Reply
Prev 1 93 94 95 96 97 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.
Pawsom
Profile Blog Joined February 2009
United States928 Posts
November 18 2011 06:03 GMT
#1881
On November 18 2011 13:15 destian wrote:
where does business logic go in an mvvm pattern?

should the viewmodel contain any business logic?


No the business logic belongs in the model. The View Model should contain the logic for presentation of data.
Frosticles
Profile Joined May 2010
United States50 Posts
November 18 2011 06:08 GMT
#1882

On November 18 2011 13:06 Frosticles wrote:
Hi, I am having trouble initializing variables using str.at(). in c++
for example,
if I have a code like

cin >> str;

b = (str.at(0));
c = (str.at(1));

when imputting a string such as 12, it wont initialize properly, and it will instead give me something like
b = 50
c = 58

I don't know why its not initializing properly

Thanks

make sure b and c are a string or char



Declaring them as char's fixed the initialization, but I'm still having troubles doing something such as multiplying them togethor.
char a = 3
char b = 4

(a * b) = 2601

Any reason why this is?
Pawsom
Profile Blog Joined February 2009
United States928 Posts
Last Edited: 2011-11-18 06:13:13
November 18 2011 06:12 GMT
#1883
On November 18 2011 15:08 Frosticles wrote:
Show nested quote +

On November 18 2011 13:06 Frosticles wrote:
Hi, I am having trouble initializing variables using str.at(). in c++
for example,
if I have a code like

cin >> str;

b = (str.at(0));
c = (str.at(1));

when imputting a string such as 12, it wont initialize properly, and it will instead give me something like
b = 50
c = 58

I don't know why its not initializing properly

Thanks

make sure b and c are a string or char



Declaring them as char's fixed the initialization, but I'm still having troubles doing something such as multiplying them togethor.
char a = 3
char b = 4

(a * b) = 2601

Any reason why this is?


You can't multiply letters. You can multiply numbers. If you want to multiply them, they will need to be ints. The reason you get bogus data is because you're multiplying the ASCII values of two stored characters.
Frosticles
Profile Joined May 2010
United States50 Posts
November 18 2011 06:16 GMT
#1884
But I cannot declare them as ints because then it just gives me bogus data like I said in the first post <.<
Craton
Profile Blog Joined December 2009
United States17264 Posts
November 18 2011 06:21 GMT
#1885
Did you neglect to convert the parsed string into an int?
twitch.tv/cratonz
tarian
Profile Joined August 2010
United States67 Posts
Last Edited: 2011-11-18 06:24:29
November 18 2011 06:23 GMT
#1886
On November 18 2011 15:08 Frosticles wrote:
Show nested quote +

On November 18 2011 13:06 Frosticles wrote:
Hi, I am having trouble initializing variables using str.at(). in c++
for example,
if I have a code like

cin >> str;

b = (str.at(0));
c = (str.at(1));

when imputting a string such as 12, it wont initialize properly, and it will instead give me something like
b = 50
c = 58

I don't know why its not initializing properly

Thanks

make sure b and c are a string or char



Declaring them as char's fixed the initialization, but I'm still having troubles doing something such as multiplying them togethor.
char a = 3
char b = 4

(a * b) = 2601

Any reason why this is?

I haven't messed with c++ in a while so I just googled char to int and found this, hope it helps:

c = atoi(&a) * atoi(&b);

The atoi() function converts from ascii to int
Xzilend
Profile Joined March 2011
Canada29 Posts
Last Edited: 2011-11-18 06:24:06
November 18 2011 06:23 GMT
#1887
You want to do:

#include <stdlib.h>

cin >> str;
int x = atoi(str);
MrBitter: "What do you do when you attack?" ... Student: "I lose?"
Pawsom
Profile Blog Joined February 2009
United States928 Posts
Last Edited: 2011-11-18 06:47:32
November 18 2011 06:45 GMT
#1888
edit nm
Frosticles
Profile Joined May 2010
United States50 Posts
November 18 2011 15:16 GMT
#1889
tyvm :D I didn't realize that you had to actually convert the character 4 to an integer 4, but it makes complete sense now, thankyou so much :D
Teim
Profile Joined October 2010
Australia373 Posts
November 19 2011 06:37 GMT
#1890
I have an algorithm question. Say I have a bunch of entities on a grid like so:

[image loading]

Now, Blueman needs to find the nearest Redman to him. The simple solution is to iterate through each man, checking that it is indeed a Redman, calculate distance, compare the distances to find the smallest one and proceed from there.

But in my application I could have thousands of these guys searching for one another at any given time, so I feel this is going to be way too slow.

Is there a better way to find the nearest guy? Memory is not an issue for my particular problem, so I'm happy to trade memory for processing time if such a thing is possible here.

(Note: At the moment I'm not actually storing a grid, just the entities on a list keeping track of their own coordinate data. But changing design is no problem here.)
A duck is a duck!
Abductedonut
Profile Blog Joined December 2010
United States324 Posts
Last Edited: 2011-11-19 07:05:58
November 19 2011 06:58 GMT
#1891
Hmm.. stupid idea but.. you could try to create "squares" around the blueman until you hit a redman based on a radius. Since you know the distance everywhere will be the same, the first redman you come into contact with should be the closest. For example... Just an idea, don't know if it would be more efficient.


[image loading]

*edit* come to think of it, the more redmans you have the more efficient that would be, sortof. You could keep a count of your redmans and switch between your method and that above based of that. For example, if your count is something like 2.. it's probably smarter to just use your method.
Kentor *
Profile Blog Joined December 2007
United States5784 Posts
Last Edited: 2011-11-19 07:17:25
November 19 2011 07:14 GMT
#1892
On November 19 2011 15:37 Teim wrote:
I have an algorithm question. Say I have a bunch of entities on a grid like so:

[image loading]

Now, Blueman needs to find the nearest Redman to him. The simple solution is to iterate through each man, checking that it is indeed a Redman, calculate distance, compare the distances to find the smallest one and proceed from there.

But in my application I could have thousands of these guys searching for one another at any given time, so I feel this is going to be way too slow.

Is there a better way to find the nearest guy? Memory is not an issue for my particular problem, so I'm happy to trade memory for processing time if such a thing is possible here.

(Note: At the moment I'm not actually storing a grid, just the entities on a list keeping track of their own coordinate data. But changing design is no problem here.)

Couple of questions: Are the number of guys of each color constant? Are they going to move at all at any later time?

I use something called a cell linked list for molecular simulations. It can probably be applied here although the scenario is different.

Also for the post above, how would the computer know that the red guy is in the square that you've drawn? It would have to check each red guy again which is the problem we are trying to avoid.
rabidch
Profile Joined January 2010
United States20289 Posts
November 19 2011 07:28 GMT
#1893
On November 19 2011 16:14 Kentor wrote:
Show nested quote +
On November 19 2011 15:37 Teim wrote:
I have an algorithm question. Say I have a bunch of entities on a grid like so:

[image loading]

Now, Blueman needs to find the nearest Redman to him. The simple solution is to iterate through each man, checking that it is indeed a Redman, calculate distance, compare the distances to find the smallest one and proceed from there.

But in my application I could have thousands of these guys searching for one another at any given time, so I feel this is going to be way too slow.

Is there a better way to find the nearest guy? Memory is not an issue for my particular problem, so I'm happy to trade memory for processing time if such a thing is possible here.

(Note: At the moment I'm not actually storing a grid, just the entities on a list keeping track of their own coordinate data. But changing design is no problem here.)

Couple of questions: Are the number of guys of each color constant? Are they going to move at all at any later time?

I use something called a cell linked list for molecular simulations. It can probably be applied here although the scenario is different.

Also for the post above, how would the computer know that the red guy is in the square that you've drawn? It would have to check each red guy again which is the problem we are trying to avoid.

The most important question that needs to be answered is do they move and do they move frequently.
LiquidDota StaffOnly a true king can play the King.
InRaged
Profile Joined February 2007
1047 Posts
November 19 2011 08:23 GMT
#1894
Teim, quadtree is your solution.
First you put all your guys into quadtree. Then, when you need to find closest, you first iterate over your guy's neighbour nodes and find the ones that have target guys in them and only then you check these target guys from those nodes to find the closest one.
FinnGamer
Profile Blog Joined December 2010
Germany2426 Posts
Last Edited: 2011-11-19 16:41:09
November 19 2011 12:29 GMT
#1895
I have a really annoying html problem, I'm trying to get a MouseOver in my area tag and I have tried many variations, but I don't get it, here's my code
        <div id="Stadt">
<img src="../Bilder/Stadtteile.png" usemap="#STT" border="0" alt="1" id="ST">
<map id="STT" name="STT">
<area shape="poly" coords="539,63,513,151,709,161,537,195,621,227,639,213,657,207,683,195,737,173,717,145,711,107,671,109,679,65,621,79,583,203,537,119," href="Über Tokyo.html#Adachi" alt="adachi" title="adachi" onmouseover="Stadtteile ('over', 'Adachi');" onmouseout="Stadtteile ('out', 'welt');">
</map>
<div id="Liste">
<a href="Adachi" title="Adachi">Adachi</a>

</div>
</div>
function StadtteileHover(nmode,srcname)
{
if (nmode == 'over') {
document.getElementById('STT').src = '../bilder/aktiv/' + srcname + '.png';
} else {
document.getElementById('STT').src = '../bilder/Stadtteile.png';
}
}

I have shortened the code to the relavent parts.
I have tried
onmouseover="this.src='../Bilder/aktiv/adachi.png';" onmouseout="this.src='../bilder/Stadtteile.jpg';"

as well.

Never mind, it was
onmouseover="if(document.images) document.ST.src='../Bilder/Aktiv/Adachi.png';"onmouseout="if(document.images) document.ST.src='../Bilder/Stadtteile.png';"
"hopefully swing the favor in your advantage." - Day[9]
klo8
Profile Joined August 2010
Austria1960 Posts
Last Edited: 2011-11-19 13:22:47
November 19 2011 13:22 GMT
#1896
Hi!

I'm currently doing a Java 2 Mobile Edition game (an RPG, also, my first real game) for a class and I'm having a bit of trouble with the game loop. Right now, it looks about like this (the game loop class is a Runnable)

public void run()
{
loadResources();
while(!gameOver)
{
updateScreen();
processKeys();
Thread.sleep(40);
}
}

So, the game loop sleeps for 40 ms at every iteration, which results in 25 fps. When processing the keys, I want to move the player character 1 tile (32x32) each time he hits one of the movement buttons. Now, I can obviously make it so the player can move 32 pixel per step (each method call to player.move() increments or decrements the position in x or y by 32) , therefore 32 * 25 pixel per second, which is way too fast. I'm kind of stumped right now on how to make it so the player character can only move between tiles while also making him move at a reasonable speed.
This post is clearly not a hurr, as you can see from the graph, the durr never intersects with the derp.
JellowLight
Profile Blog Joined October 2011
60 Posts
November 19 2011 13:28 GMT
#1897
You probably have to do your moving action at the moment that the player releases the key. This would result in 1 calculation aka 32 pixels. Or you can either use counters or a variable that stores if you have moved since the key is pressed and resets @ release.
Just some quick options i came up with.
MrShankly
Profile Blog Joined October 2009
United Kingdom371 Posts
November 19 2011 13:34 GMT
#1898
On November 19 2011 22:22 klo8 wrote:
Hi!

I'm currently doing a Java 2 Mobile Edition game (an RPG, also, my first real game) for a class and I'm having a bit of trouble with the game loop. Right now, it looks about like this (the game loop class is a Runnable)

public void run()
{
loadResources();
while(!gameOver)
{
updateScreen();
processKeys();
Thread.sleep(40);
}
}

So, the game loop sleeps for 40 ms at every iteration, which results in 25 fps. When processing the keys, I want to move the player character 1 tile (32x32) each time he hits one of the movement buttons. Now, I can obviously make it so the player can move 32 pixel per step (each method call to player.move() increments or decrements the position in x or y by 32) , therefore 32 * 25 pixel per second, which is way too fast. I'm kind of stumped right now on how to make it so the player character can only move between tiles while also making him move at a reasonable speed.


If you want the wee dude to only move 32 units at a time, but he is moving fast because hes doing that every frame you probably have 2 choices, you can only handle the input for moving the character every few frames. So he clicks the button and the guy moves, and then it will only allow him to move again after a certain amount of time, however this will result in a stuttering movement.

Another thing you could do is when the guy is told to move to the next square, the next square is stored as the players destination, and then the player is slowly animated moving to that next square, but its hard to say without knowing exactly what you want to do.


DONATE SC2 BETA KEY TO ME PLEASE
Zocat
Profile Joined April 2010
Germany2229 Posts
November 19 2011 13:34 GMT
#1899
klo8:
You can register when you moved last. And then ignore keycommands (or only move commands, depending on what you want) until you want to allow it again. You can do that frame based (normal counter reduced by 1 each time processKeys() is executed), or time based (get system time and calculate how long it has been since you issued the lock).
klo8
Profile Joined August 2010
Austria1960 Posts
Last Edited: 2011-11-19 13:47:19
November 19 2011 13:45 GMT
#1900
Wow, thanks for the quick answers! I think I'll try Zocat's approach first, it sounds the most robust.

Oh, and if you ever want to program a game in your spare time, try not doing it with J2ME. It's alright and the built-in game stuff is quite helpful, but it's all so outdated. It's based on Java 1.3, which like 10 years old by now. No generics, no foreach loops, it's pretty annoying sometimes. If I had to choose, I'd go with XNA.

By the way, it's not really the player that is moving, the character is fixed in the middle of the screen and the environment around him moves (think of Pokemon) but that's not really relevant.
This post is clearly not a hurr, as you can see from the graph, the durr never intersects with the derp.
Prev 1 93 94 95 96 97 1032 Next
Please log in or register to reply.
Live Events Refresh
CranKy Ducklings
10:00
Sea Duckling Open #140
CranKy Ducklings84
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 198
Railgan 42
Creator 14
StarCraft: Brood War
Sea 6694
Horang2 4040
GuemChi 1668
Jaedong 862
actioN 292
Mini 259
BeSt 247
Killer 230
Soma 220
EffOrt 210
[ Show more ]
Rush 169
Mind 92
Hyun 87
Bonyth 72
ToSsGirL 69
Backho 61
sas.Sziky 33
JYJ28
PianO 27
zelot 24
Aegong 14
soO 12
Terrorterran 10
Sacsri 9
sorry 9
HiyA 8
Dota 2
Gorgc6041
singsing2210
qojqva1772
Dendi596
XcaliburYe214
BananaSlamJamma90
Heroes of the Storm
Khaldor209
Other Games
B2W.Neo1194
Lowko261
Sick244
Fuzer 193
Hui .112
XaKoH 95
nookyyy 54
MindelVK19
Organizations
StarCraft 2
WardiTV622
Counter-Strike
PGL242
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• StrangeGG 67
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2050
League of Legends
• Stunt703
• HappyZerGling113
Upcoming Events
IPSL
4h 7m
dxtr13 vs OldBoy
Napoleon vs Doodle
LAN Event
4h 7m
Lambo vs Clem
Scarlett vs TriGGeR
ByuN vs TBD
Zoun vs TBD
BSL 21
6h 7m
Gosudark vs Kyrie
Gypsy vs OyAji
UltrA vs Radley
Dandy vs Ptak
Replay Cast
9h 7m
Sparkling Tuna Cup
20h 7m
WardiTV Korean Royale
22h 7m
LAN Event
1d 1h
IPSL
1d 4h
JDConan vs WIZARD
WolFix vs Cross
BSL 21
1d 6h
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
1d 19h
[ Show More ]
Wardi Open
1d 22h
WardiTV Korean Royale
2 days
Replay Cast
3 days
Kung Fu Cup
3 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
4 days
The PondCast
4 days
RSL Revival
4 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
4 days
WardiTV Korean Royale
4 days
RSL Revival
5 days
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
5 days
CranKy Ducklings
6 days
RSL Revival
6 days
herO vs Gerald
ByuN vs SHIN
Kung Fu Cup
6 days
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
Stellar Fest: Constellation Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 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.