Beispiel #1
0
func main() {
	flag.Parse()
	players := make([]barbu.Player, 4)
	for i := range players {
		var err error
		players[i], err = barbu.MakeAiPlayer(fmt.Sprintf("%d.out", i), *player_names[i])
		if err != nil {
			fmt.Printf("Unable to make player '%s': %v\n", *player_names[i], err)
			return
		}
	}
	barbu.RunGames(players, *seed, *game, *num_games, *all_perms)
}
Beispiel #2
0
func connectAsHost(addr string, port int, name, game string) {
	raddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", addr, port))
	if err != nil {
		fmt.Printf("Unable to resolve server address: %v\n", err)
		return
	}

	conn, err := net.DialTCP("tcp", nil, raddr)
	if err != nil {
		fmt.Printf("Unable to connect to server: %v\n", err)
		return
	}
	fmt.Printf("A\n")
	name_line := make([]byte, 32)
	for i := range name_line {
		name_line[i] = ' '
	}
	copy(name_line, name)
	fmt.Printf("Sending '%s': %d\n", name_line, len(name_line))
	_, err = conn.Write(name_line)
	if err != nil {
		fmt.Printf("Failed to host game: %v\n", err)
		return
	}
	fmt.Printf("B\n")
	players, closer := makePlayers(conn)
	err = barbu.RunGames(players, 0, game, 1, false)
	closer.Close()
	if err != nil {
		fmt.Printf("Error running games: %v\n", err)
		return
	}
	fmt.Printf("D\n")
	// players[0].Stdin().Write([]byte("RAWR!!!"))
	fmt.Printf("E\n")
	return
}