//NearestObstacle() returns a integer corresponding to the stick that is nearest to the ball at that moment.
NearestObstacle() returns a integer corresponding to the stick that is nearest to the ball at that moment.
// NearestObstacle () returns a integer corresponding to the stick that is nearest to the ball at that moment .
func (ball *ball) NearestObstacle(c1 chan int) {
	distance := [8]int32{61, 136, 211, 286, 361, 436, 511, 586}
	i := sort.Search(len(distance), func(i int) bool { return distance[i] >= int32(ball.X) })
	if i < len(distance) && distance[i] == int32(ball.X) {
		c1 <- i
	} else if i == 0 {
		c1 <- i
	} else if i == 8 {
		c1 <- i - 1
	} else {
		if math.Abs(float64(distance[i]-int32(ball.X))) < math.Abs(float64(distance[i-1]-int32(ball.X))) {
			c1 <- i
		} else {
			c1 <- i - 1
		}
	}
}
func ( ball * ball ) NearestObstacle ( c1 chan int ) { distance := [ 8 ] int32 { 61 , 136 , 211 , 286 , 361 , 436 , 511 , 586 } i := sort . Search ( len ( distance ) , func ( i int ) bool { return distance [ i ] >= int32 ( ball . X ) } ) if i < len ( distance ) && distance [ i ] == int32 ( ball . X ) { c1 <- i } else if i == 0 { c1 <- i } else if i == 8 { c1 <- i - 1 } else { if math . Abs ( float64 ( distance [ i ] - int32 ( ball . X ) ) ) < math . Abs ( float64 ( distance [ i - 1 ] - int32 ( ball . X ) ) ) { c1 <- i } else { c1 <- i - 1 } } }
NearestObstacle() returns a integer corresponding to the stick that is nearest to the ball at that moment.
NearestObstacle () returns a integer corresponding to the stick that is nearest to the ball at that moment .