• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 15:39
CET 20:39
KST 04:39
  • 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
[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy7ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289
Community News
Weekly Cups (March 16-22): herO doubles, Cure surprises3Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool48Weekly Cups (March 9-15): herO, Clem, ByuN win42026 KungFu Cup Announcement6BGE Stara Zagora 2026 cancelled12
StarCraft 2
General
Potential Updates Coming to the SC2 CN Server What mix of new & old maps do you want in the next ladder pool? (SC2) Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Weekly Cups (March 16-22): herO doubles, Cure surprises Weekly Cups (August 25-31): Clem's Last Straw?
Tourneys
WardiTV Mondays Sparkling Tuna Cup - Weekly Open Tournament World University TeamLeague (500$+) | Signups Open RSL Season 4 announced for March-April WardiTV Team League Season 10
Strategy
Custom Maps
[M] (2) Frigid Storage Publishing has been re-enabled! [Feb 24th 2026]
External Content
The PondCast: SC2 News & Results Mutation # 518 Radiation Zone Mutation # 517 Distant Threat Mutation # 516 Specter of Death
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ Gypsy to Korea Soulkey's decision to leave C9 How much money terran looses from gas steal? mca64Launcher - New Version with StarCraft: Remast
Tourneys
[ASL21] Ro24 Group C [Megathread] Daily Proleagues [ASL21] Ro24 Group B 2026 Changsha Offline Cup
Strategy
What's the deal with APM & what's its true value Fighting Spirit mining rates Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Darkest Dungeon Nintendo Switch Thread Stormgate/Frost Giant Megathread General RTS Discussion Thread Path of Exile
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
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 Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia
Community
General
US Politics Mega-thread Canadian Politics Mega-thread Russo-Ukrainian War Thread European Politico-economics QA Mega-thread Things Aren’t Peaceful in Palestine
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Req][Books] Good Fantasy/SciFi books Movie Discussion! [Manga] One Piece
Sports
Cricket [SPORT] 2024 - 2026 Football Thread Formula 1 Discussion Tokyo Olympics 2021 Thread General nutrition recommendations
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1458 users

The Big Programming Thread - Page 801

Forum Index > General Forum
Post a Reply
Prev 1 799 800 801 802 803 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.
Acrofales
Profile Joined August 2010
Spain18246 Posts
November 22 2016 10:24 GMT
#16001
On November 22 2016 19:23 Manit0u wrote:

width = Math.ceil(width);
width = Math.round(width);


Amazing...

Enjoying your new job, are you? :'D
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
November 22 2016 11:50 GMT
#16002
that's probably a back up just in case the first one fails ROFL
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
November 22 2016 11:58 GMT
#16003
On November 22 2016 19:23 Manit0u wrote:

width = Math.ceil(width);
width = Math.round(width);


Amazing...

What's amazing here, I'm missing it. Do you need to execute them both to get the desired result or the fact that you can do Math.ceil and Math.round feels amazing to you after years and years of PHP torture development
"windows bash is a steaming heap of shit" tofucake
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2016-11-22 12:02:49
November 22 2016 12:02 GMT
#16004
--- Nuked ---
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
November 22 2016 13:27 GMT
#16005
On November 22 2016 21:02 Nesserev wrote:
Show nested quote +
On November 22 2016 20:58 Djagulingu wrote:
On November 22 2016 19:23 Manit0u wrote:

width = Math.ceil(width);
width = Math.round(width);


Amazing...

What's amazing here, I'm missing it. Do you need to execute them both to get the desired result or the fact that you can do Math.ceil and Math.round feels amazing to you after years and years of PHP torture development

It's amazing that someone could write such code... it's a real WTF... calling Math.round is totally unneccessary.

I don't wanna believe that someone was dumb enough to write a Math.round right below a Math.ceil.
"windows bash is a steaming heap of shit" tofucake
Manit0u
Profile Blog Joined August 2004
Poland17706 Posts
November 22 2016 13:41 GMT
#16006
On November 22 2016 19:24 Acrofales wrote:
Show nested quote +
On November 22 2016 19:23 Manit0u wrote:

width = Math.ceil(width);
width = Math.round(width);


Amazing...

Enjoying your new job, are you? :'D


My new job starts on the 1st of December. I'm still fighting with the old shit
Time is precious. Waste it wisely.
tofucake
Profile Blog Joined October 2009
Hyrule19197 Posts
November 22 2016 13:48 GMT
#16007
On November 22 2016 20:58 Djagulingu wrote:
Show nested quote +
On November 22 2016 19:23 Manit0u wrote:

width = Math.ceil(width);
width = Math.round(width);


