11
\$\begingroup\$

I'm working on a KOTH contest, and it is a little bit more on the complicated side. Each bot is expected to keep track of a lot of state. For example, move history, position in the board, position of other bots, etc.

It seems to me like the best way to do this would be to make each bot an instance of a class, rather than a full program communicating over command line arguments.

However, I'm worried about this since, by nature, this would restricts all entrants to a single language. Is this okay? And I go through with restricting it to a single language, what language is most appropriate? I'd like to do it in Java since it's very widespread and pretty easy to get started with. If I restrict it to Java, will that hurt participation on a technical or social aspect? E.g, "I'd like to participate, but I really want to do it in <language>"

Or If I instead allow persistent program that communicate over a pipe, will this make it too technically hard to implement that it will hurt participation?

\$\endgroup\$
  • 10
    \$\begingroup\$ JavaScript is an option which would allow you to host the KotH directly in a Stack Snippet for example. Using something offline has the advantage that someone can make a dummy implementation of the class and forward the calls to another process, which would then allow other languages to participate at the expense of some convenience. Whether you can afford Python really depends on how fast your controller will have to be. If performance is a concern, Java might be the better choice. \$\endgroup\$ – Martin Ender Apr 6 '16 at 15:17
  • 2
    \$\begingroup\$ Also, it is possible for bots in separate process to remain persistent and communicate with them via I/O pipes that are kept open the entire time. This is a lot trickier in some languages though, but it will probably give you the best of both worlds. Finally, there is also the option of limiting the amount of state each bot can remember by having them submit their memory in a fixed-sized string and returning it to them on the next turn (which then doesn't require bots to be persistent). \$\endgroup\$ – Martin Ender Apr 6 '16 at 15:19
  • \$\begingroup\$ @MartinBüttner I'm not super worried about performance. I'm okay with leaving the whole contest running for a while. Really, I'm more worried about the social aspect, e.g. "Dang it, this looks like a really fun challenge, but I don't know python and don't feel like learning it. Oh well, I guess I won't compete." \$\endgroup\$ – DJMcMayhem Apr 6 '16 at 15:20
  • 7
    \$\begingroup\$ You may not be worried about performance as the contest master, but as a potential contestant I am worried about performance. If it takes two hours to test whether a tweak to my bot improved it or not, I probably won't enter. \$\endgroup\$ – Peter Taylor Apr 6 '16 at 15:50
  • \$\begingroup\$ No master botting allowed. \$\endgroup\$ – mbomb007 Apr 6 '16 at 16:50
  • 1
    \$\begingroup\$ @DrGreenEggsandHamDJ It's hard to tell what kind of run times you'll end up with. Even for "fast" games, the number of entries sometimes overwhelms it and you end up having to run it for many hours each time. Something that seems fine for 8-10 players can easily be terrible with 50+ (rare, but it happens). I'd recommend making easy optimizations where you can. \$\endgroup\$ – Geobits Apr 6 '16 at 17:05
  • 1
    \$\begingroup\$ I vote for Java. It is pretty popular, and although it may not as fast as some other compiled languages like C++, Java it at least in the same ballpark, and is certainly faster than most interpreted languages like Python. Speed and popularity aught to be your two criteria when deciding what language to use. (This is not an endorsement for single language KotH's - just my opinion on what language to use if you decide to make one.) \$\endgroup\$ – Rainbolt Apr 6 '16 at 17:18
  • \$\begingroup\$ You could offer both options with Java. Make an extendable class (for those who find string-based I/O too convenient) and add a subclass that communicates with an external process. \$\endgroup\$ – feersum Apr 6 '16 at 20:29
  • 5
    \$\begingroup\$ Whichever language you choose, it's a good idea to include a bot template with comments like // Bot logic goes here and // Turn history; access with this.history[turn_number]. This makes it easier for people to participate even if they don't really know the language (but can read a tutorial and work by trial and error). \$\endgroup\$ – Zgarb Apr 9 '16 at 17:38
10
\$\begingroup\$

Use whatever you're comfortable with...

...but make sure it's a moderately-well-known language to encourage more submissions from more people.

Here is a (not exhaustive, in no particular order) list of languages I personally would consider to be good choices for a single-language King of the Hill challenge:

  • Java
  • Python
  • C++
  • JavaScript
  • C#

Ultimately, since you'll be writing the controller code, the language choice is up to you.

\$\endgroup\$
4
\$\begingroup\$

JavaScript

function MyBot(action){
  this.action = action;
  this.moves = [];
}
var bot = new MyBot(function(){return "LRD";});
  • You can do it online, where most everyone who would want to participate is.
  • It's similar to many langs in terms of syntax (C-like), and is far simpler to use, being a scripting language.
  • (BONUS: You can emulate Python with it.)

Why not JavaScript?

  • If you need to have long-running programs (e.g. long-lasting while loops), DO NOT use JavaScript, as it stalls the webpage. (Or use node, though I confess I don't know much about it.)
  • If you need more math stuff, use another lang with libraries. JS has some nice math functions, but will make you implement stuff like primality and otherstuff.
  • IF you need speed, there are other languages more suited for that purpose..
\$\endgroup\$
  • \$\begingroup\$ I know a lot about node. If you need help, please ask me. \$\endgroup\$ – user51533 Apr 12 '16 at 18:11
  • 1
    \$\begingroup\$ "far simpler to use" is very subjective. Static vs dynamic type checking is one of the classic programmer holy wars. \$\endgroup\$ – Peter Taylor Apr 12 '16 at 21:43
  • \$\begingroup\$ @PeterTaylor I was referring to the fact that this is a scripting language, objectively requiring less boilerplate. \$\endgroup\$ – Conor O'Brien Apr 12 '16 at 21:45
  • 1
    \$\begingroup\$ C doesn't require much boilerplate either. BTW another "con" is that JavaScript doesn't have integer types, which trips up lots of people who know other languages but don't know JS. \$\endgroup\$ – Peter Taylor Apr 12 '16 at 21:48
  • \$\begingroup\$ @PeterTaylor I don't know C, but that's interesting! And in writing this, I sorta take it as axiom that the user is somewhat familiar with the Lang, else the same could be said about just any Lang. \$\endgroup\$ – Conor O'Brien Apr 12 '16 at 21:51
  • \$\begingroup\$ Surely a significant factor in selecting the language for a single-language koth should be the barrier to entry for people who don't know the language but want to try hacking together a bot? \$\endgroup\$ – Peter Taylor Apr 12 '16 at 21:55
  • \$\begingroup\$ @PeterTaylor That's true. I did that with Java on a KotH once. Then again, once you understand there's a lack of types, you can get along pretty well. \$\endgroup\$ – Conor O'Brien Apr 12 '16 at 22:19
3
\$\begingroup\$

Java

I wrote this answer under the assumption that there exists a good reason for limiting a challenge to only one language.

Popularity: In 2014, an overwhelming majority of universities use Java or Python as the tool of choice for teaching introduction to programming. More recently, the 2016 developer survey showed that JavaScript was the most popular language among front-end and back-end developers, with Python being more popular with Math and Data folks, and Java being the most well-known among students.

Performance: Of those three languages, Java is usually the fastest (when compared using each languages most widely used runtime environment). See here for a more direct comparison of Java and Python. See here for a direct comparison of JavaScript and Java.

If the goal is to optimize both performance and ease of participation, then Java is the correct choice.

\$\endgroup\$
  • \$\begingroup\$ "as of 2014"? 2 years can make a lot of difference! \$\endgroup\$ – Optimizer Apr 12 '16 at 17:40
  • 1
    \$\begingroup\$ @Optimizer If you can find a more recent article detailing the most popular intro to CS languages, edit the post. If it changes the conclusion to another language, feel free to edit that too. \$\endgroup\$ – Rainbolt Apr 12 '16 at 17:41
  • \$\begingroup\$ I am suspect of the timing for Python for several reasons. First and foremost, only a single execution is timed. Also, the code is very poorly written - some simple optimizations would improve the performance. It seems you didn't read the note about Java's inaccurate timing, which, when corrected, makes it much closer in performance to Python. \$\endgroup\$ – Mego Apr 12 '16 at 18:27
  • \$\begingroup\$ @Mego I actually did read the entire article before using it as a reference, although I didn't study the code and reflect on what optimizations could have been made to each of the programs. I saw the note about Java maxing out two cores while other programs only maxed out one. If we "correct" Java's score by doubling it, it's still more than ten times faster than Python's score, so my point still stands. \$\endgroup\$ – Rainbolt Apr 12 '16 at 18:57
  • 1
    \$\begingroup\$ It's also comparing apples to oranges - Java uses JIT compilation (from byte code to machine code), while Python (at least, with CPython) doesn't. I'd expect using PyPy or Jython would close the gap. \$\endgroup\$ – Mego Apr 12 '16 at 19:09
  • \$\begingroup\$ @Mego Should we identify and eliminate all of the differences between Java and Python, and then run our benchmark? "Crap. We forgot to rename Python to Java. Apples to oranges! Gotta start our benchmark over again." \$\endgroup\$ – Rainbolt Apr 12 '16 at 19:14
  • \$\begingroup\$ I'm going to choose to ignore your straw man argument and offer further reasoning: using the best (performance-wise) freely-available JVM (Oracle's HotSpot) and comparing it to a mediocre Python implementation (CPython) is the logical equivalent of a race between a prized race horse and a three-legged donkey. \$\endgroup\$ – Mego Apr 12 '16 at 19:18
  • \$\begingroup\$ @Mego Before you start throwing logical fallacies at me, consider that before you offered further reasoning, your comment, "There is at least one difference between Java and Python; therefore, we are comparing apples to oranges." is a non sequitur. The real debate is about whether the difference is significant enough to call it "apples to oranges". My "straw man argument" was not an attempt to refute your claim, but it was an attempt to shift the burden of proof back to you since you are the one who made the claim that we are comparing apples to oranges. \$\endgroup\$ – Rainbolt Apr 12 '16 at 19:53
  • 1
    \$\begingroup\$ (cont.) And now that you've backed up your claim, I can counter. Cython is, according to Wikipedia, the most widely used implementation of Python, and is developed by the Python core developers. Likewise, "The Java Runtime Environment (JRE) released by Oracle is a software distribution containing a stand-alone Java VM (HotSpot), browser plugin, Java standard libraries and a configuration tool. It is the most common Java environment installed on Windows computers." Comparing a race horse to a three legged donkey? That's a bit of a hyperbole. \$\endgroup\$ – Rainbolt Apr 12 '16 at 19:54
  • \$\begingroup\$ Comparing any AOT-compiled language with any JIT-compiled language is going to be a meaningless comparison, because of the vast performance differences between the two methods. Such a comparison will be dominated by the differences between AOT and JIT, and thus the actual performance of the language itself won't make much of an impact on the outcome. If a JIT-compiled version of Python was used instead (such as PyPy or Jython), the comparison would be much more meaningful. \$\endgroup\$ – Mego Apr 12 '16 at 20:04
  • 1
    \$\begingroup\$ @Mego Fine, point conceded. Now what percentage of the world actually uses JIT-comiled Python compared to Cython? Also, can you find a benchmark comparing Java to Jython or PyPy? I want to compare popularity and speed, not just speed. \$\endgroup\$ – Rainbolt Apr 12 '16 at 20:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .