• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:37
CEST 15:37
KST 22:37
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Weekly Cups (June 30 - July 6): Classic Doubles1[BSL20] Non-Korean Championship 4x BSL + 4x China7Flash Announces Hiatus From ASL64Weekly Cups (June 23-29): Reynor in world title form?13FEL Cracov 2025 (July 27) - $8000 live event22
StarCraft 2
General
Weekly Cups (June 30 - July 6): Classic Doubles Program: SC2 / XSplit / OBS Scene Switcher The SCII GOAT: A statistical Evaluation Statistics for vetoed/disliked maps Weekly Cups (June 23-29): Reynor in world title form?
Tourneys
RSL: Revival, a new crowdfunded tournament series FEL Cracov 2025 (July 27) - $8000 live event Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays Korean Starcraft League Week 77
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma
Brood War
General
SC uni coach streams logging into betting site BGH Auto Balance -> http://bghmmr.eu/ ASL20 Preliminary Maps Flash Announces Hiatus From ASL Player “Jedi” cheat on CSL
Tourneys
[BSL20] Grand Finals - Sunday 20:00 CET [BSL20] Non-Korean Championship 4x BSL + 4x China CSL Xiamen International Invitational The Casual Games of the Week Thread
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Path of Exile Nintendo Switch Thread What do you want from future RTS games? Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Stop Killing Games - European Citizens Initiative Summer Games Done Quick 2024! Summer Games Done Quick 2025!
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion 2024 - 2025 Football Thread NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 732 users

The Big Programming Thread - Page 127

Forum Index > General Forum
Post a Reply
Prev 1 125 126 127 128 129 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
Last Edited: 2012-03-15 14:29:23
March 15 2012 14:26 GMT
#2521
On March 15 2012 21:34 sluggaslamoo wrote:
Show nested quote +
On March 15 2012 21:22 Manit0u wrote:
On March 15 2012 20:59 lolmlg wrote:
On March 15 2012 20:35 Manit0u wrote:
From what I read about design in Java, you should avoid getters and setters at all costs. Just like you should avoid extends.

If you plan to avoid get and set methods then you'll be avoiding a standard so far-reaching that it is done automatically by many IDEs. People avoid it when the length of their class makes them upset. I can't think of another good reason.

As for extends there are some languages in which inheritance of that kind no longer exists, but that does not mean it should be avoided.

On March 15 2012 20:51 fonger wrote:
On March 15 2012 20:47 mgj wrote:
On March 15 2012 20:35 Manit0u wrote:
From what I read about design in Java, you should avoid getters and setters at all costs. Just like you should avoid extends.


Why? Java doesn't have properties, so what is the alternative? Never allow state? Java is not a functional language...

Avoiding extends.... Again, why? "implements" is not equivalent. Inheritance is very useful.

The alternative is public variables, which would save time if all you're doing is returning static values that you've already explicitly set through the setter. Ultimately if you have a class that consists entirely of data, straight getters and straight setters then you should re-write it as a completely public "struct equivalent" just so you can see that it was a poor choice to make it in the first place.

Basically, if your class has no invariants, what's the point of having it as a class in the first place?

By doing that you're violating any number of abstraction principles and will probably wind up with UI code dependent on implementation.


Why getters, setters and extends are evil.

http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html
http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html


Or you could just combine all of these articles and put it under "Why Java is evil".

I've been seriously rofling at all these silly design patterns that java developers have created to get around the limitations of Java. "interfaces over implementation", "why extends is evil", etc, etc. Everyone trying to follow Dijkstra's style of 'goto statement considered harmful' yet failing because instead of coming up with a solution (Pascal) they just side-step the real issue.

I mean yes, I do implement Java in this way (no extends, lots of interfaces for flexibility), but not because its good, its because Java is bad. Trust me, I bought into this shit when I was in my teens, how naive I was.

Hence I pretty much wouldn't touch Java with a 10 foot pole. The only time I do is with JRuby, except its just Ruby translated to Java bytecode so I can use Java libraries.

