Ejemplo n.º 1
0
func (t Turn) toWire(id uint32, wire botapi.Turn) {
	wire.SetId(id)
	switch t.Kind {
	case Wait:
		wire.SetWait()
	case Move:
		wire.SetMove(t.Direction.toWire())
	case Attack:
		wire.SetAttack(t.Direction.toWire())
	case SelfDestruct:
		wire.SetSelfDestruct()
	}
}
Ejemplo n.º 2
0
func (b *Board) nextLoc(id RobotID, t botapi.Turn) Loc {
	currentLoc := b.robotLoc(id)
	// If they aren't moving, return their current loc
	if t.Which() != botapi.Turn_Which_move {
		return currentLoc
	}

	// They're moving, return where they're going

	xOff, yOff := directionOffsets(t.Move())
	nextLoc := Loc{
		X: currentLoc.X + xOff,
		Y: currentLoc.Y + yOff,
	}

	if b.isValidLoc(nextLoc) {
		return nextLoc
	}

	// TODO: Penalize people for creating incompetent bots that like travelling
	// to invalid locations, which is the case if we've reached here.
	return currentLoc
}