AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

tic tac toe
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Michael
Guest





PostPosted: Fri Oct 21, 2005 12:25 am    Post subject: tic tac toe Reply with quote



Hello guys,
I went to see my instructor today and resolved my problem with the
previous question. I know think I understand the logic of using flags. I'll
review it when I have some time, just to make sure it sticks in my head.
Anyways I have to make a tic tac toe game now for tomorrow. He explained to
me what I ought to do. But of course I am having problems implementing it in
java. First off, I think this is a basic tic tac toe game compared with
others I have seen on the net. Anyways the board is labeled like this;
123
456
789
I know I have to first count the number of x's and o's. For that I will use
two for loops (one for x's and one for o's). Then I need to set x equal to
y. IF there even, I know it is x's turn since x starts the game. If there
uneven its o's turn. My question is I know I have to count the number of x's
in a for loop. But do I just assign that to a char type, then after I count
both x's and o's I can compare them to see if there equal, if so its x's
move otherwise its o's move. Then I need to determine whether the moves are
valid or invalid. Then I need to implement a switch statement to account for
all the possible outcomes of the 9 possible causes. Any suggestions are most
welcome. Thanks again. I need to wrap my mind on the logic of implementing
these things in java.


Back to top
Andrew Thompson
Guest





PostPosted: Fri Oct 21, 2005 12:36 am    Post subject: Re: tic tac toe Reply with quote



Michael wrote:

Quote:
...Any suggestions are most
welcome. Thanks again. I need to wrap my mind on the logic of implementing
these things in java.

This might help you kick-start the process..
<http://home.earthlink.net/~patricia_shanahan/beginner.html>

Back to top
Michael
Guest





PostPosted: Fri Oct 21, 2005 2:00 am    Post subject: Re: tic tac toe Reply with quote



Hello again, I read that site; good advice. I have wrote the following thus
far. I realize I am comparing i to j here, but I what i really wish to do is
compare if the number of x's is equal to o's. SO i order to accomplish this
i would need the assignment operator = but then I can't use the if/else
statement. This is somewhat puzzling me. Any suggestions?

public class move {

public static void main(String[] args) {

String str = Stdin.readln();

char move;

// count the number of X's
int i = 0;
while(i<= str.length()){
i++;
System.out.println(i);
}
// count the number of O's
int j = 0;
while(j<= str.length()){
j++;
//System.out.println(j);
}

if(i == j){
move = 'x';
}else{
move = 'o';

System.out.println(move);
}










}
}

"Michael"
Quote:
Hello guys,
I went to see my instructor today and resolved my problem with the
previous question. I know think I understand the logic of using flags.
I'll review it when I have some time, just to make sure it sticks in my
head. Anyways I have to make a tic tac toe game now for tomorrow. He
explained to me what I ought to do. But of course I am having problems
implementing it in java. First off, I think this is a basic tic tac toe
game compared with others I have seen on the net. Anyways the board is
labeled like this;
123
456
789
I know I have to first count the number of x's and o's. For that I will
use two for loops (one for x's and one for o's). Then I need to set x
equal to y. IF there even, I know it is x's turn since x starts the game.
If there uneven its o's turn. My question is I know I have to count the
number of x's in a for loop. But do I just assign that to a char type,
then after I count both x's and o's I can compare them to see if there
equal, if so its x's move otherwise its o's move. Then I need to determine
whether the moves are valid or invalid. Then I need to implement a switch
statement to account for all the possible outcomes of the 9 possible
causes. Any suggestions are most welcome. Thanks again. I need to wrap my
mind on the logic of implementing these things in java.




Back to top
Michael
Guest





PostPosted: Fri Oct 21, 2005 2:15 am    Post subject: Re: tic tac toe Reply with quote

Question: Why is this program printing out a O, when it should be an x?
Here's my code updated code.

public class move {

public static void main(String[] args) {

String str = Stdin.readln();

boolean a = true;
char move;

// count the number of X's
int i = 0;
while(i<= str.length()){
i++;

//System.out.println(i);
}
// count the number of O's
int j = 0;
while(j<= str.length()){
j++;
//System.out.println(j);
}

a=(i%2==0 && j%2==0);
if(a){

move = 'X';
}else{
move = 'O';
}
System.out.println(move);


}
}
"Michael"
Quote:
Hello again, I read that site; good advice. I have wrote the following
thus far. I realize I am comparing i to j here, but I what i really wish
to do is compare if the number of x's is equal to o's. SO i order to
accomplish this i would need the assignment operator = but then I can't
use the if/else statement. This is somewhat puzzling me. Any suggestions?