The whole getter and setter issue can be much better explained with Responsibility Driven Design. Getters and setters aren't evil, don't be ridiculous, its just that writing getters and setter methods is a nonsensical abstraction and causes code bloat. Nothing does my head in more than seeing a class with attributes and then get() set() methods for everything, causing the class to be about 100x bigger than it needs to be. However there are some times where you will need to write a getter and setter.

Responsibility Driven Design teaches you how to name classes (or classifications) and methods, what methods mean, and how to properly abstract real business models into object oriented code, when to use extends, etc. It takes a long time to learn, but after a while it should click and a lot of the mysteries of OOP will start to make complete sense. Until then you are simply throwing darts with a blindfold on and listening to morons telling you why things are evil.


Oh well, there must've been a reason for me to stop doing anything in Java for years... But making a GUI for applications in C or C++ will be so much harder (I think, it's also been ages since I had to do with any GUIs).
Especially that I want the thing I'm working on now to be able to run on different platforms. Guess it's time to learn some wxWidgets.
Time is precious. Waste it wisely.
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
March 15 2012 14:42 GMT
#2522
On March 15 2012 23:26 Manit0u wrote:
Show nested quote +
On March 15 2012 21:34 sluggaslamoo wrote:
On March 15 2012 21:22 Manit0u wrote:
On March 15 2012 20:59 lolmlg wrote:
On March 15 2012 20:35 Manit0u wrote:
From what I read about design in Java, you should avoid getters and setters at all costs. Just like you should avoid extends.

If you plan to avoid get and set methods then you'll be avoiding a standard so far-reaching that it is done automatically by many IDEs. People avoid it when the length of their class makes them upset. I can't think of another good reason.

As for extends there are some languages in which inheritance of that kind no longer exists, but that does not mean it should be avoided.

On March 15 2012 20:51 fonger wrote:
On March 15 2012 20:47 mgj wrote:
On March 15 2012 20:35 Manit0u wrote:
From what I read about design in Java, you should avoid getters and setters at all costs. Just like you should avoid extends.


Why? Java doesn't have properties, so what is the alternative? Never allow state? Java is not a functional language...

Avoiding extends.... Again, why? "implements" is not equivalent. Inheritance is very useful.

The alternative is public variables, which would save time if all you're doing is returning static values that you've already explicitly set through the setter. Ultimately if you have a class that consists entirely of data, straight getters and straight setters then you should re-write it as a completely public "struct equivalent" just so you can see that it was a poor choice to make it in the first place.

Basically, if your class has no invariants, what's the point of having it as a class in the first place?

By doing that you're violating any number of abstraction principles and will probably wind up with UI code dependent on implementation.


Why getters, setters and extends are evil.

http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html
http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html


Or you could just combine all of these articles and put it under "Why Java is evil".

I've been seriously rofling at all these silly design patterns that java developers have created to get around the limitations of Java. "interfaces over implementation", "why extends is evil", etc, etc. Everyone trying to follow Dijkstra's style of 'goto statement considered harmful' yet failing because instead of coming up with a solution (Pascal) they just side-step the real issue.

I mean yes, I do implement Java in this way (no extends, lots of interfaces for flexibility), but not because its good, its because Java is bad. Trust me, I bought into this shit when I was in my teens, how naive I was.

Hence I pretty much wouldn't touch Java with a 10 foot pole. The only time I do is with JRuby, except its just Ruby translated to Java bytecode so I can use Java libraries.

The whole getter and setter issue can be much better explained with Responsibility Driven Design. Getters and setters aren't evil, don't be ridiculous, its just that writing getters and setter methods is a nonsensical abstraction and causes code bloat. Nothing does my head in more than seeing a class with attributes and then get() set() methods for everything, causing the class to be about 100x bigger than it needs to be. However there are some times where you will need to write a getter and setter.

Responsibility Driven Design teaches you how to name classes (or classifications) and methods, what methods mean, and how to properly abstract real business models into object oriented code, when to use extends, etc. It takes a long time to learn, but after a while it should click and a lot of the mysteries of OOP will start to make complete sense. Until then you are simply throwing darts with a blindfold on and listening to morons telling you why things are evil.


