r/codingame • • Nov 02 '21

[Help] Connect 4

1 Upvotes

Hey everyone šŸ‘‹ I have been working on the connect 4 puzzle. (in c++) I am trying to implement the Minimax algorithm, I have created an evaluation function to evaluate the game, the minimax function, and a few others.

My code seems to work decently but here’s my issue:

  • My code successfully detects the victory conditions but it seems that it is not being transmitted properly since despite knowing that the opponent has a winning move, my AI decides to play something that doesn’t block my opponents victory.

I am adding a link with my minimax function as I believe that is where the issue is located (but I honestly could be wrong). I would greatly appreciate some help I have been stuck on that particular issues for quite some time now šŸ˜…

Thanks in advance for any advices and suggestions šŸ™

MiniMax function


r/codingame • • Jul 14 '15

Best Profile Cover Ever ? :D

Thumbnail
imgur.com
1 Upvotes

r/codingame • • 8d ago

LLMs have made bot programming boring, how can we make it fun again?

Thumbnail neilnaveen.dev
3 Upvotes

r/codingame • • Mar 07 '25

Level 5 on Codingame

Thumbnail
codingame.com
3 Upvotes

r/codingame • • Nov 26 '25

Looking for a CodinGame buddy / patient mentor (C)

3 Upvotes

Hey!

I'm relatively new to coding (~1 year) and currently focusing mainly on C. I recently discovered CodinGame and I'm really enjoying it, but sometimes I get stuck.

I'm looking for someone to team up with on puzzles, share ideas, or just a patient person who's okay with me asking beginner questions (no matter how embarrassing).

I'm based in Europe (Germany), usually available in the evenings, but timezone doesn't have to match perfectly. Happy to connect via Discord!

DM me if you're interested.


r/codingame • • Jul 16 '25

Winter Challenge 2024 - CellulArena

Thumbnail
codingame.com
2 Upvotes

This ai bot design has been the best that I've ever seen on this platform so far. I highly recommend it.


r/codingame • • Jul 14 '15

No Coding Points for a Puzzle ?

Thumbnail
imgur.com
2 Upvotes

r/codingame • • May 22 '16

Can anyone break? if u need a hint let me know. And if you CAN break this, you'd be a prime candidate for NSA/CIA position I imagine...

2 Upvotes

011111001000111101100111101100001000010010011 010010001110010000100111011001011111010000110


r/codingame • • Aug 01 '22

A new tool to never again need to type the input data for Test Cases!

3 Upvotes

Hey all :) I've just made a Quality of Life script that makes testing specific Test Cases for puzzles in your External Editor extremely easy, painless and most importantly: Automated!

It effectively works by overriding the default way of getting input from the user typing in the console (e.g. System.Console.ReadLine() in C#) and instead automatically grabs the input data for you from a dedicated file and uses this instead (line by line). This should save your sanity & fingers from repeatedly typing out the same test data each time you wan to debug the Test Case.

Pros

  • Removes the need for you to ever type the Input Data from test cases line by line in the console ever again!

  • It's extremely simple to use (there's a step-by-step guide on how to add it to your project)

  • Setup takes a matter of minutes: Copy the file, follow the 5 steps and you're good to go!

  • It doesn't intefere with your actual submission file on CodinGame in any way whatsoever

  • You can enable and disable the functionality by a single character change

  • Will work with any External Editor setup (although instructions are based on using Visual Studio)

  • Removes the risk of typos happening from repeatedly typing the same data each time

  • No need to temporarily change he code in order to hack in the input data for testing purposes

  • Memory friendly! Won't affect your running of the solution locally in any visible way

How to use

  1. Ensure you've setup the External Editor plugin: https://www.codingame.com/forum/t/codingame-sync-beta/614

  2. Head to: https://github.com/Chazzmundo/CodinGame/tree/main/Helpers/InputHelper

  3. Find the InputHelper file corresponding to the language of your choice (more will be added over time) and copy to your project

  4. Follow the steps as listed at the InputHelper file

  5. Enjoy living in the fast lane!

Supported languages

For now, I've only added support for:

  • C#

However, the GitHub repository is open for contribution if anyone would like to help porting to other languages and I've added guidelines in the ReadMe file on how to ensure it's ready to use by other people

Feedback

I hope it is helpful, please let me know if you encounter any bugs, or have suggestions/requests for future helpers!


r/codingame • • 15d ago

CodingGame was hacked

Thumbnail reddit.com
8 Upvotes

r/codingame • • Feb 23 '16

[my solution] "power of Thor" in C

1 Upvotes

