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 

tictactoe

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
CPSCmajor
Guest





PostPosted: Sat Oct 29, 2005 7:51 pm    Post subject: tictactoe Reply with quote



I have no idea where to even start on this...
Any suggestions?

In this problem, you will modify the TicTacToe class from the textbook.
Add a method flipVertical that flips the board position along the
vertical axis. For example, the position
x x o
o
x
is flipped to
o x x
o
x
This is not useful for playing the game, but it can be useful for
recognizing a winning strategy in a database of strategies.

Also supply a flipHorizontal method that would flip the original
position to
x
o
x x o
(Hint: If you are clever and understand how two-dimensional arrays are
implemented as "arrays of arrays", this method can be much simpler than
the vertical flip.)

What is your implementation of the flipVertical and flipHorizontal
methods?

Back to top
Rhino
Guest





PostPosted: Sat Oct 29, 2005 9:38 pm    Post subject: Re: tictactoe Reply with quote




"CPSCmajor" <bmerritt1987 (AT) gmail (DOT) com> wrote

Quote:
I have no idea where to even start on this...
Any suggestions?

In this problem, you will modify the TicTacToe class from the textbook.
Add a method flipVertical that flips the board position along the
vertical axis. For example, the position
x x o
o
x
is flipped to
o x x
o
x
This is not useful for playing the game, but it can be useful for
recognizing a winning strategy in a database of strategies.

Also supply a flipHorizontal method that would flip the original
position to
x
o
x x o
(Hint: If you are clever and understand how two-dimensional arrays are
implemented as "arrays of arrays", this method can be much simpler than
the vertical flip.)

What is your implementation of the flipVertical and flipHorizontal
methods?

I'm sorry but that is just so simple that I can't believe you don't know how

to do that. It seems a lot more likely that you are simply asking us to
write your homework for you. Surely even a novice Java programmer can create
a new array based on an existing array where the new one has x's where the
old one had o's (and vice versa) and where the spaces are still spaces. If
not, you need some serious one-on-one tutoring with someone who can review
the basics with you.

Rhino






Back to top
andreas kinell
Guest





PostPosted: Sat Oct 29, 2005 11:35 pm    Post subject: Re: tictactoe Reply with quote




"CPSCmajor" <bmerritt1987 (AT) gmail (DOT) com> schrieb im Newsbeitrag
news:1130615466.252620.216950 (AT) g44g2000cwa (DOT) googlegroups.com...
Quote:
I have no idea where to even start on this...

open the course book

andreas



Back to top
CPSCmajor
Guest





PostPosted: Sun Oct 30, 2005 3:28 am    Post subject: Re: tictactoe Reply with quote


Rhino wrote:
Quote:
"CPSCmajor" <bmerritt1987 (AT) gmail (DOT) com> wrote in message
news:1130615466.252620.216950 (AT) g44g2000cwa (DOT) googlegroups.com...
I have no idea where to even start on this...
Any suggestions?

In this problem, you will modify the TicTacToe class from the textbook.
Add a method flipVertical that flips the board position along the
vertical axis. For example, the position
x x o
o
x
is flipped to
o x x
o
x
This is not useful for playing the game, but it can be useful for
recognizing a winning strategy in a database of strategies.

Also supply a flipHorizontal method that would flip the original
position to
x
o
x x o
(Hint: If you are clever and understand how two-dimensional arrays are
implemented as "arrays of arrays", this method can be much simpler than
the vertical flip.)

What is your implementation of the flipVertical and flipHorizontal
methods?

I'm sorry but that is just so simple that I can't believe you don't know how
to do that. It seems a lot more likely that you are simply asking us to
write your homework for you. Surely even a novice Java programmer can create
a new array based on an existing array where the new one has x's where the
old one had o's (and vice versa) and where the spaces are still spaces. If
not, you need some serious one-on-one tutoring with someone who can review
the basics with you.

Rhino

Ok if I thought it was that easy then I would do it, obviously! I'm not
trying to get people to do my homework, I just asked for any
suggestions, not to be insulted.


Back to top
CPSCmajor
Guest