public class move {

public static void main(String[] args) {

String str = Stdin.readln();

char move;

// count the number of X's
int i = 0;
while(i<= str.length()){
i++;
System.out.println(i);
}
// count the number of O's
int j = 0;
while(j<= str.length()){
j++;
//System.out.println(j);
}

if(i == j){
move = 'x';
}else{
move = 'o';

System.out.println(move);
}










}
}

"Michael" news:EzW5f.247980$1i.229272 (AT) pd7tw2no (DOT) ..
Hello guys,
I went to see my instructor today and resolved my problem with the
previous question. I know think I understand the logic of using flags.
I'll review it when I have some time, just to make sure it sticks in my
head. Anyways I have to make a tic tac toe game now for tomorrow. He
explained to me what I ought to do. But of course I am having problems
implementing it in java. First off, I think this is a basic tic tac toe
game compared with others I have seen on the net. Anyways the board is
labeled like this;
123
456
789
I know I have to first count the number of x's and o's. For that I will
use two for loops (one for x's and one for o's). Then I need to set x
equal to y. IF there even, I know it is x's turn since x starts the game.
If there uneven its o's turn. My question is I know I have to count the
number of x's in a for loop. But do I just assign that to a char type,
then after I count both x's and o's I can compare them to see if there
equal, if so its x's move otherwise its o's move. Then I need to
determine whether the moves are valid or invalid. Then I need to
implement a switch statement to account for all the possible outcomes of
the 9 possible causes. Any suggestions are most welcome. Thanks again. I
need to wrap my mind on the logic of implementing these things in java.






Back to top
Michael
Guest





PostPosted: Fri Oct 21, 2005 3:02 am    Post subject: Re: tic tac toe Reply with quote

I got it to prints x's now. Just to implement the switch statement now I
think to account for all possibilities.
"Michael" <mbialowas (AT) shaw (DOT) ca> wrote

Quote:
Question: Why is this program printing out a O, when it should be an x?
Here's my code updated code.

public class move {

public static void main(String[] args) {

String str = Stdin.readln();

boolean a = true;
char move;

// count the number of X's
int i = 0;
while(i<= str.length()){
i++;

//System.out.println(i);
}
// count the number of O's
int j = 0;
while(j<= str.length()){
j++;
//System.out.println(j);
}

a=(i%2==0 && j%2==0);
if(a){

move = 'X';
}else{
move = 'O';
}
System.out.println(move);


}
}
"Michael" news:BYX5f.244709$oW2.153239 (AT) pd7tw1no (DOT) ..
Hello again, I read that site; good advice. I have wrote the following
thus far. I realize I am comparing i to j here, but I what i really wish
to do is compare if the number of x's is equal to o's. SO i order to
accomplish this i would need the assignment operator = but then I can't
use the if/else statement. This is somewhat puzzling me. Any suggestions?

public class move {

public static void main(String[] args) {

String str = Stdin.readln();

char move;

// count the number of X's
int i = 0;
while(i<= str.length()){
i++;
System.out.println(i);
}
// count the number of O's
int j = 0;
while(j<= str.length()){
j++;
//System.out.println(j);
}

if(i == j){
move = 'x';
}else{
move = 'o';

System.out.println(move);
}










}
}

"Michael" news:EzW5f.247980$1i.229272 (AT) pd7tw2no (DOT) ..
Hello guys,
I went to see my instructor today and resolved my problem with the
previous question. I know think I understand the logic of using flags.
I'll review it when I have some time, just to make sure it sticks in my
head. Anyways I have to make a tic tac toe game now for tomorrow. He
explained to me what I ought to do. But of course I am having problems
implementing it in java. First off, I think this is a basic tic tac toe
game compared with others I have seen on the net. Anyways the board is
labeled like this;
123
456
789
I know I have to first count the number of x's and o's. For that I will
use two for loops (one for x's and one for o's). Then I need to set x
equal to y. IF there even, I know it is x's turn since x starts the
game. If there uneven its o's turn. My question is I know I have to
count the number of x's in a for loop. But do I just assign that to a
char type, then after I count both x's and o's I can compare them to see
if there equal, if so its x's move otherwise its o's move. Then I need
to determine whether the moves are valid or invalid. Then I need to
implement a switch statement to account for all the possible outcomes of
the 9 possible causes. Any suggestions are most welcome. Thanks again. I
need to wrap my mind on the logic of implementing these things in java.








Back to top
Roedy Green
Guest