Oh well, there must've been a reason for me to stop doing anything in Java for years... But making a GUI for applications in C or C++ will be so much harder (I think, it's also been ages since I had to do with any GUIs).
Especially that I want the thing I'm working on now to be able to run on different platforms. Guess it's time to learn some wxWidgets.


Hmmm what to do with GUI's. Are you writing a desktop app, web app or a game?

Swing is very easy to create GUI's with, but its very slow and cumbersome to custom code. I've tried Swing and JRuby, terrible idea also.

If you are writing desktop apps you should really look at the new html on a desktop app movement. I haven't done much of it as I'm pretty much doing GUI's in OpenGL or on the web.

But as a Ruby dev I guess I have to recommend this. It allows you to use Ruby/Javascript/Html and write a desktop app.

http://bowlineapp.com/

Ruby is a great language too. :D

Appcelerator Titanium is a much more commercial version and allows you to even build native apps that do the same thing (Ruby/Html/JS). They had a free indie license last time I tried it.

http://www.appcelerator.com/
http://developer.appcelerator.com/doc/desktop/ruby

And for the love of god please don't use PhoneGap, its terrible.

Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
March 15 2012 15:07 GMT
#2523
I'm writing a 2D game...
Time is precious. Waste it wisely.
heroyi
Profile Blog Joined March 2009
United States1064 Posts
Last Edited: 2012-03-15 15:08:46
March 15 2012 15:08 GMT
#2524
printf("\n\n");
printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);


I can't do this...I have been trying to look up for help but i cant find it (been trying for 2 days so maybe someone else can help me).

side note: I am still new to this and learning c++. I know some stuff (like functions, loops, arrays etc...) xD

Anyway I am trying to create a tic tac toe with visual c++ but I need help creating the board and trying to write something that would help tell the computer to put an "x" or an "o" at w.e square space the user wants to do AND show/re-draw the updated board with the new move. I have tried various things but i don't understand it (attempting to use 2d array mind you)...

^^I dont understand this code. I have studied the code for awhile but considering its C language there are somethings in there i dont understand (like how the person is able to printf the board and yet somehow associate the board space to a specific array coordinate). I dont need help on how to figure out the winner or getting the input from the player. I was wondering if someone could show me/help me figure out how to create and initialize the board (I would also like an explanation behind the mechanic/process).


I got the code from here: http://www.dreamincode.net/forums/topic/135129-the-tic-tac-toe-program/

tl;dr
I need help creating the tic tac toe board and find out how to mark the user specific point with an "X" or an "O". (I have tried asking the user to put in an x,y coordinate point and use that to mark the spot on the board but again that doesnt work)
wat wat in my pants
icystorage
Profile Blog Joined November 2008
Jollibee19343 Posts
March 15 2012 15:20 GMT
#2525
im trying to make a sequence diagram but i got one problem

i have 4 actors, namely attendant, cashier, supervisor and manager. there are some functions that are limited only to a specific position, now my what happens if i have a action/function weyhere they all can use/access it? do i make a more general actor like employee?
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
Last Edited: 2012-03-15 15:54:55
March 15 2012 15:43 GMT
#2526
On March 16 2012 00:08 heroyi wrote:
printf("\n\n");
printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);


I can't do this...I have been trying to look up for help but i cant find it (been trying for 2 days so maybe someone else can help me).

side note: I am still new to this and learning c++. I know some stuff (like functions, loops, arrays etc...) xD

Anyway I am trying to create a tic tac toe with visual c++ but I need help creating the board and trying to write something that would help tell the computer to put an "x" or an "o" at w.e square space the user wants to do AND show/re-draw the updated board with the new move. I have tried various things but i don't understand it (attempting to use 2d array mind you)...

