Amazonial - Puzzle Discussion

Feel free to send your feedback or ask some help here!

1 Like

Hello everybody.

My actual rank is #41 in league gold, and (with the advisory of marchette) my priority in score evaluation is the nearest distance to opponent.
Before i continue, what will be the more importante : including surface evaluation in the score or a MinMax or other else.

Tx

Enemy detection in the fog.

1 Like

Yes, this is what i mean by saying “nearest distance to opponent”. At this time, i have a simple fog detection like the cell around every build event in the fog.
For a push from the fog, there is max 3 cells around the build cell, and for a move in the fog, a max of 8 cells around the build cell.

I am in hesitation to accurate it with the failed move or failed push, and so and so, before implementing other strategies like control surface score or minmax etc…

Hello everybody, I’m new in CodinGame and I’m not very good in Js. Here is my code for wondev woman in Wood League 2. I want to make my character to move around the center, but it doesn’t work. Sorry for my comments, they are in french.

var size = parseInt(readline());
var unitsPerPlayer = parseInt(readline());
var milieu;
var dir1;
var dir2;
var diffX;
var diffY;
var oldUnitX;
var oldUnitY;
// game loop
while (true) {
    for (var i = 0; i < size; i++) {
        var row = readline();
    }
    for (var i = 0; i < unitsPerPlayer; i++) {
        var inputs = readline().split(' ');
        var unitX = parseInt(inputs[0]);
        var unitY = parseInt(inputs[1]);
    }
    for (var i = 0; i < unitsPerPlayer; i++) {
        var inputs = readline().split(' ');
        var otherX = parseInt(inputs[0]);
        var otherY = parseInt(inputs[1]);
    }
    milieu=size/2;
    oldUnitX=unitX;
    oldUnitY=unitY;
    
    if (unitX<milieu){
        unitX+=1;
    } else {
        unitX-=1;
    }//aller au centre pour X
    
    if (unitY<milieu){
        unitY+=1;
    } else {
        unitY-=1;
    }//aller au centre pour Y
    
    diffX=oldUnitX-unitX;//différence de direction
    diffY=oldUnitY-unitY;//différence de direction
    switch (diffX){
        case -1:
            switch (diffY){
                case -1:
                    dir1="NW";
                    dir2="SE";
                    break;   
                case 0:
                    dir1="W";
                    dir2="E";
                    break;
                case 1:
                    dir1="SW";
                    dir2="NE";
                    break;
            }
            break;
        case 0:
            switch (diffY){
                case -1:
                    dir1="N";
                    dir2="S";
                    break;
                case 1:
                    dir1="S";
                    dir2="N";
                    break;
            }
            break;
        case 1:
            switch (diffY){
                case -1:
                    dir1="NE";
                    dir2="SW";
                    break;
                case 0:
                    dir1="E";
                    dir2="W";
                    break;
                case 1:
                    dir1="NW";
                    dir2="SE";
                    break;
            }
            break;
    }//interpéteur
    
    
    var legalActions = parseInt(readline());
    for (var i = 0; i < legalActions; i++) {
        var inputs = readline().split(' ');
        var atype = inputs[0];
        var index = parseInt(inputs[1]);
        dir1;
        dir2;
    }
    
    
    // Write an action using print()
    // To debug: printErr('Debug messages...');

    print(atype+' '+index+' '+dir1+' '+dir2);
}

If someone can help me it would be nice please.
Thanks,
Fireye025

hey @Fireye025, sorry to answer to so late. Perhaps you can specify what issue you encounter exactly. Saying “it doesn’t work” does not help us. Is it the first multiplayer game you try?

Hello there. :slight_smile:

This is not my first time programming, but first time on codingame.
I’m having a hard time while solving wondev woman stage 1, I’m pretty sure it’s due to my lack of understanding of C++ and/or a memory leak.

After a few turns (15 to 30), my representation of the map gets filled with incoherent stuff, the move direction given by input (N/E/SW, etc) seems to be the empty string (as debug has shown), and sometimes (not always) it ends with really ugly messages of maybe 100 lines, filled with stuff like
*** Error in '/tmp/Answer': malloc(): memory corruption (fast): 0x000055555576fdd0 *** ======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x70bcb)[0x7ffff69b5bcb]

