示例#1
0
// boardFromWireWithInitial converts the wire representation to the board
func boardFromWireWithInitial(wire botapi.InitialBoard) (*Board, error) {
	wb, err := wire.Board()
	if err != nil {
		return new(Board), err
	}

	w, h := int(wb.Width()), int(wb.Height())
	b := EmptyBoard(BoardConfig{
		Size: Loc{X: w, Y: h},
	})
	b.Round = int(wb.Round())

	bots, err := wb.Robots()
	if err != nil {
		return b, err
	}

	for i := 0; i < bots.Len(); i++ {
		bot := bots.At(i)
		loc := Loc{
			X: int(bot.X()),
			Y: int(bot.Y()),
		}
		b.Locs[loc] = robotFromWire(bot)
	}

	cells, err := wire.Cells()
	if err != nil {
		return b, err
	}

	for i := 0; i < cells.Len(); i++ {
		cell := cells.At(i)
		x, y := i%w, i/w
		b.Cells[x][y] = cellFromWire[cell]
	}

	return b, nil
}
示例#2
0
文件: engine.go 项目: bcspragu/Gobots
// ToWireWithInitial converts the board to the wire representation with respect
// to the given faction (since the wire factions are us vs. them), including
// information about which cells are which type.
func (b *Board) ToWireWithInitial(out botapi.InitialBoard, faction int) error {
	wireBoard, err := out.NewBoard()
	b.ToWire(wireBoard, faction)

	cells, err := botapi.NewCellType_List(out.Segment(), int32(b.Size.X*b.Size.Y))
	if err != nil {
		return err
	}

	if err = out.SetCells(cells); err != nil {
		return err
	}

	for x, col := range b.Cells {
		for y, cell := range col {
			cells.Set(x+y*b.Size.X, cellToWire[cell])
		}
	}
	return nil
}