Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

tictactoe
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?


Report this thread to moderator Post Follow-up to this message
Old Post
CPSCmajor
10-30-05 12:02 AM


Re: tictactoe
"CPSCmajor" <bmerritt1987@gmail.com> wrote in message
news:1130615466.252620.216950@g44g2000cwa.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






Report this thread to moderator Post Follow-up to this message
Old Post
Rhino
10-30-05 12:02 AM


Re: tictactoe
"CPSCmajor" <bmerritt1987@gmail.com> schrieb im Newsbeitrag
news:1130615466.252620.216950@g44g2000cwa.googlegroups.com...
>I have no idea where to even start on this...

open the course book

andreas



Report this thread to moderator Post Follow-up to this message
Old Post
andreas kinell
10-30-05 12:02 AM


Re: tictactoe
Rhino wrote:
> "CPSCmajor" <bmerritt1987@gmail.com> wrote in message
> news:1130615466.252620.216950@g44g2000cwa.googlegroups.com... 
> I'm sorry but that is just so simple that I can't believe you don't know h
ow
> 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 crea
te
> 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.


Report this thread to moderator Post Follow-up to this message
Old Post
CPSCmajor
10-30-05 08:57 AM


Re: tictactoe
Rhino wrote:
> "CPSCmajor" <bmerritt1987@gmail.com> wrote in message
> news:1130615466.252620.216950@g44g2000cwa.googlegroups.com... 
> I'm sorry but that is just so simple that I can't believe you don't know h
ow
> 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 crea
te
> 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.


Report this thread to moderator Post Follow-up to this message
Old Post
CPSCmajor
10-30-05 08:57 AM


Re: tictactoe
"CPSCmajor" <bmerritt1987@gmail.com> wrote in message
news:1130642933.974303.182720@o13g2000cwo.googlegroups.com...
>
> Rhino wrote: 
textbook. 
than 
how 
create 
the 
If 
review 
>
> 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



Report this thread to moderator Post Follow-up to this message
Old Post
Rhino
10-30-05 08:57 AM


Re: tictactoe
CPSCmajor wrote:
> 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Alan Krueger
11-02-05 08:58 AM


Re: tictactoe
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.


Report this thread to moderator Post Follow-up to this message
Old Post
CPSCmajor
11-03-05 12:00 AM


Re: tictactoe
"CPSCmajor" <bmerritt1987@gmail.com> wrote in message
news:1130955871.373115.46170@o13g2000cwo.googlegroups.com...
> 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




Report this thread to moderator Post Follow-up to this message
Old Post
Rhino
11-04-05 12:02 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 01:42 AM.

 

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.