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 ...


2

Thanks Jacek for your post. Let's make a quick summary of the most obvious issues and we'll go over them: number of files the functions in certain files belong in other files due to their naming clear dependencies for functions in other files redundant comments code formatting (empty lines, not using PEP8, using doc-string for multi-line print, not using f-...


1

Code structure review It is C-style code. As you have added C++ tag, I assume you intend to write C++ code. Think from OOP point of view and abstractions will improve. Methods and signatures will improve and unnecessary passing of parameters will be avoided. void choose_position(int position, std::string* current_player); void find_row_column(int position, ...


1

Use another type for board representation Maintaining an array of strings, constantly making comparisons and possibly copying it in a few places can get very expensive very fast, which makes representing the board internally using std::string inefficient. Using a plain char is more suitable, maybe even Enums to map the characters to integral vales. Use ...


1

int possible_opponent(int row, int column, std::string opponent){ You're passing opponent by value, which duplicates the string. It's normal to pass strings by const reference, or better yet use a string_view. std::string ori_position = board[row][column]; board[row][column] = opponent; if (check_the_game() == "X"){ board[row][...


2

No time for a full review, but here are some general remarks: making_board: try and use verbs, as methods are things that perform actions, i.e. make_board or setup_board (you seem to do this right for the other methods, so maybe this is just the odd one out). C++ code often differs from C by using capital letters instead of underscores to separate method ...


Top 50 recent answers are included