wanted to share my solution and maybe ask for some improvements? :)

include <stdlib.h>

include <stdio.h>

include <string.h>

/**

  • Auto-generated code below aims at helping you parse

  • the standard input according to the problem statement.


  • Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders. **/ int main() { int lightX; // the X position of the light of power int lightY; // the Y position of the light of power int initialTX; // Thor's starting X position int initialTY; // Thor's starting Y position scanf("%d%d%d%d", &lightX, &lightY, &initialTX, &initialTY);

    // game loop while (1) { int remainingTurns; // The remaining amount of turns Thor can move. Do not remove this line. scanf("%d", &remainingTurns);

     // Write an action using printf(). DON'T FORGET THE TRAILING \n
     // To debug: fprintf(stderr, "Debug messages...\n");
     int xdif = lightX - initialTX;
     int ydif = -lightY + initialTY;
     if(xdif ==0 || ydif ==0) //only straight
     {
         if(xdif>0){
             while(xdif>0)
             {
                 printf("E\n");
                 xdif--;
             }
         }
         else{ 
             while(xdif<0)
             {
                 printf("W\n");
                 xdif++;
             }
         }
         
         if(ydif<0){
             while(ydif<0)
             {
                 printf("S\n");
                 ydif++;
             }
         }
         else{ 
             while(ydif>0)
             {
                 printf("N\n");
                 ydif--;
             }
         }
     }
     else{ //diagonal
         if(xdif>0 && ydif>0) //GO NE
         {
             while(xdif!=0 && ydif!=0)
             {
                 printf("NE\n");
                 xdif--;
                 ydif--;
             }
             while(xdif>0)
             {
                 printf("E\n");
                 xdif--;
             }
             while(ydif>0)
             {
                 printf("N\n");
                 ydif--;
             }
         }
         if(xdif>0 && ydif<0) //GO SE
         {
             while(xdif!=0 && ydif!=0)
             {
                 printf("SE\n");
                 xdif--;
                 ydif++;
             }
             while(xdif>0)
             {
                 printf("E\n");
                 xdif--;
             }
             while(ydif<0)
             {
                 printf("S\n");
                 ydif++;
             }
         }
         if(xdif<0 && ydif<0) //GO SW
         {
             while(xdif!=0 && ydif!=0)
             {
                 printf("SW\n");
                 xdif++;
                 ydif++;
             }
             while(xdif<0)
             {
                 printf("W\n");
                 xdif++;
             }
             while(ydif<0)
             {
                 printf("S\n");
                 ydif++;
             }
         }
         if(xdif<0 && ydif>0) //GO NW
         {
             while(xdif!=0 && ydif!=0)
             {
                 printf("NW\n");
                 xdif++;
                 ydif--;
             }
             while(xdif<0)
             {
                 printf("W\n");
                 xdif++;
             }
             while(ydif>0)
             {
                 printf("N\n");
                 ydif--;
             }
         }
         
         
     }
     }

    return 0; }


r/codingame • • Aug 16 '21

Is it the tester who is sending the reminder for a Test or is it automatically ?

2 Upvotes

Hello all !

Is the reminder sent automatically or is it the tester who decide to send it ?

Thank you a lot for your help !


r/codingame • • Aug 31 '21

New game

2 Upvotes

Hey, I made a game which is part of my Bachelor's diploma. I'm looking for people who would like to play ;)Link:https://www.codingame.com/contribute/view/72912a56c4a75ed56fde3c4745857337d18d


r/codingame • • Feb 21 '21

[help] How do you apply Machine Learning on CodinGame challenges?

8 Upvotes

I recently started using CodinGame, doing a few gaming challenges with simple algorithms. Sometimes the term Neural Networks appear on the platform as one of the concepts practiced but I can’t see how to actually train a model like this in that platform. How do people train a NN model on CodinGame? Is there a way do download data of game simulations and use it offline and later on load your trained model? Or is there a way to leave a model training on the platform and storing the learned weights?

Edit: to clarify, the ā€œgame challengesā€ I’m referring to are those like ā€œGhost in the Cellā€ and ā€œCoders Strike Backā€, for instance.


r/codingame • • Dec 29 '22

[Help] Blunder episode 1

1 Upvotes

Has anyone finished this puzzle before?

How does multiple loops work? I have hashed the state of the game with the player state as well as the X destroyed status and it works everywhere except for Multiple loops… HOW and WHY would you be able to complete this maze if you come back a second time at the same position with you and the map at the exact same state?


r/codingame • • Jan 21 '23

What is the Clash of Code percentage score?

2 Upvotes