^^I dont understand this code. I have studied the code for awhile but considering its C language there are somethings in there i dont understand (like how the person is able to printf the board and yet somehow associate the board space to a specific array coordinate). I dont need help on how to figure out the winner or getting the input from the player. I was wondering if someone could show me/help me figure out how to create and initialize the board (I would also like an explanation behind the mechanic/process).


I got the code from here: http://www.dreamincode.net/forums/topic/135129-the-tic-tac-toe-program/

tl;dr
I need help creating the tic tac toe board and find out how to mark the user specific point with an "X" or an "O". (I have tried asking the user to put in an x,y coordinate point and use that to mark the spot on the board but again that doesnt work)


You want the simplest, but a bit ugly, solution?

Store board rows as variables, then, depending on the move, just clear screen and display the board again using desired variables.
This is going to be ugly because you'll have to make variables for all possible positions and then store useless data.

Example:
string rowdefault = "---|---|---";
string rowxnn = "X|---|---";
string rowxno = "X|---|O";

There's what, 11-12 possible row combinations?

It's pretty simple. When a player makes a move you just set activeRow1 = rowxnn for example and then just print activeRow1 \n ActiveRow2 \n ActiveRow3 \n

Edit:
What the code you pointed to does is enter a loop and asking people to enter their field of choice. Then, while the loop is running it assigns X or O (depending on a player) to a specific location in the array and displays it.
This: printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
means: print first item in third array dimension, second item in third..., ...
If that's what you're wondering...

The board in this 3d array looks like that:
[0][0] [0][1] [0][2]
[1][0] [1][1] [1][2]
[2][0] [2][1] [2][2]
Time is precious. Waste it wisely.
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
Last Edited: 2012-03-15 15:48:14
March 15 2012 15:47 GMT
#2527
a sequence diagram displays an actual execution sequence of method calls, it doesn't provide any information on who *can* access what, only on what method invocation *does* lead to what other method invocations. Shamelessly googled and hotlinked example image:
[image loading]

what kind of diagram are you really trying to make?
Gold isn't everything in life... you need wood, too!
icystorage
Profile Blog Joined November 2008
Jollibee19343 Posts
March 15 2012 15:58 GMT
#2528
On March 16 2012 00:47 MisterD wrote:
a sequence diagram displays an actual execution sequence of method calls, it doesn't provide any information on who *can* access what, only on what method invocation *does* lead to what other method invocations. Shamelessly googled and hotlinked example image:
[image loading]

what kind of diagram are you really trying to make?


well there is some methods which are limited to the manager only, how can i show that in the diagram? make an actor Manager?

what kind of diagram? sequence diagram :x. lol i dont get the question D:
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
March 15 2012 16:40 GMT
#2529
in a sequence diagram, who *can* call what is completely irrelevant, you can't display it. That's just my point. You display a sequence of method calls the in the order in which they occur during a your programs execution, you do not display who could have called what. If you want to display a list of methods for every class including the visibility information of these methods, you need a class diagram. Again shamelessly googled and hotlinked example image:
[image loading]

That's why i asked what kind of diagram you actually want to draw. If you want to visualize class members and their visibility (and composition), you want to make a class diagram, not a sequence diagram.
Gold isn't everything in life... you need wood, too!
icystorage
Profile Blog Joined November 2008
Jollibee19343 Posts
March 15 2012 16:41 GMT
#2530
On March 16 2012 01:40 MisterD wrote:
in a sequence diagram, who *can* call what is completely irrelevant, you can't display it. That's just my point. You display a sequence of method calls the in the order in which they occur during a your programs execution, you do not display who could have called what. If you want to display a list of methods for every class including the visibility information of these methods, you need a class diagram. Again shamelessly googled and hotlinked example image:
[image loading]

That's why i asked what kind of diagram you actually want to draw. If you want to visualize class members and their visibility (and composition), you want to make a class diagram, not a sequence diagram.


