<commit_before>package main

import "time"

func (game *GameInfo) runEngine() {
	for i := range game.Teams {
		go handleTeam(&game.Teams[i])
	}
}

func handleTeam(team *Team) {
	for team.Life > 0 {
		time.Sleep(1 * time.Second)

		if team.Energy <= 0 {
			team.Shield = false
		}

		if team.Shield {
			team.Energy--
			continue
		}

		team.Life--
	}
}<commit_msg>handle goroutines exit conditions<commit_after>package main

import (
	"log"
	"sync"
	"time"
)

func (game *GameInfo) runEngine(wg *sync.WaitGroup) {
	wg.Add(len(game.Teams))
	for i := range game.Teams {
		go game.handleTeam(&game.Teams[i], wg)
	}
}

func (game *GameInfo) handleTeam(team *Team, wg *sync.WaitGroup) {
	for team.Life > 0 && game.Running {
		time.Sleep(1 * time.Second)

		if team.Energy <= 0 {
			team.Shield = false
		}

		if team.Shield {
			team.Energy--
			continue
		}

		team.Life--
	}
	log.Println("Exiting team", team.Name)
	wg.Done()
}
{'fraction_non_alphanumeric': 0.1525974025974026, 'fraction_numerical': 0.006493506493506494, 'mean_word_length': 3.0929203539823007, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2243842', 'n_tokens_mistral': 413, 'n_tokens_neox': 365, 'n_words': 81}