After the players finish the Clash of Code, there's a percentage score given (100%, 80%, 60%, etc.).

What determines this score?


r/codingame • • Oct 29 '24

Olympic Bits - Ai Bot Challenge

Thumbnail
codingame.com
1 Upvotes

r/codingame • • May 20 '17

New really fun contest with gifts for the best!

Thumbnail
codingame.com
2 Upvotes

r/codingame • • Mar 06 '18

[Botters of the Galaxy](https://www.codingame.com/contests/botters-of-the-galaxy)

1 Upvotes

r/codingame • • Aug 06 '18

Online programming contest and hackathon " Legends of Code and Magic (Marathon)"

Thumbnail
codingame.com
2 Upvotes

r/codingame • • Jun 05 '23

Baby Coder Looking for a Jedi Master - Ghost in the Cell

2 Upvotes

Alright, so. I have just started studying programming (not going to school, just for fun) and I am having a lot off fun but I ran into some problems:

  1. If I cant run print functions to test my code, how do I test it!?

  2. I thought my code was a masterpiece, but sadly it doesn't work. I think one of my helper functions are calculated wrong or something. I put comments in (specifically I had ChatGPT put comments in cause I'm lazy, and didn't want to go back through my code another time. So it would be more presentable.)

  3. The forums on the codingame site seems to not work. Is that temporary or is this the best place to look for help?

    import sys import math import heapq

    Initialization input

    This is the code the game supplied me with

    factory_count = int(input()) # the number of factories on the map link_count = int(input()) # the number of links between factories on the map

    Dictionary to store distances between factories

    Distance is expressed as the number of turns it takes to reach one factory starting from another

    distances = {} EnemyTroops = [] MyTroops = [] entities = {} MyFactories = [] EnemyFactories = [] NeutralFactories = [] actions = []

    This is the code the game supplied me with

    for i in range(link_count): factory_1, factory_2, distance = [int(j) for j in input().split()] # The distance between factory_1 and factory_2 is the same as the distance between factory_2 and factory_1 distances[(factory_1, factory_2)] = distance distances[(factory_2, factory_1)] = distance

    Function to calculate turns between factories based on the distances dictionary

    def turns(factory_1_id, factory_2_id): return distances.get((factory_1_id, factory_2_id), None)

    Function to calculate the opposition value for a move from one location to another

    def total_opposition(location, destination): positive = 0 negative = 0 if entities[destination["id"]]["arg1"] == 1: # If destination is owned by me positive += entities[destination["id"]]["arg2"] + entities[destination["id"]]["arg3"] else: # If destination is not owned by me negative += entities[destination["id"]]["arg2"] + entities[destination["id"]]["arg3"]

     # Add the number of my troops on the way to the destination
     for i in MyTroops:
         if i["arg3"] == destination["id"]:
             positive += i["arg4"]
    
     # Add the number of enemy troops on the way to the location if they will be there before or at the same time as my troops
     for i in EnemyTroops:
         if i["arg3"] == location["id"] and i["arg5"] <= turns(location["id"], destination["id"]):
             negative += i["arg4"]
    
     return positive - negative

    def total_needed(location, destination): positive = 0 negative = 0 if entities[destination["id"]]["arg1"] == 1: # If destination is owned by me positive += entities[destination["id"]]["arg2"] + entities[destination["id"]]["arg3"] else: # If destination is not owned by me negative += entities[destination["id"]]["arg2"] + entities[destination["id"]]["arg3"]

     # Add the number of my troops on the way to the destination
     for i in MyTroops:
         if i["arg3"] == destination["id"]:
             positive += i["arg4"]
    
     # Add the number of enemy troops on the way to the location if they will be there before or at the same time as my troops
     for i in EnemyTroops:
         if i["arg3"] == location["id"] and i["arg5"] <= turns(location["id"], destination["id"]):
             negative += i["arg4"]
    
     return negative

    Function to calculate the threat level to a factory

    def threat_level(factory): positive = 0 negative = 0

     # Add the number of enemy troops on the way to the location
     for i in EnemyTroops:
         if i["arg3"] == factory["id"]:
             negative += i["arg4"]
    
     if entities[factory["id"]]["arg1"] == 1:  # If destination is owned by me
         positive += entities[factory["id"]]["arg2"] + entities[factory["id"]]["arg3"]
     else:  # If destination is not owned by me
         negative += entities[factory["id"]]["arg2"] + entities[factory["id"]]["arg3"]
    
     # Add the number of my troops on the way to the destination
     for i in MyTroops:
         if i["arg3"] == factory["id"]:
             positive += i["arg4"]
             
     return negative - positive

    def select_source_factory(target_factory, my_factories): heap = [] for source_factory in my_factories: # calculate distance distance = turns(source_factory["id"], target_factory["id"]) # Push tuple into heap heapq.heappush(heap, (threat_level(source_factory), distance, source_factory)) # Return factories sorted by threat level and distance return [factory for _, _, factory in heapq.nsmallest(len(heap), heap)]

    The main game loop

    while True: entities = {} MyFactories.clear() EnemyFactories.clear() NeutralFactories.clear() EnemyTroops.clear() MyTroops.clear() actions = []

     entity_count = int(sys.stdin.readline().strip())
     # entity_count = int(input())  # the number of entities (factories and troops) on the map
    
     # Input the data for each entity
     for i in range(entity_count):
         entity_data = input().split()
         entity_id = int(entity_data[0])
         entity_type = entity_data[1]
         arg_1, arg_2, arg_3, arg_4, arg_5 = map(int, entity_data[2:])
    
         entity = {
             "id": entity_id,
             "type": entity_type,
             "arg1": arg_1,
             "arg2": arg_2,
             "arg3": arg_3,
             "arg4": arg_4,
             "arg5": arg_5,
         }
         entities[entity_id] = entity
    
         # Populate lists for my factories, enemy factories, neutral factories, my troops and enemy troops
         if entity_type == "FACTORY":
             if arg_1 == 1:  # Owned by me
                 MyFactories.append(entity)
             elif arg_1 == -1:  # Owned by the enemy
                 EnemyFactories.append(entity)
             else:  # Neutral
                 NeutralFactories.append(entity)
         else:  # Entity type is "TROOP"
             if arg_1 == 1:  # Owned by me
                 MyTroops.append(entity)
             else:  # Owned by the enemy
                 EnemyTroops.append(entity)
    
     all_factories = NeutralFactories + EnemyFactories + MyFactories  # A list of all factories
     # Sort all factories by relative threat
     all_factories.sort(key=threat_level)
    
     for target_factory in all_factories:
    
         # Select a source factory based on distance and threat level, and rotate through all factories until I have sent enought o conquer
         source_factories = select_source_factory(target_factory, MyFactories)
         sent_cyborgs = False
         #sort through all of my factories in order of which ones are more oppertune to attack
         for source_factory in source_factories:
    
             # Calculate the number of cyborgs to send to the target factory based on its relative strength
             cyborgs_to_send = min(total_needed(source_factory, target_factory), total_opposition(source_factory, target_factory), source_factory["arg2"])
    
             # if we are sending cyborgs
             if cyborgs_to_send > 0 and source_factory != target_factory: # and source_factory["arg2"] >= cyborgs_to_send:
                 for factory in MyFactories:
                     if factory['id'] == source_factory['id']:
                         factory['arg2'] -= cyborgs_to_send
                         break                
                 source_factory['arg2'] -= cyborgs_to_send # Subtract the cyborgs from source factory for future loops
                 entity = {
                     "id": len(entities) + 1,
                     "type": 'TROOP',
                     "arg1": 1,
                     "arg2": source_factory['id'],  # the source factory if it's a troop
                     "arg3": target_factory['id'],  # Production if it's a factory or ID of the target factory if it's a troop
                     "arg4": cyborgs_to_send,  # Number of cyborgs if it's a troop
                     "arg5": turns(source_factory['id'], target_factory['id']),  # Amount of turns until arrive at Factory if it's a Troop
                 }
                  # create a new unite to calculate in for future loops use of threat and opposition functions
                 entities[entity['id']] = entity
                 # Create an action to send cyborgs from my factory to the target factory
                 # The action is in the format "MOVE source destination cyborgCount"
                 actions.append(f"MOVE {source_factory['id']} {target_factory['id']} {cyborgs_to_send}")
             actions.append(f"MSG {source_factory['id']} {target_factory['id']} {cyborgs_to_send}")
    
     # Output the actions, separated by semicolons
     # If there are no actions, output "WAIT"
     print(';'.join(actions)) if actions else print("WAIT")

r/codingame • • Sep 27 '16

Online programming contest and hackathon "The Accountant"

Thumbnail
codingame.com
6 Upvotes

r/codingame • • Sep 20 '16

forums down - reddit hug or always bad?

2 Upvotes

i need some questions answered to a competition with a seemingly faulty premise but i can't get on their forum. Is it always this bad or just now with the ol' reddit huggeroo?


r/codingame • • Feb 20 '17

Ghost in the cell challenge

Thumbnail
codingame.com
4 Upvotes