okay i get it now thank you very much good sir and thank you for being patient with me!
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
nyxnyxnyx
Profile Joined April 2010
Indonesia2978 Posts
March 15 2012 16:47 GMT
#2531
I'm really struggling with Java atm (Year 2 college) and would really appreciate guidance from a mentor good at it. Will even compensate in any way possible. Please do PM me if you feel you are up to the task, thank you!!
cool beans
heroyi
Profile Blog Joined March 2009
United States1064 Posts
Last Edited: 2012-03-15 18:33:22
March 15 2012 18:28 GMT
#2532
On March 16 2012 00:43 Manit0u wrote:
Show nested quote +
On March 16 2012 00:08 heroyi wrote:
printf("\n\n");
printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);


I can't do this...I have been trying to look up for help but i cant find it (been trying for 2 days so maybe someone else can help me).

side note: I am still new to this and learning c++. I know some stuff (like functions, loops, arrays etc...) xD

Anyway I am trying to create a tic tac toe with visual c++ but I need help creating the board and trying to write something that would help tell the computer to put an "x" or an "o" at w.e square space the user wants to do AND show/re-draw the updated board with the new move. I have tried various things but i don't understand it (attempting to use 2d array mind you)...

^^I dont understand this code. I have studied the code for awhile but considering its C language there are somethings in there i dont understand (like how the person is able to printf the board and yet somehow associate the board space to a specific array coordinate). I dont need help on how to figure out the winner or getting the input from the player. I was wondering if someone could show me/help me figure out how to create and initialize the board (I would also like an explanation behind the mechanic/process).


I got the code from here: http://www.dreamincode.net/forums/topic/135129-the-tic-tac-toe-program/

tl;dr
I need help creating the tic tac toe board and find out how to mark the user specific point with an "X" or an "O". (I have tried asking the user to put in an x,y coordinate point and use that to mark the spot on the board but again that doesnt work)


You want the simplest, but a bit ugly, solution?

Store board rows as variables, then, depending on the move, just clear screen and display the board again using desired variables.
This is going to be ugly because you'll have to make variables for all possible positions and then store useless data.

Example:
string rowdefault = "---|---|---";
string rowxnn = "X|---|---";
string rowxno = "X|---|O";

There's what, 11-12 possible row combinations?

It's pretty simple. When a player makes a move you just set activeRow1 = rowxnn for example and then just print activeRow1 \n ActiveRow2 \n ActiveRow3 \n

Edit:
What the code you pointed to does is enter a loop and asking people to enter their field of choice. Then, while the loop is running it assigns X or O (depending on a player) to a specific location in the array and displays it.
This: printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
means: print first item in third array dimension, second item in third..., ...
If that's what you're wondering...

The board in this 3d array looks like that:
[0][0] [0][1] [0][2]
[1][0] [1][1] [1][2]
[2][0] [2][1] [2][2]

thanks for the help.

I actually prefer not to use your solution (it is viable and I will resort to it if I cannot find alternatives) since that is quite "ugly."
Is there a way to make it work by trying to setup a x,y coordinate system and mark the spot based on the user input? For example:

I would display the board out like this:
int tictacboard[3][3] =
{0,1,2},
{3,4,5},
{6,7,8};
cout << " " << tictacboard[][]

however knowing when creating an array, the cells are arranged as so (because its a 3x3 2d array):
[0][0] [0][1] [0][2]
[1][0] [1][1] [1][2]
[2][0] [2][1] [2][2]
thus i want the array read as tictacboard[x][y] //(<--- want as x,y system)

ask user to choose number to mark the spot( say he chose "4"):


tictacboard[1][1] = 'X'
cout << tictacboard

now when it is player's turn it will show:
{0,1,2}
{3,X,5}
{6,7,8}

if player has chosen spaces 0,4,8 to mark the compiler would read this as:
tictacboard[0][0] = 'X'
tictacboard[1][1] = 'X'
tictacboard[2][2] = 'X'
thus showing:
{X,1,2}
{3,X,5}
{6,7,X}


^^or something similar
possible?help?AIUTO
wat wat in my pants
uNiGNoRe
Profile Blog Joined June 2007
Germany1115 Posts
Last Edited: 2012-03-15 23:39:26
March 15 2012 23:38 GMT
#2533
On March 16 2012 03:28 heroyi wrote:
+ Show Spoiler +
On March 16 2012 00:43 Manit0u wrote:
Show nested quote +
On March 16 2012 00:08 heroyi wrote:
printf("\n\n");
printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);