Amazing...

What's amazing here, I'm missing it. Do you need to execute them both to get the desired result or the fact that you can do Math.ceil and Math.round feels amazing to you after years and years of PHP torture development

using round after ceil is pointless because ceil rounds up
Liquipediaasante sana squash banana
Mr. Wiggles
Profile Blog Joined August 2010
Canada5894 Posts
November 22 2016 14:53 GMT
#16008
On November 22 2016 22:27 Djagulingu wrote:
Show nested quote +
On November 22 2016 21:02 Nesserev wrote:
On November 22 2016 20:58 Djagulingu wrote:
On November 22 2016 19:23 Manit0u wrote:

width = Math.ceil(width);
width = Math.round(width);


Amazing...

What's amazing here, I'm missing it. Do you need to execute them both to get the desired result or the fact that you can do Math.ceil and Math.round feels amazing to you after years and years of PHP torture development

It's amazing that someone could write such code... it's a real WTF... calling Math.round is totally unneccessary.

I don't wanna believe that someone was dumb enough to write a Math.round right below a Math.ceil.

I'm wondering what source control history would show for that. Was the second line added months later, was it put in at the same time?

Maybe it used my favourite encountered commit message: "fixes an bug"
you gotta dance
Manit0u
Profile Blog Joined August 2004
Poland17706 Posts
Last Edited: 2016-11-22 16:40:38
November 22 2016 16:39 GMT
#16009
On November 22 2016 23:53 Mr. Wiggles wrote:
Show nested quote +
On November 22 2016 22:27 Djagulingu wrote:
On November 22 2016 21:02 Nesserev wrote:
On November 22 2016 20:58 Djagulingu wrote:
On November 22 2016 19:23 Manit0u wrote:

width = Math.ceil(width);
width = Math.round(width);


Amazing...

What's amazing here, I'm missing it. Do you need to execute them both to get the desired result or the fact that you can do Math.ceil and Math.round feels amazing to you after years and years of PHP torture development

It's amazing that someone could write such code... it's a real WTF... calling Math.round is totally unneccessary.

I don't wanna believe that someone was dumb enough to write a Math.round right below a Math.ceil.

I'm wondering what source control history would show for that. Was the second line added months later, was it put in at the same time?

Maybe it used my favourite encountered commit message: "fixes an bug"


The only available history for it is when they moved from svn to git over a year ago. I don't have access to anything prior to that. Considering how the rest of the code base looks for this system I think it's a pretty safe bet to assume that both lines were created at the same time. Another possibility is a sloppy merge, but there's no history for that.
Time is precious. Waste it wisely.
Neshapotamus
Profile Blog Joined May 2006
United States163 Posts
Last Edited: 2016-11-22 20:01:46
November 22 2016 19:39 GMT
#16010
On November 22 2016 17:50 Neshapotamus wrote:
Don't know why your using a generic V. Use integer instead.

Why?

It is much more straight forward to use an integer. Generics are a template. At this point, you already know the structure. No need to complicate your code by using generics. From looking at his code, he is getting confused cause he is dealing with all different types of topics like generics, hashmaps. hashsets, linkedlist.


Visited should be a boolean array. The size of visited should be equal to the number of verticies. Make this a class level scope.


Why?

he should do this so he can re-use this for DFS


You don't have to explicitly terminate your algorithms. It will reach all the connected components by itself and complete.


Still have to check whether you reached end or not. No need to keep searching the graph if you found your destination. Moreover, you want it to terminate differently, e.g. return true if it found end and false if it didn't. That is missing from the algorithm, I agree.

BFS/DFS has the property that it will only visit the nodes that it is part of its network. The algorithm will auto terminate after it has visited every node. Yes, you can add an early termination, but what if you are given an end vertex that is not part of the connected components? You will traverse the entire graph anyways. It runs in O(V + E) time if you are using an adjacency list, which is pretty darn fast.



DFS should be implemented using recursion. Otherwise, you will have to create your own stack. This is where having visited at a class scope will help.

You bfs has a fundamental problem.
*Write the for loop first
*Inside the for loop, check to see if you have visited the adjacent nodes. Then mark the adjacent nodes as being visited.


Some other tips:
Don't use a hashmap, use an array. (You can create an array of list<int> per index. The index of the array maps to vertex.)



You're making some assumptions here about the form of the input he's getting. But yes, numbering the nodes and using an array would also be a more efficient way of checking whether a node was visited than using a hashset.

