tictac toe marks

Started by
28 comments, last by phil67rpg 10 years, 11 months ago

Sorry, I don't see any of these attempts of an "easy way out" working. Looking at this code and the breakout code, no amount of switching language, UML drawings or doing apps instead of games will allow avoiding to take a huge step back and learn some basic and fundamental programming first. That means understanding and knowing how and when to apply them, not "research" as in "I skimmed over a tutorial and compiled the code".

The code is an insane mess of copy/paste, arrays are used, but then stuff is just copied and hard coded for every field in the array, showing a complete lack of understanding WHY an array is used in the first place.

Data that should be grouped in a class or struct is instead spread over a bunch of different arrays, functions are just doing all kinds of stuff.

There's endless if/else-copy/paste replacing a simple division.

Despite making the same mistake in the breakout thread, this function is again presenting an entire frame when it should just set a value (so I doubt that it was even understood what those magical D3D functions are actually doing).

There is also no recognizable understanding of the difference between game logic and graphics. Graphical representation isn't the game, it's what you put ON TOP of the game, so a player can see what he's doing. The "core" of the game doesn't care about graphics, sprites, 2D/3D, keyboards or mice. Inputs are used to trigger functions of the game and graphics are used to display the state of the game.

You can't buy a Spanish dictionary, learn how to pronounce two or three words and then try to write an entire novel. You need to learn the grammar and rules, have a decent vocabulary and know common phrases and idioms.

In this case: you need to learn programming. The language here isn't C++ (or C#, Basic or any other specific language), it's basic programming concepts. Not just knowing what a loop looks like, but how to use them. Forget about GUI and 3D (or even 2D). Running requires knowing how to walk first. Otherwise you're not getting far and keep hurting yourself.

Planning for TicTacToe or a calculator by using ULM and flow charts is overkill. Maybe a nice practice, but if you need a flow chart to understand the game logic behind TicTacToe (of which 95% should be covered by a standard game loop), you are clearly overcomplicating a very simple thing. Frankly, at this point it seems more like avoiding the real issue rather than tackling it. Like constantly "taking a break from programming" it won't magically make you write better code.

Shhhh....
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.
Advertisement

so how do I get better at programming? should I read and work through a book?

Programming is about problem solving, Phil. A language is only a way to express your solutions to a specific problem. You break the overall problem into simpler segments, then repeat that process until the individual problems are simple enough to have clear solutions. You also use problem solving skills to find information and work around obstacles. There are a lot of tools available, and you can make your own tools where there are none. The tool that you need to acquaint yourself with in this case is the debugger. You can keep coming around here and asking us about things if you want, but if you rely on us too much then you're cheating yourself out of the experience of solving problems for yourself.

Honestly, I'm not mad at you or anything. You don't owe me anything and I'm not here to grade your performance. I just think you'd be doing yourself a favor if - when you come across some difficulty - you stop yourself and start asking more abstract questions:

  • How likely is it that other people have had this kind of problem before?
  • What tools are available that could help me understand this problem better?
  • What are other approaches I could take that might bypass this whole problem area?
  • Where could I find information about this kind of problem, or examples from other people who have solved it?
  • Why is this thing happening this way and what can I do to change it?

What Trienco is saying to you is that you have this tendency to encounter a problem and just go, "What's the one-stop-shop solution to this?"

If you want to be a programmer then you need to start solving problems.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

how do I get rid of magic numbers?

Generally by giving them names and making them constants, but that only applies to numbers that _must_ be defined in the program and won't change at runtime. The resolution or window size for a PC application should not be a magic number or a constant, because you don't know what hardware people are using.

In your case: by learning how to use structs, arrays, loops and functions.

Just doing a find/replace and creating thousands of constants like "block1TopLeftX" and "block3BottomRightY" might get rid of magic numbers, but is also insanely silly, because a sane person would never want to hard code everything for every single block in every single level of a game like Breakout (which will be thousands or even a lot more). Always tell yourself "there will probably be a bug in this code, I don't want to fix the same bug in 10000 copies of this". In fact, writing the same snippet more than twice (at most) is usually a bad sign.

Force yourself to keep things flexible. Plan for change, write code that will work no matter if your game board is 3x3, 5x5 or any other size (somewhat limited by screen size) and don't assume you will always need 3-in-a-row. Make board and required row size a variable and don't use magic numbers or constants. Remove the option to just hard code everything and force yourself to think in algorithms instead of a huge list of if-elses.

f@dzhttp://festini.device-zero.de

Remove the option to just hard code everything and force yourself to think in algorithms instead of a huge list of if-elses.

how do I get better at algorithms

These short questions are not going to get you anywhere. You get better by challenging yourself to write programs that do something that is near the edge of your abilities.

Forget about doing anything graphical for at least six months. Write console programs to do something challenging. Some examples of challenges:
* "Hello, world!"
* Print a multiplication table
* Calculator where the user is asked for operation and operands
* Print the calendar for any month in history
* Tic-tac-toe, two players
* Tic-tac-toe with AI
* Calculator where the user can enter any expression (e.g., "50*(4-2)+8*9")
* Interpreter for a simple scripting language
* Make the calculator above work with arbitrarily long numbers (if you use a library for this it's not very challenging, but still instructive because you'll learn how to interface with a library, and perhaps you'll get some ideas of how libraries should be written, which is how all code should be written.)
* Chess engine
* Relational database management system
* Compiler

I am sure you can write "Hello, world" and I am sure you can't write a compiler. So somewhere in that list there must be a challenge that is doable but not too too hard for you. Or you can make your own challenge, more in line with what interests you. Work on it. Don't give up, even if it's hard. Rinse. Repeat.

should I use c++ or c#?

should I use c++ or c#?

At long last, I am fully convinced that phil is just trolling us all. Well done, phil. Well done.

what is trolling

This topic is closed to new replies.

Advertisement