Ejemplo n.º 1
0
// Return index k of insertion point for the given player, given
// players sorted by Id.  The player currently at k-1 is on the 'left'
// of the argument, while the player at k is on the 'right'.  To
// insert, right-shift elements at k and above.
func (nm *V23Manager) findInsertion(p *model.Player) int {
	for k, member := range nm.players {
		if p.Id() < member.p.Id() {
			return k
		}
	}
	return len(nm.players)
}
Ejemplo n.º 2
0
func (nm *V23Manager) recognizeOther(p *model.Player) {
	if nm.chatty {
		log.Printf("I (%v) am recognizing %v.", nm.Me(), p)
	}
	vp := &vPlayer{p, ifc.GameServiceClient(nm.serverName(p.Id()))}

	// Keep the player list sorted.
	k := nm.findInsertion(p)
	nm.players = append(nm.players, nil)
	copy(nm.players[k+1:], nm.players[k:])
	nm.players[k] = vp

	if nm.chatty {
		log.Printf("I (%v) recognize %v.", nm.Me(), p)
	}
	if nm.isRunning {
		nm.checkDoors()
	} else {
		if nm.chatty {
			log.Printf("Not running, so not checking doors post recog.")
		}
	}
}
Ejemplo n.º 3
0
func (nm *V23Manager) findPlayerIndex(p *model.Player) int {
	return findIndex(len(nm.players),
		func(i int) bool { return nm.players[i].p.Id() == p.Id() })
}