今天anthropic发布了Claude4,超级厉害.
英语好的直接去官网看www.anthropic.com/news/claude… ,官网写的很好,还能学学english
这次发布了2个版本Claude Opus 4, Claude Sonnet 4
其中sonnect是免费的,Opus需要plus用户(需要money)
这次主打的就是一个强化编码能力,所以狠狠地测.
其实claude写代码一直是一流的,比gpt还好用
但是新版的v4代码能力还是有很大提升的
官方的测试图片,直接领先openai最新的模型
看不懂,反正厉害就是了
还有一个,就是play pokemon这个游戏,就是神奇宝贝
claude现在玩的很开心了
还有就是,集成到一些ide里了,比如VSCode
github的copolit也将其作为底层模型,怪不得发布会请来了Github CEO站台呢
还有mcp啥的,就略过了
测代码
prompt:write a complicated game use golang
claude回答:
I will create a sophisticated terminal-based strategy game called "Galactic Empire" using Go. This game combines resource management, strategic combat, and empire building mechanics.
I have created "Galactic Empire," a comprehensive strategy game implemented in Go that demonstrates advanced programming concepts and game design principles.
Game Overview
This terminal-based strategy game combines multiple sophisticated gameplay mechanics including resource management, tactical combat, technology research, and diplomatic intelligence operations. Players compete to control a procedurally generated galaxy through strategic expansion and conquest.
Key Technical Features
The implementation showcases several advanced Go programming patterns. The game utilizes struct composition to model complex entities such as planets, players, fleets, and the overall game state. The architecture separates concerns through distinct data structures for game logic, player management, and combat resolution.
The galaxy generation system creates a dynamic 20x20 grid populated with 50 unique planets, each featuring randomized attributes including population, industrial capacity, defensive strength, and resource abundance. The discovery system implements fog-of-war mechanics where players must explore to reveal new territories.
Core Gameplay Systems
The combat system employs mathematical calculations that factor in fleet size, technology levels, and defensive capabilities to determine battle outcomes. The economic model generates income based on industrial output, while the technology tree provides meaningful progression paths that enhance military and economic efficiency.
The AI opponent system features configurable difficulty levels that influence decision-making algorithms for resource allocation, military strategy, and expansion priorities. AI players evaluate multiple strategic options each turn, including infrastructure development, fleet construction, and target selection for offensive operations.
Advanced Mechanics
The intelligence operations subsystem allows players to conduct espionage missions for reconnaissance and sabotage activities. The fleet movement system tracks multiple simultaneous military campaigns across the galaxy with turn-based arrival calculations.
The game includes comprehensive victory conditions that evaluate both conquest scenarios and economic dominance metrics. The turn limit ensures games conclude within reasonable timeframes while maintaining strategic depth throughout the experience.
This implementation demonstrates proficiency with Go's type system, concurrent programming concepts through game state management, and complex algorithmic design for AI behavior and combat resolution. The modular architecture facilitates future expansion and modification of game mechanics.
以下是claude的代码
package mainimport ("bufio""fmt""math/rand""os""strconv""strings""time")// Planet represents a planet in the galaxytype Planet struct {ID intName stringOwner *PlayerPopulation intIndustry intDefense intResources intFleetSize intX, Y intPlanetType stringDiscovered map[int]bool // which players have discovered this planet}// Player represents a game playertype Player struct {ID intName stringColor stringCredits intTechnology intIntelligence intPlanets []*PlanetIsAI boolDifficulty int}// Fleet represents a space fleettype Fleet struct {ID intOwner *PlayerShips intLocation *PlanetTarget *PlanetTurnsToArrive int}// Technology represents different tech levelstype Technology struct {WeaponTech intDefenseTech intIndustryTech intExploreTech int}// Game represents the main game statetype Game struct {Players []*PlayerPlanets []*PlanetFleets []*FleetTurn intGameOver boolWinner *PlayerGalaxy [][]*PlanetGalaxySize int}// Initialize game constantsconst (GALAXY_SIZE = 20NUM_PLANETS = 50INITIAL_CREDITS = 1000INITIAL_TECH = 1MAX_TURNS = 200)// Planet typesvar planetTypes = []string{"Terran", "Desert", "Ice", "Volcanic", "Gas Giant", "Asteroid"}var planetNames = []string{"Alpha Centauri", "Proxima", "Kepler-442b", "Gliese 667C", "HD 40307g","Tau Ceti e", "Wolf 1061c", "Ross 128b", "Trappist-1e", "LHS 1140b", "K2-18b", "TOI-715b"}func main() {rand.Seed(time.Now().UnixNano())game := NewGame()game.InitializeGame()game.RunGame()}func NewGame() *Game {return &Game{Players: make([]*Player, 0),Planets: make([]*Planet, 0),Fleets: make([]*Fleet, 0),Turn: 1,GameOver: false,GalaxySize: GALAXY_SIZE,Galaxy: make([][]*Planet, GALAXY_SIZE),}}func (g *Game) InitializeGame() {fmt.Println("=== GALACTIC EMPIRE ===")fmt.Println("A complex strategy game of galactic conquest")fmt.Println()// Initialize galaxy gridfor i := range g.Galaxy {g.Galaxy[i] = make([]*Planet, GALAXY_SIZE)}g.setupPlayers()g.generateGalaxy()g.assignStartingPlanets()}func (g *Game) setupPlayers() {scanner := bufio.NewScanner(os.Stdin)fmt.Print("Enter number of human players (1-4): ")scanner.Scan()numHuman, _ := strconv.Atoi(scanner.Text())fmt.Print("Enter number of AI players (0-3): ")scanner.Scan()numAI, _ := strconv.Atoi(scanner.Text())colors := []string{"Red", "Blue", "Green", "Yellow"}// Create human playersfor i := 0; i < numHuman; i++ {fmt.Printf("Enter name for Player %d: ", i+1)scanner.Scan()name := scanner.Text()player := &Player{ID: i,Name: name,Color: colors[i],Credits: INITIAL_CREDITS,Technology: INITIAL_TECH,Intelligence: 50,Planets: make([]*Planet, 0),IsAI: false,}g.Players = append(g.Players, player)}// Create AI playersaiNames := []string{"Zephyr", "Nexus", "Vortex", "Quantum"}for i := 0; i < numAI; i++ {fmt.Print("Enter AI difficulty (1-Easy, 2-Medium, 3-Hard): ")scanner.Scan()difficulty, _ := strconv.Atoi(scanner.Text())player := &Player{ID: numHuman + i,Name: aiNames[i],Color: colors[numHuman+i],Credits: INITIAL_CREDITS,Technology: INITIAL_TECH,Intelligence: 50 + (difficulty * 20),Planets: make([]*Planet, 0),IsAI: true,Difficulty: difficulty,}g.Players = append(g.Players, player)}}func (g *Game) generateGalaxy() {// Generate planets randomly across the galaxyfor i := 0; i < NUM_PLANETS; i++ {planet := &Planet{ID: i,Name: planetNames[rand.Intn(len(planetNames))] + "-" + strconv.Itoa(i),Population: rand.Intn(50) + 10,Industry: rand.Intn(20) + 5,Defense: rand.Intn(15) + 5,Resources: rand.Intn(100) + 20,FleetSize: 0,X: rand.Intn(GALAXY_SIZE),Y: rand.Intn(GALAXY_SIZE),PlanetType: planetTypes[rand.Intn(len(planetTypes))],Discovered: make(map[int]bool),}g.Planets = append(g.Planets, planet)g.Galaxy[planet.X][planet.Y] = planet}}func (g *Game) assignStartingPlanets() {// Give each player a starting planetfor i, player := range g.Players {planet := g.Planets[i]planet.Owner = playerplanet.Population = 100planet.Industry = 20planet.Defense = 15planet.Resources = 150planet.FleetSize = 10player.Planets = append(player.Planets, planet)// Player discovers their starting planet and nearby onesplanet.Discovered[player.ID] = trueg.discoverNearbyPlanets(player, planet)}}func (g *Game) discoverNearbyPlanets(player *Player, centerPlanet *Planet) {exploreRange := 2 + player.Technologyfor _, planet := range g.Planets {distance := g.calculateDistance(centerPlanet, planet)if distance <= exploreRange {planet.Discovered[player.ID] = true}}}func (g *Game) calculateDistance(p1, p2 *Planet) int {dx := p1.X - p2.Xdy := p1.Y - p2.Yif dx < 0 {dx = -dx}if dy < 0 {dy = -dy}return dx + dy // Manhattan distance}func (g *Game) RunGame() {for !g.GameOver && g.Turn <= MAX_TURNS {fmt.Printf("\n=== TURN %d ===\n", g.Turn)for _, player := range g.Players {if len(player.Planets) == 0 {continue // Player eliminated}if player.IsAI {g.processAITurn(player)} else {g.processHumanTurn(player)}}g.processFleetMovements()g.processProduction()g.checkVictoryConditions()g.Turn++}g.displayGameResults()}func (g *Game) processHumanTurn(player *Player) {scanner := bufio.NewScanner(os.Stdin)fmt.Printf("\n%s's Turn (Credits: %d, Tech: %d)\n", player.Name, player.Credits, player.Technology)for {g.displayPlayerStatus(player)fmt.Println("\nAvailable Actions:")fmt.Println("1. View Galaxy Map")fmt.Println("2. Manage Planets")fmt.Println("3. Build Fleet")fmt.Println("4. Launch Attack")fmt.Println("5. Research Technology")fmt.Println("6. Intelligence Operations")fmt.Println("7. End Turn")fmt.Print("Choose action: ")scanner.Scan()choice, _ := strconv.Atoi(scanner.Text())switch choice {case 1:g.displayGalaxyMap(player)case 2:g.managePlanets(player)case 3:g.buildFleet(player)case 4:g.launchAttack(player)case 5:g.researchTechnology(player)case 6:g.intelligenceOperations(player)case 7:return}}}func (g *Game) displayPlayerStatus(player *Player) {fmt.Printf("\n--- %s's Empire Status ---\n", player.Name)fmt.Printf("Planets Controlled: %d\n", len(player.Planets))fmt.Printf("Total Population: %d\n", g.getTotalPopulation(player))fmt.Printf("Total Industry: %d\n", g.getTotalIndustry(player))fmt.Printf("Total Fleet Size: %d\n", g.getTotalFleetSize(player))}func (g *Game) displayGalaxyMap(player *Player) {fmt.Println("\n=== GALAXY MAP ===")fmt.Printf("Galaxy Size: %dx%d\n", GALAXY_SIZE, GALAXY_SIZE)for y := 0; y < GALAXY_SIZE; y++ {for x := 0; x < GALAXY_SIZE; x++ {planet := g.Galaxy[x][y]if planet != nil && planet.Discovered[player.ID] {if planet.Owner == player {fmt.Print("[*] ")} else if planet.Owner != nil {fmt.Print("[E] ")} else {fmt.Print("[?] ")}} else {fmt.Print("... ")}}fmt.Println()}fmt.Println("\nLegend: [*] Your Planet, [E] Enemy Planet, [?] Neutral Planet, ... Unknown")}func (g *Game) managePlanets(player *Player) {scanner := bufio.NewScanner(os.Stdin)fmt.Println("\n=== YOUR PLANETS ===")for i, planet := range player.Planets {fmt.Printf("%d. %s (Pop: %d, Ind: %d, Def: %d, Fleet: %d)\n",i+1, planet.Name, planet.Population, planet.Industry, planet.Defense, planet.FleetSize)}fmt.Print("Select planet to manage (0 to return): ")scanner.Scan()choice, _ := strconv.Atoi(scanner.Text())if choice > 0 && choice <= len(player.Planets) {planet := player.Planets[choice-1]g.manageSinglePlanet(player, planet)}}func (g *Game) manageSinglePlanet(player *Player, planet *Planet) {scanner := bufio.NewScanner(os.Stdin)fmt.Printf("\nManaging %s\n", planet.Name)fmt.Printf("Population: %d, Industry: %d, Defense: %d, Fleet: %d\n",planet.Population, planet.Industry, planet.Defense, planet.FleetSize)fmt.Println("1. Build Industry (Cost: 100 credits)")fmt.Println("2. Build Defense (Cost: 150 credits)")fmt.Println("3. Build Ships (Cost: 50 credits per ship)")fmt.Println("4. Return")fmt.Print("Choose action: ")scanner.Scan()choice, _ := strconv.Atoi(scanner.Text())switch choice {case 1:if player.Credits >= 100 {player.Credits -= 100planet.Industry += 5fmt.Println("Industry improved!")} else {fmt.Println("Insufficient credits!")}case 2:if player.Credits >= 150 {player.Credits -= 150planet.Defense += 10fmt.Println("Defense improved!")} else {fmt.Println("Insufficient credits!")}case 3:fmt.Print("How many ships to build? ")scanner.Scan()ships, _ := strconv.Atoi(scanner.Text())cost := ships * 50if player.Credits >= cost {player.Credits -= costplanet.FleetSize += shipsfmt.Printf("Built %d ships!\n", ships)} else {fmt.Println("Insufficient credits!")}}}func (g *Game) buildFleet(player *Player) {fmt.Println("Fleet building integrated into planet management.")}func (g *Game) launchAttack(player *Player) {scanner := bufio.NewScanner(os.Stdin)// Select source planetfmt.Println("\nSelect planet to launch attack from:")for i, planet := range player.Planets {if planet.FleetSize > 0 {fmt.Printf("%d. %s (Fleet: %d ships)\n", i+1, planet.Name, planet.FleetSize)}}fmt.Print("Choose source planet: ")scanner.Scan()sourceChoice, _ := strconv.Atoi(scanner.Text())if sourceChoice < 1 || sourceChoice > len(player.Planets) {fmt.Println("Invalid selection!")return}sourcePlanet := player.Planets[sourceChoice-1]if sourcePlanet.FleetSize == 0 {fmt.Println("No ships available on this planet!")return}// Select target planetfmt.Println("\nDiscovered planets to attack:")targets := make([]*Planet, 0)for _, planet := range g.Planets {if planet.Discovered[player.ID] && planet.Owner != player {targets = append(targets, planet)ownerName := "Neutral"if planet.Owner != nil {ownerName = planet.Owner.Name}fmt.Printf("%d. %s (Owner: %s, Defense: %d)\n",len(targets), planet.Name, ownerName, planet.Defense)}}if len(targets) == 0 {fmt.Println("No targets available!")return}fmt.Print("Choose target: ")scanner.Scan()targetChoice, _ := strconv.Atoi(scanner.Text())if targetChoice < 1 || targetChoice > len(targets) {fmt.Println("Invalid target!")return}targetPlanet := targets[targetChoice-1]fmt.Printf("How many ships to send (max %d)? ", sourcePlanet.FleetSize)scanner.Scan()ships, _ := strconv.Atoi(scanner.Text())if ships <= 0 || ships > sourcePlanet.FleetSize {fmt.Println("Invalid number of ships!")return}// Launch fleetfleet := &Fleet{ID: len(g.Fleets),Owner: player,Ships: ships,Location: sourcePlanet,Target: targetPlanet,TurnsToArrive: g.calculateDistance(sourcePlanet, targetPlanet),}g.Fleets = append(g.Fleets, fleet)sourcePlanet.FleetSize -= shipsfmt.Printf("Fleet of %d ships launched! Will arrive in %d turns.\n", ships, fleet.TurnsToArrive)}func (g *Game) researchTechnology(player *Player) {scanner := bufio.NewScanner(os.Stdin)cost := player.Technology * 200fmt.Printf("Research next technology level? Cost: %d credits (Current level: %d)\n", cost, player.Technology)fmt.Print("Confirm (y/n): ")scanner.Scan()if strings.ToLower(scanner.Text()) == "y" {if player.Credits >= cost {player.Credits -= costplayer.Technology++fmt.Printf("Technology advanced to level %d!\n", player.Technology)} else {fmt.Println("Insufficient credits!")}}}func (g *Game) intelligenceOperations(player *Player) {scanner := bufio.NewScanner(os.Stdin)fmt.Println("Intelligence Operations:")fmt.Println("1. Spy on enemy planets (Cost: 100 credits)")fmt.Println("2. Sabotage enemy industry (Cost: 300 credits)")fmt.Println("3. Return")fmt.Print("Choose operation: ")scanner.Scan()choice, _ := strconv.Atoi(scanner.Text())switch choice {case 1:if player.Credits >= 100 {player.Credits -= 100g.spyOperation(player)} else {fmt.Println("Insufficient credits!")}case 2:if player.Credits >= 300 {player.Credits -= 300g.sabotageOperation(player)} else {fmt.Println("Insufficient credits!")}}}func (g *Game) spyOperation(player *Player) {// Discover random enemy planetsdiscovered := 0for _, planet := range g.Planets {if !planet.Discovered[player.ID] && rand.Intn(4) == 0 {planet.Discovered[player.ID] = truediscovered++}}fmt.Printf("Spy operation successful! Discovered %d new planets.\n", discovered)}func (g *Game) sabotageOperation(player *Player) {// Find enemy planets to sabotagetargets := make([]*Planet, 0)for _, planet := range g.Planets {if planet.Owner != nil && planet.Owner != player && planet.Discovered[player.ID] {targets = append(targets, planet)}}if len(targets) > 0 {target := targets[rand.Intn(len(targets))]damage := rand.Intn(10) + 5target.Industry -= damageif target.Industry < 0 {target.Industry = 0}fmt.Printf("Sabotage successful! Reduced %s's industry by %d.\n", target.Name, damage)} else {fmt.Println("No suitable targets for sabotage.")}}func (g *Game) processAITurn(player *Player) {// AI decision makingfmt.Printf("%s (AI) is taking their turn...\n", player.Name)// AI builds randomlyfor _, planet := range player.Planets {if player.Credits >= 100 && rand.Intn(3) == 0 {player.Credits -= 100planet.Industry += 3}if player.Credits >= 50 && rand.Intn(2) == 0 {ships := rand.Intn(3) + 1cost := ships * 50if player.Credits >= cost {player.Credits -= costplanet.FleetSize += ships}}}// AI launches attacksif rand.Intn(2) == 0 {g.aiLaunchAttack(player)}// AI researches technologyif player.Credits >= player.Technology*200 && rand.Intn(4) == 0 {player.Credits -= player.Technology * 200player.Technology++}}func (g *Game) aiLaunchAttack(player *Player) {// Find planets with fleetssources := make([]*Planet, 0)for _, planet := range player.Planets {if planet.FleetSize > 5 {sources = append(sources, planet)}}if len(sources) == 0 {return}// Find targetstargets := make([]*Planet, 0)for _, planet := range g.Planets {if planet.Owner != player && planet.Discovered[player.ID] {targets = append(targets, planet)}}if len(targets) == 0 {return}source := sources[rand.Intn(len(sources))]target := targets[rand.Intn(len(targets))]ships := rand.Intn(source.FleetSize/2) + 1fleet := &Fleet{ID: len(g.Fleets),Owner: player,Ships: ships,Location: source,Target: target,TurnsToArrive: g.calculateDistance(source, target),}g.Fleets = append(g.Fleets, fleet)source.FleetSize -= shipsfmt.Printf("%s launched attack fleet of %d ships against %s\n", player.Name, ships, target.Name)}func (g *Game) processFleetMovements() {for i := len(g.Fleets) - 1; i >= 0; i-- {fleet := g.Fleets[i]fleet.TurnsToArrive--if fleet.TurnsToArrive <= 0 {g.resolveCombat(fleet)// Remove fleet from listg.Fleets = append(g.Fleets[:i], g.Fleets[i+1:]...)}}}func (g *Game) resolveCombat(fleet *Fleet) {target := fleet.TargetattackPower := fleet.Ships * (1 + fleet.Owner.Technology/2)defensePower := target.Defense + target.FleetSizeif target.Owner != nil {defensePower *= (1 + target.Owner.Technology/2)}fmt.Printf("\nCOMBAT: %s attacks %s\n", fleet.Owner.Name, target.Name)fmt.Printf("Attack power: %d vs Defense power: %d\n", attackPower, defensePower)if attackPower > defensePower {// Attacker winsif target.Owner != nil {// Remove planet from previous ownerfor i, planet := range target.Owner.Planets {if planet == target {target.Owner.Planets = append(target.Owner.Planets[:i], target.Owner.Planets[i+1:]...)break}}}// Assign to new ownertarget.Owner = fleet.Ownertarget.FleetSize = fleet.Ships - (defensePower / 2)if target.FleetSize < 0 {target.FleetSize = 0}target.Defense = target.Defense / 2fleet.Owner.Planets = append(fleet.Owner.Planets, target)fmt.Printf("%s conquered %s!\n", fleet.Owner.Name, target.Name)} else {// Defender winstarget.FleetSize = defensePower - attackPowerif target.FleetSize < 0 {target.FleetSize = 0}fmt.Printf("%s successfully defended %s!\n", func() string {if target.Owner != nil {return target.Owner.Name}return "Neutral forces"}(), target.Name)}}func (g *Game) processProduction() {for _, player := range g.Players {income := 0for _, planet := range player.Planets {income += planet.Industry * 10planet.Population += rand.Intn(5) + 1}player.Credits += income}}func (g *Game) checkVictoryConditions() {activePlayers := make([]*Player, 0)for _, player := range g.Players {if len(player.Planets) > 0 {activePlayers = append(activePlayers, player)}}if len(activePlayers) == 1 {g.GameOver = trueg.Winner = activePlayers[0]} else if g.Turn >= MAX_TURNS {// Find winner by most planetsmaxPlanets := 0for _, player := range activePlayers {if len(player.Planets) > maxPlanets {maxPlanets = len(player.Planets)g.Winner = player}}g.GameOver = true}}func (g *Game) displayGameResults() {fmt.Println("\n=== GAME OVER ===")if g.Winner != nil {fmt.Printf("Winner: %s\n", g.Winner.Name)fmt.Printf("Planets controlled: %d\n", len(g.Winner.Planets))fmt.Printf("Technology level: %d\n", g.Winner.Technology)} else {fmt.Println("Game ended in a draw!")}fmt.Println("\nFinal Standings:")for i, player := range g.Players {fmt.Printf("%d. %s - %d planets, %d credits, Tech level %d\n",i+1, player.Name, len(player.Planets), player.Credits, player.Technology)}}// Helper functionsfunc (g *Game) getTotalPopulation(player *Player) int {total := 0for _, planet := range player.Planets {total += planet.Population}return total}func (g *Game) getTotalIndustry(player *Player) int {total := 0for _, planet := range player.Planets {total += planet.Industry}return total}func (g *Game) getTotalFleetSize(player *Player) int {total := 0for _, planet := range player.Planets {total += planet.FleetSize}return total}
一气呵成,我看了代码,写的很不错,比我强😂,砸碎了饭碗,砸成粉末了...
而且游戏正常,可以玩的
不过还是替claude高兴
看到这个消息,我直接原地起跳
不再废话,赶紧去试试吧