Yes, I am making several assumptions. Since we know this is a graph search problems, I can infer from this statement that he is given the total number of vertices and the edges between each vertex was given ahead of time (the edges are not dynamic) before calling bfs. You have to do a little bit of pre-processing to get to this state from whatever his input would be. I am trying to help him understand the basic concept with only the minimum amount code he needs to accomplish his task.


Create a variable called PathTo. PathTo should be a integer array; The size of PathTo array should be equal to the number of verticies. You will need this to build a complete path from source to destination.

Here is a method you should implement if you take my suggestion above:
public boolean hasPathTo(int v); //run in constant time
public Iterable<Integer> pathTo(int v); //use the PathTo variable and create a path



You're assuming he has to return the path. Might all be unnecessary. -

I am suggesting this to help him debug.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2016-11-23 01:01:07
November 22 2016 22:56 GMT
#16011
On November 22 2016 19:23 Manit0u wrote:

width = Math.ceil(width);
width = Math.round(width);


Amazing...


I remember seeing this in Java before.

Math.ceil takes a double and returns a double
Math.round takes a double and returns a long

Instead of doing `int w = (int) Math.ceil(width);` you would do `int w = Math.round(Math.ceil(width));` if you wanted to get the nearest number rounded up.

In this case though, who really knows why they're reassigning the long result back to the double width...
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-23 03:21:53
November 23 2016 02:17 GMT
#16012
well w/e
this was the dumbest project ever

the problem is clearly the tests

appreciate all the replies though

Unfortunately if I had more time I would use your suggestions to clean up my code. Maybe I could simplify some of this to figure out what is going on.. or at least pass the stupid tests anyways.

What's sad is that I actually broke the GUI and started passing more tests (and the changes I made make absolutely no sense at all)
Manit0u
Profile Blog Joined August 2004
Poland17706 Posts
November 23 2016 03:35 GMT
#16013
On November 23 2016 07:56 Blisse wrote:
Show nested quote +
On November 22 2016 19:23 Manit0u wrote:

width = Math.ceil(width);
width = Math.round(width);


Amazing...


I remember seeing this in Java before.

Math.ceil takes a double and returns a double
Math.round takes a double and returns a long

Instead of doing `int w = (int) Math.ceil(width);` you would do `int w = Math.round(Math.ceil(width));` if you wanted to get the nearest number rounded up.

In this case though, who really knows why they're reassigning the long result back to the double width...


Want to hear the best part? It's JavaScript
Time is precious. Waste it wisely.
Hanh
Profile Joined June 2016
146 Posts
November 23 2016 04:17 GMT
#16014
On November 23 2016 11:17 travis wrote:
well w/e
this was the dumbest project ever

the problem is clearly the tests

appreciate all the replies though

Unfortunately if I had more time I would use your suggestions to clean up my code. Maybe I could simplify some of this to figure out what is going on.. or at least pass the stupid tests anyways.

What's sad is that I actually broke the GUI and started passing more tests (and the changes I made make absolutely no sense at all)


Regardless of the quality of the tests, Acrofales is right and you aren't implementing BFS correctly. You actually just need to move a line of your code.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
November 23 2016 04:22 GMT
#16015
yeah I realized that today at school
didn't actually stop me from passing the test, though. which is kind of funny.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
November 23 2016 04:23 GMT
#16016
I'm making a dungeon game and my trolls around running around like they're on meth. I can't figure out how to calm them down. This is in pygame.

The heartbeat:
    def run_game(self):
# Heartbeat
while not (self.game_over or self.level.player.is_dead):
self.handle_events()
self.move_creatures()
self.draw_screen()
pygame.time.wait(100)
self.end_game()


where draw_screen is
    def draw_screen(self):
# Update game visuals
self.screen.fill((0, 0, 0))
self.draw_blocks()
pygame.display.flip()
self.clock.tick(60)


The problem is that I can make the trolls slow down by increasing the wait time between game cycles, but then the player moves too slowly. I'm looking for a fair way to slow down how frequently the trolls move. Any ideas?
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
meatpudding
Profile Joined March 2011
Australia520 Posts
November 23 2016 04:49 GMT
#16017
On November 23 2016 13:23 WarSame wrote:
I'm making a dungeon game and my trolls around running around like they're on meth. I can't figure out how to calm them down. This is in pygame.

The heartbeat:
    def run_game(self):
# Heartbeat
while not (self.game_over or self.level.player.is_dead):
self.handle_events()
self.move_creatures()
self.draw_screen()
pygame.time.wait(100)
self.end_game()


where draw_screen is
    def draw_screen(self):
# Update game visuals
self.screen.fill((0, 0, 0))
self.draw_blocks()
pygame.display.flip()
self.clock.tick(60)