I can't do this...I have been trying to look up for help but i cant find it (been trying for 2 days so maybe someone else can help me).

side note: I am still new to this and learning c++. I know some stuff (like functions, loops, arrays etc...) xD

Anyway I am trying to create a tic tac toe with visual c++ but I need help creating the board and trying to write something that would help tell the computer to put an "x" or an "o" at w.e square space the user wants to do AND show/re-draw the updated board with the new move. I have tried various things but i don't understand it (attempting to use 2d array mind you)...

^^I dont understand this code. I have studied the code for awhile but considering its C language there are somethings in there i dont understand (like how the person is able to printf the board and yet somehow associate the board space to a specific array coordinate). I dont need help on how to figure out the winner or getting the input from the player. I was wondering if someone could show me/help me figure out how to create and initialize the board (I would also like an explanation behind the mechanic/process).


I got the code from here: http://www.dreamincode.net/forums/topic/135129-the-tic-tac-toe-program/

tl;dr
I need help creating the tic tac toe board and find out how to mark the user specific point with an "X" or an "O". (I have tried asking the user to put in an x,y coordinate point and use that to mark the spot on the board but again that doesnt work)


You want the simplest, but a bit ugly, solution?

Store board rows as variables, then, depending on the move, just clear screen and display the board again using desired variables.
This is going to be ugly because you'll have to make variables for all possible positions and then store useless data.

Example:
string rowdefault = "---|---|---";
string rowxnn = "X|---|---";
string rowxno = "X|---|O";

There's what, 11-12 possible row combinations?

It's pretty simple. When a player makes a move you just set activeRow1 = rowxnn for example and then just print activeRow1 \n ActiveRow2 \n ActiveRow3 \n

Edit:
What the code you pointed to does is enter a loop and asking people to enter their field of choice. Then, while the loop is running it assigns X or O (depending on a player) to a specific location in the array and displays it.
This: printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
means: print first item in third array dimension, second item in third..., ...
If that's what you're wondering...

The board in this 3d array looks like that:
[0][0] [0][1] [0][2]
[1][0] [1][1] [1][2]
[2][0] [2][1] [2][2]

thanks for the help.

I actually prefer not to use your solution (it is viable and I will resort to it if I cannot find alternatives) since that is quite "ugly."
Is there a way to make it work by trying to setup a x,y coordinate system and mark the spot based on the user input? For example:

I would display the board out like this:
int tictacboard[3][3] =
{0,1,2},
{3,4,5},
{6,7,8};
cout << " " << tictacboard[][]

however knowing when creating an array, the cells are arranged as so (because its a 3x3 2d array):
[0][0] [0][1] [0][2]
[1][0] [1][1] [1][2]
[2][0] [2][1] [2][2]
thus i want the array read as tictacboard[x][y] //(<--- want as x,y system)

ask user to choose number to mark the spot( say he chose "4"):


tictacboard[1][1] = 'X'
cout << tictacboard

now when it is player's turn it will show:
{0,1,2}
{3,X,5}
{6,7,8}

if player has chosen spaces 0,4,8 to mark the compiler would read this as:
tictacboard[0][0] = 'X'
tictacboard[1][1] = 'X'
tictacboard[2][2] = 'X'
thus showing:
{X,1,2}
{3,X,5}
{6,7,X}


^^or something similar
possible?help?AIUTO


Well, the first thing you should decide on is if you want to use a char array or an int array. If you want to use characters like 'X' and 'O' you should probably use a char array.

char tictacboard[3][3] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'}
};

Printing the board could be done like this: (This is the same as on the linked website, just using cout instead of printf.)

