Java Programmers ,I Need Help Fixing This Code. - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Java Programmers ,I Need Help Fixing This Code. (2368 Views)
| Java Programmers ,I Need Help Fixing This Code. by Lucasiangrey(op): 9:01am On Oct 02, 2017*. Modified: 5:06pm On Oct 02, 2017 |
I started learning computer programming recently(about two months ago) on my own...So,i am still doing the very basic stuffs...I wanted to write a working code with what i have learnt...So,i decided to write a tic-tac-toe game(no GUI),as to that , i wrote the code bellow...The code works but it has a very big problem and I have been trying to fix it since yesterday,i couldn't.....The problem is that when there is a win,it mistakes the winner always..if Tobi and Dele are the players,when Tobi wins, it will give the win to Dele,just like that.... I know the documentation is poor (remember I am a beginner). Help me fix this.. //tic-tac-toe game |
| Re: Java Programmers ,I Need Help Fixing This Code. by yorex2011: 9:02am On Oct 02, 2017 |
Wtf is this, no explanation of problem, nothing, just dropped code... Na wa o |
| Re: Java Programmers ,I Need Help Fixing This Code. by Lucasiangrey(op): 9:17am On Oct 02, 2017 |
yorex2011:I am really Sorry about that...was not done...just modified it. |
| Re: Java Programmers ,I Need Help Fixing This Code. by Jacktheripper: 9:40am On Oct 02, 2017 |
Leave the programming world u lameass |
| Re: Java Programmers ,I Need Help Fixing This Code. by Lucasiangrey(op): 9:44am On Oct 02, 2017 |
Jacktheripper:k...like you were never once a beginner...thanks for the comment anyway. |
| Re: Java Programmers ,I Need Help Fixing This Code. by Lucasiangrey(op): 10:05am On Oct 02, 2017 |
Javanian
WhiZTiM |
| Re: Java Programmers ,I Need Help Fixing This Code. by Lucasiangrey(op): 11:34am On Oct 02, 2017 |
If you know of people who can help,please give them mention ...i couldn't move forward in my learning due to this... |
| Re: Java Programmers ,I Need Help Fixing This Code. by WhiZTiM(m): 2:34pm On Oct 02, 2017 |
Jacktheripper:@OP, don't mind this one... He's prolly high on some rare stuff. Stop using nairaland's code feature for long codes... Its crappy... really buggy... Use some other online code pasting services. BTW, where and what is the definition of the function "checkWin();" ...? ![]() |
| Re: Java Programmers ,I Need Help Fixing This Code. by ToyinDipo(m): 4:32pm On Oct 02, 2017 |
You didn't initialize turn, so it's the second player always playing first, instead of the intended first player. The code need some refactoring, but here are the simple ones: method checkWin should take in a parameter that holds the player who played last, so that you won't need to duplicate the if else blocks for each player Before making a call to the checkWin method, you should test for the number of moves played, if it's not up to 5, then there is no need Also, you could wrap the check for the non diagonal lines thus: for (int i=0; i<=2; i++) { for (int r =0; r<=2; r++) { if (games[i, 0] == games[i, 1] && games[i, 0] == games[i, 2]) { return true; } if (games[0, i] == games[1, i] && games[0, i] == games[2, i]) { return true; } } } |
| Re: Java Programmers ,I Need Help Fixing This Code. by Lucasiangrey(op): 5:18pm On Oct 02, 2017 |
WhiZTiM:I don't know how to use any other code feature ...in fact i don't know what exactly that mean. ..modified It.... is meant to be isAWin()...I used checkWin when i wrote he code...but when i was about posting it here,I had to change the name of the boolean method so it reflect its purpose better (just to avoid insults ). Just so you know,you inspire me a lot...though,I may not be participating in this programming section but believe me,you made me get a laptop(you made me understand even b4 learning programming that writing a working code is different from writing an efficient code ...i saw your contribution and a guy called josh to the thread about solving project euler's problems)... |
| Re: Java Programmers ,I Need Help Fixing This Code. by Lucasiangrey(op): 5:41pm On Oct 02, 2017 |
ToyinDipo:CODE FIXED!...thanks a lot bro...that loop you gave is a far more concise code(took about 3minutes to understand )...Thanks...But,how good is my code on a scale of 0 to 5 ?. |
| Re: Java Programmers ,I Need Help Fixing This Code. by ToyinDipo(m): 7:23pm On Oct 02, 2017 |
Lucasiangrey:You are welcome. For a beginner, 4/5 |
| Re: Java Programmers ,I Need Help Fixing This Code. by WhiZTiM(m): 5:57pm On Oct 06, 2017 |
Lucasiangrey:Wow .. Thank you for the kind compliments. This, and the apparent evidence for your passion has motivated me to go a step further with your project... So, lets attempt improve your work... First, what JDK version are you using? ...or which IDE are you using? And what version? I simply want to confirm whether you can use Java 8 features. |
| Re: Java Programmers ,I Need Help Fixing This Code. by asibedaniel: 11:13am On Oct 07, 2017 |
Please can anyone help me with CSS I don't know how to space objects |
| Re: Java Programmers ,I Need Help Fixing This Code. by Lucasiangrey(op): 10:22pm On Oct 09, 2017 |
WhiZTiM:thanks,sir...i am using jdk1.7. |
| Re: Java Programmers ,I Need Help Fixing This Code. by WhiZTiM(m): 11:42am On Oct 10, 2017 |
Lucasiangrey:Ok. Can you install JDK1.8? You can download the Netbeans 8.2 and Java8 bundle here: http://www.oracle.com/technetwork/java/javase/downloads/jdk-netbeans-jsp-142931.html Once you do so, buzz me. |
| Re: Java Programmers ,I Need Help Fixing This Code. by Lucasiangrey(op): 3:22am On Oct 13, 2017 |
WhiZTiM:I have installed jdk1.8 and netbeans sir.I have been using notepad ++ , i don't think i know how to use this netbeans well,yet.if it's not a necessity, i will like to just continue with the notepad ++ otherwise , i can dedicate few days to practice code and learn some features of that IDE...thanks. |
| Re: Java Programmers ,I Need Help Fixing This Code. by HottestFire: 7:30pm On Oct 13, 2017 |
Lucasiangrey: ![]() As a self taught programmer, playing around the IDE shouldn't be hard...You've tried. |
Programmers I Need Help • Java Programmers • Java Programmers Plz Help Out • 2 • 3 • 4
Help Pls • Data Science • Programmers: Do You Memorize/cram Your Codes?
;
.. Thank you for the kind compliments.