Computer Science Canada Help With TICTACTOE |
Author: | programmer1337 [ Mon Jun 11, 2012 9:53 pm ] | ||
Post subject: | Help With TICTACTOE | ||
Ok so I have my two player tic tac toe working, now I need my easy option to work against cpu, for easy i made it a random number generator, now after 3 or 4 moves the input box just quits and the program stops without checking for a win...here is my code
|
Author: | Tony [ Mon Jun 11, 2012 11:58 pm ] |
Post subject: | Re: Help With TICTACTOE |
programmer1337 @ Mon Jun 11, 2012 9:53 pm wrote: now after 3 or 4 moves the input box just quits and the program stops without checking for a win...
That's unfortunate... perhaps you should fix that. |
Author: | Zren [ Tue Jun 12, 2012 3:06 am ] |
Post subject: | RE:Help With TICTACTOE |
I can see how it get's into an infinite loop, but nothing that would make it quit. |
Author: | programmer1337 [ Tue Jun 12, 2012 7:31 am ] |
Post subject: | RE:Help With TICTACTOE |
can you give me a hint please |
Author: | programmer1337 [ Tue Jun 12, 2012 8:24 am ] |
Post subject: | RE:Help With TICTACTOE |
I found out that if you choose to pick a spot where the computer picks it turns into an infinite loop, but I dont know why? |
Author: | Zren [ Tue Jun 12, 2012 2:28 pm ] |
Post subject: | RE:Help With TICTACTOE |
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Math.html#random() Quote: Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
Casting from double to int is the same as flooring the number. I strongly suggest writing a randomIntInRange(min, max) or something where both the parameters are included in the range. Tip: Make sure you test that function before including it in this project. In other words, make a new project called 'Test' that you just have a main class + main function that you use to write stand alone functions in. |
Author: | programmer1337 [ Tue Jun 12, 2012 3:08 pm ] |
Post subject: | Re: RE:Help With TICTACTOE |
Zren @ Tue Jun 12, 2012 2:28 pm wrote: http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Math.html#random()
Ok so I did what you said, and it has not fixed anything, my problem was that when I pick a spot in the array that the random number generator has chosen also, the input box closes and it creates an infinite loopQuote: Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
Casting from double to int is the same as flooring the number. I strongly suggest writing a randomIntInRange(min, max) or something where both the parameters are included in the range. Tip: Make sure you test that function before including it in this project. In other words, make a new project called 'Test' that you just have a main class + main function that you use to write stand alone functions in. |
Author: | programmer1337 [ Wed Jun 13, 2012 11:56 am ] |
Post subject: | RE:Help With TICTACTOE |
fixed ![]() |