PostPosted: Sun Oct 30, 2005 3:29 am    Post subject: Re: tictactoe Reply with quote


Rhino wrote:
Quote:
"CPSCmajor" <bmerritt1987 (AT) gmail (DOT) com> wrote in message
news:1130615466.252620.216950 (AT) g44g2000cwa (DOT) googlegroups.com...
I have no idea where to even start on this...
Any suggestions?

In this problem, you will modify the TicTacToe class from the textbook.
Add a method flipVertical that flips the board position along the
vertical axis. For example, the position
x x o
o
x
is flipped to
o x x
o
x
This is not useful for playing the game, but it can be useful for
recognizing a winning strategy in a database of strategies.

Also supply a flipHorizontal method that would flip the original
position to
x
o
x x o
(Hint: If you are clever and understand how two-dimensional arrays are
implemented as "arrays of arrays", this method can be much simpler than
the vertical flip.)

What is your implementation of the flipVertical and flipHorizontal
methods?

I'm sorry but that is just so simple that I can't believe you don't know how
to do that. It seems a lot more likely that you are simply asking us to
write your homework for you. Surely even a novice Java programmer can create
a new array based on an existing array where the new one has x's where the
old one had o's (and vice versa) and where the spaces are still spaces. If
not, you need some serious one-on-one tutoring with someone who can review
the basics with you.

Rhino

Ok if I thought it was that easy then I would do it, obviously! I'm not
trying to get people to do my homework, I just asked for any
suggestions, not to be insulted.


Back to top
Rhino
Guest





PostPosted: Sun Oct 30, 2005 4:59 am    Post subject: Re: tictactoe Reply with quote


"CPSCmajor" <bmerritt1987 (AT) gmail (DOT) com> wrote

Quote:

Rhino wrote:
"CPSCmajor" <bmerritt1987 (AT) gmail (DOT) com> wrote in message
news:1130615466.252620.216950 (AT) g44g2000cwa (DOT) googlegroups.com...
I have no idea where to even start on this...
Any suggestions?

In this problem, you will modify the TicTacToe class from the
textbook.
Add a method flipVertical that flips the board position along the
vertical axis. For example, the position
x x o
o
x
is flipped to
o x x
o
x
This is not useful for playing the game, but it can be useful for
recognizing a winning strategy in a database of strategies.

Also supply a flipHorizontal method that would flip the original
position to
x
o
x x o
(Hint: If you are clever and understand how two-dimensional arrays are
implemented as "arrays of arrays", this method can be much simpler
than
the vertical flip.)

What is your implementation of the flipVertical and flipHorizontal
methods?

I'm sorry but that is just so simple that I can't believe you don't know
how
to do that. It seems a lot more likely that you are simply asking us to
write your homework for you. Surely even a novice Java programmer can
create
a new array based on an existing array where the new one has x's where
the
old one had o's (and vice versa) and where the spaces are still spaces.
If
not, you need some serious one-on-one tutoring with someone who can
review
the basics with you.

Rhino

Ok if I thought it was that easy then I would do it, obviously! I'm not
trying to get people to do my homework, I just asked for any
suggestions, not to be insulted.

I'd be more inclined to believe you if you'd shown even a single line of

code representing an attempt to solve the problem. But maybe you're just
really discouraged by hard Java seems to be right now. I'll give you the
benefit of the doubt - for now.

Anyway, I wasn't trying to insult you; I was trying to give you a vote of
confidence: you can do this! It's simply not that difficult.

Consider a simpler problem. Start with one dimensional array that has a mix
of "x", "o", and blank elements. Can you make another array whose elements
are exactly the same?

Here's your original array:

String[] myArray = {"x", "o", " "}; //original array

You want the second array to have the same number of elements as the
original array. How do you do it? Let's assume that we want code that will
work for any number of elements in the original array so that I can 'flip'
ANY size of array. The code to create a new empty array of the same size as
the original one is this:

String[] secondArray = new String[myArray.length];

[Every array has a variable called 'length' which contains the size of the
array; you use the expression 'myArray.length' to determine the number of
elements in the array called myArray.]

