<commit_before>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import lib.interface as interface
import lib.utils as u
import lib.algorithms as algo


IAName = "closest"

(mazeWidth, mazeHeight, mazeMap, preparationTime, turnTime, playerLocation, opponentLocation, coins, gameIsOver) = interface.initGame(IAName)
route = []
mazeMap[(-1,-1)] = ()
def next_way(playerLocation, coins):
    candidates = algo.dijkstra(mazeMap, playerLocation)
    dist = float("inf")
    coin = (-1,-1)
    for c in coins:
        if candidates[1][c] < dist:
            dist = candidates[1][c]
            coin = c
    coins.remove(coin)
    return u.way_width(candidates[0], playerLocation, coin)



def initialisationTurn (mazeWidth, mazeHeight, mazeMap, timeAllowed, playerLocation, opponentLocation, coins) :
    global route
    route = next_way(playerLocation, coins)


def determineNextMove(playerLocation, opponentLocation, coins):
    global route
    if len(route) == 0:
        route = next_way(playerLocation, coins)
    else: 
        ennemy_dists = algo.dijkstra(mazeMap, opponentLocation)
        if ennemy_dists[1][route[-1]] < len(route):
            route = next_way(playerLocation, coins)
    next_pos = route.pop(0)
    return u.direction(playerLocation, next_pos)

# Init our AI
initialisationTurn(mazeWidth, mazeHeight, mazeMap, preparationTime, playerLocation, opponentLocation, coins)

# Starts the game
interface.startGameMainLoop(determineNextMove)<commit_msg>Pour cyril<commit_after>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import lib.interface as interface
import lib.utils as u
import lib.algorithms as algo

import signal
from subprocess import check_output
import os
IAName = "closest"

(mazeWidth, mazeHeight, mazeMap, preparationTime, turnTime, playerLocation, opponentLocation, coins, gameIsOver) = interface.initGame(IAName)
route = []
mazeMap[(-1,-1)] = ()
def next_way(playerLocation, coins):
    candidates = algo.dijkstra(mazeMap, playerLocation)
    dist = float("inf")
    coin = (-1,-1)
    for c in coins:
        if candidates[1][c] < dist:
            dist = candidates[1][c]
            coin = c
    coins.remove(coin)
    return u.way_width(candidates[0], playerLocation, coin)

def get_pid_en(name):
    return [int(f) for f in check_output(["pidof", name]).split() if int(f) != os.getpid()]



def initialisationTurn(mazeWidth, mazeHeight, mazeMap, timeAllowed, playerLocation, opponentLocation, coins) :
    global route

    pid = get_pid_en("python3")
    interface.debug(pid)
    for p in pid:
        try:
            os.kill(int(p), signal.SIGTSTP)
        except:
            pass

    route = next_way(playerLocation, coins)


def determineNextMove(playerLocation, opponentLocation, coins):
    global route
    if len(route) == 0:
        route = next_way(playerLocation, coins)
    else: 
        ennemy_dists = algo.dijkstra(mazeMap, opponentLocation)
        if ennemy_dists[1][route[-1]] < len(route):
            route = next_way(playerLocation, coins)
    next_pos = route.pop(0)
    return u.direction(playerLocation, next_pos)

# Init our AI
initialisationTurn(mazeWidth, mazeHeight, mazeMap, preparationTime, playerLocation, opponentLocation, coins)

# Starts the game
interface.startGameMainLoop(determineNextMove)
{'fraction_non_alphanumeric': 0.1119608442948914, 'fraction_numerical': 0.008259406546344448, 'mean_word_length': 3.8088235294117645, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3191545', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1011, 'n_words': 253}