cout << "\n\n";
cout << " " << tictacboard[0][0] << " | " << tictacboard[0][1] << " | " << tictacboard[0][2] << "\n";
cout << "---|---|---\n";
cout << " " << tictacboard[1][0] << " | " << tictacboard[1][1] << " | " << tictacboard[1][2] << "\n";
cout << "---|---|---\n";
cout << " " << tictacboard[2][0] << " | " << tictacboard[2][1] << " | " << tictacboard[2][2] << "\n";

An easy way to write to the board would be:

// get player input
int fieldNumber;
cin >> fieldNumber;
tictacboard[fieldNumber / 3][fieldNumber % 3] = 'X';

I'm not sure if this is what you want to hear, since it's basically the same as on that website...
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
Last Edited: 2012-03-15 23:55:55
March 15 2012 23:54 GMT
#2534
What you're proposing is exactly what the program you linked to does...
Take a closer look at it and all of your problems should be gone.

Edit: Beat me to it
Time is precious. Waste it wisely.
heroyi
Profile Blog Joined March 2009
United States1064 Posts
Last Edited: 2012-03-16 02:40:13
March 16 2012 02:24 GMT
#2535

*btw thanks for the help guys. I figured that I could find a more simpler and less complex solution then the link shows. I don't wanna do it the way the link did it considering it had a lot of cout statements which I felt was unnecessary when you could just display out the array.

edit: God I feel stupid now...
wat wat in my pants
Sluggy
Profile Joined June 2010
United States128 Posts
Last Edited: 2012-03-16 02:31:54
March 16 2012 02:31 GMT
#2536
On March 16 2012 11:24 heroyi wrote:
Why is it when I input:

char tictacboard[3][3] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'}
};
int i = 0;
int j = 0;

for(i = 0; i < 3 ; i++)
{ for(j = 0 ; j < 3 ; j++)
{cout << tictacboard[i][j] << " " << endl;}}

the output is:
1
2
3
4
5
6
7
8
9

...why and how can I print the numbers out 3x3 like I thought I told it to do...

*btw thanks for the help guys. I figured that I could find a more simpler and less complex solution then the link shows.



It's doing what you're telling it to do. Think about how many times endl is getting called with your current code and see if you can find where you should put it.
heroyi
Profile Blog Joined March 2009
United States1064 Posts
March 16 2012 02:38 GMT
#2537
On March 16 2012 11:31 Sluggy wrote:
Show nested quote +
On March 16 2012 11:24 heroyi wrote:
Why is it when I input:

char tictacboard[3][3] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'}
};
int i = 0;
int j = 0;

for(i = 0; i < 3 ; i++)
{ for(j = 0 ; j < 3 ; j++)
{cout << tictacboard[i][j] << " " << endl;}}

the output is:
1
2
3
4
5
6
7
8
9

...why and how can I print the numbers out 3x3 like I thought I told it to do...

*btw thanks for the help guys. I figured that I could find a more simpler and less complex solution then the link shows.



It's doing what you're telling it to do. Think about how many times endl is getting called with your current code and see if you can find where you should put it.

god dammit i feel retarded now...I just realized and came here hoping i could edit it out :/