PostPosted: Fri Oct 21, 2005 3:07 am    Post subject: Re: tic tac toe Reply with quote

On Fri, 21 Oct 2005 00:25:08 GMT, "Michael" <mbialowas (AT) shaw (DOT) ca> wrote
or quoted :

Quote:
My question is I know I have to count the number of x's
in a for loop.
this depends on your representation.


Plausible ones include:

int[3][3]
index rows 0 1 2 and cols 0 1 2
0=blank, 1=X -1=O

This makes checking rows and columns more mathematically obvious.

int[9]

then you have to figure out rows and cols using / and % -- an
unnecessary complication

another is
char[3][3]
where the position is X O or blank


another is enum matrix where the three possibilities are X O and BLANK
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Back to top
Andrew Thompson
Guest





PostPosted: Fri Oct 21, 2005 3:20 am    Post subject: Re: tic tac toe Reply with quote

Michael wrote:

( Please trim any text you are not immediately replying to )

Quote:
...Just to implement the switch statement now I
think to account for all possibilities.

I am not sure what you mean here, but it sounds as
though you are back on the track?

Good self-help! :-)

Back to top
IchBin
Guest





PostPosted: Fri Oct 21, 2005 3:29 am    Post subject: Re: tic tac toe Reply with quote

Michael wrote:
Quote:

