Tag Info

1

From a short review; the tilescale is 16 which is a great value to multiply or divide with, so x = x/tilescale; z = z/tilescale; can become x = x >> 4; //Divide by 16 (tilescale) z = z >> 4; //Divide by 16 (tilescale) this does mean that changing the tilescale can become a performance drag (like in real games) So are 256 and 4, so return(...

4

Descriptive variable names You have this: player = scanner.nextLine(); Does the input reflect a player? I think a more descriptive name would be playerInput. That makes the switch more readable as well. Make methods do one thing (single responsibility principle) Your shootBall method does three things: asking for input, calculating the result, and printing ...

2

You only need one instance of Random and Scanner for the whole programm. Especially creating new instances of Scanner is bad, because it locks resources, that you never free by closing it. For the switch you are unnecessarily using the new expression syntax which is used when you want to return a value which you don't. The more conventional syntax would be: ...

2

Nomenclature create_grid does not just create the grid - it runs the entire game and then kills the process. It should be divided up into multiple functions, but that aside, it does not do what's on the tin. Forced-exit Your use of sys.exit() is not a great idea. What if a unit tester (who would have a difficult time anyway, given the size of your function) ...

1

Remove commented out code All the code that has been commented out distracts from the actual code. You commented it out for a reason: you don't need it anymore. Type Hints These help the user see what is accepted by a function, and what is returned by a function. It's helpful when you need to remember what functions accept what types of values. from typing ...

2

From a lengthy review; Clean up tags that are not used (doubles like body or unused like nav) Use a beautifier like https://beautifier.io/ Make sure you close your tags properly (the closing tag of the time section was missing) Leverage css styling, inline styling does not scale, and HTML is not the right place to style! document.getElementById is supported ...

1

Thank's all for yours answers and solutions! I'm read every example and teaches myself something new. Guys - you are great! This is my solution. And of course I except from this global variables. import random class game(): num_wins = 0 num_losses = 0 num_ties = 0 def run_game(): choices = ["paper", "...

1

Without the profile numbers you have, I can't suggest changes that make assumptions about the input to the function. For instance, if you knew that most times the 'check if the game is over' fails, you could only run the check once the player has a piece in every row and a piece in every column. I will also be picking off small things, as I don't know what ...

1

When reading this function alone, without any surrounding code, I wonder where the initial + 1 for the position comes from. That looks like an off-by-one bug to me. I don't know whether it is indeed a bug, it's just suspicious. The calls to tuple() look redundant since the current_position already is a tuple. Doesn't your IDE warn about such things? The word ...

1

There is a lot of room for improvement in your code. First, I'd like to address an unusual request you made: Please don't recomend using functions. Why not? They are a fundamental notion in programming, and can't really be avoided. Glossing over the fact that you already use a bunch of functions like print, input, append, etc., and assuming you are ...

4

Functionally not 100% similar but shorter version of code. Taking advantage of walrus operator and modulo 3 tricks: from random import choice choices = ['rock', 'paper', 'scissors'] results = ['user wins', 'computer wins', 'draw'] totals = [0, 0, 0] while True: while (user_choice := input('Please choose {}, {} or {}: '.format(*choices))) not in ...

11

Please check it if you can, and give your opinion! Enable more warnings warning: this statement may fall through [-Wimplicit-fallthrough=] unused variables int a, b, i; Spell check funtion Do not re-enter main() Yes, it is possible, yet makes code review and debug a bear and hard to spin this code off into its own TicTacToe() function. Don't do that. ...

1

Naming is important When you're in the flow and writing code you'll typically remember what variables refer to and you'll often be able to hold the whole code context in your head, particularly with relatively small examples like this. However, as the code gets bigger / after you've stepped away from it for a while having good names really makes the code ...

4

Looks good overall! For example, good job using enums, and writing helpful comments. A few additional possible improvements, implemented below: In the declaration for DIRECTIONS, you don't need to cast 9 to usize; it can do so implicitly. Move the code for char_repr to an implementation of Display for CellType. Consider making more things usize instead of ...

2

Just a few quick things that jump out at me (I didn't go over all of it): Using static for everything is awkward. Usually you want to avoid storing state in statics. I know this is a simple app without multiple classes so you can get away with it here. But following more typical rules of thumb, you would make all these variables and methods non-static. If ...

2

Not sure about whether a solution could be more Pythonic, but I think it can be more efficient. At present your code is iterating over each cell twice, before anything is printed. I would suggest using a collection of possible winning strings. You only need to iterate over the cells once and each time you encounter a 0 that row, col and if applicable, ...

3

There are multiple things you could improve in your code. The name of the game I feel that it'd be better to call your game method run_game. You should also run it multiple times in a while loop, asking the user each time if they want to exit. When they say they want to exit, you can call the results function to display the results. The results Not only do ...

5

I'll just go over some small improvements I noticed you can make. my_win = 0 my_loss = 0 my_tie = 0 def game(): global my_tie, my_loss, my_win Global variables should be avoided whenever possible. The only reason I can see that these are globals is because of results() but you never actually call results(). It's probably better to just leave these as ...

1

Your first question "can the board be made more aesthetically pleasing" is subjective, but I would prefer, for only ASCII characters, something like: X | O | 2 ---+---+--- 3 | X | 5 ---+---+--- 6 | 7 | O But you could make it even more fancier by using Unicode Box-drawing characters, you can copy and paste these from the Wikipedia page 'Box-...

1

Intersection logic For the intersection logic, maybe it would be appropriate to make a method on the cell class that would determine if another cell (e.g. tank) overlaps with it. Refer to this answer for inspiration. Review Just as a POJO is created for the definition of Directions I'd recommend setting up a POJO for the colors used in drawMap. That way ...

1

Regardless of whether you choose to use procedural or object-oriented syntax, you should definitely make a distinct separation in your script between the "processing" and "displaying" parts. In other words, don't park you function declarations inside your html table. To defend your script from users hand-crafting/hacking the board layout,...

Top 50 recent answers are included