Diclonius Posted September 4, 2013 Author Share Posted September 4, 2013 (edited) int a = 10, b = 6;if(a > b) { for(int i = b; i <= a; i++) { }} else { for(int i = a; i <= b; i++) { }}=int a = 10, b = 6;for(int i = Math.min(a, b); i <= Math.max(a, b); i++) {} But then the positions could be backwards. I need fullPath to be in order. I'm not just looping through all the tiles, I'm looping from pos1 to pos2 Edited September 4, 2013 by Diclonius Link to comment Share on other sites More sharing options...
codingstyle Posted September 8, 2013 Share Posted September 8, 2013 (edited) using u++ but u = u-1 seriously? (u--) Useful class btw. Edited September 8, 2013 by codingstyle Link to comment Share on other sites More sharing options...
Diclonius Posted September 8, 2013 Author Share Posted September 8, 2013 using u++ but u = u-1 seriously? (u--) Useful class btw. I wasn't 100% sure so I just played it safe :P Also it has some trouble getting to the ends of the path, I don't know why . Link to comment Share on other sites More sharing options...
lolmanden Posted September 8, 2013 Share Posted September 8, 2013 Great work . Link to comment Share on other sites More sharing options...
codingstyle Posted September 10, 2013 Share Posted September 10, 2013 (edited) I know that this will sound a bit fussy, but you really have to work on your java naming conventions. This will improve the readability and quality of your code so much in the long term!things i recognised: Objects = lowercase (Script s) use the final keyword (final Script s, final boolean direction, ....)Things i don't understand: if(direction) { for(int u = 0; u < fullPath.size(); u++) { Position p = fullPath.get(u); if(S.distance(p) < 11) { int xOffSet = MethodProvider.random(3)-1; int yOffSet = MethodProvider.random(3)-1; return new Position(p.getX()+ xOffSet,p.getY()+yOffSet,S.myZ()); } } } else { for(int u = fullPath.size()-1; u > 0; u=u-1) { Position p = fullPath.get(u); if(S.distance(p) < 10) { int xOffSet = MethodProvider.random(5)-2; int yOffSet = MethodProvider.random(5)-2; return new Position(p.getX()+ xOffSet,p.getY()+yOffSet,S.myZ()); } } } why do you have different offset based on the direction your walking?why do you have different conditions? (S.distance(p) < 10 ...... S.distance(p) < 11)please rework the things i told you and post again Edit: make Script private and rethink private/public on your methods... Edited September 10, 2013 by codingstyle Link to comment Share on other sites More sharing options...
Diclonius Posted September 12, 2013 Author Share Posted September 12, 2013 (edited) I know that this will sound a bit fussy, but you really have to work on your java naming conventions. This will improve the readability and quality of your code so much in the long term! things i recognised: Objects = lowercase (Script s) use the final keyword (final Script s, final boolean direction, ....) Things i don't understand: if(direction) { for(int u = 0; u < fullPath.size(); u++) { Position p = fullPath.get(u); if(S.distance(p) < 11) { int xOffSet = MethodProvider.random(3)-1; int yOffSet = MethodProvider.random(3)-1; return new Position(p.getX()+ xOffSet,p.getY()+yOffSet,S.myZ()); } } } else { for(int u = fullPath.size()-1; u > 0; u=u-1) { Position p = fullPath.get(u); if(S.distance(p) < 10) { int xOffSet = MethodProvider.random(5)-2; int yOffSet = MethodProvider.random(5)-2; return new Position(p.getX()+ xOffSet,p.getY()+yOffSet,S.myZ()); } } }why do you have different offset based on the direction your walking?why do you have different conditions? (S.distance(p) < 10 ...... S.distance(p) < 11) please rework the things i told you and post again Edit: make Script private and rethink private/public on your methods... The different offsets and the 10 and 11 are just mistakes when copy and pasting between versions :P. I know my java conventions are poor, I was never tought java. I learnt it through videos and e-books so I haven't had the chance for people to point the mistakes I make so I really appreciate you doing so. Next year I plan to study computer science at uni so then I will hopefully learn these things. Edited September 12, 2013 by Diclonius Link to comment Share on other sites More sharing options...
codingstyle Posted September 13, 2013 Share Posted September 13, 2013 The different offsets and the 10 and 11 are just mistakes when copy and pasting between versions . I know my java conventions are poor, I was never tought java. I learnt it through videos and e-books so I haven't had the chance for people to point the mistakes I make so I really appreciate you doing so. Next year I plan to study computer science at uni so then I will hopefully learn these things. http://docs.oracle.com/javase/tutorial/java/ even if you know most of the stuff there read it all again, because you may have some bad habits, which you didn't know of Also you will leran java naming conventions 1 Link to comment Share on other sites More sharing options...