# Programming challenge: write GOlang object code that respects Go guidelines

Learning GO and I wrote this for a programming challenge. It's working (building and running) but I think the code is not what the GO code should be:

• I'm using the `structure` element correctly? especially the methods of structure?
• at `PlayTurn ()` Method, I reassign the results (otherwise they are not taken into account) because the scope. How to write it better? Pointer?
• I'm struggling with `In t`, `float64` And throwing all the time. What is the good practice in this context where I need to float for an intermediate precision but the inputs and outputs are int?

complete script:

``````main package

to import
fmt
"math"
"you"
"strconv"
)

// Pod is life
write Pod struct {
position point
vx, vy, angle, nextCpID int
hasShieldOn bool
}

func squaredDist (a, b Dot) int {
return (a.x-b.x) * (a.x-b.x) + (a.y-b.y) * (a.y-b.y)
}
func distance (a, b point) float64 {
return math.Sqrt (float64 (squaredDist (a, b)))
}

func (pod Pod) getAngle (p Dot) float64 {
d: = distance (p, pod.position)
dx: = float64 (p.x-pod.position.x) / d
dy: = float64 (p.y-pod.position.y) / d
a: = math.Acos (dx) * 180.0 / math.Pi

// If the point I want is below me, I have to change the angle to make it right
yes dy <0 {
a = 360.0 - a
}
return a
}

func (pod Pod) diffAngle (p Dot) float64 {
a: = pod.getAngle (p)
pangle: = float64 (pod.angle)

right: = 0.0
yes pangle <= a {
right = a - pangle
} else {
right = 360.0 - pangle + a
}

left := 0.0
if pangle >= a {
left = pangle - a
} else {
left = pangle + 360.0 - a
}

Yeah that's right < left {
return right
}
return -left
}

func (pod Pod) rotate(p Dot) int {
a := pod.diffAngle(p)

// Can't turn more than 18° in one turn !
if a > 18.0 {
a = 18.0
} more if a < -18.0 {
a = -18.0
}

pod.angle += int(math.Round(a))

if pod.angle >= 360.0 {
pod.angle = pod.angle - 360.0
} else if pod.angle <0.0 {
pod.angle + = 360.0
}
back pod.angle
}

func (pod Pod) boost (t int) (int, int) {
yes pod.hasShieldOn {
back pod.vx, pod.vy
}
pangle: = float64 (pod.angle)
pod.vx + = int (math.Round (math.Cos (pangle) * float64 (t)))
pod.vy + = int (math.Round (math.Sin (pangle) * float64 (t)))
back pod.vx, pod.vy
}

// T shoud will become a float later
func (pod Pod) move (t int) (int, int) {
pod.position.x + = pod.vx * t
pod.position.y + = pod.vy * t
return pod.position.x, pod.position.y
}

func (pod Pod) endTurn () (int, int) {
// round the position if necessary
pod.vx = int (float64 (pod.vx) * 0.85)
pod.vy = int (float64 (pod.vy) * 0.85)
back pod.vx, pod.vy
}

func (pod Pod) playTurn (p point, int t) {
pod.angle = pod.rotate (p)
pod.vx, pod.vy = pod.boost (t)
pod.position.x, pod.position.y = pod.move (1)
pod.vx, pod.vy = pod.endTurn ()
fmt.Fprintf (os.Stderr, " nPedition of Predicated Power:")
fmt.Fprintf (os.Stderr, " n (% d,% d) speed (% d,% d)", pod.position.x, pod.position.y, pod.vx, pod.vy)
}

// Dot is the king
write Dot struct {
x, and int
}

func main () {
var laps int
fmt.Scan (and turns)

var checkpointCount int
fmt.Scan (& checkpointCount)
var checkPoints []Point
for i: = 0; i <checkpointCount; i ++ {
var checkpointX, checkpointY int
fmt.Scan (& checkpointX, & checkpointY)
checkPoints = append (checkPoints, point {checkpointX, checkpointY})
}
var myPods Sheath
var susPods Sheath
for {
for i: = 0; i <2; i ++ {
// x: x position of your pod
// y and position of your pod
// vx: x speed of your pod
// vy: and speed of your pod
// angle: angle of your pod
// nextCheckPointId: next control point ID of your pod
var x, y, vx, vy, angle, nextCheckPointID int
fmt.Scan (& x, & y, & vx, & vy, & angle, & nextCheckPointID)
mypods[i] = Pod {Dot {x, y}, vx, vy, angle, nextCheckPointID, false}
fmt.Fprintf (os.Stderr, " nActual Pod position:")
fmt.Fprintf (os.Stderr, " n (% d,% d) speed (% d,% d)", myPods[i].position.x, myPods[i].position.y, myPods[i].vx, myPods[i].vy)
}
for i: = 0; i <2; i ++ {
// x2: position x of the opponent's pod
// y2: position and of the opponent's pod
// vx2: x speed of the opponent's pod
// vy2: and speed of the opponent's pod
// angle2: angle of the opponent's pod
// nextCheckPointId2: next control point id of the opponent's pod
var x2, y2, vx2, vy2, angle2, nextCheckPointID2 int
fmt.Scan (& x2, & y2, & vx2, & vy2, & angle2, & nextCheckPointID2)
susPods[i] = Pod {Dot {x2, y2}, vx2, vy2, angle2, nextCheckPointID2, false}
}

// fmt.Fprintln (os.Stderr, "Debug messages ...")
for _, pod: = myPods range {
nx: = checkPoints[pod.nextCpID].x - 3 * pod.vx
ny: = checkPoints[pod.nextCpID].y - 3 * pod.vy
// Predicting where my pods will be next turn:
pod.playTurn (Point {nx, ny}, 100)
//
fmt.Println (strconv.Itoa (nx) + "" + strconv.Itoa (ny) + "100")
}
}
}
``````