New answers tagged

1

The core logic of Number generation and comparison can be greatly simplified by using For /L and For /F loops in conjunction with indexed arrays: @Echo Off Setlocal EnableDelayedExpansion :Gameloop CLS Set /A Matches=0,R1=!Random! %%9+1,R2=!Random! %%9+1,R3=!Random! %%9+1 For /L %%i in (1 1 3)Do ( rem Prompt For Selection of Guesses N%%i [ 1 2 3 ] <...


2

I'd say that your code looks quite nice, but there are definitely things that could be (and need to be) improved. One thing that does not need to be improved is the efficiency of the code. I did some quick benchmarking, and the frame time is about 2-3ms, which is completely fine. Here are the things I would fix: Lines should not exceed 80 characters in ...


1

One way to simplify your code a lot is to generate a new board in your mergeLeft() function, instead of trying to modify it in place. It opens up room to use other techniques that would greatly simplify the logic in your function, like, popping results from the source array as you work with them, or filtering out zeros. An example of how you might ...


1

Review Some review points on your code Always delimit code blocks with {}. Eg if (target !== 0) startIndex++; is safer as if (target !== 0) { startIndex++; } Avoid using continue (Its a goto in disguise). Rather the line if (array[endIndex] === 0) continue; is better as if (array[endIndex]) { /*... loop code ...*/ }. See rewrite. Try to reduce ...


2

The two most important things to fix here are: Your code is non-reentrant, relying on a global wn surface which prevents coexistence of other surfaces in the same process; this is fairly easily fixed by passing in wn to your classes. Also, you've hard-coded a font that many (most?) other people will not have, so your code is non-portable. This might not be ...


3

Using __all__ = [] is mostly useless in the main program, and should probably be removed. This is hard to read: MSG_CORRECT = '\033[32mCorrect!\033[0m' MSG_INCORRECT = '\033[31mIncorrect\033[0m' This is much easier: from colorama import Fore MSG_CORRECT = Fore.GREEN + 'Correct!' + Fore.RESET MSG_INCORRECT = Fore.RED + 'Incorrect' + Fore.RESET Note: Style....


1

You are hard-coding which board indices You check. If You look how indices change, then there are rather simple patterns how they are generated. a) For example generate indices through some loop // // For example to go through all rows // for (int row = 0; row < 3; row++) { auto myCount = 0; auto emptyCount = 0; auto emptyIndex = 0; // ...


0

Enable more compiler warnings. With gcc -std=c17 -Wall -Wextra -Wwrite-strings -Wno-parentheses -Wpedantic -Warray-bounds -Wstrict-prototypes -Wconversion I see, amongst others: 222224.c: In function ‘recover_from_miss’: 222224.c:57:1: warning: label ‘ball_found’ defined but not used [-Wunused-label] ball_found: ^~~~~~~~~~ 222224.c: In function ‘cleanup’:...


1

Curious, this code looks a lot like the code in this question. I'm not saying that you have another account, but you don't happen to be in the same class or something? Your formatting seems to be inconsistent, use an automatic code formatter (your IDE most likely has one). private static final Scanner SC = new Scanner(System.in); Don't shorten names just ...


2

It looks like pretty good procedural code overall. Scope int i, j; // CONTATORI These indices can be local to functions. Globals are fine, but not in this case. Also sposta is probably always local to movimenti() function. Magic numbers void stampaBordi() // STAMPA LA CORNICE DEL CAMPO DI GIOCO { for(i=1;i<=19;i++) { GotoXY(i,22); putch('-...


6

Always write source code and comments in English (I'm not a native English speaker either). You will sooner or later need to share code with other people around the world, like you just did here and now. Therefore it needs to be in English. More importantly still, learning two technical programming terms for everything when you only need to learn one is ...


5

Some suggestions in no particular order: Organize your header files. I like to group related things together. In this case, "standard" versus "OS specific". I also default to sorting things alphabetically/asciibetically if there is no reason to do otherwise. Group related things: functions with functions, variables with variables. Don't ...


Top 50 recent answers are included