[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file /includes/functions.php on line 4586: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3765)
[phpBB Debug] PHP Warning: in file /includes/functions.php on line 4588: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3765)
[phpBB Debug] PHP Warning: in file /includes/functions.php on line 4589: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3765)
[phpBB Debug] PHP Warning: in file /includes/functions.php on line 4590: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3765)
AI Challenge Forums • View topic - Java: Best way to force a move before time limit

It is currently Wed Jan 17, 2018 9:18 am Advanced search

Java: Best way to force a move before time limit

Random stuff about the contest, posts that don't fit in the other forums.

Java: Best way to force a move before time limit

Postby seripischad » Tue Sep 14, 2010 8:36 pm

seripischad
Cadet
 
Posts: 2
Joined: Tue Sep 14, 2010 8:07 pm

Re: Java: Best way to force a move before time limit

Postby neurotik » Tue Sep 14, 2010 10:40 pm

neurotik
Cadet
 
Posts: 7
Joined: Mon Sep 13, 2010 7:49 pm

Re: Java: Best way to force a move before time limit

Postby seripischad » Wed Sep 15, 2010 12:03 am

I appreciate the response. I tried that last night. Worked fine for around 20 turns then seemed to jam up the JVM.
seripischad
Cadet
 
Posts: 2
Joined: Tue Sep 14, 2010 8:07 pm

Re: Java: Best way to force a move before time limit

Postby Terr » Wed Sep 15, 2010 12:04 am

I agree that the "no thread" restrictions chafe a bit, but I suspect it's there to keep certain programming languages from having an advantage, as well as to keep the contest focused on logic rather than implementation.

That said, I'd use instead of bringing in a bunch of swing/AWT junk into the mix.

I think the "safe way" is to design your AI so that it progressively builds the information it needs to make good decisions and periodically checks to see if it has time (or not) to refine its solutions. Unless you're doing some sort of brute-force future prediction, hopefully one second is more than enough to react to any game turn.
Terr
Brigadier-General
 
Posts: 155
Joined: Mon Sep 13, 2010 9:19 pm

Re: Java: Best way to force a move before time limit

Postby pootzek » Wed Sep 15, 2010 8:49 am

pootzek
Cadet
 
Posts: 1
Joined: Sat Sep 11, 2010 2:09 pm

Re: Java: Best way to force a move before time limit

Postby GMNightmare » Wed Sep 15, 2010 7:45 pm

Pro-tip:
You shouldn't be using Collections.sort after the first turn.

But if you must, you should be checking between every iteration of the loop, so not before, but inside.
GMNightmare
Cadet
 
Posts: 9
Joined: Sat Sep 11, 2010 10:43 pm

Re: Java: Best way to force a move before time limit

Postby Terr » Wed Sep 15, 2010 11:01 pm

On that note, bear in mind that you can use a plain Java array if you're OK with the fixed size, and use the utility methods of java.util.Arrays to do sorting.

Although perhaps the best solution is to teach a man to fish: Get and IDE like Eclipse or Netbeans and do some real Profiling to find out where the bottlenecks are.
Terr
Brigadier-General
 
Posts: 155
Joined: Mon Sep 13, 2010 9:19 pm

Re: Java: Best way to force a move before time limit

Postby odinsbane » Fri Sep 17, 2010 6:04 pm

Arrays.sort(T[] a, Comparator<? super T> c), you can make a comparator that checks the time. That way if you are out of time you can raise an exception and it will stop sorting. You'll need to put your sort in a try/catch block.

This could work for Collections.sort() also, though I've heard collections.sort hasn't been compiling lately?
odinsbane
Cadet
 
Posts: 4
Joined: Fri Sep 17, 2010 2:29 am

Re: Java: Best way to force a move before time limit

Postby Terr » Fri Sep 17, 2010 6:17 pm

Terr
Brigadier-General
 
Posts: 155
Joined: Mon Sep 13, 2010 9:19 pm

Re: Java: Best way to force a move before time limit

Postby luismi » Mon Sep 20, 2010 2:19 pm

Sometimes Collections.sort takes more time that is needed and the engine throws timeout, in the most cases this occurs simply cause the collection is empty or they're lots of duplicated objects inside.

I've collection.sort in several parts of my program whith complex comparators and i've dealed with a lot of timeouts for problems as described above, once the problems was solved the calculations go faster again.

(My english isn't very good :P )

regards.
luismi
Lieutenant
 
Posts: 16
Joined: Sun Sep 12, 2010 10:50 am

Next

Return to Misc

Who is online

Users browsing this forum: No registered users and 1 guest

cron