Hot answers tagged

23

I'm one of the developers of Untrusted (neunenak). Your solution is completely ethical/fair/okay. The whole idea behind the game was that the player could write whatever code they needed to be able to progress to the next level. We do have a lot of code in the game's framework designed to make really easy and uncreative solutions impossible, but that's just ...


23

Your DynamicArray class is mimicking an ArrayList which is exactly that: a dynamic array. Use this instead of reinventing the wheel. Use break; instead of System.exit(0) to exit a loop. It leaves room to add more instructions beyond the loop without having to change the implementation. It's also a more natural way to break out of a loop. getUser() and ...


22

There's a lot to say here, so let's not waste any time and jump right into it: You said that you didn't want to hear the using namespace std;-drill, but using namespace std; is so dangerous that I'm just going to ignore that and give it to you anyways. So here it goes: Don't use using namespace std;, you're going to shoot yourself in the foot eventually. ...


17

You are organizing your algorithms into two categories: working algorithms and non-working algorithms; this is rather Manichean. You should try to design something where an algorithm is not "working" but "approaching the expected result better than the other ones". In other words, don't try to find "who works", but "who works better". The best thing you ...


16

This is two and a half years old, but for the sake of future viewers: Overall your coding style looks pretty good, especially for someone new to Clojure. I don't have any comments on the AI engine itself, but here are a few structural notes: not-nil? already exists in clojure.core as some?. Docstrings are usually phrased actively: e.g. "Returns the result ...


16

Readability Inconsistencies in coding style: Decide where You put an asterisk. Now You have things like this: ps_decoder_t *ps, const char* fileName. A few unreasonable var-names. What's size_t k? cst_voice* v? const Command *p? Mixing cases. Now You can't really recognize if it's a function or variable name, just by bluntly looking at the code. That's not ...


16

Here are some things that may help you improve your code. Don't abuse using namespace std I know you said you don't want to hear this, but your code is unusable as a library until this is addressed. Putting using namespace std at the top of every program is a bad habit that you'd do well to avoid. If you put it into a header (a .h file) it makes your ...


15

Yes, you really need to use loops and generalize this! In order for you to learn the most, I won't give any exact code but I will tell you a bit about what you need to do Your array seems to be index 1-9 based, I would recommend using index 0 to 8 instead. Array index always start at zero, it just seem like you're just not using it. Instead, use it. Use ...


13

AbstractScorer Are you sure you need the precision of double for scoring? I only ask because I recently had reason to down-convert a system to float because it had many millions of scorable items and the memory saving ended up being significant. toString() It is best practice to put a toString on each and every class you implement. The toString method is ...


13

When confronted with a problem like this it helps to implement the chain-of-responsibility pattern. In this case, you have a hierarchy of sorts, with a winning move, defensive move, and a random move. You should create an interface along the lines of: public interface TicTacToeStrategy { public boolean apply(Button[] buttons); } Then, you should have ...


13

Genesis It's best practices to let statements like if, for, try ... be followed by a space to disinguish them from method invocations. protected String last = null; protected is pointless since Genesis is a final class and hence can't be extended. This variable holds the last what? Advancing in the code it's apparentlylastResponse. Let's rename it ...


13

Avoid numbered variables char space_1 = ' '; char space_2 = ' '; char space_3 = ' '; char space_4 = ' '; char space_5 = ' '; char space_6 = ' '; char space_7 = ' '; char space_8 = ' '; char space_9 = ' '; int space_1y, space_1x; int space_2y, space_2x; int space_3y, space_3x; int space_4y, space_4x; int space_5y, space_5x; int space_6y, space_6x; int ...


12

In addition to what @Jeroen already said... The User class It's not so good that the User class initializes a Scanner from System.in. The fact that this class reads from the console is a hidden requirement that might not be obvious to users using this class. Also, is it really important for this class to read from the console? Wouldn't it be good enough ...


12

