<commit_before>package battle

import (
	"time"

	"github.com/finalist736/seabotserver"
	"github.com/finalist736/seabotserver/logs"
)

func (s *Battle) Handle(bot *seabotserver.TcpBot, turn *seabotserver.FBTurn) {
	s.BattleChannel <- &BattleChannelData{bot, turn, false}
}

func (s *Battle) Exit(bot *seabotserver.TcpBot) {
	s.BattleChannel <- &BattleChannelData{bot, nil, true}
}

func (s *Battle) Listener() {
	var data *BattleChannelData
	timer := time.Tick(time.Second * 10)
	tb := seabotserver.ToBot{}
	tb.Turn = &seabotserver.TBTurn{}

	tbNextTurn := seabotserver.ToBot{}
	tbNextTurn.Turn = &seabotserver.TBTurn{}

	tbOppTurn := seabotserver.ToBot{}
	tbOppTurn.Turn = &seabotserver.TBTurn{}
	tbOppTurn.Turn.Opponent = &seabotserver.TBOpponentTurn{}

	var opponent *seabotserver.TcpBot
	for {
		select {
		case data = <-s.BattleChannel:

			switch data.Exit {
			case true:
				// need to close this battle!
				errMsg := &seabotserver.ToBot{
					Error: &seabotserver.TBError{Error: "player disconnected"}}
				if s.Bot1.ID == data.Bot.ID {
					s.Bot2.Send(errMsg)
					s.Bot2.Done <- true
				} else {
					s.Bot1.Send(errMsg)
					s.Bot1.Done <- true
				}
				return

			case false:
				//fmt.Printf("some data from bot: %d\n\t%+v\n", data.Bot.ID, data.Turn)
				if data.Turn == nil || data.Bot == nil {
					continue
				}

				if s.CurrentTurnID != data.Bot.ID {
					data.Bot.Send(&seabotserver.ToBot{Error: &seabotserver.TBError{Error: "incorrect turn"}})
					continue
				}

				if data.Turn.Shot[0] < 0 || data.Turn.Shot[0] > 9 ||
					data.Turn.Shot[1] < 0 || data.Turn.Shot[1] > 9 {
					data.Bot.Send(&seabotserver.ToBot{Error: &seabotserver.TBError{Error: "incorrect point"}})
					continue
				}
				var field *int
				var opppole *[10][10]int<commit_msg>verbose error 'incorrect turn'<commit_after>package battle

import (
	"fmt"
	"time"

	"github.com/finalist736/seabotserver"
	"github.com/finalist736/seabotserver/logs"
)

func (s *Battle) Handle(bot *seabotserver.TcpBot, turn *seabotserver.FBTurn) {
	s.BattleChannel <- &BattleChannelData{bot, turn, false}
}

func (s *Battle) Exit(bot *seabotserver.TcpBot) {
	s.BattleChannel <- &BattleChannelData{bot, nil, true}
}

func (s *Battle) Listener() {
	var data *BattleChannelData
	timer := time.Tick(time.Second * 10)
	tb := seabotserver.ToBot{}
	tb.Turn = &seabotserver.TBTurn{}

	tbNextTurn := seabotserver.ToBot{}
	tbNextTurn.Turn = &seabotserver.TBTurn{}

	tbOppTurn := seabotserver.ToBot{}
	tbOppTurn.Turn = &seabotserver.TBTurn{}
	tbOppTurn.Turn.Opponent = &seabotserver.TBOpponentTurn{}

	var opponent *seabotserver.TcpBot
	for {
		select {
		case data = <-s.BattleChannel:

			switch data.Exit {
			case true:
				// need to close this battle!
				errMsg := &seabotserver.ToBot{
					Error: &seabotserver.TBError{Error: "player disconnected"}}
				if s.Bot1.ID == data.Bot.ID {
					s.Bot2.Send(errMsg)
					s.Bot2.Done <- true
				} else {
					s.Bot1.Send(errMsg)
					s.Bot1.Done <- true
				}
				return

			case false:
				//fmt.Printf("some data from bot: %d\n\t%+v\n", data.Bot.ID, data.Turn)
				if data.Turn == nil || data.Bot == nil {
					continue
				}

				if s.CurrentTurnID != data.Bot.ID {
					data.Bot.Send(
						&seabotserver.ToBot{
							Error: &seabotserver.TBError{
								Error: fmt.Sprintf("not your turn! now turn bot id: %d. but your bot id: %d",
									s.CurrentTurnID, data.Bot.ID)}})
					continue
				}

				if data.Turn.Shot[0] < 0 || data.Turn.Shot[0] > 9 ||
					data.Turn.Shot[1] < 0 || data.Turn.Shot[1] > 9 {
					data.Bot.Send(
						&seabotserver.ToBot{
							Error: &seabotserver.TBError{
								Error: "incorrect point"}})
					continue
				}
				var field *int
				var opppole *[10][10]int
{'fraction_non_alphanumeric': 0.14842699650443666, 'fraction_numerical': 0.013444474321054048, 'mean_word_length': 3.128745837957825, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 7, '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': '3694459', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1454, 'n_words': 276}