public class move {

public static void main(String[] args) {

String str = Stdin.readln();

I do not know of a Stdin in Java.


Quote:
// count the number of X's
int i = 0;
while(i<= str.length()){
i++;

Your not counting the number of X's but the total number of char in the

string.

Quote:
//System.out.println(i);
}
// count the number of O's
int j = 0;
while(j<= str.length()){
j++;
//System.out.println(j);
}

Again your not counting the number of O's but the total number of char
in the string.


--


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)

Back to top
Michael
Guest





PostPosted: Fri Oct 21, 2005 4:30 am    Post subject: Re: tic tac toe Reply with quote

almost there, I think. Just trying to figure out whether my switch statement
should be of a character type or integer type. I am puzzled bc I am inputing
xoxoxo***7 to get a winning combination.Any suggestions thanks again
"Roedy Green" <my_email_is_posted_on_my_website (AT) munged (DOT) invalid> wrote in
message news:4kmgl1hkg4o9d8accp8cv0nrsg3vbsl20b (AT) 4ax (DOT) com...
Quote:
On Fri, 21 Oct 2005 00:25:08 GMT, "Michael" <mbialowas (AT) shaw (DOT) ca> wrote
or quoted :

My question is I know I have to count the number of x's
in a for loop.
this depends on your representation.

Plausible ones include:

int[3][3]
index rows 0 1 2 and cols 0 1 2
0=blank, 1=X -1=O

This makes checking rows and columns more mathematically obvious.

int[9]

then you have to figure out rows and cols using / and % -- an
unnecessary complication

another is
char[3][3]
where the position is X O or blank


another is enum matrix where the three possibilities are X O and BLANK
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Back to top
DrMatrix
Guest





PostPosted: Sat Oct 22, 2005 12:13 am    Post subject: Re: tic tac toe Reply with quote

In article <EzW5f.247980$1i.229272@pd7tw2no>,
"Michael" <mbialowas (AT) shaw (DOT) ca> wrote:

Quote:
I know I have to first count the number of x's and o's. For that I will use
two for loops (one for x's and one for o's). Then I need to set x equal to
y. IF there even, I know it is x's turn since x starts the game.

That sounds like a lot of extra trouble. Since X and O alternate. you
could just define a boolean.

boolean itIsXsTurn = true; // Since it starts out with X's turn

After each turn, just:

itIsXsTurn = !itIsXsTurn;

Or Set an int variable where 0 represents X's turn and 1 represents O's

int turnFlag;

After each turn simply

turnFlag = 1 - turnFlag;

Back to top
Monique Y. Mudama
Guest





PostPosted: Mon Oct 24, 2005 7:42 pm    Post subject: Re: tic tac toe Reply with quote

On 2005-10-23, Mark Haase penned:
Quote:

This is a silly way to do it, Michael. For one thing, this means
that X always has to go first at the beginning of the game; the O
player can never make the first move.


I'm pretty sure this is one of the rules of Tic Tac Toe, at least as I
learned it. X goes first.

--
monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Back to top
Oliver Wong
Guest





PostPosted: Tue Oct 25, 2005 8:33 pm    Post subject: Re: tic tac toe Reply with quote


"Monique Y. Mudama" <spam (AT) bounceswoosh (DOT) org> wrote

Quote:
On 2005-10-23, Mark Haase penned:

This is a silly way to do it, Michael. For one thing, this means
that X always has to go first at the beginning of the game; the O
player can never make the first move.


I'm pretty sure this is one of the rules of Tic Tac Toe, at least as I
learned it. X goes first.

It's a rule whose presence doesn't fundamentally change the nature of
the game, so it seems entirely plausible that there would be variants out
there which omit or include it. Similarly, it isn't fundamental to the game
that the two symbols be "X" and the other be "O". They could just as well be
"+" and "0", or "1" and "2" and every strategy in the "original" variant
would be exactly equally effective in the latter variant.

Contrast this with a variant where a player selects a location, and a
Gaussian probability cloud is generated centered on the location the player
selected. The most probably event is that the location selected gets marked
with the player's symbol, but there's a non-zero probability that some
random other location will get marked instead (with squares nearer to your
selection getting marked with higher probability). Further assume that
players can overwrite each other's mark (that is, a player whose symbol is X
may attempt to mark a location which is already marked with O [she may or
may not succeed, due to the randomness of the tile that actually gets
marked]). In this variant, there exists a strategy for the original tic tac
toe game which has a different effectiveness in this game. For example, in
tic tac toe, you there exists a strategy to never lose (you'll always tie or
win), whereas in this variant, that same strategy may lead to a loss
(especially if you're unlucky and never get the square you intended).

The above, by the way, is a computer simulation of the physical game
where you have a board with rotating triangular shapes. Each face of the
triangular shape is marked with blank, X and O respectively, and the players
are to throw bean-bags at the shapes to get them to rotate so that the
locations become "marked" with the desired symbol.

Because of these equivalence (or non-equivalence) of strategies, one
might argue that all the variants from the first set ("X always goes first"
vs "X and O take turns in going first") are the "same" game, while the
variant in the second set is a "new" game.

- Oliver



Back to top
Roedy Green
Guest





PostPosted: Tue Oct 25, 2005 10:52 pm    Post subject: Re: tic tac toe Reply with quote

On Mon, 24 Oct 2005 13:42:03 -0600, "Monique Y. Mudama"
<spam (AT) bounceswoosh (DOT) org> wrote, quoted or indirectly quoted someone who
said :

Quote:
I'm pretty sure this is one of the rules of Tic Tac Toe, at least as I
learned it. X goes first.

That's the way my grandma taught it to me. Part of the game is to
sucker the other naive player into letting you go first.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Back to top
Andrew Thompson
Guest





PostPosted: Tue Oct 25, 2005 11:06 pm    Post subject: Re: tic tac toe Reply with quote

Roedy Green wrote:

Quote:
On Mon, 24 Oct 2005 13:42:03 -0600, "Monique Y. Mudama"
[email]spam (AT) bounceswoosh (DOT) org[/email]> wrote, quoted or indirectly quoted someone who
said :

I'm pretty sure this is one of the rules of Tic Tac Toe, at least as I
learned it. X goes first.

That's the way my grandma taught it to me. Part of the game is to
sucker the other naive player into letting you go first.

I walked into a conference room one day, where one of the
other participants had seized the opportunity (in a quiet
moment) to draw a grid on the whiteboard.

He marked an 'X' in one of the boxes, then thrust the marker at
me, "Your turn". I drew a pyramid figure in an occupied space on
the grid.

"THAT'S not how you play Tic-Tic-Toe" ..he complained.

"What makes you think I'm playing Tic-Tac-Toe?" I replied,
before handing his marker back ..point first, and strolling off.

Back to top
DrMatrix
Guest





PostPosted: Wed Oct 26, 2005 1:20 am    Post subject: Re: tic tac toe Reply with quote

In article <4odtl116pvcpo63ldmi5q6k1m5s7e5f015 (AT) 4ax (DOT) com>,
Roedy Green <my_email_is_posted_on_my_website (AT) munged (DOT) invalid> wrote:

Quote:
On Mon, 24 Oct 2005 13:42:03 -0600, "Monique Y. Mudama"
[email]spam (AT) bounceswoosh (DOT) org[/email]> wrote, quoted or indirectly quoted someone who
said :

I'm pretty sure this is one of the rules of Tic Tac Toe, at least as I
learned it. X goes first.

That's the way my grandma taught it to me. Part of the game is to
sucker the other naive player into letting you go first.

What difference does that make? If either player plays rationally (makes
the best possible moves each turn), then the game is a win or draw for
that player. If both players play rationally, the game is necessarily a
draw.

There is no advantage to going first.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.