yea, I played with the endl around and just realized how the code was actually interpreting it...thanks for the help though. Now maybe I can try to actually create this tic tac toe game...
wat wat in my pants
heroyi
Profile Blog Joined March 2009
United States1064 Posts
March 16 2012 05:10 GMT
#2538
http://www.cplusplus.com/forum/general/60651/
^^ I am trying to create my program somewhat similar to this now however I keep getting the error that my variables x, y are undeclared when stated in my array. Why is it that the link above works (although the endl is wrongly placed while my coding keeps getting error messages)...is it because of how he groups them all up with braces?
wat wat in my pants
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
March 16 2012 09:36 GMT
#2539
for (int x = 0; x < 7; x++) { <- x is declared first thing in this line, same for y in the next line. Make sure you didn't write for(x=0... but for(int x=0...
Gold isn't everything in life... you need wood, too!
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
Last Edited: 2012-03-16 13:48:06
March 16 2012 13:47 GMT
#2540

#include <iostream>
using namespace std;

void displayGraph(int map[6][6]);

int main()
{
int map[6][6] =
{
{1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1}
};

displayGraph(map);

system("PAUSE");

return 0;
}

void displayGraph(int map[6][6])
{
for (int x = 0; x < 7; x++)
{
for (int y = 0; y < 7; y++)
{
if (map[x][y] == 1)
{
cout << "#";
}
else if (map[x][y] == 0)
{
cout << " ";
}
}
}
return;
}


Cleared up the code (global variables are unnecessary here, used prototype for displayGraph function) and removed endlines. Experiment with it
Time is precious. Waste it wisely.
Prev 1 125 126 127 128 129 1031 Next
Please log in or register to reply.
Live Events Refresh
Wardi Open
11:00
#43
WardiTV1322
OGKoka 522
Harstem420
Rex169
IndyStarCraft 165
CranKy Ducklings122
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
OGKoka 522
Harstem 420
Hui .184
Rex 169
IndyStarCraft 165
StarCraft: Brood War
Bisu 3073
Flash 2328
Jaedong 1756
Hyuk 1094
firebathero 707
EffOrt 657
Larva 521
ZerO 478
actioN 454
Soulkey 441
[ Show more ]
Stork 397
Snow 306
Soma 298
GuemChi 163
Mind 133
sSak 118
Light 108
Pusan 106
PianO 94
Sharp 77
JulyZerg 75
hero 73
TY 65
Barracks 48
Sea.KH 44
Aegong 36
sorry 32
Free 29
zelot 27
GoRush 25
HiyA 24
soO 23
Movie 18
JYJ17
yabsab 17
Terrorterran 11
Shine 10
IntoTheRainbow 10
ivOry 5
Dota 2
qojqva3148
Gorgc2576
XaKoH 629
XcaliburYe297
syndereN293
League of Legends
singsing2583
Dendi1
Counter-Strike
byalli270
markeloff134
Super Smash Bros
Mew2King169
Other Games
hiko1144
B2W.Neo1069
crisheroes369
Beastyqt345
Lowko293
ArmadaUGS140
Liquid`VortiX70
ZerO(Twitch)20
Organizations
Other Games
gamesdonequick37693
StarCraft: Brood War
UltimateBattle 978
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2960
• WagamamaTV335
League of Legends
• Nemesis5594
Upcoming Events
RotterdaM Event
2h 23m
Replay Cast
10h 23m
Sparkling Tuna Cup
20h 23m
WardiTV European League
1d 2h
MaNa vs sebesdes
Mixu vs Fjant
ByuN vs HeRoMaRinE
ShoWTimE vs goblin
Gerald vs Babymarine
Krystianer vs YoungYakov
PiGosaur Monday
1d 10h
The PondCast
1d 20h
WardiTV European League
1d 22h
Jumy vs NightPhoenix
Percival vs Nicoract
ArT vs HiGhDrA
MaxPax vs Harstem
Scarlett vs Shameless
SKillous vs uThermal
uThermal 2v2 Circuit
2 days
Replay Cast
2 days
RSL Revival
2 days
ByuN vs SHIN
Clem vs Reynor
[ Show More ]
Replay Cast
3 days
RSL Revival
3 days
Classic vs Cure
FEL
4 days
RSL Revival
4 days
FEL
4 days
FEL
5 days
BSL20 Non-Korean Champi…
5 days
Bonyth vs QiaoGege
Dewalt vs Fengzi
Hawk vs Zhanhun
Sziky vs Mihu
Mihu vs QiaoGege
Zhanhun vs Sziky
Fengzi vs Hawk
Sparkling Tuna Cup
5 days
RSL Revival
5 days
FEL
6 days
BSL20 Non-Korean Champi…
6 days
Bonyth vs Dewalt
QiaoGege vs Dewalt
Hawk vs Bonyth
Sziky vs Fengzi
Mihu vs Zhanhun
QiaoGege vs Zhanhun
Fengzi vs Mihu
Liquipedia Results

Completed

BSL Season 20
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
CSL Xiamen Invitational
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.