The code is full of repetition that can be removed. By just adding these two methods, it becomes much more readable. private boolean IsValue(int buttonNumber, String value) { return buttons[buttonNumber].getText().equals(value); } private void SetValue(int buttonNumber, String value) { buttons[buttonNumber].setText(value); buttons[buttonNumber]....


12

It's a two-player game. Both the AI and the human player should implement a common Player interface. That would make it easy to convert it into a human-human game, for example. Input validation happens partly in getNumbers() (the regex match and a consecutive numbers check) and partly in toIntArray() (another consecutive numbers check). It would be nice ...


12

Header files You have a lot of implementation code in that header file (files.h). Header files should only contain the function or class headers, the implementation should go into an extra cpp file. That makes your code more organized and also more performant, because your code would be included as is in every file that includes your header file. Out-...


12

Here are a number of things that may help you improve your program. Eliminate global variables where practical Having routines dependent on global variables makes it that much more difficult to understand the logic and introduces many opportunities for error. For this program, it would be easy and natural to wrap nearly all of the global variables in a ...


11

Overall, your code looks quite good. There is something however which you can simplify a lot. Consider these two code-parts: if (!ninjaControl.isOnGround()) { airTime = airTime + tpf; } else { airTime = 0; } if (binding.equals("CharLeft")) { if (value) { left = true; } else { left = false; } } else if (binding.equals("...


11

First, you are usually good about naming your variables, but you still have a few single-letter variables in here, o, p, and v, to name a few. These should be more descriptive of what they are. Second, your code would be a bit more readable if you put spaces around your operators, like for(var i = 0; i < n; i++) {. JSLint says you should do this too. ...


11

Just a quick remark: the amount of horizontal scrolling doesn't make for very readable/maintainable code: private static String transform(String s) { //transform a string into something the program can read return s.toLowerCase().replace("?", "").replace(".", "").replace("!", "").replace(",", "").replace("_", "").replace("~", "").replace("`", "").replace("'"...


10

There's something which worries me about using this as a sample for a job application: which is that it contains no virtual methods and no subclasses. No matter how clearly-written your code may be, it doesn't demonstrate an understanding of inheritance: which (I don't know) might be an important criterion in a job application. If this is valid criticism, ...


10

Does this program follow the elements of OOPs paradigm, abstraction and encapsulation? Not really. It started almost fine with a field contents enum (why override toString and not change actual output?), but then degenerated rapidly. Your main class does everything: startup and lifecycle, IO, game logic, game data storage, game AI. While it is decomposed ...


10

So what your AI is basically doing is looking for two in a row, and then block that row, right? In that case the first thing I would do is split your code up in two methods: setAI - which actually performs the move of the AI - and findBlockable - which finds a field that blocks three in a row. [you can see if you can come up with better names.] I'm also ...


10

Your python coding is great, there isn't anything I can come up with that affects your style. I like the basic idea of your simple AI system, but it needs to be refined a bit to make it good in practice. In addition you can extend it with a lot of funky things. The issues First, let's take a look at the subset selection part. Here I can see 3 potential ...


10

(The problem with the "test" option is that choice is still equal to the first user's input, "test". You should read another line of input into choice to get the response: if (choice.equals("test")) { System.out.println( "HOW'S THIS MYSTERIOUS 'TEST' GOING, HUH?! DID I GET AN A++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++?!")...


9

I was started to review the code a few days ago and it seems that rolfl was faster. Anyway, some other thoughts including things which are in the github repository. Build system: It took a while to load the project into Eclipse. There is no .project file nor pom.xml for Maven nor anything else. I suggest you using a build tool, Maven and Gradle are quite ...


9

Overall I think you have too much code in the main method. You should split that into more digestible segments. Perhaps some more methods in your GameLogic class (which probably should be split into one Game class and one GameBot / Player class). (At least) one method for determining the next move, one method for choosing the proper action based on the ...


9

As Loki Astari points out, there is a complete Tic Tac Toe strategy. However, I'm going to ignore that and just review the code that you posted. The main reason is that I think that a code review is more productive if you can compare code that at least follows the same algorithm. I would get rid of the global variables and replace them with class ...


9

Code style Naming The interface naming convention has a capital I at the beginning of your name so your TreeNode should be called ITreeNode. Public members should follow the Pascal Case typing e.g instead of bool nodeState { get; } the name should be bool NodeState { get; } Private variables should follow the camel Case typing e.g instead of Sequence ...


8

TicTacToe.py from TicTacToeUtil import * Per the style guide, Wildcard imports (from <module> import *) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools. In this case that would be a bit unwieldy: from TicTacToeUtil import (GameState, ...


Only top voted, non community-wiki answers of a minimum length are eligible