or

at abort.c. function __GI_abort () on line 89 at libc_fatal.c. function __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7ffff6aaadd0 "*** Error in '%s': %s: 0x%s ***\n") on line 175

Honestly I wouldn’t be surprised if I found by accident some secrets of codingame’s internal architecture here.

Firstly, I can’t debug that issue because IT WORKS the first few turns. What can I do, std::cout some more variables ? It will just (and has) display the expected values at first and still not work after.

Secondly, I know the information I gave here is not very useful, but I can’t show you where my error would be (I have no idea, it works after all !), and I can’t provide the whole code for you to scan, per the forum rules. :disappointed:

Here’s a taste of how my map is “corrupted” after some time :
Map as expected (similar to the 18 previous turns) :
. . . 0 . . . . . 0 2 0 . . . 0 0 1 2 0 . 0 0 1 0 0 2 0 . 0 0 1 1 1 . . . 0 3 0 . . . . . 2 . . .

Next turn, getting a bit fucked up :
0 0 0 0 0 0 0 0 . 0 2 0 . . 0 0 0 1 2 0 . 0 0 1 0 0 2 0 0 0 0 0 0 0 0 0 . 0 3 0 . . 0 . . 2 . . 208

The turn after that, utter chaos :
-154277032 0 0 0 0 0 0 32767 . 0 2 0 . . -154277032 0 0 1 2 0 . 32767 0 1 0 0 2 0 0 0 0 0 0 0 0 0 . 0 3 0 . . 0 . . 2 . . 208

Since it fails only after some time, my guess is very little memory is given to me, and I leak it somehow (but I didn’t even use new or pointers when that error first came up !) ; and it overrides some values… or something.

I’m desperate for help, I can’t do anything, any suggestion would be appreciated. This is stupid, it’s not even very complex, it’s 200 lines of “Random move unless you can win immediately”.

Also, is there a limit (in std::cerr) on the number of displayed characters by the programmer, on codingame ?

PS : welp, I hoped rubber duck debugging would help, but I’m at the end of my post and it’s still the same :frowning:

Thanks to someone who private messaged me, this was solved.

It was partly because of an x/y inversion (ex : move 1;3 into 1;4 is possible, but it’s 4;1 that has the height needed to win, not 1;4). Still not sure where was the problem, but I redid the whole map access, switched some variables and renamed.

The random factor was just “when I detect a winning move”, not memory.

Once this was solved, still some errors displayed at the end, because I win, but keep calling cin because it’s a while(1), which probably contains the last description of the game or something, and then EOF (look what I was pushing into the map)
row #0 =[MOVE&BUILD]
row #1 =[0]
row #2 =[SW]
row #3 =[N]
row #4 =[MOVE&BUILD]

So I used a wonGame boolean instead of while(1), now there are no error messages.

Forgive me father for I have cined too much.

Hello,