The problem is that I can make the trolls slow down by increasing the wait time between game cycles, but then the player moves too slowly. I'm looking for a fair way to slow down how frequently the trolls move. Any ideas?


Lots of ways to do this. In move_creatures you could add a counter like this
counter += 1
if counter < threshold: return
# reset the counter
counter = 0
...
# actual code here
Be excellent to each other.
Acrofales
Profile Joined August 2010
Spain18246 Posts
November 23 2016 07:16 GMT
#16018
On November 23 2016 13:23 WarSame wrote:
I'm making a dungeon game and my trolls around running around like they're on meth. I can't figure out how to calm them down. This is in pygame.

The heartbeat:
    def run_game(self):
# Heartbeat
while not (self.game_over or self.level.player.is_dead):
self.handle_events()
self.move_creatures()
self.draw_screen()
pygame.time.wait(100)
self.end_game()


where draw_screen is
    def draw_screen(self):
# Update game visuals
self.screen.fill((0, 0, 0))
self.draw_blocks()
pygame.display.flip()
self.clock.tick(60)


The problem is that I can make the trolls slow down by increasing the wait time between game cycles, but then the player moves too slowly. I'm looking for a fair way to slow down how frequently the trolls move. Any ideas?


I believe the solution is:
self.remove_meth()



Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2016-11-23 14:22:36
November 23 2016 14:17 GMT
#16019
--- Nuked ---
tofucake
Profile Blog Joined October 2009
Hyrule19197 Posts
November 23 2016 15:15 GMT
#16020
[image loading]

some of our devs need to learn how to manage their queries :\
Liquipediaasante sana squash banana
Prev 1 799 800 801 802 803 1032 Next
Please log in or register to reply.
Live Events Refresh
OSC
18:00
OSC Elite Rising Star #18
SteadfastSC145
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
elazer 256
SteadfastSC 145
SpeCial 141
UpATreeSC 113
JuggernautJason67
mouzHeroMarine 42
MindelVK 33
StarCraft: Brood War
Britney 14183
Calm 2751
EffOrt 541
Horang2 405
Shuttle 345
ggaemo 75
Backho 57
HiyA 42
soO 20
ivOry 5
Dota 2
Gorgc8695
Counter-Strike
fl0m1536
Other Games
summit1g5003
tarik_tv2627
Grubby2239
B2W.Neo909
Beastyqt633
ArmadaUGS119
C9.Mang0107
mouzStarbuck75
QueenE69
Mew2King50
Trikslyr50
Organizations
Other Games
gamesdonequick1769
BasetradeTV24
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• Kozan
• sooper7s
• Migwel
• LaughNgamezSOOP
• AfreecaTV YouTube
• IndyKCrew
• intothetv
StarCraft: Brood War
• RayReign 9
• 80smullet 9
• ZZZeroYoutube
• STPLYoutube
• BSLYoutube
Dota 2
• C_a_k_e 1576
• WagamamaTV541
League of Legends
• Nemesis4187
• Jankos1713
• TFBlade780
Other Games
• Scarra1320
• imaqtpie1011
• Shiphtur146
Upcoming Events
Replay Cast
4h 22m
WardiTV Team League
16h 22m
Big Brain Bouts
21h 22m
Fjant vs SortOf
YoungYakov vs Krystianer
Reynor vs HeRoMaRinE
RSL Revival
1d 14h
Cure vs Zoun
herO vs Rogue
WardiTV Team League
1d 16h
Platinum Heroes Events
1d 19h
BSL
2 days
RSL Revival
2 days
ByuN vs Maru
MaxPax vs TriGGeR
WardiTV Team League
2 days
BSL
2 days
[ Show More ]
Replay Cast
3 days
Replay Cast
3 days
Afreeca Starleague
3 days
Light vs Calm
Royal vs Mind
Wardi Open
3 days
Monday Night Weeklies
3 days
OSC
4 days
Sparkling Tuna Cup
4 days
Afreeca Starleague
4 days
Rush vs PianO
Flash vs Speed
Replay Cast
5 days
Afreeca Starleague
5 days
BeSt vs Leta
Queen vs Jaedong
Replay Cast
6 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2026-03-25
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
BSL Season 22
CSL Elite League 2026
CSL Season 20: Qualifier 1
ASL Season 21
Acropolis #4 - TS6
RSL Revival: Season 4
Nations Cup 2026
NationLESS Cup
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

2026 Changsha Offline CUP
CSL Season 20: Qualifier 2
CSL 2026 SPRING (S20)
Acropolis #4
IPSL Spring 2026
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
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 © 2026 TLnet. All Rights Reserved.