function BotLogic(_par, made_moves, ships, mines, chests, bomb_num, dinamite_num, rocks, _data, torpedo_num)
{
	var th = this
//--------------------------------//
	var dim
	// made_moves.push({i: 2, j:2})
	for(var a=0; a<rocks.length; a++){
		var ta = rocks[a].getTakes()
		for(var b=0; b< ta.length; b++)
			if(searchObjectWithPar(made_moves, [["i", ta[b].i], ["j", ta[b].j]]) == -1)
				made_moves.push(ta[b])
	}

	// console.log(made_moves)


	this.getTargets = function(){

		console.log("Money", _data.num_bot_money)
  console.log("Torpedo", _data.torpedo_num_bot)
  console.log("Bomb", _data.multibomb_num_bot)
  console.log("Dynamite", _data.dinamite_num_bot)
		dim = _par.getDimension()
		// console.log(made_moves.length)
		var array = new Array()
		var targ = calculateMove()
		array.push(targ)
		for(var a=0; a<targ.length; a++)
			made_moves.push(targ[a])
		var bon = useBonus()
		if(bon){
			array.push(bon)
			for(var a=0; a<bon.length; a++)
				made_moves.push(bon[a])
		}

		
		return array
		// return [[{i:0, j:0}, {i:0, j:1}, {i:1, j:0}, {i:1, j:1}]]
	}

	this.getNumBomb = function(){
		return bomb_num
	}

	this.getNumDinamit = function(){
		return dinamite_num
	}

	this.getNumTorpedo = function(){
		return torpedo_num
	}
// PRIVATE//
	function calculateMove(){
		var req
		for(var a=0; a<made_moves.length; a++){
			var sh = searchShip(made_moves[a].i, made_moves[a].j)
			if(sh && !checkFullHit(sh))
				req = searchCellAroundHit(made_moves[a].i, made_moves[a].j)
			if(req)
				break
		}
		if(!req || searchObjectWithPar(made_moves, [["i", req.i], ["j", req.j]]))
			req = searchRandomCell()
		var ar = new Array()
		ar.push(req)
		return ar
	}

	function useBonus(){
		if(torpedo_num > 0)
			// if(Math.random() < .7)
			{
				if(_data.torpedo_num_bot<=0)
					return
				torpedo_num --
				_data.torpedo_num_bot --
				return useTorpedo()
			}

		if(_data.dinamite_num_bot > 0)
			// if(Math.random() < .7)
			{
				if(_data.dinamite_num_bot<=0)
					return
				bomb_num --
				_data.dinamite_num_bot --
				return useBomb()
			}
		
		if(_data.multibomb_num_bot > 0)
			// if(Math.random() < .7)
			{
				if(_data.multibomb_num_bot<=0)
					return
				dinamite_num --
				_data.multibomb_num_bot --
				return useDinamite()
			}
		
	}

	function useDinamite(){
		var targ = calculateMove()[0]
		var ret = new Array()
		if(Math.round(Math.random()) == 1){
			var num_call = 0
			while((targ.i >=dim-3 || searchOn(targ.i, targ.j) || searchOn(targ.i + 1, targ.j) || searchOn(targ.i + 2, targ.j))){
				num_call++	
				targ = searchRandomCell()
				if(num_call >100)
					return
			}
			ret.push(targ)
			ret.push({i: targ.i + 1, j: targ.j})
			ret.push({i: targ.i + 2, j: targ.j})
		}else{
			var num_call = 0
			while((targ.j >=dim-3 || searchOn(targ.i, targ.j) || searchOn(targ.i, targ.j + 1) || searchOn(targ.i, targ.j + 2))){
				num_call++		
				targ = searchRandomCell()
				if(num_call >100)
					return
			}
			ret.push(targ)
			ret.push({i: targ.i, j: targ.j + 1})
			ret.push({i: targ.i, j: targ.j + 2})
		}
		return ret
	}

	function useBomb(){
		var targ = calculateMove()[0]

		var num_call = 0
		while((targ.i >=dim-2 || targ.j >=dim-2 || searchOn(targ.i, targ.j) || searchOn(targ.i, targ.j + 1) || searchOn(targ.i + 1, targ.j) || searchOn(targ.i + 1, targ.j + 1))){
			num_call++
			targ = searchRandomCell()
			if(num_call >100)
				return
		}
		// console.log(targ)
		var ret = new Array()
		ret.push(targ)
		ret.push({i: targ.i, j: targ.j + 1})
		ret.push({i: targ.i + 1, j: targ.j})
		ret.push({i: targ.i + 1, j: targ.j + 1})
		return ret
	}

	function useTorpedo(){
		var targ = calculateMove()[0]

		var num_call = 0
		while((targ.i >=dim-2 || targ.j >=dim-2
			|| targ.i <1 || targ.j <1
			 || searchOn(targ.i, targ.j) || searchOn(targ.i - 1, targ.j) || searchOn(targ.i + 1, targ.j) || searchOn(targ.i, targ.j - 1) || searchOn(targ.i, targ.j + 1))){
			num_call++
			targ = searchRandomCell()
			if(num_call >100)
				return
		}
		// console.log(targ)
		var ret = new Array()
		ret.push(targ)
		ret.push({i: targ.i - 1, j: targ.j})
		ret.push({i: targ.i + 1, j: targ.j})
		ret.push({i: targ.i, j: targ.j - 1})
		ret.push({i: targ.i, j: targ.j + 1})
		return ret
	}

	// Поиск корабля в ячейке
	function searchShip(i, j){
		for(var a=0; a< ships.length; a++){
			var mas = ships[a].getTakes()
			for(var b=0; b<mas.length; b++)
				if(mas[b].i == i && mas[b].j == j)
					return ships[a]

		}
	}
	// Подбит корабль полностью или нет
	function checkFullHit(ship){
		if(ship.getTakes().length == ship.getHits().length)
			true
	}
	// Поиск ячейки вокруг повреждения
	function searchCellAroundHit(i, j){
		var search_mas = buildMasIndex(i-1, j-1, 3)
		for(var a=0; a<search_mas.length; a++)
			if(a%2 == 1 &&
				searchObjectWithPar(made_moves, [["i", search_mas[a][0]], ["j", search_mas[a][1]]] ) == -1 &&
				search_mas[a][0] >=0 && search_mas[a][0] <=(dim-1) &&
				search_mas[a][1] >=0 && search_mas[a][1] <=(dim-1)
				)
				return {i: search_mas[a][0], j: search_mas[a][1]}
	}
	// Поиск рандомной ячейки
	function searchRandomCell(){
		var rand_i = Math.round(Math.random() * (dim-1))
		var rand_j = Math.round(Math.random() * (dim-1))
		while(searchObjectWithPar(made_moves, [["i", rand_i], ["j", rand_j]]) != -1){
			rand_i = Math.round(Math.random() * (dim-1))
			rand_j = Math.round(Math.random() * (dim-1))
		}

		return {i: rand_i, j: rand_j}
	}

	function searchOn(i, j){
		var ar = new Array()
		// ar = ar.concat(_data.rocks)
		ar = ar.concat(made_moves)
		for(var a=0; a<ar.length; a++){
			// var g = ar[a].getTakes()
			// for(var b = 0; b<g.length; b++)
				if(ar[a].i == i && ar[a].j == j)
					return true
		}
	}
}