I have a problem that sometimes, not always, appears in C# when it’s running my solution. It does not seem to be a compilation problem neither, I think, a programmation problem. Here’s what the error output says:

  • Assertion at gc.c:958, condition `is_ok (error)’ not met, function:mono_gc_init_finalizer_thread, Couldn’t create thread. Error 0x0 assembly: type: member:(null)

=================================================================
Native Crash Reporting

Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.

/proc/self/maps:
00400000-0084f000 r-xp 00000000 00:32 1153 /usr/bin/mono-sgen
00a4e000-00a56000 r–p 0044e000 00:32 1153 /usr/bin/mono-sgen
00a56000-00a5b000 rw-p 00456000 00:32 1153 /usr/bin/mono-sgen
00a5b000-00a72000 rw-p 00000000 00:00 0
011a8000-01240000 rw-p 00000000 00:00 0 [heap]
413b9000-413c9000 rwxp 00000000 00:00 0


/usr/lib/mono/aot-cache/amd64/mscorlib.dll.so
7f180ff7d000-7f180ff7e000 r–p 0063a000 00:32 1166 /usr/lib/mono/aot-cache/amd64/mscorlib.dll.so
7f180ff7e000-7f180ff7f000 rw-p 0063b000 00:32 1166 /usr/lib/mono/aot-cache/amd64/mscorlib.dll.so
7f180ff7f000-7f180ffa8000 rw-p 00000000 00:00 0
7f180ffa8000-7f18103ff000 r–p 00000000 00:32 1163 /usr/lib/mono/4.5/mscorlib.dll
7f18103ff000-7f18113ff000 rw-p 00000000 00:00 0
7f18113ff000-7f1811400000 —p 00000000 00:00 0
7f1811400000-7f1812000000 rw-p 00000000 00:00 0
7f18120e8000-7f18121a0000 rw-p 00000000 00:00 0
7f18121a3000-7f18121d7000 rw-p 00000000 00:00 0
7f18121d7000-7f1812394000 r–p 00000000 00:32 3244 /usr/lib/mono/4.5/mcs.exe
7f1812394000-7f1812398000 rw-p 00000000 00:00 0
7f1812399000-7f181239a000 rw-p 00000000 00:00 0
7f181239a000-7f18123f9000 —p 00000000 00:00 0
7f18123f9000-7f18123fc000 r–p 00000000 00:32 1102 /lib/x86_64-linux-gnu/libnss_files-2.28.so
7f18123fc000-7f1812403000 r-xp 00003000 00:32 1102 /lib/x86_64-linux-gnu/libnss_files-2.28.so

=================================================================
Basic Fault Adddress Reporting

Memory around native instruction pointer (0x7f181272d8bb):0x7f181272d8ab d2 4c 89 ce bf 02 00 00 00 b8 0e 00 00 00 0f 05 .L…
0x7f181272d8bb 48 8b 8c 24 08 01 00 00 64 48 33 0c 25 28 00 00 H…$…dH3.%(…
0x7f181272d8cb 00 44 89 c0 75 1d 48 81 c4 10 01 00 00 5b c3 66 .D…u.H…[.f
0x7f181272d8db 0f 1f 44 00 00 48 8b 15 89 35 18 00 f7 d8 64 89 …D…H…5…d.

=================================================================
Native stacktrace:

0x521ff6 - /bin/mono : (null)
0x4b6211 - /bin/mono : (null)
0x7f18128e5730 - /lib/x86_64-linux-gnu/libpthread.so.0 : (null)
0x7f181272d8bb - /lib/x86_64-linux-gnu/libc.so.6 : gsignal
0x7f1812718535 - /lib/x86_64-linux-gnu/libc.so.6 : abort
0x714374 - /bin/mono : (null)
0x6fa6e1 - /bin/mono : (null)
0x71425b - /bin/mono : (null)
0x71481d - /bin/mono : monoeg_assertion_message
0x689a5f - /bin/mono : (null)
0x590f7b - /bin/mono : (null)
0x435c57 - /bin/mono : (null)
0x47f0c4 - /bin/mono : mono_main
0x42c17b - /bin/mono : (null)
0x7f181271a09b - /lib/x86_64-linux-gnu/libc.so.6 : __libc_start_main
0x42c8a3 - /bin/mono : (null)

=================================================================
Telemetry Dumper:

Entering thread summarizer pause from 0x7f18126f3780
Finished thread summarizer pause from 0x7f18126f3780.

Waiting for dumping threads to resume

Debug info from gdb:

And here it ends. I honestly don’t know what to do about this. A replay where it happens : https://www.codingame.com/replay/402904327

Is it my code somewhere or is this a bug ?

it might be related to https://www.codingame.com/forum/t/java-random-error-occurred-during-initialization-of-vm/120354/10
Can you still reproduce the issue?

I seem unable to reproduce the issue. Problem seems solved. Thank you !

Just a question: what happens if I try to build on a cell where there is an enemy that I did not see? Is the move cancelled (so that it is ? Is the move even included in the list of legal moves?

I did not see the answer in the rules in bronze league.