Ejemplo n.º 1
0
func boards(replay botapi.Replay) ([]*Board, error) {
	var cells [][]CellType
	w, err := replay.Initial()
	if err != nil {
		return nil, err
	}
	ib, err := boardFromWireWithInitial(w)
	if err != nil {
		return nil, err
	}
	cells = ib.Cells

	// After 0
	rs, err := replay.Rounds()
	if err != nil {
		return nil, err
	}

	bs := make([]*Board, rs.Len()+1)
	bs[0] = ib
	for i := 0; i < rs.Len(); i++ {
		w, err := rs.At(i).EndBoard()
		if err != nil {
			return nil, err
		}
		b, err := boardFromWire(w)
		if err != nil {
			return nil, err
		}
		b.Cells = cells
		bs[i+1] = b
	}
	return bs, nil
}
Ejemplo n.º 2
0
func addReplayRound(orig botapi.Replay, round botapi.Replay_Round) (*capnp.Message, error) {
	newMsg, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		return nil, err
	}
	newReplay, err := botapi.NewRootReplay(seg)
	if err != nil {
		return nil, err
	}
	gid, err := orig.GameId()
	if err != nil {
		return nil, err
	}
	if err := newReplay.SetGameId(gid); err != nil {
		return nil, err
	}
	initBoard, err := orig.Initial()
	if err != nil {
		return nil, err
	}
	if err := newReplay.SetInitial(initBoard); err != nil {
		return nil, err
	}
	origRounds, err := orig.Rounds()
	if err != nil {
		return nil, err
	}
	rounds, _ := botapi.NewReplay_Round_List(seg, int32(origRounds.Len())+1)
	for i := 0; i < origRounds.Len(); i++ {
		if err := rounds.Set(i, origRounds.At(i)); err != nil {
			return nil, err
		}
	}
	if err := rounds.Set(rounds.Len()-1, round); err != nil {
		return nil, err
	}
	newReplay.SetRounds(rounds)
	return newMsg, nil
}