[Community Puzzle] Snake

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @Dr_Meyss,validated by @FE40536,@Devonor and @The_Capra_Aegagrus_H.
If you have any issues, feel free to ping them.

Very nice, love it :slight_smile:

How to do more than 6M ?

I try to minimize a path in the first round like in travelling salesman problem, then I use A* to travel from one predetermined node to the next

A pleasant surprise to find this one on the optimization tab today. Loved it.

Hi,

The initial positions occupied by the snake are 10;10 11;10 12;10 13;10 & 14;10 I don’t think having a rabbit being placed in any of these positions should be a thing as it doesn’t make sense that a rabbit could be there at the same time as the snake.

Skip them !!! at first turn , if there are some rabbits !!! :smiley:
It’s what you have observed or a supposition ?

It’s not a supposition, it’s an observation.

Nice puzzle. Thanks for the submission!
I have one small suggestion: The leaderboard evaluation should not be carried out with random maps in order to improve comparability. My score varies by ± 500000 points depending on the position of the sun it seems.

1 Like

There is a case who you are better with random. Resubmit many times. :smiley:

I wonder what might be in Test case 70. All test cases are passing (even these randomized) and I’m receiving over 4M points. Maybe a small hint what I have missed?

70 is the number of rabbits, since there are more rabbits you can score more points.

Nice job reaching 6.7M in PHP @cedricdd ! I guess a lucky submit is involved, but that you also found good heuristics to not rely too much on CPU power?

Hey @Dr_Meyss. Fun puzzle, but the variance created by random validators creates some unfairness. I suspect most people in the top 10, with 6.3M+ points or so probably have more or less equally good searches, but some got lucky and/or submitted more times.

I have some ideas how it could be made more fair. Are you interested?

1 Like

Yeah you can’t do much in 50ms, the bulk is done on first turn and I try to improve it on each turns.

How did you do to make more than 6M? Can you explain your technique ?

Sorry Snake Game has crashed!

The game has crashed. Please contact the author and enclose the following error:
java.lang.ArrayIndexOutOfBoundsException: 0
at com.codingame.game.Referee.gameTurn(Referee.java:289)
at com.codingame.gameengine.core.GameManager.start(GameManager.java:122)
at com.codingame.gameengine.core.RefereeMain.start(RefereeMain.java:67)
at com.codingame.gameengine.core.RefereeMain.main(RefereeMain.java:50)

How it happened , i’ll see that ?? It’s normal if you make an erroned output and if you try to hack ???

Hi Dr Meyss.

I try to compute a Alpha Star Algorithm to search best path because it’s the first idea which comes in mind for the moment to reach the 6 Millions. Perhaps my code was too complexe for IDE.

But I will try a new code to avoid this bug.

I’m not sure it’s possible to hack the code. But your answer makes me smile.

Thanks I try to solve it in another way.

Keep your informed only if needed.

Just a last question. I try to get a top score and I need to understand the calculation score.

The score can be negative in certain case?
And concerning the combo is it possible when two rabbits are not touching.

Sorry I know you explained it in other posts but I need to compute it sometimes offline to avoid Codingame max limitation and offline tests are the expert way to reach the top.

Thanks for your time.

The bug is here : Odon’t know why I verify the length before:

            List<String> outputs = player.getOutputs();
            // Check validity of the player output and compute the new game state
            String ans = outputs.get(0);
            String[] as = ans.split(" "); 
            if(as.length != 2) {
            	gameManager.loseGame("You must give 2 space separated integers.");
            }
            int X = Integer.parseInt(as[0]); //here is the 289th line
            int Y = Integer.parseInt(as[1]);

And the score is calculated like that :smiley:


        for(int i = 0;i < MAX_POINTS;++i) {
        		if(!vis[i] && coord_points[i].X == X && coord_points[i].Y == Y) {
        			int add_combo = 0;
        			if(turn - lturn_combo <= 2) {
        				combo++;
        			}
        			else {
        				
	    				combo = 1;
        			}
        			if(combo > 1) { 
    					add_combo = 15000 * combo;
    					GameManager.formatSuccessMessage("COMBO x " + String.valueOf(combo) );
    				} 

        			int penalty = (lturn_combo != -10000) && (turn - lturn_combo) > 10 ? turn*(turn - lturn_combo) : 0; 
        			COMBOt = add_combo;
        			PENALITEt = penalty;
        			SCORE += 10000 + add_combo - penalty;
        			ADDSCORE = 10000 + add_combo - penalty;
        			findscore = 1;
        			vis[i] = true;
        			points_sprite[i].setVisible(false); 
        			snake.Length_snake++; 
        			NB_POINTS++;
        			isin[snake.Length_snake-1] = true;        			 
        			lturn_combo=  turn;
        			break;
        		}
        		 
        	}
1 Like