New answers tagged

0

ttt is not a good class name and should probably be renamed to TicTacToe. Conversely, Tictactoe is not a good name for a module and should be lowercase. Add PEP484 type hints to your signatures, such as size: int. createGrid should be create_grid by PEP8; similar for your other functions and variables. Do not add parens around your if predicates; this is not ...


1

thanks for sharing your code. What I like Dependency Injection Naming according to the conventions use of JVM provided fuctionality (Collections.*()) what I'd improve OOP stuff Obsessive Interface creation At least the classe you shared here have Interfaces but only one implementation. On Top their Names only differ by the 'I' as first letter. This ...


3

Your mainloop and Ai functions take a BOARD object by value, which will make a copy. You can pass those as const BOARD &board to avoid this. And since the board object already has the Cells data, you shouldn't need to pass that in as a separate parameter. From your comment near the end, you're already aware you should use the random number facilities ...


3

It's good to see the improvements you've made to your code! There's still more that can be done better though, some of which I'll list below. Use a consistent code style The style of your code has lots of inconsistencies. Some of them are related to the use of spaces (especially around commas) and empty lines. A code formatting tool, like Artistic Style or ...


1

Thanks NewWalker for your post. I can see you have big ideas for your game, and that means you'll need to learn some new ideas for getting the game to completion. The first thing that jumps out at me is it's one huge blob of code. Coding is about re-using code snippets, so we try to make functions where you give it a value (or not), it does some processing, ...


2

Welcome to CodeReview! Your code is very much "beginner" code, and I don't propose to change that too much. Instead, I'm going to point you at some things that you can do better in the same framework. Global variables You are using globals, which everyone is going to tell you is bad, bad, bad. It's horrible to use globals. Dogs and cats lying down ...


4

This is a fun start to a game. Decrease your reliance on globals, passing around variables in function parameters instead. Encapsulating the character stats in a class will make things easier. You need to work on your spelling and grammar - for example, you're power is the to call -> your power is the ability to call. Consider representing the element ...


2

Consistency Sometimes you use accessor methods, sometimes you access instance variables directly. Sometimes you use parentheses around message send arguments, sometimes you don't. You should choose one style and stick with it. If you are editing some existing code, you should adapt your style to be the same as the existing code. If you are part of a team, ...


2

I'm not a Ruby programmer, but there are a couple of general improvements I can think of for this code: Better initialization: There is no need to pass the random number and num_of_guess to the class. Generating a random number is part of the core definition of this game, and I will put it in the class. For num_of_guess, just set it to zero. There's no ...


1

char *strdup_(const char *src) { char *dst = malloc(strlen (src) + 1); if (dst == NULL) return NULL; strcpy(dst, src); return dst; } You are calling strlen in order to allocate memory, and then calling strcpy which works by calling strlen first! Remember the length, and use ...


5

Answers to your questions How can I deal with cleaning up resources in a more concise way? As of now, I'm trying to emulate exception handling by letting errors bubble up to main and doing general cleanup there. I thought about passing around a structure (allocator pattern) to error-throwing functions. C++ makes this a lot easier, with RAII and language ...


Top 50 recent answers are included