Now, to put the same elements in the second array as the first, you use a
loop, usually a 'for' loop, as opposed to a 'do' loop or 'while' loop:
for (int ix=0; ix < myArray.length; ix++) {

if (myArray[ix].equals("x")) flippedArray[ix] = "x";

else if (myArray[ix].equals("o")) flippedArray[ix] = "y";

else if (myArray[ix].equals(" ")) flippedArray[ix] = " ";

else {

System.err.println("Discovered element that is not x, o, or blank.");

}

}

The loop examines each element of the original array one at a time, from the
first to the last. Remember, array elements are numbered started at 0 in
Java.

For each element of the original array, the 'if' statements inspect the
value in the original array. Since the values in the arrays are Strings, we
have to use the equals() method, not an equal sign! The 'if/else' statements
look at a given element in the original array: if the value is an "x", we
write an "x" into the corresponding element of the second array; same thing
for "o" and " " (blank). If any OTHER value is found in the original array,
we display an error message. (In a professional program, we'd do something
snazzier but let's walk before we run.)

Now, to check our work, we need a loop to display the original array and
another loop to display the second array. This is the code for the first
array:

System.out.println("Original array:");

for (int ix=0; ix < myArray.length; ix++) {

System.out.println("[" + ix + "]: " + myArray[ix]);

}

I'll let you write the corresponding code for the second array; it's
virtually identical except that you change the text that you print before
the loop and the name of the array used throughout the loop.

Now, EXECUTE the code that we have developed. What happens? It works, right?
If not, try to figure out what went wrong. If you can't figure it out on
your own, post again and describe the problem clearly, making sure that you
post the code that isn't working so other people can see the problem and
help you.

Okay, let's assume you finally have this simpler code working. You're almost
done with your 'flip' logic!

In order to accomplish the original objective of the problem, all you have
to do is add a second dimension to the original array and modify your for
loops to handle two dimensions instead of one. The other thing you have to
do is make sure that the second array has an "o" written to it wherever the
original array had an "x" and an "x" where the original array had an "o".
That's it! You've solved the whole problem!

Okay, now give this all a try and post again if you're having problems.
Somebody will probably help IF you show some effort. Don't expect much help
though if you just throw up your hands in despair and say you don't know
what to do. Ask a concrete question that will help you solve the problem and
convince us that you are trying by showing us the code that doesn't work. If
you don't do that, no one will believe that you are actually trying.

You can do this stuff; we all learned it at some point and it was a struggle
for many of us. Those who succeeded were those who made a steady, rational
effort to figure out what we were doing wrong. If you don't have it in you
to work at learning Java, then drop the course and take something else.

Rhino



Back to top
Alan Krueger
Guest





PostPosted: Wed Nov 02, 2005 4:38 am    Post subject: Re: tictactoe Reply with quote

CPSCmajor wrote:
Quote:
I have no idea where to even start on this...
Any suggestions?

Talk to your instructor and ask for help? That's typically what they're
there for.

Back to top
CPSCmajor
Guest





PostPosted: Wed Nov 02, 2005 6:24 pm    Post subject: Re: tictactoe Reply with quote

I just realized that I never posted back but I figured it out...I
didn't have to ask for help...after I posted this then I started
thinking about the problem and wrote the code that night and never
checked this again...thanks for the follow up though.

Back to top
Rhino
Guest





PostPosted: Thu Nov 03, 2005 10:52 pm    Post subject: Re: tictactoe Reply with quote


"CPSCmajor" <bmerritt1987 (AT) gmail (DOT) com> wrote

Quote:
I just realized that I never posted back but I figured it out...I
didn't have to ask for help...after I posted this then I started
thinking about the problem and wrote the code that night and never
checked this again...thanks for the follow up though.

And you apparently never saw the reply I made to your "lost" note too. Oh

well, that'll teach me not to write lengthy notes!

I'm glad to see that you figured out your problem yourself; that's always
the most satisfying result.

You may also have learned a new problem-solving technique: try to explain
the problem you're having to someone else; somehow, that effort often helps
you understand the problem better and often gives you an idea about another
way of attacking it. I suspect that may have happened for you in this case,
just as it has happened to me several times in the past.

Rhino

Rhino




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

 
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.